i8254.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __I8254_H
  2. #define __I8254_H
  3. #include "iodev.h"
  4. struct kvm_kpit_timer {
  5. struct hrtimer timer;
  6. int irq;
  7. s64 period; /* unit: ns */
  8. s64 scheduled;
  9. ktime_t last_update;
  10. atomic_t pending;
  11. };
  12. struct kvm_kpit_channel_state {
  13. u32 count; /* can be 65536 */
  14. u16 latched_count;
  15. u8 count_latched;
  16. u8 status_latched;
  17. u8 status;
  18. u8 read_state;
  19. u8 write_state;
  20. u8 write_latch;
  21. u8 rw_mode;
  22. u8 mode;
  23. u8 bcd; /* not supported */
  24. u8 gate; /* timer start */
  25. ktime_t count_load_time;
  26. };
  27. struct kvm_kpit_state {
  28. struct kvm_kpit_channel_state channels[3];
  29. struct kvm_kpit_timer pit_timer;
  30. u32 speaker_data_on;
  31. struct mutex lock;
  32. struct kvm_pit *pit;
  33. bool inject_pending; /* if inject pending interrupts */
  34. unsigned long last_injected_time;
  35. };
  36. struct kvm_pit {
  37. unsigned long base_addresss;
  38. struct kvm_io_device dev;
  39. struct kvm_io_device speaker_dev;
  40. struct kvm *kvm;
  41. struct kvm_kpit_state pit_state;
  42. };
  43. #define KVM_PIT_BASE_ADDRESS 0x40
  44. #define KVM_SPEAKER_BASE_ADDRESS 0x61
  45. #define KVM_PIT_MEM_LENGTH 4
  46. #define KVM_PIT_FREQ 1193181
  47. #define KVM_MAX_PIT_INTR_INTERVAL HZ / 100
  48. #define KVM_PIT_CHANNEL_MASK 0x3
  49. void kvm_inject_pit_timer_irqs(struct kvm_vcpu *vcpu);
  50. void kvm_pit_timer_intr_post(struct kvm_vcpu *vcpu, int vec);
  51. void kvm_pit_load_count(struct kvm *kvm, int channel, u32 val);
  52. struct kvm_pit *kvm_create_pit(struct kvm *kvm);
  53. void kvm_free_pit(struct kvm *kvm);
  54. void kvm_pit_reset(struct kvm_pit *pit);
  55. #endif