feature (acpi): implemented acpi table lookup

This commit is contained in:
antifallobst 2023-03-22 00:03:06 +01:00
parent 148dfe5a62
commit ed977586a5
2 changed files with 34 additions and 1 deletions

View File

@ -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

View File

@ -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, "<ACPI> RSDP header verification failed");
}
acpi_find_table(((rsdp_descriptor_v2_T*)boot_info->rsdp)->xsdt_address, "FACP");
break;
}
default: {
@ -28,3 +32,18 @@ void acpi_init(boot_info_T* boot_info) {
}
}
}
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, "<ACPI> table '%.4' not found (no matching xsdt entry)");
return NULL;
}