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 --- kapi/kapi/devices/driver_registry.hpp | 36 +++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'kapi') diff --git a/kapi/kapi/devices/driver_registry.hpp b/kapi/kapi/devices/driver_registry.hpp index 8af76b01..196b14c1 100644 --- a/kapi/kapi/devices/driver_registry.hpp +++ b/kapi/kapi/devices/driver_registry.hpp @@ -8,9 +8,45 @@ #include #include +#include + namespace kapi::devices { + //! @addtogroup kapi-devices + //! @{ + + struct driver_descriptor + { + virtual ~driver_descriptor() = default; + + //! Get the name of the driver + [[nodiscard]] virtual auto name() const noexcept -> std::string_view = 0; + + //! Create a new instance of the driver represented by this descriptor. + [[nodiscard]] virtual auto make_instance() const -> kstd::shared_ptr = 0; + }; + + template + struct kernel_driver + { + constexpr auto static instance = Type{}; + [[using gnu: section("kernel_drivers"), used, visibility("hidden")]] constexpr auto static pointer{ + kstd::make_observer(&instance), + }; + }; + + template + struct platform_driver + { + constexpr auto static instance = Type{}; + [[using gnu: section("platform_drivers"), used, visibility("hidden")]] constexpr auto static pointer{ + kstd::make_observer(&instance), + }; + }; + + //! @} + //! @addtogroup kapi-devices-kernel-defined //! @{ -- cgit v1.2.3