diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-09 15:54:04 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-09 15:54:04 +0200 |
| commit | f6bea6a5f1939f3261392633f6caca186befd555 (patch) | |
| tree | 1aee4819f9d5cb998716c300c9202324a061cef8 /kernel | |
| parent | aa208226f992523865328d4612ae4a7679f57a04 (diff) | |
| download | teachos-f6bea6a5f1939f3261392633f6caca186befd555.tar.xz teachos-f6bea6a5f1939f3261392633f6caca186befd555.zip | |
kapi: restructure ACPI implementation
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | kernel/kapi/acpi.cpp | 124 | ||||
| -rw-r--r-- | kernel/kapi/acpi/multiple_apic_description_table.cpp | 70 | ||||
| -rw-r--r-- | kernel/kapi/acpi/pointers.cpp | 55 | ||||
| -rw-r--r-- | kernel/kapi/acpi/system_description_table_header.cpp | 51 |
5 files changed, 179 insertions, 124 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 67db0a8..8af6fe7 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -1,6 +1,9 @@ add_library("kernel_objs" OBJECT # Platform-independent KAPI implementation "kapi/acpi.cpp" + "kapi/acpi/multiple_apic_description_table.cpp" + "kapi/acpi/pointers.cpp" + "kapi/acpi/system_description_table_header.cpp" "kapi/boot_modules.cpp" "kapi/cio.cpp" "kapi/cpu.cpp" diff --git a/kernel/kapi/acpi.cpp b/kernel/kapi/acpi.cpp index 1283d7e..e7c4921 100644 --- a/kernel/kapi/acpi.cpp +++ b/kernel/kapi/acpi.cpp @@ -1,16 +1,13 @@ #include "kapi/acpi.hpp" -#include "kapi/memory.hpp" #include "kapi/system.hpp" #include "kernel/acpi/manager.hpp" #include <kstd/memory> -#include <kstd/units> #include <algorithm> #include <atomic> -#include <bit> #include <cstddef> #include <cstdint> #include <optional> @@ -25,127 +22,6 @@ namespace kapi::acpi auto constinit manager = std::optional<kernel::acpi::manager>{}; } // namespace - auto root_system_description_pointer::oem_id() const noexcept -> std::string_view - { - return {m_oem_id.data(), m_oem_id.size()}; - } - - auto root_system_description_pointer::revision() const noexcept -> std::uint8_t - { - return m_revision; - } - - auto root_system_description_pointer::signature() const noexcept -> std::string_view - { - return {m_signature.data(), m_signature.size()}; - } - - auto root_system_description_pointer::table_address() const noexcept -> memory::physical_address - { - auto raw = std::bit_cast<std::uint32_t>(m_rsdt_address); - return memory::physical_address{static_cast<std::uintptr_t>(raw)}; - } - - auto root_system_description_pointer::validate() const noexcept -> bool - { - return validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(root_system_description_pointer)}); - } - - auto extended_system_description_pointer::length() const noexcept -> kstd::units::bytes - { - return kstd::units::bytes{m_length}; - } - - auto extended_system_description_pointer::table_address() const noexcept -> memory::physical_address - { - return memory::physical_address{std::bit_cast<std::uintptr_t>(m_xsdt_address)}; - } - - auto extended_system_description_pointer::validate() const noexcept -> bool - { - return validate_checksum({reinterpret_cast<std::byte const *>(this), m_length}); - } - - [[nodiscard]] auto system_description_table_header::checksum() const noexcept -> std::uint8_t - { - return m_checksum; - } - - [[nodiscard]] auto system_description_table_header::creator_revision() const noexcept -> std::uint32_t - { - return m_creator_revision; - } - - [[nodiscard]] auto system_description_table_header::creator_id() const noexcept -> std::uint32_t - { - return m_creator_id; - } - - [[nodiscard]] auto system_description_table_header::length() const noexcept -> kstd::units::bytes - { - return kstd::units::bytes{m_length}; - } - - [[nodiscard]] auto system_description_table_header::oem_id() const noexcept -> std::string_view - { - return {m_oem_id.data(), m_oem_id.size()}; - } - - [[nodiscard]] auto system_description_table_header::oem_revision() const noexcept -> std::uint32_t - { - return m_oem_revision; - } - - [[nodiscard]] auto system_description_table_header::oem_table_id() const noexcept -> std::string_view - { - return {m_oem_table_id.data(), m_oem_table_id.size()}; - } - - [[nodiscard]] auto system_description_table_header::revision() const noexcept -> std::uint8_t - { - return m_revision; - } - - [[nodiscard]] auto system_description_table_header::signature() const noexcept -> std::string_view - { - return {m_signature.data(), m_signature.size()}; - } - - [[nodiscard]] auto madt_header::local_interrupt_controller_address() const noexcept -> memory::physical_address - { - return memory::physical_address{static_cast<std::uintptr_t>(m_local_interrupt_controller_address)}; - } - - [[nodiscard]] auto madt_header::flags() const noexcept -> std::uint32_t - { - return m_flags; - } - - [[nodiscard]] auto madt_subtable_header::type() const noexcept -> std::uint8_t - { - return m_type; - } - - [[nodiscard]] auto madt_subtable_header::length() const noexcept -> std::size_t - { - return m_length; - } - - [[nodiscard]] auto madt_local_apic::apic_id() const noexcept -> std::uint8_t - { - return m_apic_id; - } - - [[nodiscard]] auto madt_local_apic::flags() const noexcept -> std::uint32_t - { - return m_flags; - } - - [[nodiscard]] auto madt_local_apic::processor_id() const noexcept -> std::uint32_t - { - return m_processor_id; - } - auto init(root_system_description_pointer const & sdp) -> bool { auto static constinit initialized = std::atomic_flag{}; diff --git a/kernel/kapi/acpi/multiple_apic_description_table.cpp b/kernel/kapi/acpi/multiple_apic_description_table.cpp new file mode 100644 index 0000000..c0360a3 --- /dev/null +++ b/kernel/kapi/acpi/multiple_apic_description_table.cpp @@ -0,0 +1,70 @@ +#include "kapi/acpi.hpp" +#include "kapi/memory.hpp" + +#include <cstddef> +#include <cstdint> + +namespace kapi::acpi +{ + + auto multiple_apic_description_table::local_interrupt_controller_address() const noexcept -> memory::physical_address + { + return memory::physical_address{static_cast<std::uintptr_t>(m_local_interrupt_controller_address)}; + } + + auto multiple_apic_description_table::flags() const noexcept -> std::uint32_t + { + return m_flags; + } + + auto multiple_apic_description_table_entry::type() const noexcept -> types + { + return static_cast<types>(m_type); + } + + auto multiple_apic_description_table_entry::length() const noexcept -> std::size_t + { + return m_length; + } + + auto processor_local_apic::apic_id() const noexcept -> std::uint8_t + { + return m_apic_id; + } + + auto processor_local_apic::active_flags() const noexcept -> flags + { + return static_cast<flags>(m_flags); + } + + auto processor_local_apic::processor_id() const noexcept -> std::uint32_t + { + return m_processor_id; + } + + auto multiple_apic_description_table::begin() const noexcept -> iterator + { + auto base = reinterpret_cast<std::byte const *>(this); + base += sizeof(multiple_apic_description_table); + auto limit = reinterpret_cast<std::byte const *>(this); + limit += length().value; + return iterator{reinterpret_cast<multiple_apic_description_table_entry const *>(base), + reinterpret_cast<multiple_apic_description_table_entry const *>(limit)}; + } + + auto multiple_apic_description_table::cbegin() const noexcept -> iterator + { + return begin(); + } + + auto multiple_apic_description_table::end() const noexcept -> iterator + { + return {}; + } + + auto multiple_apic_description_table::cend() const noexcept -> iterator + { + return end(); + } + +} // namespace kapi::acpi diff --git a/kernel/kapi/acpi/pointers.cpp b/kernel/kapi/acpi/pointers.cpp new file mode 100644 index 0000000..63831e9 --- /dev/null +++ b/kernel/kapi/acpi/pointers.cpp @@ -0,0 +1,55 @@ +#include "kapi/acpi.hpp" +#include "kapi/memory.hpp" + +#include <kstd/units> + +#include <bit> +#include <cstddef> +#include <cstdint> +#include <string_view> + +namespace kapi::acpi +{ + + auto root_system_description_pointer::oem_id() const noexcept -> std::string_view + { + return {m_oem_id.data(), m_oem_id.size()}; + } + + auto root_system_description_pointer::revision() const noexcept -> std::uint8_t + { + return m_revision; + } + + auto root_system_description_pointer::signature() const noexcept -> std::string_view + { + return {m_signature.data(), m_signature.size()}; + } + + auto root_system_description_pointer::table_address() const noexcept -> memory::physical_address + { + auto raw = std::bit_cast<std::uint32_t>(m_rsdt_address); + return memory::physical_address{static_cast<std::uintptr_t>(raw)}; + } + + auto root_system_description_pointer::validate() const noexcept -> bool + { + return validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(root_system_description_pointer)}); + } + + auto extended_system_description_pointer::length() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{m_length}; + } + + auto extended_system_description_pointer::table_address() const noexcept -> memory::physical_address + { + return memory::physical_address{std::bit_cast<std::uintptr_t>(m_xsdt_address)}; + } + + auto extended_system_description_pointer::validate() const noexcept -> bool + { + return validate_checksum({reinterpret_cast<std::byte const *>(this), m_length}); + } + +} // namespace kapi::acpi diff --git a/kernel/kapi/acpi/system_description_table_header.cpp b/kernel/kapi/acpi/system_description_table_header.cpp new file mode 100644 index 0000000..f688b4d --- /dev/null +++ b/kernel/kapi/acpi/system_description_table_header.cpp @@ -0,0 +1,51 @@ +#include "kapi/acpi.hpp" + +#include <kstd/units> + +#include <cstdint> +#include <string_view> + +namespace kapi::acpi +{ + + [[nodiscard]] auto system_description_table_header::creator_revision() const noexcept -> std::uint32_t + { + return m_creator_revision; + } + + [[nodiscard]] auto system_description_table_header::creator_id() const noexcept -> std::uint32_t + { + return m_creator_id; + } + + [[nodiscard]] auto system_description_table_header::length() const noexcept -> kstd::units::bytes + { + return kstd::units::bytes{m_length}; + } + + [[nodiscard]] auto system_description_table_header::oem_id() const noexcept -> std::string_view + { + return {m_oem_id.data(), m_oem_id.size()}; + } + + [[nodiscard]] auto system_description_table_header::oem_revision() const noexcept -> std::uint32_t + { + return m_oem_revision; + } + + [[nodiscard]] auto system_description_table_header::oem_table_id() const noexcept -> std::string_view + { + return {m_oem_table_id.data(), m_oem_table_id.size()}; + } + + [[nodiscard]] auto system_description_table_header::revision() const noexcept -> std::uint8_t + { + return m_revision; + } + + [[nodiscard]] auto system_description_table_header::signature() const noexcept -> std::string_view + { + return {m_signature.data(), m_signature.size()}; + } + +} // namespace kapi::acpi |
