1dd0bca4015c61c5c7f0774fc25da0a15c4622b0
[lunaix-os.git] / lunaix-os / includes / hal / acpi / madt.h
1 #ifndef __LUNAIX_ACPI_MADT_H
2 #define __LUNAIX_ACPI_MADT_H
3
4 #include "sdt.h"
5
6 #define ACPI_MADT_LAPIC 0x0  // Local APIC
7 #define ACPI_MADT_IOAPIC 0x1 // I/O APIC
8 #define ACPI_MADT_INTSO 0x2  // Interrupt Source Override
9
10 /**
11  * @brief ACPI Interrupt Controller Structure (ICS) Header
12  *
13  */
14 typedef struct
15 {
16     uint8_t type;
17     uint8_t length;
18 } ACPI_TABLE_PACKED acpi_ics_hdr_t;
19
20 /**
21  * @brief ACPI Processor Local APIC Structure (PLAS)
22  * This structure tell information about our Local APIC per processor. Including
23  * the MMIO addr.
24  *
25  */
26 typedef struct
27 {
28     acpi_ics_hdr_t header;
29     uint8_t processor_id;
30     uint8_t apic_id;
31     u32_t flags;
32 } ACPI_TABLE_PACKED acpi_apic_t;
33
34 /**
35  * @brief ACPI IO APIC Structure (IOAS)
36  *
37  * This structure tell information about our I/O APIC on motherboard. Including
38  * the MMIO addr.
39  *
40  */
41 typedef struct
42 {
43     acpi_ics_hdr_t header;
44     uint8_t ioapic_id;
45     uint8_t reserved;
46     u32_t ioapic_addr;
47     // The global system interrupt offset for this IOAPIC. (Kind of IRQ offset
48     // for a slave IOAPIC)
49     u32_t gis_offset;
50 } ACPI_TABLE_PACKED acpi_ioapic_t;
51
52 /**
53  * @brief ACPI Interrupt Source Override (INTSO)
54  *
55  * According to the ACPI Spec, the IRQ config between APIC and 8259 PIC can be
56  * assumed to be identically mapped. However, some manufactures may have their
57  * own preference and hence expections may be introduced. This structure provide
58  * information on such exception.
59  *
60  */
61 typedef struct
62 {
63     acpi_ics_hdr_t header;
64     uint8_t bus;
65     // source, which is the original IRQ back in the era of IBM PC/AT, the 8259
66     // PIC
67     uint8_t source;
68     // global system interrupt. The override of source in APIC mode
69     u32_t gsi;
70     uint16_t flags;
71 } ACPI_TABLE_PACKED acpi_intso_t;
72
73 typedef struct
74 {
75     acpi_sdthdr_t header;
76     void* apic_addr;
77     u32_t flags;
78     // Here is a bunch of packed ICS reside here back-to-back.
79 } ACPI_TABLE_PACKED acpi_madt_t;
80
81 typedef struct
82 {
83     void* apic_addr;
84     acpi_apic_t* apic;
85     acpi_ioapic_t* ioapic;
86     acpi_intso_t** irq_exception;
87 } ACPI_TABLE_PACKED acpi_madt_toc_t;
88
89 #endif /* __LUNAIX_ACPI_MADT_H */