aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-11-11 14:29:25 +0100
committerFelix Morgner <felix.morgner@ost.ch>2026-11-12 14:40:40 +0100
commitf639297d1b96b6aeb3d3822a63b9a602e1f814fb (patch)
treec0a79775896f76b5b35ffd75100f9466ef60549c
parent7676db54f6c3f5e19d78b2d2b0250e1838c30ef6 (diff)
downloadkernel-f639297d1b96b6aeb3d3822a63b9a602e1f814fb.tar.xz
kernel-f639297d1b96b6aeb3d3822a63b9a602e1f814fb.zip
libs/acpi: implement MCFG table support
-rw-r--r--libs/acpi/CMakeLists.txt1
-rw-r--r--libs/acpi/acpi/acpi.hpp1
-rw-r--r--libs/acpi/acpi/data/mcfg.cpp38
-rw-r--r--libs/acpi/acpi/data/mcfg.hpp65
-rw-r--r--libs/acpi/acpi/data/mcfg.tests.cpp55
5 files changed, 160 insertions, 0 deletions
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 <acpi/common/table_signature.hpp> // IWYU pragma: export
#include <acpi/common/table_type.hpp> // IWYU pragma: export
#include <acpi/data/madt.hpp> // IWYU pragma: export
+#include <acpi/data/mcfg.hpp> // IWYU pragma: export
#include <acpi/data/rsdt.hpp> // IWYU pragma: export
#include <acpi/data/xsdt.hpp> // IWYU pragma: export
#include <acpi/pointers.hpp> // 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 <acpi/data/mcfg.hpp>
+
+#include <cstdint>
+
+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<std::uintptr_t, base_address_offset>();
+ }
+
+ auto mcfg_entry::segment_group_number() const noexcept -> std::uint16_t
+ {
+ return read<std::uint16_t, segment_group_number_offset>();
+ }
+
+ auto mcfg_entry::start_bus_number() const noexcept -> std::uint8_t
+ {
+ return read<std::uint8_t, start_bus_number_offset>();
+ }
+
+ auto mcfg_entry::end_bus_number() const noexcept -> std::uint8_t
+ {
+ return read<std::uint8_t, end_bus_number_offset>();
+ }
+
+} // 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 <acpi/acpi.hpp>
+
+#include <acpi/common/table_signature.hpp>
+#include <acpi/common/table_type.hpp>
+#include <acpi/common/vla_table.hpp>
+
+#include <kstd/cstring.hpp>
+
+#include <array>
+#include <cstddef>
+#include <cstdint>
+#include <tuple>
+
+namespace acpi
+{
+
+ template<>
+ struct table_signature<struct mcfg>
+ {
+ constexpr char static const value[] = "MCFG"; // NOLINT(modernize-avoid-c-arrays)
+ };
+
+ template<>
+ struct table_type<table_signature_v<struct mcfg>>
+ {
+ 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<typename ValueType, std::size_t Offset>
+ [[nodiscard]] auto read() const noexcept -> ValueType
+ {
+ static_assert(Offset + sizeof(ValueType) <= std::tuple_size_v<decltype(m_data)>, "Read out of bounds");
+ auto result = ValueType{};
+ kstd::libc::memcpy(&result, m_data.data() + Offset, sizeof(ValueType));
+ return result;
+ }
+
+ std::array<std::byte, 16> m_data;
+ };
+
+ struct mcfg : vla_table<mcfg_entry, mcfg>
+ {
+ private:
+ [[maybe_unused]] std::array<std::byte, 8> 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 <acpi/data/mcfg.hpp>
+
+#include <acpi/test_data/tables.hpp>
+
+#include <catch2/catch_test_macros.hpp>
+
+#include <iterator>
+
+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<acpi::mcfg const *>(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