aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kapi')
-rw-r--r--kapi/CMakeLists.txt1
-rw-r--r--kapi/include/kapi/acpi.hpp25
-rw-r--r--kapi/include/kapi/acpi/multiple_apic_description_table.hpp104
-rw-r--r--kapi/include/kapi/acpi/pointers.hpp79
-rw-r--r--kapi/include/kapi/acpi/system_description_table_header.hpp76
-rw-r--r--kapi/include/kapi/acpi/table_iterator.hpp64
-rw-r--r--kapi/include/kapi/acpi/table_type.hpp22
7 files changed, 8 insertions, 363 deletions
diff --git a/kapi/CMakeLists.txt b/kapi/CMakeLists.txt
index c9aa23f..99a8725 100644
--- a/kapi/CMakeLists.txt
+++ b/kapi/CMakeLists.txt
@@ -15,6 +15,7 @@ target_include_directories("kapi" INTERFACE
)
target_link_libraries("kapi" INTERFACE
+ "libs::acpi"
"libs::kstd"
"gcc"
diff --git a/kapi/include/kapi/acpi.hpp b/kapi/include/kapi/acpi.hpp
index 5323fee..01fd113 100644
--- a/kapi/include/kapi/acpi.hpp
+++ b/kapi/include/kapi/acpi.hpp
@@ -1,16 +1,11 @@
#ifndef TEACHOS_KAPI_ACPI_HPP
#define TEACHOS_KAPI_ACPI_HPP
-#include "kapi/acpi/multiple_apic_description_table.hpp" // IWYU pragma: export
-#include "kapi/acpi/pointers.hpp" // IWYU pragma: export
-#include "kapi/acpi/system_description_table_header.hpp" // IWYU pragma: export
-#include "kapi/acpi/table_type.hpp"
-
#include <kstd/memory>
#include <kstd/units>
-#include <cstddef>
-#include <span>
+#include <acpi/acpi.hpp>
+
#include <string_view>
namespace kapi::acpi
@@ -22,28 +17,22 @@ namespace kapi::acpi
//! Initialize the ACPI subsystem and discover the available tables.
//!
//! @return true iff. a valid system description tabled was found, false otherwise.
- auto init(root_system_description_pointer const & sdp) -> bool;
-
- //! Validate and ACPI entity checksum.
- //!
- //! @param data The data to validate the checksum of.
- //! @return true iff. the checksum is valid, false otherwise.
- auto validate_checksum(std::span<std::byte const> data) -> bool;
+ auto init(::acpi::rsdp const & sdp) -> bool;
//! Get a pointer to 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>;
+ auto get_table(std::string_view signature) -> kstd::observer_ptr<::acpi::sdt const>;
//! Get a type-cast pointer to an ACPI table by its signature.
//!
//! @tparam Signature The signature of the table to get
//! @return A pointer to the table if found, nullptr otherwise.
template<char const * Signature>
- auto get_table() -> kstd::observer_ptr<table_type_t<Signature> const>
+ auto get_table() -> kstd::observer_ptr<::acpi::table_type_t<Signature> const>
{
- return kstd::make_observer(static_cast<table_type_t<Signature> const *>(get_table(Signature).get()));
+ return kstd::make_observer(static_cast<::acpi::table_type_t<Signature> const *>(get_table(Signature).get()));
}
//! @}
@@ -54,7 +43,7 @@ namespace kapi::acpi
//! Retrieve the RSDP or XSDP for this system.
//!
//! @return a pointer to either the RSDP or XSDP data structure, or @p nullptr if neither is present.
- auto get_root_pointer() -> kstd::observer_ptr<root_system_description_pointer const>;
+ auto get_root_pointer() -> kstd::observer_ptr<::acpi::rsdp const>;
//! @}
diff --git a/kapi/include/kapi/acpi/multiple_apic_description_table.hpp b/kapi/include/kapi/acpi/multiple_apic_description_table.hpp
deleted file mode 100644
index 33acac9..0000000
--- a/kapi/include/kapi/acpi/multiple_apic_description_table.hpp
+++ /dev/null
@@ -1,104 +0,0 @@
-#ifndef TEACHOS_KAPI_ACPI_MUTIPLE_APIC_DESCRIPTION_TABLE_HEADER_HPP
-#define TEACHOS_KAPI_ACPI_MUTIPLE_APIC_DESCRIPTION_TABLE_HEADER_HPP
-
-// IWYU pragma: private, include "kapi/acpi.hpp"
-
-#include "kapi/acpi/system_description_table_header.hpp"
-#include "kapi/acpi/table_iterator.hpp"
-#include "kapi/acpi/table_type.hpp"
-#include "kapi/memory.hpp"
-
-#include <kstd/ext/bitfield_enum>
-#include <kstd/units>
-
-#include <cstddef>
-#include <cstdint>
-#include <type_traits>
-
-namespace kapi::acpi
-{
-
- //! @addtogroup kapi-acpi-kernel-defined
- //! @{
-
- struct [[gnu::packed]] multiple_apic_description_table_entry
- {
- enum struct types : std::uint8_t
- {
- processor_local_apic,
- io_apic,
- io_apic_interrupt_source_override,
- io_apic_nmi_source,
- local_apic_nmi_interrupts,
- local_apic_address_override,
- processor_local_x2_apic,
- };
-
- [[nodiscard]] auto type() const noexcept -> types;
- [[nodiscard]] auto length() const noexcept -> std::size_t;
-
- private:
- std::uint8_t m_type;
- std::uint8_t m_length;
- };
-
- //! The common header for all
- struct [[gnu::packed]] multiple_apic_description_table : system_description_table_header
- {
- using iterator = table_iterator<multiple_apic_description_table_entry const>;
- using const_iterator = iterator;
-
- [[nodiscard]] auto local_interrupt_controller_address() const noexcept -> memory::physical_address;
- [[nodiscard]] auto flags() const noexcept -> std::uint32_t;
-
- [[nodiscard]] auto begin() const noexcept -> iterator;
- [[nodiscard]] auto cbegin() const noexcept -> iterator;
- [[nodiscard]] auto end() const noexcept -> iterator;
- [[nodiscard]] auto cend() const noexcept -> iterator;
-
- private:
- std::uint32_t m_local_interrupt_controller_address;
- std::uint32_t m_flags;
- };
-
- struct [[gnu::packed]] processor_local_apic : multiple_apic_description_table_entry
- {
- enum struct flags : std::uint32_t
- {
- processor_enabled = 1,
- online_capable = 2,
- };
-
- [[nodiscard]] auto apic_id() const noexcept -> std::uint8_t;
- [[nodiscard]] auto active_flags() const noexcept -> flags;
- [[nodiscard]] auto processor_id() const noexcept -> std::uint32_t;
-
- private:
- std::uint8_t m_processor_id;
- std::uint8_t m_apic_id;
- std::uint32_t m_flags;
- };
-
- //! @}
-
- //! @addtogroup kapi-acpi
- //! @{
-
- constexpr char const madt_table_signature[] = "APIC"; // NOLINT
-
- template<>
- struct table_type<madt_table_signature>
- {
- using type = multiple_apic_description_table;
- };
-
- //! @}
-
-} // namespace kapi::acpi
-
-template<>
-struct kstd::ext::is_bitfield_enum<kapi::acpi::processor_local_apic::flags> : std::true_type
-{
-};
-
-#endif
diff --git a/kapi/include/kapi/acpi/pointers.hpp b/kapi/include/kapi/acpi/pointers.hpp
deleted file mode 100644
index 2b88720..0000000
--- a/kapi/include/kapi/acpi/pointers.hpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#ifndef TEACHOS_KAPI_ACPI_POINTERS_HPP
-#define TEACHOS_KAPI_ACPI_POINTERS_HPP
-
-// IWYU pragma: private, include "kapi/acpi.hpp"
-
-#include "kapi/memory.hpp"
-
-#include <kstd/units>
-
-#include <array>
-#include <cstddef>
-#include <cstdint>
-#include <string_view>
-
-namespace kapi::acpi
-{
-
- //! @addtogroup kapi-acpi-kernel-defined
- //! @{
-
- //! A pointer to the Root System Description Table.
- struct [[gnu::packed]] root_system_description_pointer
- {
- //! Get the ID of the OEM, usually a vendor name.
- [[nodiscard]] auto oem_id() const noexcept -> std::string_view;
-
- //! Get the revision of the ACPI Root System Description Table.
- //!
- //! @note Revisions greater or equal to two indicate that the system uses the Extended System Description Table, and
- //! as such that table should be use to query information.
- [[nodiscard]] auto revision() const noexcept -> std::uint8_t;
-
- //! Get the signature of this pointer.
- //!
- //! A valid RSDP must always carry the signature "RSD PTR ".
- [[nodiscard]] auto signature() const noexcept -> std::string_view;
-
- //! Get the physical address of the pointed-to Root System Description Table.
- [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
-
- //! Validate the checksum of this RSDP.
- //!
- //! @return @p true iff. the checksum of this RSDP is valid, @p false otherwise.
- [[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;
- };
-
- //! A pointer to the Extended System Description Table.
- struct [[gnu::packed]] extended_system_description_pointer : root_system_description_pointer
- {
- //! Get the length of the data contained in this pointer.
- [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
-
- //! Get the address of the pointed-to Extended System Description Table.
- [[nodiscard]] auto table_address() const noexcept -> memory::physical_address;
-
- //! Validate the checksum of this XSDP.
- //!
- //! @return @p true iff. the checksum of this RSDP is valid, @p false otherwise.
- [[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;
- };
-
- //! @}
-
-} // namespace kapi::acpi
-
-#endif
diff --git a/kapi/include/kapi/acpi/system_description_table_header.hpp b/kapi/include/kapi/acpi/system_description_table_header.hpp
deleted file mode 100644
index b336ea1..0000000
--- a/kapi/include/kapi/acpi/system_description_table_header.hpp
+++ /dev/null
@@ -1,76 +0,0 @@
-#ifndef TEACHOS_KAPI_ACPI_SYSTEM_DESCRIPTION_TABLE_HEADER_HPP
-#define TEACHOS_KAPI_ACPI_SYSTEM_DESCRIPTION_TABLE_HEADER_HPP
-
-// IWYU pragma: private, include "kapi/acpi.hpp"
-
-#include "kapi/acpi/table_type.hpp"
-
-#include <kstd/units>
-
-#include <array>
-#include <cstdint>
-#include <string_view>
-
-namespace kapi::acpi
-{
-
- //! @addtogroup kapi-acpi-kernel-defined
- //! @{
-
- //! The common header of all System Description Tables.
- struct [[gnu::packed]] system_description_table_header
- {
- //! Get the revision of the utility used to create this table.
- [[nodiscard]] auto creator_revision() const noexcept -> std::uint32_t;
-
- //! Get the vendor ID of the utility used to create this table.
- [[nodiscard]] auto creator_id() const noexcept -> std::uint32_t;
-
- //! Get the length of the entire table, including this header.
- [[nodiscard]] auto length() const noexcept -> kstd::units::bytes;
-
- //! Get the ID of the OEM.
- [[nodiscard]] auto oem_id() const noexcept -> std::string_view;
-
- //! Get the OEMs revision number of this table.
- [[nodiscard]] auto oem_revision() const noexcept -> std::uint32_t;
-
- //! Get the OEMs ID of this table.
- [[nodiscard]] auto oem_table_id() const noexcept -> std::string_view;
-
- //! Get the revision number of the structure of this table.
- [[nodiscard]] auto revision() const noexcept -> std::uint8_t;
-
- //! Get the signature of this table.
- [[nodiscard]] auto signature() const noexcept -> std::string_view;
-
- private:
- std::array<char, 4> m_signature;
- std::uint32_t m_length;
- std::uint8_t m_revision;
- [[maybe_unused]] std::uint8_t m_checksum;
- std::array<char, 6> m_oem_id;
- std::array<char, 8> m_oem_table_id;
- std::uint32_t m_oem_revision;
- std::uint32_t m_creator_id;
- std::uint32_t m_creator_revision;
- };
-
- //! @}
- //
- //! @addtogroup kapi-acpi
- //! @{
-
- constexpr char const rsdt_table_signature[] = "RSDT"; // NOLINT
-
- template<>
- struct table_type<rsdt_table_signature>
- {
- using type = system_description_table_header;
- };
-
- //! @}
-
-} // namespace kapi::acpi
-
-#endif
diff --git a/kapi/include/kapi/acpi/table_iterator.hpp b/kapi/include/kapi/acpi/table_iterator.hpp
deleted file mode 100644
index 998d6d6..0000000
--- a/kapi/include/kapi/acpi/table_iterator.hpp
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef TEACHOS_KAPI_ACPI_TABLE_ITERATOR_HPP
-#define TEACHOS_KAPI_ACPI_TABLE_ITERATOR_HPP
-
-#include <bit>
-#include <cstddef>
-#include <iterator>
-
-namespace kapi::acpi
-{
-
- template<typename EntryType>
- struct table_iterator
- {
- using iterator_category = std::forward_iterator_tag;
- using value_type = EntryType;
- using pointer = value_type *;
- using reference = value_type &;
- using difference_type = std::ptrdiff_t;
-
- constexpr table_iterator() noexcept = default;
-
- constexpr table_iterator(pointer entry, pointer limit) noexcept
- : m_entry{entry}
- , m_limit{limit}
- {}
-
- constexpr auto operator++() noexcept -> table_iterator &
- {
- auto decayed = std::bit_cast<std::byte *>(m_entry);
- decayed += m_entry->length();
- m_entry = std::bit_cast<pointer>(decayed);
- return *this;
- }
-
- constexpr auto operator++(int) noexcept -> table_iterator
- {
- auto copy = *this;
- ++*this;
- return copy;
- }
-
- constexpr auto operator*() const noexcept -> reference
- {
- return *m_entry;
- }
-
- constexpr auto operator==(table_iterator const & other) const noexcept -> bool
- {
- return m_entry == other.m_entry || (is_end() && other.is_end());
- }
-
- private:
- [[nodiscard]] constexpr auto is_end() const noexcept -> bool
- {
- return m_entry == m_limit;
- }
-
- pointer m_entry{};
- pointer m_limit{};
- };
-
-} // namespace kapi::acpi
-
-#endif
diff --git a/kapi/include/kapi/acpi/table_type.hpp b/kapi/include/kapi/acpi/table_type.hpp
deleted file mode 100644
index e088a24..0000000
--- a/kapi/include/kapi/acpi/table_type.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef TEACHOS_KAPI_ACPI_TABLE_TYPE_HPP
-#define TEACHOS_KAPI_ACPI_TABLE_TYPE_HPP
-
-// IWYU pragma: private
-
-namespace kapi::acpi
-{
-
- //! @addtogroup kapi-acpi-kernel-defined
- //! @{
-
- template<char const *>
- struct table_type;
-
- template<char const * Signature>
- using table_type_t = typename table_type<Signature>::type;
-
- //! @}
-
-} // namespace kapi::acpi
-
-#endif