acpi: cleanup smbios lookup to use actual smbios structs
Signed-off-by: Andy-Python-Programmer <andypythonappdeveloper@gmail.com>
diff --git a/stage23/lib/acpi.c b/stage23/lib/acpi.c
index 5f02cc91..df7a4eef 100644
--- a/stage23/lib/acpi.c
+++ b/stage23/lib/acpi.c
@@ -54,19 +54,23 @@ void acpi_get_smbios(void **smbios32, void **smbios64) {
*smbios64 = NULL;
for (size_t i = 0xf0000; i < 0x100000; i += 16) {
- if (!memcmp((char *)i, "_SM_", 4)
- && !acpi_checksum((void *)i, *((uint8_t *)(i + 5)))) {
+ struct smbios_entry_point_32 *ptr = (struct smbios_entry_point_32 *)i;
+
+ if (!memcmp(ptr->anchor_str, "_SM_", 4) &&
+ !acpi_checksum((void *)ptr, ptr->length)) {
printv("acpi: Found SMBIOS 32-bit entry point at %x\n", i);
- *smbios32 = (void *)i;
+ *smbios32 = (void *)ptr;
break;
}
}
for (size_t i = 0xf0000; i < 0x100000; i += 16) {
- if (!memcmp((char *)i, "_SM3_", 5)
- && !acpi_checksum((void *)i, *((uint8_t *)(i + 6)))) {
+ struct smbios_entry_point_64 *ptr = (struct smbios_entry_point_64 *)i;
+
+ if (!memcmp(ptr->anchor_str, "_SM3_", 5) &&
+ !acpi_checksum((void *)ptr, ptr->length)) {
printv("acpi: Found SMBIOS 64-bit entry point at %x\n", i);
- *smbios64 = (void *)i;
+ *smbios64 = (void *)ptr;
break;
}
}
@@ -150,13 +154,14 @@ void acpi_get_smbios(void **smbios32, void **smbios64) {
if (memcmp(&cur_table->VendorGuid, &smbios_guid, sizeof(EFI_GUID)) != 0)
continue;
- if (acpi_checksum(cur_table->VendorTable,
- *((uint8_t *)(cur_table->VendorTable + 5))) != 0)
+ struct smbios_entry_point_32 *ptr = (struct smbios_entry_point_32 *)cur_table->VendorTable;
+
+ if (acpi_checksum((void *)ptr, ptr->length) != 0)
continue;
- printv("acpi: Found SMBIOS 32-bit entry point at %X\n", cur_table->VendorTable);
+ printv("acpi: Found SMBIOS 32-bit entry point at %X\n", ptr);
- *smbios32 = cur_table->VendorTable;
+ *smbios32 = (void *)ptr;
break;
}
@@ -168,13 +173,14 @@ void acpi_get_smbios(void **smbios32, void **smbios64) {
if (memcmp(&cur_table->VendorGuid, &smbios3_guid, sizeof(EFI_GUID)) != 0)
continue;
- if (acpi_checksum(cur_table->VendorTable,
- *((uint8_t *)(cur_table->VendorTable + 6))) != 0)
+ struct smbios_entry_point_64 *ptr = (struct smbios_entry_point_64 *)cur_table->VendorTable;
+
+ if (acpi_checksum((void *)ptr, ptr->length) != 0)
continue;
- printv("acpi: Found SMBIOS 64-bit entry point at %X\n", cur_table->VendorTable);
+ printv("acpi: Found SMBIOS 64-bit entry point at %X\n", ptr);
- *smbios64 = cur_table->VendorTable;
+ *smbios64 = (void *)ptr;
break;
}
diff --git a/stage23/lib/acpi.h b/stage23/lib/acpi.h
index 0638344f..5686b186 100644
--- a/stage23/lib/acpi.h
+++ b/stage23/lib/acpi.h
@@ -24,7 +24,7 @@ struct rsdp {
char oem_id[6];
uint8_t rev;
uint32_t rsdt_addr;
- // Rev 2 only after this comment
+ // Revision 2 only after this comment
uint32_t length;
uint64_t xsdt_addr;
uint8_t ext_checksum;
@@ -36,6 +36,59 @@ struct rsdt {
char ptrs_start[];
} __attribute__((packed));
+struct smbios_entry_point_32 {
+ char anchor_str[4];
+ /// This value summed with all the values of the table.
+ uint8_t checksum;
+ /// Length of the entry point table.
+ uint8_t length;
+ /// Major version of SMBIOS.
+ uint8_t major_version;
+ /// Minor version of SMBIOS.
+ uint8_t minor_version;
+ /// Size of the largest SMBIOS structure, in bytes, and encompasses the
+ /// structureâs formatted area and text strings
+ uint16_t max_structure_size;
+ uint8_t entry_point_revision;
+ char formatted_area[5];
+
+ char intermediate_anchor_str[5];
+ /// Checksum for values from intermediate anchor str to the
+ /// end of table.
+ uint8_t intermediate_checksum;
+ /// Total length of SMBIOS Structure Table, pointed to by the structure
+ /// table address, in bytes.
+ uint16_t table_length;
+ /// 32-bit physical starting address of the read-only SMBIOS Structure
+ /// Table.
+ uint32_t table_address;
+ /// Total number of structures present in the SMBIOS Structure Table.
+ uint16_t number_of_structures;
+ /// Indicates compliance with a revision of this specification.
+ uint8_t bcd_revision;
+} __attribute__((packed));
+
+struct smbios_entry_point_64 {
+ char anchor_str[5];
+ /// This value summed with all the values of the table.
+ uint8_t checksum;
+ /// Length of the entry point table.
+ uint8_t length;
+ /// Major version of SMBIOS.
+ uint8_t major_version;
+ /// Minor version of SMBIOS.
+ uint8_t minor_version;
+ uint8_t docrev;
+ uint8_t entry_point_revision;
+ uint8_t reserved;
+ /// Size of the largest SMBIOS structure, in bytes, and encompasses the
+ /// structureâs formatted area and text strings
+ uint16_t max_structure_size;
+ /// 64-bit physical starting address of the read-only SMBIOS Structure
+ /// Table.
+ uint64_t table_address;
+} __attribute__((packed));
+
uint8_t acpi_checksum(void *ptr, size_t size);
void *acpi_get_rsdp(void);
