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.
This commit is contained in:
Undefine authored and Sönke Holz committed 2026-10-21 19:03:12 +02:00
1 parent 473ef7da92
commit 14b039b24f
5 files changed
+49 -14

No files matched your search

+5
View File
@@ -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}
+2 -14
View File
@@ -21,6 +21,7 @@
#include <Kernel/Library/StdLib.h>
#include <Kernel/Memory/TypedMapping.h>
#include <Kernel/Sections.h>
#include <LibACPI/Table.h>
namespace Kernel::ACPI {
@@ -120,8 +121,6 @@ void Parser::enumerate_static_tables(Function<void(StringView, PhysicalAddress,
}
}
static bool validate_table(::ACPI::Structures::SDTHeader const&, size_t length);
UNMAP_AFTER_INIT void Parser::locate_static_data()
{
locate_main_system_description_table();
@@ -352,7 +351,7 @@ UNMAP_AFTER_INIT void Parser::initialize_main_system_description_table()
auto sdt = Memory::map_typed<::ACPI::Structures::SDTHeader>(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;
}
}
@@ -0,0 +1,4 @@
set(SOURCES
Table.cpp
)
serenity_lib(LibACPI acpi)
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2026, Undefine <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "Table.h"
#include <AK/BitCast.h>
namespace ACPI {
bool validate_table(::ACPI::Structures::SDTHeader const& header)
{
auto const* sdt = reinterpret_cast<u8 const*>(&header);
u8 checksum = 0;
for (size_t i = 0; i < header.length; i++)
checksum += sdt[i];
return checksum == 0;
}
}
+15
View File
@@ -0,0 +1,15 @@
/*
* Copyright (c) 2026, Undefine <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "Definitions.h"
namespace ACPI {
bool validate_table(::ACPI::Structures::SDTHeader const& header);
}