:: commit 4e55d2877783c935434ce9fa634d3a4d83d06997

mintsuki <mintsuki@protonmail.com> — 2021-03-07 02:57

parents: d96bdf775b

acpi: Implement UEFI version of acpi_get_rsdp()

diff --git a/stage23/lib/acpi.c b/stage23/lib/acpi.c
index bd18f5a6..2f9ddb8d 100644
--- a/stage23/lib/acpi.c
+++ b/stage23/lib/acpi.c
@@ -6,7 +6,7 @@
 #include <lib/libc.h>
 #include <lib/print.h>
 
-// Following function based on https://github.com/qword-os/lai/blob/master/helpers/pc-bios.c's function lai_bios_calc_checksum()
+// Following function based on https://github.com/managarm/lai/blob/master/helpers/pc-bios.c's function lai_bios_calc_checksum()
 uint8_t acpi_checksum(void *ptr, size_t size) {
     uint8_t sum = 0, *_ptr = ptr;
     for (size_t i = 0; i < size; i++)
@@ -14,6 +14,8 @@ uint8_t acpi_checksum(void *ptr, size_t size) {
     return sum;
 }
 
+#if defined (bios)
+
 void *acpi_get_rsdp(void) {
     size_t ebda = EBDA;
 
@@ -32,6 +34,33 @@ void *acpi_get_rsdp(void) {
     return NULL;
 }
 
+#endif
+
+#if defined (uefi)
+
+#include <efi.h>
+
+void *acpi_get_rsdp(void) {
+    for (size_t i = 0; i < gST->NumberOfTableEntries; i++) {
+        EFI_CONFIGURATION_TABLE *cur_table = &gST->ConfigurationTable[i];
+        EFI_GUID acpi_2_guid = ACPI_20_TABLE_GUID;
+
+        if (memcmp(&cur_table->VendorGuid, &acpi_2_guid, sizeof(EFI_GUID)) != 0)
+            continue;
+
+        if (acpi_checksum(cur_table->VendorTable, sizeof(struct rsdp)) != 0)
+            continue;
+
+        print("acpi: Found RSDP at %X\n", cur_table->VendorTable);
+
+        return (void *)cur_table->VendorTable;
+    }
+
+    return NULL;
+}
+
+#endif
+
 void *acpi_get_table(const char *signature, int index) {
     int cnt = 0;
 
tab: 248 wrap: offon