Fix naming

This commit is contained in:
apio 2022-09-25 21:43:28 +02:00
parent f1a7138568
commit 07d6fe388d
6 changed files with 28 additions and 36 deletions

View File

@ -6,20 +6,20 @@ namespace ACPI
struct XSDT struct XSDT
{ {
SDTHeader header; SDTHeader header;
uint64_t PointerToOtherSDT[1]; uint64_t other_sdt[1];
}; };
struct RSDT struct RSDT
{ {
SDTHeader header; SDTHeader header;
uint32_t PointerToOtherSDT[1]; uint32_t other_sdt[1];
}; };
SDTHeader* GetRSDTOrXSDT(); SDTHeader* get_rsdt_or_xsdt();
bool ValidateRSDTOrXSDT(SDTHeader* rootSDT); bool validate_rsdt_or_xsdt(SDTHeader* root_sdt);
bool IsXSDT(); bool is_xsdt();
void* FindTable(SDTHeader* rootSDT, const char* signature); void* find_table(SDTHeader* root_sdt, const char* signature);
} }

View File

@ -16,5 +16,5 @@ namespace ACPI
uint32_t CreatorRevision; uint32_t CreatorRevision;
}; };
bool ValidateSDTHeader(SDTHeader* header); bool validate_sdt_header(SDTHeader* header);
} }

View File

