^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #ifndef __I8254_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #define __I8254_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <kvm/iodev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) struct kvm_kpit_channel_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) u32 count; /* can be 65536 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) u16 latched_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) u8 count_latched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) u8 status_latched;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) u8 status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) u8 read_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) u8 write_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) u8 write_latch;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) u8 rw_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) u8 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) u8 bcd; /* not supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) u8 gate; /* timer start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) ktime_t count_load_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct kvm_kpit_state {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) /* All members before "struct mutex lock" are protected by the lock. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct kvm_kpit_channel_state channels[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u32 flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) bool is_periodic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) s64 period; /* unit: ns */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct hrtimer timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) u32 speaker_data_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct mutex lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) atomic_t reinject;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) atomic_t pending; /* accumulated triggered timers */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) atomic_t irq_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct kvm_irq_ack_notifier irq_ack_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct kvm_pit {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct kvm_io_device dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct kvm_io_device speaker_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct kvm *kvm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct kvm_kpit_state pit_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int irq_source_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct kvm_irq_mask_notifier mask_notifier;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct kthread_worker *worker;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) struct kthread_work expired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define KVM_PIT_BASE_ADDRESS 0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define KVM_SPEAKER_BASE_ADDRESS 0x61
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define KVM_PIT_MEM_LENGTH 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define KVM_PIT_FREQ 1193181
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define KVM_MAX_PIT_INTR_INTERVAL HZ / 100
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define KVM_PIT_CHANNEL_MASK 0x3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) void kvm_free_pit(struct kvm *kvm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) void kvm_pit_load_count(struct kvm_pit *pit, int channel, u32 val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int hpet_legacy_start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) void kvm_pit_set_reinject(struct kvm_pit *pit, bool reinject);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif