Implement APIC, RTC, basic ACPI parser and timer support
[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 } __attribute__((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     uint32_t flags;
32 } __attribute__((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     uint32_t ioapic_addr;
47     // The global system interrupt offset for this IOAPIC. (Kind of IRQ offset for a slave IOAPIC)
48     uint32_t gis_offset;
49 } __attribute__((packed)) acpi_ioapic_t;
50
51 /**
52  * @brief ACPI Interrupt Source Override (INTSO)
53  *
54  * According to the ACPI Spec, the IRQ config between APIC and 8259 PIC can be
55  * assumed to be identically mapped. However, some manufactures may have their
56  * own preference and hence expections may be introduced. This structure provide
57  * information on such exception.
58  *
59  */
60 typedef struct
61 {
62     acpi_ics_hdr_t header;
63     uint8_t bus;
64     // source, which is the original IRQ back in the era of IBM PC/AT, the 8259
65     // PIC
66     uint8_t source;
67     // global system interrupt. The override of source in APIC mode
68     uint32_t gsi;
69     uint16_t flags;
70 } __attribute__((packed)) acpi_intso_t;
71
72 typedef struct
73 {
74     acpi_sdthdr_t header;
75     void* apic_addr;
76     uint32_t flags;
77     // Here is a bunch of packed ICS reside here back-to-back.
78 } __attribute__((packed)) acpi_madt_t;
79
80 typedef struct
81 {
82     void* apic_addr;
83     acpi_apic_t* apic;
84     acpi_ioapic_t* ioapic;
85     acpi_intso_t** irq_exception;
86 } acpi_madt_toc_t;
87
88 #endif /* __LUNAIX_ACPI_MADT_H */