diff --git a/kernel/inc/drivers/acpi/acpi.h b/kernel/inc/drivers/acpi/acpi.h index 69bb53b..84f6ff5 100644 --- a/kernel/inc/drivers/acpi/acpi.h +++ b/kernel/inc/drivers/acpi/acpi.h @@ -4,7 +4,21 @@ #define NOX_ACPI_H #include "boot/boot_info.h" +#include "utils/string.h" -void acpi_init(boot_info_T* boot_info); +typedef struct { + char signature [4]; + uint32_t length; + uint8_t revision; + uint8_t checksum; + char oem_id [6]; + char oem_table_id [8]; + uint32_t oem_revision; + uint32_t creator_id; + uint32_t creator_revision; +} __attribute__((packed)) acpi_sdt_header_T; + +void acpi_init (boot_info_T* boot_info); +acpi_sdt_header_T* acpi_find_table (acpi_sdt_header_T* xsdt, string_t table_id); #endif //NOX_ACPI_H diff --git a/kernel/src/drivers/acpi/acpi.c b/kernel/src/drivers/acpi/acpi.c index a5b2a3e..8b206f1 100644 --- a/kernel/src/drivers/acpi/acpi.c +++ b/kernel/src/drivers/acpi/acpi.c @@ -3,10 +3,12 @@ #include "drivers/acpi/acpi.h" #include "drivers/acpi/rsdp.h" #include "utils/logger.h" +#include "utils/memory.h" void acpi_init(boot_info_T* boot_info) { log(LOG_INFO, "Initializing ACPI - RSDP: 0x%x", boot_info->rsdp); rsdp_descriptor_v1_T* rsdp = boot_info->rsdp; + switch (rsdp->revision) { case 0: { log(LOG_INFO, " Version: 1.0"); @@ -20,6 +22,8 @@ void acpi_init(boot_info_T* boot_info) { if (!rsdp_descriptor_v2_verify(boot_info->rsdp)) { log(LOG_WARNING, " RSDP header verification failed"); } + + acpi_find_table(((rsdp_descriptor_v2_T*)boot_info->rsdp)->xsdt_address, "FACP"); break; } default: { @@ -27,4 +31,19 @@ void acpi_init(boot_info_T* boot_info) { break; } } +} + +acpi_sdt_header_T* acpi_find_table(acpi_sdt_header_T* xsdt, string_t table_id) { + uint32_t num_entries = (xsdt->length - sizeof(acpi_sdt_header_T)) / 8; + + uint64_t* sdt_list = (uint64_t*)&xsdt[1]; + + for (int i = 0; i < num_entries; i++) { + acpi_sdt_header_T* sdt = (acpi_sdt_header_T*)(sdt_list[i]); + if (!memory_compare(sdt->signature, (void*)table_id, 4)) continue; + return sdt; + } + + log(LOG_WARNING, " table '%.4' not found (no matching xsdt entry)"); + return NULL; } \ No newline at end of file