diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-25 00:29:35 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-25 00:29:35 +0200 |
| commit | 906510c90750b09d5b05914f03f190c14460e03e (patch) | |
| tree | a2fd68da5b60cd16256c7d818b8a0204d7659bbd | |
| parent | 36b6b74679833866837d7bc412ba81ebd2c86136 (diff) | |
| download | kernel-906510c90750b09d5b05914f03f190c14460e03e.tar.xz kernel-906510c90750b09d5b05914f03f190c14460e03e.zip | |
chore: hide protocol implementations
| -rw-r--r-- | arch/x86_64/arch/bus/isa.cpp | 58 | ||||
| -rw-r--r-- | arch/x86_64/arch/bus/isa.hpp | 10 | ||||
| -rw-r--r-- | kernel/kernel/bus/boot_modules.cpp | 68 | ||||
| -rw-r--r-- | kernel/kernel/bus/boot_modules.hpp | 7 |
4 files changed, 74 insertions, 69 deletions
diff --git a/arch/x86_64/arch/bus/isa.cpp b/arch/x86_64/arch/bus/isa.cpp index f0ed02f4..ee195519 100644 --- a/arch/x86_64/arch/bus/isa.cpp +++ b/arch/x86_64/arch/bus/isa.cpp @@ -10,37 +10,43 @@ namespace arch::bus { - isa::isa() - : kapi::devices::bus{"isa"} - {} - - auto isa::enumerate(kapi::devices::bus &) -> void - { - // NOTE: ISA does not support enumeration, but we need to fulfill the interface. - } - - auto isa::match(kapi::devices::device const & device, kapi::devices::driver const & driver) const - -> kstd::result<std::uint32_t> + namespace { - auto device_signature = device.as<isa_signature>(); - auto driver_claim = driver.as<isa_claim>(); - - if (!device_signature || !driver_claim) - { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } - - if (!std::ranges::contains(driver_claim->supported_names(), device_signature->isa_name())) + struct isa_protocol final : kapi::devices::bus_protocol { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } + auto enumerate(kapi::devices::bus &) -> void override + { + // NOTE: ISA does not support enumeration, but we need to fulfill the interface. + } + + [[nodiscard]] auto match(kapi::devices::device const & device, kapi::devices::driver const & driver) const + -> kstd::result<std::uint32_t> override + { + auto device_signature = device.as<isa_signature>(); + auto driver_claim = driver.as<isa_claim>(); + + if (!device_signature || !driver_claim) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } + + if (!std::ranges::contains(driver_claim->supported_names(), device_signature->isa_name())) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } + + return 0u; + } + } constinit protocol_instance; + } // namespace - return 0u; - } + isa::isa() + : kapi::devices::bus{"isa"} + {} - auto isa::protocol() -> isa * + auto isa::protocol() -> kapi::devices::bus_protocol * { - return this; + return &protocol_instance; } } // namespace arch::bus
\ No newline at end of file diff --git a/arch/x86_64/arch/bus/isa.hpp b/arch/x86_64/arch/bus/isa.hpp index 58bc042f..87832c3c 100644 --- a/arch/x86_64/arch/bus/isa.hpp +++ b/arch/x86_64/arch/bus/isa.hpp @@ -5,7 +5,6 @@ #include <kstd/result.hpp> -#include <cstdint> #include <span> #include <string_view> @@ -39,17 +38,12 @@ namespace arch::bus }; //! The ISA bus. - struct isa final : public kapi::devices::bus, kapi::devices::bus_protocol + struct isa final : public kapi::devices::bus { //! Construct a default ISA bus. isa(); - auto enumerate(kapi::devices::bus & self) -> void override; - - [[nodiscard]] auto match(kapi::devices::device const & device, kapi::devices::driver const & driver) const - -> kstd::result<std::uint32_t> override; - - [[nodiscard]] auto protocol() -> isa * override; + [[nodiscard]] auto protocol() -> kapi::devices::bus_protocol * override; }; } // namespace arch::bus diff --git a/kernel/kernel/bus/boot_modules.cpp b/kernel/kernel/bus/boot_modules.cpp index ac5a2068..069d414f 100644 --- a/kernel/kernel/bus/boot_modules.cpp +++ b/kernel/kernel/bus/boot_modules.cpp @@ -11,50 +11,60 @@ namespace kernel::bus { - auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool + namespace { - for (auto token : std::views::split(cmdline, ' ')) + auto has_parameter(std::string_view cmdline, std::string_view key, std::string_view value) -> bool { - 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) + for (auto token : std::views::split(cmdline, ' ')) { - return true; + 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; } - return false; - } - boot_modules::boot_modules() - : kapi::devices::bus{"boot_modules"} - {} + struct boot_modules_protocol : kapi::devices::bus_protocol + { + auto enumerate(kapi::devices::bus &) -> void override + { + // The boot modules virtual bus does not support enumeration. + } - auto boot_modules::enumerate(kapi::devices::bus &) -> void {} + [[nodiscard]] auto match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const + -> kstd::result<unsigned> override + { + auto signature = dev.as<kapi::boot_modules::boot_module_signature>(); + auto claim = drv.as<kapi::boot_modules::boot_module_claim>(); - auto boot_modules::match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const - -> kstd::result<unsigned> - { - auto signature = dev.as<kapi::boot_modules::boot_module_signature>(); - auto claim = drv.as<kapi::boot_modules::boot_module_claim>(); + if (!signature || !claim) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } - if (!signature || !claim) - { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } + auto const [key, value] = claim->parameter(); - auto const [key, value] = claim->parameter(); + if (!has_parameter(signature->command_line(), key, value)) + { + return kstd::failure(kapi::devices::driver_match_errc::no_match); + } - if (!has_parameter(signature->command_line(), key, value)) - { - return kstd::failure(kapi::devices::driver_match_errc::no_match); - } + return 0u; + } - return 0u; - } + } constinit protocol_instance; + } // namespace + + boot_modules::boot_modules() + : kapi::devices::bus{"boot_modules"} + {} auto boot_modules::protocol() -> kapi::devices::bus_protocol * { - return this; + return &protocol_instance; } } // namespace kernel::bus diff --git a/kernel/kernel/bus/boot_modules.hpp b/kernel/kernel/bus/boot_modules.hpp index 147cfdf2..c73e0d74 100644 --- a/kernel/kernel/bus/boot_modules.hpp +++ b/kernel/kernel/bus/boot_modules.hpp @@ -11,15 +11,10 @@ namespace kernel::bus //! The boot modules bus. //! //! Boot modules used to back devices may be attached to this bus. - struct boot_modules final : kapi::devices::bus, kapi::devices::bus_protocol + struct boot_modules final : kapi::devices::bus { boot_modules(); - auto enumerate(kapi::devices::bus & self) -> void override; - - [[nodiscard]] auto match(kapi::devices::device const & dev, kapi::devices::driver const & drv) const - -> kstd::result<unsigned> override; - [[nodiscard]] auto protocol() -> kapi::devices::bus_protocol * override; }; |