@ -9,7 +9,7 @@
extern BOOTBOOT bootboot; extern BOOTBOOT bootboot;
ACPI::SDTHeader* ACPI::GetRSDTOrXSDT() ACPI::SDTHeader* ACPI::get_rsdt_or_xsdt()
{ {
static void* cache = nullptr; static void* cache = nullptr;
if (cache) return (SDTHeader*)cache; if (cache) return (SDTHeader*)cache;
@ -28,42 +28,34 @@ ACPI::SDTHeader* ACPI::GetRSDTOrXSDT()
} }
kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, numPages); kdbgln("Mapped RSDT/XSDT to virtual address %lx, uses %ld pages", (uint64_t)cache, numPages);
SDTHeader* result = (SDTHeader*)cache; SDTHeader* result = (SDTHeader*)cache;
char OEMID[7];
memcpy(OEMID, result->OEMID, 6);
OEMID[6] = 0;
kdbgln("OEMID: %s", OEMID);
char OEMTableID[9];
memcpy(OEMTableID, result->OEMTableID, 8);
OEMTableID[8] = 0;
kdbgln("OEMTableID: %s", OEMTableID);
return result; return result;
} }
bool ACPI::ValidateRSDTOrXSDT(ACPI::SDTHeader* rootSDT) bool ACPI::validate_rsdt_or_xsdt(ACPI::SDTHeader* root_sdt)
{ {
if (!ValidateSDTHeader(rootSDT)) return false; if (!validate_sdt_header(root_sdt)) return false;
if (strncmp(rootSDT->Signature, "XSDT", 4) == 0) return true; if (strncmp(root_sdt->Signature, "XSDT", 4) == 0) return true;
if (strncmp(rootSDT->Signature, "RSDT", 4) == 0) return true; if (strncmp(root_sdt->Signature, "RSDT", 4) == 0) return true;
return false; return false;
} }
bool ACPI::IsXSDT() bool ACPI::is_xsdt()
{ {
static bool cached = false; static bool cached = false;
static bool cache = false; static bool cache = false;
if (cached) return cache; if (cached) return cache;
SDTHeader* rootSDT = GetRSDTOrXSDT(); SDTHeader* rootSDT = get_rsdt_or_xsdt();
cache = (strncmp(rootSDT->Signature, "XSDT", 4) == 0); cache = (strncmp(rootSDT->Signature, "XSDT", 4) == 0);
cached = true; cached = true;
return cache; return cache;
} }
void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature) void* ACPI::find_table(ACPI::SDTHeader* root_sdt, const char* signature)
{ {
bool isXSDT = IsXSDT(); bool isXSDT = is_xsdt();
int entries = (rootSDT->Length - sizeof(SDTHeader)) / (isXSDT ? 8 : 4); int entries = (root_sdt->Length - sizeof(SDTHeader)) / (isXSDT ? 8 : 4);
kdbgln("Searching for table %s in the %s at %lx (table contains %d entries)", signature, isXSDT ? "XSDT" : "RSDT", kdbgln("Searching for table %s in the %s at %lx (table contains %d entries)", signature, isXSDT ? "XSDT" : "RSDT",
(uint64_t)rootSDT, entries); (uint64_t)root_sdt, entries);
for (int i = 0; i < entries; i++) for (int i = 0; i < entries; i++)
{ {
@ -71,13 +63,13 @@ void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature)
SDTHeader* h; SDTHeader* h;
if (isXSDT) if (isXSDT)
{ {
uint64_t reversedAddress = (uint64_t)((XSDT*)rootSDT)->PointerToOtherSDT[i]; uint64_t reversedAddress = (uint64_t)((XSDT*)root_sdt)->other_sdt[i];
uint64_t correctAddress = reversedAddress >> 32 | reversedAddress << 32; uint64_t correctAddress = reversedAddress >> 32 | reversedAddress << 32;
h = (SDTHeader*)correctAddress; h = (SDTHeader*)correctAddress;
} }
else else
{ {
uint32_t entry = ((RSDT*)rootSDT)->PointerToOtherSDT[i]; uint32_t entry = ((RSDT*)root_sdt)->other_sdt[i];
h = (SDTHeader*)(uint64_t)entry; h = (SDTHeader*)(uint64_t)entry;
} }
if (!h) if (!h)
@ -88,7 +80,7 @@ void* ACPI::FindTable(ACPI::SDTHeader* rootSDT, const char* signature)
kdbgln("Physical address of entry: %lx", (uint64_t)h); kdbgln("Physical address of entry: %lx", (uint64_t)h);
SDTHeader* realHeader = (SDTHeader*)MemoryManager::get_unaligned_mapping(h); SDTHeader* realHeader = (SDTHeader*)MemoryManager::get_unaligned_mapping(h);
kdbgln("Mapped entry to virtual address %lx", (uint64_t)realHeader); kdbgln("Mapped entry to virtual address %lx", (uint64_t)realHeader);
if (!ValidateSDTHeader(realHeader)) if (!validate_sdt_header(realHeader))
{ {
kwarnln("Header of entry %d is not valid, skipping this entry", i); kwarnln("Header of entry %d is not valid, skipping this entry", i);
MemoryManager::release_unaligned_mapping(realHeader); MemoryManager::release_unaligned_mapping(realHeader);

View File

@ -1,6 +1,6 @@
#include "acpi/SDT.h" #include "acpi/SDT.h"
bool ACPI::ValidateSDTHeader(ACPI::SDTHeader* header) bool ACPI::validate_sdt_header(ACPI::SDTHeader* header)
{ {
uint8_t sum = 0; uint8_t sum = 0;

View File

@ -132,9 +132,9 @@ extern "C" void _start()
kinfoln("Prepared scheduler tasks"); kinfoln("Prepared scheduler tasks");
ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT(); ACPI::SDTHeader* rootSDT = ACPI::get_rsdt_or_xsdt();
bool isXSDT = ACPI::IsXSDT(); bool isXSDT = ACPI::is_xsdt();
if (!ACPI::ValidateRSDTOrXSDT(rootSDT)) kerrorln("Invalid %s", isXSDT ? "XSDT" : "RSDT"); if (!ACPI::validate_rsdt_or_xsdt(rootSDT)) kerrorln("Invalid %s", isXSDT ? "XSDT" : "RSDT");
framebuffer0.clear(Color::Cyan); framebuffer0.clear(Color::Cyan);

View File

@ -14,19 +14,19 @@
static void try_acpi_reboot() static void try_acpi_reboot()
{ {
kdbgln("Fetching pointer to RSDT/XSDT"); kdbgln("Fetching pointer to RSDT/XSDT");
ACPI::SDTHeader* rootSDT = ACPI::GetRSDTOrXSDT(); ACPI::SDTHeader* rootSDT = ACPI::get_rsdt_or_xsdt();
if (!rootSDT) if (!rootSDT)
{ {
kwarnln("The pointer to the RSDT/XSDT is null"); kwarnln("The pointer to the RSDT/XSDT is null");
return; return;
} }
if (!ACPI::ValidateRSDTOrXSDT(rootSDT)) if (!ACPI::validate_rsdt_or_xsdt(rootSDT))
{ {
kwarnln("The RSDT/XSDT is invalid"); kwarnln("The RSDT/XSDT is invalid");
return; return;
} }
kdbgln("Searching for the FADT"); kdbgln("Searching for the FADT");
ACPI::FADT* fadt = (ACPI::FADT*)ACPI::FindTable(rootSDT, "FACP"); ACPI::FADT* fadt = (ACPI::FADT*)ACPI::find_table(rootSDT, "FACP");
if (!fadt) if (!fadt)
{ {
kwarnln("Unable to find the FADT"); kwarnln("Unable to find the FADT");