diff --git a/src/platform/acpi.cpp b/src/platform/acpi.cpp index d2ccf6a..36589aa 100644 --- a/src/platform/acpi.cpp +++ b/src/platform/acpi.cpp @@ -10,6 +10,60 @@ Mutex ACPI::controllerMutex; volatile ACPI* ACPI::controller = nullptr; +enum LAPIC_VALUES { + LAPIC_DISABLE = 0x10000, + LAPIC_SW_ENABLE = 0x100, + LAPIC_CPUFOCUS = 0x200, + LAPIC_NMI = (4 << 8), + TMR_PERIODIC = 0x20000, + TMR_BASEDIV = (1 << 20), +}; + +enum IOAPIC_FIELDS { + IOAPIC_REGSEL = 0x0, IOAPIC_REGWIN = 0x10, +}; + +enum IOAPIC_REGS { + IOAPIC_ID = 0x0, IOAPIC_VER = 0x1, IOAPIC_REDTBL = 0x10, +}; + +struct ACPI::Header { + uint32_t signature; + uint32_t length; + uint8_t revision; + uint8_t checksum; + uint8_t oem[6]; + uint8_t oemTableId[8]; + uint32_t oemRevision; + uint32_t creatorId; + uint32_t creatorRevision; +}; +struct ACPI::Madt : Header { + uint32_t localApicAddr; + uint32_t flags; +}; +struct ACPI::ApicHeader { + uint8_t type; + uint8_t length; +}; +struct ACPI::ApicLocalApic : ApicHeader { + uint8_t acpiProcessorId; + uint8_t apicId; + uint32_t flags; +}; +struct ACPI::ApicIoApic : ApicHeader { + uint8_t ioApicId; + uint8_t reserved; + uint32_t ioApicAddress; + uint32_t globalSystemInterruptBase; +}; +struct ACPI::ApicInterruptOverride : ApicHeader { + uint8_t bus; + uint8_t source; + uint32_t interrupt; + uint16_t flags; +}; + ACPI* ACPI::getController() { if (controller) return const_cast(controller); Mutex::CriticalLock lock(controllerMutex); @@ -132,7 +186,7 @@ void ACPI::ParseApic(const Madt *madt) { Pagetable::map(localApicAddr); const uint8_t *p = reinterpret_cast(madt + 1); - const uint8_t *end = p + (madt->header.length - sizeof(Madt)); + const uint8_t *end = p + (madt->Header::length - sizeof(Madt)); while (p < end) { const ApicHeader *header = reinterpret_cast(p); @@ -141,15 +195,14 @@ void ACPI::ParseApic(const Madt *madt) { uint16_t type = header->type; uint16_t length = header->length; if (type == 0) { - const ApicLocalApic *s = reinterpret_cast(p); + const ApicLocalApic *s = reinterpret_cast(header); acpiCpuIds[acpiCpuCount++] = s->apicId; } else if (type == 1) { - const ApicIoApic *s = reinterpret_cast(p); + const ApicIoApic *s = reinterpret_cast(header); ioApicAddr = reinterpret_cast(uintptr_t(s->ioApicAddress)); Pagetable::map(ioApicAddr); } else if (type == 2) { - const ApicInterruptOverride *s = - reinterpret_cast(p); + const ApicInterruptOverride *s = reinterpret_cast(header); (void)s; // TODO: handle interrupt overrides } diff --git a/src/platform/include/acpi.hpp b/src/platform/include/acpi.hpp index 5185ee2..159af28 100644 --- a/src/platform/include/acpi.hpp +++ b/src/platform/include/acpi.hpp @@ -27,66 +27,6 @@ class ACPI { LAPIC_TMRDIV = 0x3E0, LAPIC_LAST = 0x38F, }; - - private: - enum LAPIC_VALUES { - LAPIC_DISABLE = 0x10000, - LAPIC_SW_ENABLE = 0x100, - LAPIC_CPUFOCUS = 0x200, - LAPIC_NMI = (4 << 8), - TMR_PERIODIC = 0x20000, - TMR_BASEDIV = (1 << 20), - }; - - enum IOAPIC_FIELDS { - IOAPIC_REGSEL = 0x0, IOAPIC_REGWIN = 0x10, - }; - - enum IOAPIC_REGS { - IOAPIC_ID = 0x0, IOAPIC_VER = 0x1, IOAPIC_REDTBL = 0x10, - }; - - struct Header { - uint32_t signature; - uint32_t length; - uint8_t revision; - uint8_t checksum; - uint8_t oem[6]; - uint8_t oemTableId[8]; - uint32_t oemRevision; - uint32_t creatorId; - uint32_t creatorRevision; - }; - struct Madt { - Header header; - uint32_t localApicAddr; - uint32_t flags; - }; - struct ApicHeader { - uint8_t type; - uint8_t length; - }; - struct ApicLocalApic { - ApicHeader header; - uint8_t acpiProcessorId; - uint8_t apicId; - uint32_t flags; - }; - struct ApicIoApic { - ApicHeader header; - uint8_t ioApicId; - uint8_t reserved; - uint32_t ioApicAddress; - uint32_t globalSystemInterruptBase; - }; - struct ApicInterruptOverride { - ApicHeader header; - uint8_t bus; - uint8_t source; - uint32_t interrupt; - uint16_t flags; - }; - union IOApicRedir { struct { uint8_t vector :8; @@ -104,6 +44,13 @@ class ACPI { }; private: + struct Header; + struct Madt; + struct ApicHeader; + struct ApicLocalApic; + struct ApicIoApic; + struct ApicInterruptOverride; + static Mutex controllerMutex; static volatile ACPI *controller;