From da93a248114c9bb630ce4f5610fc3fd9707ae06d Mon Sep 17 00:00:00 2001 From: Fredrik Holmqvist Date: Tue, 22 Dec 2020 22:53:17 +0100 Subject: [PATCH] efi_guid struct gets equals, simplify EFI acpi_init Change-Id: Id4bc985dc1e6f44b594f6ca5dabd3fdac8e1cac2 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3545 Reviewed-by: Alex von Gluck IV --- headers/private/kernel/platform/efi/types.h | 8 ++++++++ src/system/boot/platform/efi/acpi.cpp | 22 ++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/headers/private/kernel/platform/efi/types.h b/headers/private/kernel/platform/efi/types.h index 8aec5553d5..2c1df000c9 100644 --- a/headers/private/kernel/platform/efi/types.h +++ b/headers/private/kernel/platform/efi/types.h @@ -82,6 +82,14 @@ typedef struct efi_guid { uint16_t data2; uint16_t data3; uint8_t data4[8]; + + bool equals(const efi_guid& other) const { + bool matches = data1 == other.data1 && data2 == other.data2 + && data3 == other.data3; + for (auto i = 0; matches && i < 8; i++) + matches = data4[i] == other.data4[i]; + return matches; + } } efi_guid; typedef void* efi_handle; diff --git a/src/system/boot/platform/efi/acpi.cpp b/src/system/boot/platform/efi/acpi.cpp index 3b5a45f024..1f8f5954e1 100644 --- a/src/system/boot/platform/efi/acpi.cpp +++ b/src/system/boot/platform/efi/acpi.cpp @@ -205,22 +205,16 @@ acpi_init() // Try to find the ACPI RSDP. for (uint32 i = 0; i < entries; i++) { - acpi_rsdp *rsdp = NULL; + if (!table[i].VendorGuid.equals(acpi)) + continue; - efi_guid vendor = table[i].VendorGuid; + acpi_rsdp *rsdp = (acpi_rsdp *)(table[i].VendorTable); + if (strncmp((char *)rsdp, ACPI_RSDP_SIGNATURE, 8) == 0) + TRACE(("acpi_init: found ACPI RSDP signature at %p\n", rsdp)); - if (vendor.data1 == acpi.data1 - && vendor.data2 == acpi.data2 - && vendor.data3 == acpi.data3 - && strncmp((char *)vendor.data4, (char *)acpi.data4, 8) == 0) { - rsdp = (acpi_rsdp *)(table[i].VendorTable); - if (strncmp((char *)rsdp, ACPI_RSDP_SIGNATURE, 8) == 0) - TRACE(("acpi_init: found ACPI RSDP signature at %p\n", rsdp)); - - if (rsdp != NULL && acpi_check_rsdt(rsdp) == B_OK) { - gKernelArgs.arch_args.acpi_root = rsdp; - break; - } + if (rsdp != NULL && acpi_check_rsdt(rsdp) == B_OK) { + gKernelArgs.arch_args.acpi_root = rsdp; + break; } } }