2
0

interrupt.rs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. use alloc::vec::Vec;
  2. #[derive(Debug)]
  3. pub struct IoApic {
  4. pub id: u8,
  5. /// The physical address at which to access this I/O APIC.
  6. pub address: u32,
  7. /// The global system interrupt number where this I/O APIC's inputs start.
  8. pub global_system_interrupt_base: u32,
  9. }
  10. #[derive(Debug)]
  11. pub struct NmiLine {
  12. pub processor: NmiProcessor,
  13. pub line: LocalInterruptLine,
  14. }
  15. /// Indicates which local interrupt line will be utilized by an external interrupt. Specifically,
  16. /// these lines directly correspond to their requisite LVT entries in a processor's APIC.
  17. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  18. pub enum LocalInterruptLine {
  19. Lint0,
  20. Lint1,
  21. }
  22. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  23. pub enum NmiProcessor {
  24. All,
  25. ProcessorUid(u32),
  26. }
  27. /// Polarity indicates what signal mode the interrupt line needs to be in to be considered 'active'.
  28. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  29. pub enum Polarity {
  30. SameAsBus,
  31. ActiveHigh,
  32. ActiveLow,
  33. }
  34. /// Trigger mode of an interrupt, describing how the interrupt is triggered.
  35. ///
  36. /// When an interrupt is `Edge` triggered, it is triggered exactly once, when the interrupt
  37. /// signal goes from its opposite polarity to its active polarity.
  38. ///
  39. /// For `Level` triggered interrupts, a continuous signal is emitted so long as the interrupt
  40. /// is in its active polarity.
  41. ///
  42. /// `SameAsBus`-triggered interrupts will utilize the same interrupt triggering as the system bus
  43. /// they communicate across.
  44. #[derive(Debug, Clone, Copy, PartialEq, Eq)]
  45. pub enum TriggerMode {
  46. SameAsBus,
  47. Edge,
  48. Level,
  49. }
  50. /// Describes a difference in the mapping of an ISA interrupt to how it's mapped in other interrupt
  51. /// models. For example, if a device is connected to ISA IRQ 0 and IOAPIC input 2, an override will
  52. /// appear mapping source 0 to GSI 2. Currently these will only be created for ISA interrupt
  53. /// sources.
  54. #[derive(Debug)]
  55. pub struct InterruptSourceOverride {
  56. pub isa_source: u8,
  57. pub global_system_interrupt: u32,
  58. pub polarity: Polarity,
  59. pub trigger_mode: TriggerMode,
  60. }
  61. /// Describes a Global System Interrupt that should be enabled as non-maskable. Any source that is
  62. /// non-maskable can not be used by devices.
  63. #[derive(Debug)]
  64. pub struct NmiSource {
  65. pub global_system_interrupt: u32,
  66. pub polarity: Polarity,
  67. pub trigger_mode: TriggerMode,
  68. }
  69. #[derive(Debug)]
  70. pub struct Apic {
  71. pub local_apic_address: u64,
  72. pub io_apics: Vec<IoApic>,
  73. pub local_apic_nmi_lines: Vec<NmiLine>,
  74. pub interrupt_source_overrides: Vec<InterruptSourceOverride>,
  75. pub nmi_sources: Vec<NmiSource>,
  76. /// If this field is set, you must remap and mask all the lines of the legacy PIC, even if
  77. /// you choose to use the APIC. It's recommended that you do this even if ACPI does not
  78. /// require you to.
  79. pub also_has_legacy_pics: bool,
  80. }
  81. #[derive(Debug)]
  82. #[non_exhaustive]
  83. pub enum InterruptModel {
  84. /// This model is only chosen when the MADT does not describe another interrupt model. On `x86_64` platforms,
  85. /// this probably means only the legacy i8259 PIC is present.
  86. Unknown,
  87. /// Describes an interrupt controller based around the Advanced Programmable Interrupt Controller (any of APIC,
  88. /// XAPIC, or X2APIC). These are likely to be found on x86 and x86_64 systems and are made up of a Local APIC
  89. /// for each core and one or more I/O APICs to handle external interrupts.
  90. Apic(Apic),
  91. }