aboutsummaryrefslogtreecommitdiff
path: root/kernel/kapi
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/kapi')
-rw-r--r--kernel/kapi/boot_module/bus.cpp97
-rw-r--r--kernel/kapi/boot_module/registry.cpp131
-rw-r--r--kernel/kapi/boot_modules/device.cpp39
3 files changed, 39 insertions, 228 deletions
diff --git a/kernel/kapi/boot_module/bus.cpp b/kernel/kapi/boot_module/bus.cpp
deleted file mode 100644
index 17052629..00000000
--- a/kernel/kapi/boot_module/bus.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-#include <kapi/boot_modules/bus.hpp>
-
-#include <kapi/boot_modules.hpp>
-#include <kapi/devices.hpp>
-
-#include <kstd/format.hpp>
-#include <kstd/memory.hpp>
-#include <kstd/result.hpp>
-#include <kstd/string.hpp>
-
-#include <cstddef>
-#include <ranges>
-#include <string_view>
-
-namespace kapi::boot_modules
-{
- auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool
- {
- for (auto token : std::views::split(cmdline, ' '))
- {
- auto const text = std::string_view{token};
- auto const equals = text.find('=');
- if (equals != std::string_view::npos && text.substr(0, equals) == key && text.substr(equals + 1) == value)
- {
- return true;
- }
- }
- return false;
- }
-
- boot_module_device::boot_module_device(std::size_t index, struct module const & module)
- : kapi::devices::device{kstd::format("boot_module{}", index)}
- , m_module(module)
- {}
-
- auto boot_module_device::command_line() const -> std::string_view
- {
- return m_module.name;
- }
-
- auto boot_module_device::module() const -> boot_modules::module const &
- {
- return m_module;
- }
-
- auto boot_module_device::query_interface(kapi::devices::interface_id interface) -> void *
- {
- if (interface == boot_module_identification::id)
- {
- return static_cast<boot_module_identification *>(this);
- }
-
- return kapi::devices::device::query_interface(interface);
- }
-
- boot_module_bus::boot_module_bus(registry const * registry)
- : kapi::devices::bus{"boot_modules"}
- , m_registry(registry)
- {}
-
- auto boot_module_bus::enumerate(kapi::devices::bus & self) -> void
- {
- std::size_t index = 0;
-
- for (auto const & module : *m_registry)
- {
- self.add_child(kstd::make_shared<boot_module_device>(index++, module));
- }
- }
-
- auto boot_module_bus::match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const
- -> kstd::result<unsigned>
- {
- auto const * ident = dev.as<boot_module_identification>();
- auto const * claims = drv.as<boot_module_driver_identification>();
-
- if (!ident || !claims)
- {
- return kstd::failure(kapi::devices::driver_match_errc::no_match);
- }
-
- auto const [key, value] = claims->claimed_parameter();
-
- if (!has_parameter(ident->command_line(), key, value))
- {
- return kstd::failure(kapi::devices::driver_match_errc::no_match);
- }
-
- return 0u;
- }
-
- auto boot_module_bus::protocol() -> kapi::devices::bus_protocol *
- {
- return this;
- }
-
-} // namespace kapi::boot_modules
diff --git a/kernel/kapi/boot_module/registry.cpp b/kernel/kapi/boot_module/registry.cpp
deleted file mode 100644
index 9876866b..00000000
--- a/kernel/kapi/boot_module/registry.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-#include <kapi/boot_modules/registry.hpp>
-
-#include <kapi/boot_modules.hpp>
-#include <kapi/system.hpp>
-#include <kapi/test_support/boot_modules.hpp>
-
-#include <cstddef>
-#include <optional>
-#include <utility>
-
-namespace kapi::boot_modules
-{
-
- namespace
- {
- constinit auto instance = std::optional<registry>{};
- }
-
- auto registry::init() -> void
- {
- if (instance)
- {
- system::panic("[OS] Boot module registry has already been initialized.");
- }
-
- instance.emplace();
- }
-
- auto registry::get() -> registry &
- {
- if (!instance)
- {
- system::panic("[OS] Boot module registry has not been initialized.");
- }
-
- return *instance;
- }
-
- auto registry::begin() const noexcept -> const_iterator
- {
- return m_modules.begin();
- }
-
- auto registry::end() const noexcept -> const_iterator
- {
- return m_modules.end();
- }
-
- auto registry::cbegin() const noexcept -> const_iterator
- {
- return m_modules.cbegin();
- }
-
- auto registry::cend() const noexcept -> const_iterator
- {
- return m_modules.cend();
- }
-
- auto registry::rbegin() const noexcept -> const_reverse_iterator
- {
- return m_modules.rbegin();
- }
-
- auto registry::rend() const noexcept -> const_reverse_iterator
- {
- return m_modules.rend();
- }
-
- auto registry::crbegin() const noexcept -> const_reverse_iterator
- {
- return m_modules.crbegin();
- }
-
- auto registry::crend() const noexcept -> const_reverse_iterator
- {
- return m_modules.crend();
- }
-
- auto registry::front() const noexcept -> const_reference
- {
- return m_modules.front();
- }
-
- auto registry::back() const noexcept -> const_reference
- {
- return m_modules.back();
- }
-
- auto registry::size() const noexcept -> std::size_t
- {
- return m_modules.size();
- }
-
- auto registry::empty() const noexcept -> bool
- {
- return m_modules.empty();
- }
-
- auto registry::at(std::size_t index) const -> const_reference
- {
- return m_modules.at(index);
- }
-
- auto registry::operator[](std::size_t index) const noexcept -> const_reference
- {
- return m_modules[index];
- }
-
- auto registry::add(module module) -> void
- {
- m_modules.push_back(module);
- }
-
-} // namespace kapi::boot_modules
-
-namespace kapi::test_support::boot_modules
-{
-
- auto deinit_registry() -> void
- {
- kapi::boot_modules::instance.reset();
- }
-
- auto inject_registry(kapi::boot_modules::registry && registry) -> std::optional<kapi::boot_modules::registry>
- {
- auto old = std::move(kapi::boot_modules::instance);
- kapi::boot_modules::instance.emplace(std::move(registry));
- return old;
- }
-
-} // namespace kapi::test_support::boot_modules
diff --git a/kernel/kapi/boot_modules/device.cpp b/kernel/kapi/boot_modules/device.cpp
new file mode 100644
index 00000000..84a43c1c
--- /dev/null
+++ b/kernel/kapi/boot_modules/device.cpp
@@ -0,0 +1,39 @@
+#include <kapi/boot_modules/device.hpp>
+
+#include <kapi/boot_modules/module.hpp>
+#include <kapi/devices.hpp>
+
+#include <kstd/format.hpp>
+
+#include <cstddef>
+#include <string_view>
+
+namespace kapi::boot_modules
+{
+
+ device::device(std::size_t index, kapi::boot_modules::module const & module)
+ : kapi::devices::device{kstd::format("device{}", index)}
+ , m_module(module)
+ {}
+
+ auto device::command_line() const -> std::string_view
+ {
+ return m_module.name;
+ }
+
+ auto device::module() const -> boot_modules::module const &
+ {
+ return m_module;
+ }
+
+ auto device::query_interface(kapi::devices::interface_id interface) -> void *
+ {
+ if (interface == boot_module_signature::id)
+ {
+ return static_cast<boot_module_signature *>(this);
+ }
+
+ return kapi::devices::device::query_interface(interface);
+ }
+
+} // namespace kapi::boot_modules \ No newline at end of file