diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-11-12 10:24:17 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-11-12 14:41:30 +0100 |
| commit | 1328752bd06900d7b0b45a2cb7e821b8fe58ea37 (patch) | |
| tree | ad9a794aa12bb76de09486e97b72c35c2e50e45c /libs/acpi | |
| parent | 83510526b66c17ed26ac86e75eb1632ed0630138 (diff) | |
| download | kernel-1328752bd06900d7b0b45a2cb7e821b8fe58ea37.tar.xz kernel-1328752bd06900d7b0b45a2cb7e821b8fe58ea37.zip | |
libs/acpi: clean up MCFG entry reading code
Diffstat (limited to 'libs/acpi')
| -rw-r--r-- | libs/acpi/acpi/data/mcfg.cpp | 39 | ||||
| -rw-r--r-- | libs/acpi/acpi/data/mcfg.hpp | 17 |
2 files changed, 25 insertions, 31 deletions
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 <acpi/data/mcfg.hpp> +#include <kstd/cstring.hpp> + +#include <array> +#include <cstddef> #include <cstdint> 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<typename ValueType, std::size_t Offset, std::size_t ArraySize> + [[nodiscard]] auto read(std::array<std::byte, ArraySize> 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<std::uintptr_t, base_address_offset>(); + return read<decltype(mcfg_entry_data::base_address), offsetof(mcfg_entry_data, base_address)>(m_data); } auto mcfg_entry::segment_group_number() const noexcept -> std::uint16_t { - return read<std::uint16_t, segment_group_number_offset>(); + return read<decltype(mcfg_entry_data::segment_group_number), offsetof(mcfg_entry_data, segment_group_number)>( + m_data); } auto mcfg_entry::start_bus_number() const noexcept -> std::uint8_t { - return read<std::uint8_t, start_bus_number_offset>(); + return read<decltype(mcfg_entry_data::start_bus_number), offsetof(mcfg_entry_data, start_bus_number)>(m_data); } auto mcfg_entry::end_bus_number() const noexcept -> std::uint8_t { - return read<std::uint8_t, end_bus_number_offset>(); + return read<decltype(mcfg_entry_data::end_bus_number), offsetof(mcfg_entry_data, end_bus_number)>(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 <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 { @@ -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<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; - } - //! The raw data of this entry. std::array<std::byte, 16> m_data; }; |
