From 1328752bd06900d7b0b45a2cb7e821b8fe58ea37 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 12 Nov 2026 10:24:17 +0100 Subject: libs/acpi: clean up MCFG entry reading code --- libs/acpi/acpi/data/mcfg.cpp | 39 +++++++++++++++++++++++++-------------- libs/acpi/acpi/data/mcfg.hpp | 17 ----------------- 2 files changed, 25 insertions(+), 31 deletions(-) (limited to 'libs/acpi') diff --git a/libs/acpi/acpi/data/mcfg.cpp b/libs/acpi/acpi/data/mcfg.cpp index 008a8ca3..2c79104c 100644 --- a/libs/acpi/acpi/data/mcfg.cpp +++ b/libs/acpi/acpi/data/mcfg.cpp @@ -1,21 +1,31 @@ #include +#include + +#include +#include #include namespace { - //! The offset of the base address field within an MCFG entry. - constexpr auto static base_address_offset = 0uz; - - //! The offset of the segment group number field within an MCFG entry. - constexpr auto static segment_group_number_offset = 8uz; - - //! The offset of the start bus number field within an MCFG entry. - constexpr auto static start_bus_number_offset = 10uz; + template + [[nodiscard]] auto read(std::array const & m_data) noexcept -> ValueType + { + static_assert(Offset + sizeof(ValueType) <= ArraySize, "Read out of bounds"); + auto result = ValueType{}; + kstd::libc::memcpy(&result, m_data.data() + Offset, sizeof(ValueType)); + return result; + } - //! The offset of the end bus number field within an MCFG entry. - constexpr auto static end_bus_number_offset = 11uz; + //! The structure of a single MCFG entry. + struct mcfg_entry_data + { + std::uint64_t base_address; + std::uint16_t segment_group_number; + std::uint8_t start_bus_number; + std::uint8_t end_bus_number; + }; } // namespace @@ -24,22 +34,23 @@ namespace acpi auto mcfg_entry::base_address() const noexcept -> std::uintptr_t { - return read(); + return read(m_data); } auto mcfg_entry::segment_group_number() const noexcept -> std::uint16_t { - return read(); + return read( + m_data); } auto mcfg_entry::start_bus_number() const noexcept -> std::uint8_t { - return read(); + return read(m_data); } auto mcfg_entry::end_bus_number() const noexcept -> std::uint8_t { - return read(); + return read(m_data); } } // namespace acpi \ No newline at end of file diff --git a/libs/acpi/acpi/data/mcfg.hpp b/libs/acpi/acpi/data/mcfg.hpp index 21f3293c..b0661154 100644 --- a/libs/acpi/acpi/data/mcfg.hpp +++ b/libs/acpi/acpi/data/mcfg.hpp @@ -7,12 +7,9 @@ #include #include -#include - #include #include #include -#include namespace acpi { @@ -69,20 +66,6 @@ namespace acpi } private: - //! Read a value of a specified type at a specified offset within this entry. - //! - //! @tparam ValueType The type of value to read. - //! @tparam Offset The offset within the entry to read from. - //! @return The value read from the specified offset. - 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; - } - //! The raw data of this entry. std::array m_data; }; -- cgit v1.2.3