From 5ce5c28e0f0f034cb7c704f08e59089ef303ff7e Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 1 Aug 2026 00:33:56 +0200 Subject: kapi: add automatic driver registration --- arch/x86_64/kapi/devices.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'arch/x86_64/kapi/devices.cpp') diff --git a/arch/x86_64/kapi/devices.cpp b/arch/x86_64/kapi/devices.cpp index d9a0b2b9..888b6e20 100644 --- a/arch/x86_64/kapi/devices.cpp +++ b/arch/x86_64/kapi/devices.cpp @@ -2,11 +2,15 @@ #include #include -#include +#include #include #include +#include + +#include +#include namespace kapi::devices { @@ -16,9 +20,27 @@ namespace kapi::devices auto static constinit cpu_bus = kstd::shared_ptr{}; } + extern "C" + { + // We need to suppress clang-tidy linting warnings here, since these symbols are generated by the linker and we + // cannot choose their names, unless we wanted to extend the linker script needlessly. + // NOLINTBEGIN(readability-identifier-naming) + extern kstd::observer_ptr const __start_platform_drivers; + extern kstd::observer_ptr const __stop_platform_drivers; + // NOLINTEND(readability-identifier-naming) + } + auto init_platform_drivers() -> void { - arch::drivers::init_legacy_drivers(); + auto descriptors = std::span{&__start_platform_drivers, &__stop_platform_drivers} | // + std::views::filter([](auto p) { return p != nullptr; }); + + for (auto driver : descriptors) + { + auto instance = driver->make_instance(); + kstd::println("[x86_64:DRV] registering driver '{}' ({})", instance->name(), driver->name()); + kapi::devices::driver_registry::get().add(driver->make_instance()); + } } auto init_platform_devices() -> void -- cgit v1.2.3