aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-04-06 17:24:36 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-04-06 18:07:17 +0200
commitf456f1674d48932846eb7b5ec1df630ad67e7e3d (patch)
tree1722176d1aa98d0942fb10cfade035c658bf4d14 /kapi
parentc18feddd51d1a1398d1245229c5f889dd40554b3 (diff)
downloadteachos-f456f1674d48932846eb7b5ec1df630ad67e7e3d.tar.xz
teachos-f456f1674d48932846eb7b5ec1df630ad67e7e3d.zip
kernel/acpi: discover local interrupt controllers
Diffstat (limited to 'kapi')
-rw-r--r--kapi/include/kapi/acpi.hpp91
-rw-r--r--kapi/include/kapi/devices/bus.hpp2
-rw-r--r--kapi/include/kapi/devices/device.hpp2
3 files changed, 72 insertions, 23 deletions
diff --git a/kapi/include/kapi/acpi.hpp b/kapi/include/kapi/acpi.hpp
index 11068d1..5d55d08 100644
--- a/kapi/include/kapi/acpi.hpp
+++ b/kapi/include/kapi/acpi.hpp
@@ -1,8 +1,10 @@
#ifndef TEACHOS_KAPI_ACPI_HPP
#define TEACHOS_KAPI_ACPI_HPP
+#include "kapi/devices.hpp"
#include "kapi/memory.hpp"
+#include <kstd/memory>
#include <kstd/units>
#include <array>
@@ -14,9 +16,38 @@
namespace kapi::acpi
{
- //! @addtogroup kapi-acpi
+ //! @addtogroup kapi-acpi-kernel-defined
//! @{
+ struct [[gnu::packed]] root_system_description_pointer
+ {
+ [[nodiscard]] auto oem_id() const noexcept -> std::string_view;
+ [[nodiscard]] auto revision() const noexcept -> std::uint8_t;
+ [[nodiscard]] auto signature() const noexcept -> std::string_view;
+ [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
+ [[nodiscard]] auto validate() const noexcept -> bool;
+
+ private:
+ std::array<char, 8> m_signature;
+ [[maybe_unused]] std::uint8_t m_checksum;
+ std::array<char, 6> m_oem_id;
+ std::uint8_t m_revision;
+ std::array<std::byte, 4> m_rsdt_address;
+ };
+
+ struct [[gnu::packed]] extended_system_description_pointer : root_system_description_pointer
+ {
+ [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
+ [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
+ [[nodiscard]] auto validate() const noexcept -> bool;
+
+ private:
+ std::uint32_t m_length;
+ std::array<std::byte, 8> m_xsdt_address;
+ [[maybe_unused]] std::uint8_t m_extended_checksum;
+ [[maybe_unused]] std::array<std::byte, 3> m_reserved;
+ };
+
struct [[gnu::packed]] system_description_table_header
{
[[nodiscard]] auto checksum() const noexcept -> std::uint8_t;
@@ -41,38 +72,36 @@ namespace kapi::acpi
std::uint32_t m_creator_revision;
};
- //! @}
+ struct [[gnu::packed]] madt_header : system_description_table_header
+ {
+ [[nodiscard]] auto local_interrupt_controller_address() const noexcept -> memory::physical_address;
+ [[nodiscard]] auto flags() const noexcept -> std::uint32_t;
- //! @addtogroup kapi-acpi-kernel-defined
- //! @{
+ private:
+ std::uint32_t m_local_interrupt_controller_address;
+ std::uint32_t m_flags;
+ };
- struct [[gnu::packed]] root_system_description_pointer
+ struct [[gnu::packed]] madt_subtable_header
{
- [[nodiscard]] auto oem_id() const noexcept -> std::string_view;
- [[nodiscard]] auto revision() const noexcept -> std::uint8_t;
- [[nodiscard]] auto signature() const noexcept -> std::string_view;
- [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
- [[nodiscard]] auto validate() const noexcept -> bool;
+ [[nodiscard]] auto type() const noexcept -> std::uint8_t;
+ [[nodiscard]] auto length() const noexcept -> std::size_t;
private:
- std::array<char, 8> m_signature;
- [[maybe_unused]] std::uint8_t m_checksum;
- std::array<char, 6> m_oem_id;
- std::uint8_t m_revision;
- std::array<std::byte, 4> m_rsdt_address;
+ std::uint8_t m_type;
+ std::uint8_t m_length;
};
- struct [[gnu::packed]] extended_system_description_pointer : root_system_description_pointer
+ struct [[gnu::packed]] madt_local_apic : madt_subtable_header
{
- [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
- [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
- [[nodiscard]] auto validate() const noexcept -> bool;
+ [[nodiscard]] auto apic_id() const noexcept -> std::uint8_t;
+ [[nodiscard]] auto flags() const noexcept -> std::uint32_t;
+ [[nodiscard]] auto processor_id() const noexcept -> std::uint32_t;
private:
- std::uint32_t m_length;
- std::array<std::byte, 8> m_xsdt_address;
- [[maybe_unused]] std::uint8_t m_extended_checksum;
- [[maybe_unused]] std::array<std::byte, 3> m_reserved;
+ std::uint8_t m_processor_id;
+ std::uint8_t m_apic_id;
+ std::uint32_t m_flags;
};
//! Initialize the ACPI subsystem and discover the available tables.
@@ -86,6 +115,22 @@ namespace kapi::acpi
//! @return true iff. the checksum is valid, false otherwise.
auto validate_checksum(std::span<std::byte const> data) -> bool;
+ //! Get an ACPI table by its signature.
+ //!
+ //! @param signature The signature of the table to get.
+ //! @return A pointer to the table if found, nullptr otherwise.
+ auto get_table(std::string_view signature) -> kstd::observer_ptr<system_description_table_header const>;
+
+ //! @}
+
+ //! @addtogroup kapi-acpi-platform-defined
+ //! @{
+
+ auto get_root_pointer() -> kstd::observer_ptr<root_system_description_pointer const>;
+
+ auto create_local_interrupt_controller(std::size_t major, std::size_t minor, std::uint64_t hardware_id,
+ memory::physical_address address) -> kstd::unique_ptr<devices::device>;
+
//! @}
} // namespace kapi::acpi
diff --git a/kapi/include/kapi/devices/bus.hpp b/kapi/include/kapi/devices/bus.hpp
index 052c062..a384291 100644
--- a/kapi/include/kapi/devices/bus.hpp
+++ b/kapi/include/kapi/devices/bus.hpp
@@ -1,6 +1,8 @@
#ifndef TEACHOS_KAPI_DEVICES_BUS_HPP
#define TEACHOS_KAPI_DEVICES_BUS_HPP
+// IWYU pragma: private, include "kapi/devices.hpp"
+
#include "kapi/devices/device.hpp"
#include "kapi/devices/manager.hpp"
#include "kapi/system.hpp"
diff --git a/kapi/include/kapi/devices/device.hpp b/kapi/include/kapi/devices/device.hpp
index b7b6bba..ca5033e 100644
--- a/kapi/include/kapi/devices/device.hpp
+++ b/kapi/include/kapi/devices/device.hpp
@@ -1,6 +1,8 @@
#ifndef TEACH_OS_KAPI_DEVICES_DEVICE_HPP
#define TEACH_OS_KAPI_DEVICES_DEVICE_HPP
+// IWYU pragma: private, include "kapi/devices.hpp"
+
#include <kstd/string>
#include <cstddef>