diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-11-12 10:15:32 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-11-12 14:41:29 +0100 |
| commit | 83510526b66c17ed26ac86e75eb1632ed0630138 (patch) | |
| tree | 37e3f9ce9cf7bec850c6307980df047c16e0cb34 | |
| parent | ab8de113fb03736e49d89b2cccc31f9cae355500 (diff) | |
| download | kernel-83510526b66c17ed26ac86e75eb1632ed0630138.tar.xz kernel-83510526b66c17ed26ac86e75eb1632ed0630138.zip | |
libs/acpi: don't convert addresses to pointer
Previously, ACPI table addresses in both the RSDT and XSDT were
converted to pointers. However, this is not actually correct, since
within the object model of the kernel, pointers always refer to
objects by their linear address, and the addresses encoded in ACPI
tables are, by necessity, physical addresses. The API should therefore
be honest about the fact that the addresses returned by accessors of
the RSDT and XSDT are physical addresses, not pointers to live objects.
| -rw-r--r-- | kernel/kernel/acpi/manager.cpp | 3 | ||||
| -rw-r--r-- | kernel/kernel/acpi/manager.hpp | 1 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/rsdt.cpp | 6 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/rsdt.hpp | 6 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/rsdt.tests.cpp | 2 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/xsdt.cpp | 6 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/xsdt.hpp | 6 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/xsdt.tests.cpp | 2 |
8 files changed, 13 insertions, 19 deletions
diff --git a/kernel/kernel/acpi/manager.cpp b/kernel/kernel/acpi/manager.cpp index 2ba6d558..25ef52b8 100644 --- a/kernel/kernel/acpi/manager.cpp +++ b/kernel/kernel/acpi/manager.cpp @@ -10,7 +10,6 @@ #include <algorithm> #include <cstddef> -#include <cstdint> #include <ranges> #include <string_view> @@ -55,7 +54,7 @@ namespace kernel::acpi } auto check_and_register_table = [&](auto table_address) -> void { - auto physical_table_address = kapi::memory::physical_address{reinterpret_cast<std::uintptr_t>(table_address)}; + auto physical_table_address = kapi::memory::physical_address{table_address}; auto mapped_table = kapi::memory::hhdm_to_linear(physical_table_address); auto table = static_cast<kstd::observer_ptr<::acpi::table_header const>>(mapped_table); diff --git a/kernel/kernel/acpi/manager.hpp b/kernel/kernel/acpi/manager.hpp index de344dd8..8ce5368d 100644 --- a/kernel/kernel/acpi/manager.hpp +++ b/kernel/kernel/acpi/manager.hpp @@ -5,7 +5,6 @@ #include <kstd/flat_map.hpp> #include <kstd/memory.hpp> -#include <kstd/vector.hpp> #include <string_view> diff --git a/libs/acpi/acpi/data/rsdt.cpp b/libs/acpi/acpi/data/rsdt.cpp index a8626742..99090beb 100644 --- a/libs/acpi/acpi/data/rsdt.cpp +++ b/libs/acpi/acpi/data/rsdt.cpp @@ -1,7 +1,5 @@ #include <acpi/data/rsdt.hpp> -#include <acpi/common/table_header.hpp> - #include <kstd/cstring.hpp> #include <cstddef> @@ -16,7 +14,7 @@ namespace acpi std::uint32_t address; }; - [[nodiscard]] auto rsdt_entry::address() const noexcept -> table_header * + [[nodiscard]] auto rsdt_entry::address() const noexcept -> std::uintptr_t { using type = decltype(rsdt_entry_data::address); @@ -28,7 +26,7 @@ namespace acpi kstd::libc::memcpy(&value, data.data(), size); - return reinterpret_cast<table_header *>(static_cast<uintptr_t>(value)); + return static_cast<std::uintptr_t>(value); } [[nodiscard]] auto rsdt_entry::length() const noexcept -> std::size_t diff --git a/libs/acpi/acpi/data/rsdt.hpp b/libs/acpi/acpi/data/rsdt.hpp index ca36b33d..843e6cf2 100644 --- a/libs/acpi/acpi/data/rsdt.hpp +++ b/libs/acpi/acpi/data/rsdt.hpp @@ -1,13 +1,13 @@ #ifndef ACPI_DATA_RSDT_HPP #define ACPI_DATA_RSDT_HPP -#include <acpi/common/table_header.hpp> #include <acpi/common/table_signature.hpp> #include <acpi/common/table_type.hpp> #include <acpi/common/vla_table.hpp> #include <array> #include <cstddef> +#include <cstdint> namespace acpi { @@ -37,8 +37,8 @@ namespace acpi //! Get the address of the ACPI table pointed to by this entry. //! - //! @return A pointer to the ACPI table header of the referenced table. - [[nodiscard]] auto address() const noexcept -> table_header *; + //! @return The physical address of the ACPI table header of the referenced table. + [[nodiscard]] auto address() const noexcept -> std::uintptr_t; //! Get the length of the ACPI table pointed to by this entry. //! diff --git a/libs/acpi/acpi/data/rsdt.tests.cpp b/libs/acpi/acpi/data/rsdt.tests.cpp index c111f749..691fd631 100644 --- a/libs/acpi/acpi/data/rsdt.tests.cpp +++ b/libs/acpi/acpi/data/rsdt.tests.cpp @@ -41,7 +41,7 @@ SCENARIO("RSDT parsing", "[rsdt]") THEN("the first entry has address 0x10") { - REQUIRE(rsdt->cbegin()->address() == reinterpret_cast<acpi::table_header *>(0x10)); + REQUIRE(rsdt->cbegin()->address() == 0x10); } THEN("the length is sizeof(rsdt) + 8 * sizeof(rsdt_entry)") diff --git a/libs/acpi/acpi/data/xsdt.cpp b/libs/acpi/acpi/data/xsdt.cpp index c4b109b8..6f280889 100644 --- a/libs/acpi/acpi/data/xsdt.cpp +++ b/libs/acpi/acpi/data/xsdt.cpp @@ -1,7 +1,5 @@ #include <acpi/data/xsdt.hpp> -#include <acpi/common/table_header.hpp> - #include <kstd/cstring.hpp> #include <cstddef> @@ -16,7 +14,7 @@ namespace acpi std::uint64_t address; }; - [[nodiscard]] auto xsdt_entry::address() const noexcept -> table_header * + [[nodiscard]] auto xsdt_entry::address() const noexcept -> std::uintptr_t { using type = decltype(xsdt_entry_data::address); @@ -28,7 +26,7 @@ namespace acpi kstd::libc::memcpy(&value, data.data(), size); - return reinterpret_cast<table_header *>(static_cast<uintptr_t>(value)); + return static_cast<std::uintptr_t>(value); } [[nodiscard]] auto xsdt_entry::length() const noexcept -> std::size_t diff --git a/libs/acpi/acpi/data/xsdt.hpp b/libs/acpi/acpi/data/xsdt.hpp index ef268d5f..f8c0a775 100644 --- a/libs/acpi/acpi/data/xsdt.hpp +++ b/libs/acpi/acpi/data/xsdt.hpp @@ -1,13 +1,13 @@ #ifndef ACPI_DATA_XSDT_HPP #define ACPI_DATA_XSDT_HPP -#include <acpi/common/table_header.hpp> #include <acpi/common/table_signature.hpp> #include <acpi/common/table_type.hpp> #include <acpi/common/vla_table.hpp> #include <array> #include <cstddef> +#include <cstdint> namespace acpi { @@ -37,8 +37,8 @@ namespace acpi //! Get the address of the ACPI table pointed to by this entry. //! - //! @return A pointer to the ACPI table header of the referenced table. - [[nodiscard]] auto address() const noexcept -> table_header *; + //! @return The physical address of the ACPI table header of the referenced table. + [[nodiscard]] auto address() const noexcept -> std::uintptr_t; //! Get the length of the ACPI table pointed to by this entry. //! diff --git a/libs/acpi/acpi/data/xsdt.tests.cpp b/libs/acpi/acpi/data/xsdt.tests.cpp index e5eaed67..955c08df 100644 --- a/libs/acpi/acpi/data/xsdt.tests.cpp +++ b/libs/acpi/acpi/data/xsdt.tests.cpp @@ -41,7 +41,7 @@ SCENARIO("XSDT parsing", "[xsdt]") THEN("the first entry has address 0x10") { - REQUIRE(xsdt->cbegin()->address() == reinterpret_cast<acpi::table_header *>(0x10)); + REQUIRE(xsdt->cbegin()->address() == 0x10); } THEN("the length is sizeof(xsdt) + 8 * sizeof(xsdt_entry)") |
