From f639297d1b96b6aeb3d3822a63b9a602e1f814fb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 11 Nov 2026 14:29:25 +0100 Subject: libs/acpi: implement MCFG table support --- libs/acpi/CMakeLists.txt | 1 + libs/acpi/acpi/acpi.hpp | 1 + libs/acpi/acpi/data/mcfg.cpp | 38 ++++++++++++++++++++++ libs/acpi/acpi/data/mcfg.hpp | 65 ++++++++++++++++++++++++++++++++++++++ libs/acpi/acpi/data/mcfg.tests.cpp | 55 ++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 libs/acpi/acpi/data/mcfg.cpp create mode 100644 libs/acpi/acpi/data/mcfg.hpp create mode 100644 libs/acpi/acpi/data/mcfg.tests.cpp (limited to 'libs/acpi') diff --git a/libs/acpi/CMakeLists.txt b/libs/acpi/CMakeLists.txt index 847223a8..c613178e 100644 --- a/libs/acpi/CMakeLists.txt +++ b/libs/acpi/CMakeLists.txt @@ -25,6 +25,7 @@ target_sources("acpi" PRIVATE "acpi/common/checksum.cpp" "acpi/common/table_header.cpp" "acpi/data/madt.cpp" + "acpi/data/mcfg.cpp" "acpi/data/rsdt.cpp" "acpi/data/xsdt.cpp" "acpi/pointers.cpp" diff --git a/libs/acpi/acpi/acpi.hpp b/libs/acpi/acpi/acpi.hpp index 0da44a85..292e8fdb 100644 --- a/libs/acpi/acpi/acpi.hpp +++ b/libs/acpi/acpi/acpi.hpp @@ -5,6 +5,7 @@ #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export +#include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export #include // IWYU pragma: export diff --git a/libs/acpi/acpi/data/mcfg.cpp b/libs/acpi/acpi/data/mcfg.cpp new file mode 100644 index 00000000..ffb2933d --- /dev/null +++ b/libs/acpi/acpi/data/mcfg.cpp @@ -0,0 +1,38 @@ +#include + +#include + +namespace +{ + + constexpr auto static base_address_offset = 0uz; + constexpr auto static segment_group_number_offset = 8uz; + constexpr auto static start_bus_number_offset = 10uz; + constexpr auto static end_bus_number_offset = 11uz; + +} // namespace + +namespace acpi +{ + + auto mcfg_entry::base_address() const noexcept -> std::uintptr_t + { + return read(); + } + + auto mcfg_entry::segment_group_number() const noexcept -> std::uint16_t + { + return read(); + } + + auto mcfg_entry::start_bus_number() const noexcept -> std::uint8_t + { + return read(); + } + + auto mcfg_entry::end_bus_number() const noexcept -> std::uint8_t + { + return read(); + } + +} // namespace acpi \ No newline at end of file diff --git a/libs/acpi/acpi/data/mcfg.hpp b/libs/acpi/acpi/data/mcfg.hpp new file mode 100644 index 00000000..32d5fce4 --- /dev/null +++ b/libs/acpi/acpi/data/mcfg.hpp @@ -0,0 +1,65 @@ +#ifndef ACPI_ACPI_DATA_MCFG_HPP +#define ACPI_ACPI_DATA_MCFG_HPP + +// IWYU pragma: private, include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace acpi +{ + + template<> + struct table_signature + { + constexpr char static const value[] = "MCFG"; // NOLINT(modernize-avoid-c-arrays) + }; + + template<> + struct table_type> + { + using type = struct mcfg; + }; + + struct mcfg_entry + { + [[nodiscard]] auto base_address() const noexcept -> std::uintptr_t; + [[nodiscard]] auto segment_group_number() const noexcept -> std::uint16_t; + [[nodiscard]] auto start_bus_number() const noexcept -> std::uint8_t; + [[nodiscard]] auto end_bus_number() const noexcept -> std::uint8_t; + + [[nodiscard]] constexpr auto length() const noexcept -> std::size_t + { + return 16; + } + + private: + template + [[nodiscard]] auto read() const noexcept -> ValueType + { + static_assert(Offset + sizeof(ValueType) <= std::tuple_size_v, "Read out of bounds"); + auto result = ValueType{}; + kstd::libc::memcpy(&result, m_data.data() + Offset, sizeof(ValueType)); + return result; + } + + std::array m_data; + }; + + struct mcfg : vla_table + { + private: + [[maybe_unused]] std::array m_reserved{}; + }; + +} // namespace acpi + +#endif // ACPI_ACPI_DATA_MCFG_HPP \ No newline at end of file diff --git a/libs/acpi/acpi/data/mcfg.tests.cpp b/libs/acpi/acpi/data/mcfg.tests.cpp new file mode 100644 index 00000000..9cbe475e --- /dev/null +++ b/libs/acpi/acpi/data/mcfg.tests.cpp @@ -0,0 +1,55 @@ +#include + +#include + +#include + +#include + +SCENARIO("MCFG parsing", "[acpi][mcfg]") +{ + GIVEN("The basic compiled MCFG containing a single entry") + { + auto data = acpi::test_data::tables::basic_mcfg(); + + WHEN("parsing the table") + { + auto mcfg = reinterpret_cast(data.data()); + + THEN("the signature is correct") + { + REQUIRE(mcfg->signature() == "MCFG"); + } + + THEN("validate returns true") + { + REQUIRE(mcfg->validate()); + } + + THEN("there is a single entry in the table") + { + REQUIRE(std::ranges::distance(*mcfg) == 1); + } + + THEN("the first entry has base address 0x00000000f0000000") + { + REQUIRE(mcfg->cbegin()->base_address() == 0x0000'0000'f000'0000); + } + + THEN("the first entry has segment group 0") + { + REQUIRE(mcfg->cbegin()->segment_group_number() == 0); + } + + THEN("the first entry has start bus number 0") + { + REQUIRE(mcfg->cbegin()->start_bus_number() == 0); + } + + THEN("the first entry has end bus number 0x7f") + { + REQUIRE(mcfg->cbegin()->end_bus_number() == 0x7f); + } + } + } +} \ No newline at end of file -- cgit v1.2.3