From 14b039b24f7f83f228e103e578a0db9fcc17bc0a Mon Sep 17 00:00:00 2001 From: Undefine Date: Tue, 20 Oct 2026 17:43:22 +0200 Subject: [PATCH] Kernel+LibACPI: Move table validation code to LibACPI It will be used outside of the kernel. While at it clean the function up a bit to make it a little more readable. --- Kernel/CMakeLists.txt | 5 +++++ Kernel/Firmware/ACPI/Parser.cpp | 16 ++-------------- Userland/Libraries/LibACPI/CMakeLists.txt | 4 ++++ Userland/Libraries/LibACPI/Table.cpp | 23 +++++++++++++++++++++++ Userland/Libraries/LibACPI/Table.h | 15 +++++++++++++++ 5 files changed, 49 insertions(+), 14 deletions(-) create mode 100644 Userland/Libraries/LibACPI/CMakeLists.txt create mode 100644 Userland/Libraries/LibACPI/Table.cpp create mode 100644 Userland/Libraries/LibACPI/Table.h diff --git a/Kernel/CMakeLists.txt b/Kernel/CMakeLists.txt index 23dc9fc57c4..7bd99ad70fe 100644 --- a/Kernel/CMakeLists.txt +++ b/Kernel/CMakeLists.txt @@ -637,6 +637,10 @@ set(AK_SOURCES ../AK/UUID.cpp ) +set(ACPI_SOURCES + ../Userland/Libraries/LibACPI/Table.cpp +) + set(DT_SOURCES ../Userland/Libraries/LibDeviceTree/DeviceTree.cpp ../Userland/Libraries/LibDeviceTree/FlattenedDeviceTree.cpp @@ -840,6 +844,7 @@ set(SOURCES ${KERNEL_SOURCES} ${GENERATED_SOURCES} ${AK_SOURCES} + ${ACPI_SOURCES} ${DT_SOURCES} ${EDID_SOURCES} ${ELF_SOURCES} diff --git a/Kernel/Firmware/ACPI/Parser.cpp b/Kernel/Firmware/ACPI/Parser.cpp index bdc6ead12a5..ca327c1d841 100644 --- a/Kernel/Firmware/ACPI/Parser.cpp +++ b/Kernel/Firmware/ACPI/Parser.cpp @@ -21,6 +21,7 @@ #include #include #include +#include namespace Kernel::ACPI { @@ -120,8 +121,6 @@ void Parser::enumerate_static_tables(Function(m_main_system_description_table, length).release_value_but_fixme_should_propagate_errors(); - dmesgln("ACPI: Main Description Table valid? {}", validate_table(*sdt, length)); + dmesgln("ACPI: Main Description Table valid? {}", ::ACPI::validate_table(*sdt)); if (m_xsdt_supported) { auto& xsdt = (::ACPI::Structures::XSDT const&)*sdt; @@ -403,15 +402,4 @@ UNMAP_AFTER_INIT Parser::Parser(PhysicalAddress rsdp, PhysicalAddress fadt, Inte locate_static_data(); } -static bool validate_table(::ACPI::Structures::SDTHeader const& v_header, size_t length) -{ - u8 checksum = 0; - auto* sdt = (u8 const*)&v_header; - for (size_t i = 0; i < length; i++) - checksum += sdt[i]; - if (checksum == 0) - return true; - return false; -} - } diff --git a/Userland/Libraries/LibACPI/CMakeLists.txt b/Userland/Libraries/LibACPI/CMakeLists.txt new file mode 100644 index 00000000000..f74b700d3b2 --- /dev/null +++ b/Userland/Libraries/LibACPI/CMakeLists.txt @@ -0,0 +1,4 @@ +set(SOURCES + Table.cpp +) +serenity_lib(LibACPI acpi) diff --git a/Userland/Libraries/LibACPI/Table.cpp b/Userland/Libraries/LibACPI/Table.cpp new file mode 100644 index 00000000000..7e168e41929 --- /dev/null +++ b/Userland/Libraries/LibACPI/Table.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2026, Undefine + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "Table.h" +#include + +namespace ACPI { + +bool validate_table(::ACPI::Structures::SDTHeader const& header) +{ + auto const* sdt = reinterpret_cast(&header); + + u8 checksum = 0; + for (size_t i = 0; i < header.length; i++) + checksum += sdt[i]; + + return checksum == 0; +} + +} diff --git a/Userland/Libraries/LibACPI/Table.h b/Userland/Libraries/LibACPI/Table.h new file mode 100644 index 00000000000..f21616e253f --- /dev/null +++ b/Userland/Libraries/LibACPI/Table.h @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2026, Undefine + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include "Definitions.h" + +namespace ACPI { + +bool validate_table(::ACPI::Structures::SDTHeader const& header); + +}