diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-25 23:39:23 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-25 23:39:23 +0200 |
| commit | b486b794abaf35b0b2376662173eb07549252cfc (patch) | |
| tree | 1a387cd16000c59a644fb80dd3ef91c37d220177 | |
| parent | 23e0b53bd8e40a8b69e30cd31eefc816b3c1af5d (diff) | |
| download | kernel-b486b794abaf35b0b2376662173eb07549252cfc.tar.xz kernel-b486b794abaf35b0b2376662173eb07549252cfc.zip | |
kapi: introduce the "bus" facet
| -rw-r--r-- | kapi/kapi/devices/bus.hpp | 11 | ||||
| -rw-r--r-- | kernel/kapi/devices/bus.cpp | 10 |
2 files changed, 21 insertions, 0 deletions
diff --git a/kapi/kapi/devices/bus.hpp b/kapi/kapi/devices/bus.hpp index af9f2c33..2a306031 100644 --- a/kapi/kapi/devices/bus.hpp +++ b/kapi/kapi/devices/bus.hpp @@ -4,6 +4,7 @@ // IWYU pragma: private, include <kapi/devices.hpp> #include <kapi/devices/device.hpp> +#include <kapi/devices/interface_id.hpp> #include <kstd/memory.hpp> #include <kstd/print.hpp> @@ -21,6 +22,9 @@ namespace kapi::devices //! A bus device that represents a logical/physical tree of devices and busses. struct bus : device { + //! The id of the bus facet. + constexpr auto static id = interface_id{"bus"}; + //! Construct a bus with the given name. //! //! @param name The name of the bus. @@ -33,6 +37,9 @@ namespace kapi::devices //! @param child The child device to attach. auto add_child(kstd::shared_ptr<device> child) -> void; + //! Get the children attached to this bus. + //! + //! @return A vector of all children attached to this bus. [[nodiscard]] auto children() const -> std::span<kstd::shared_ptr<device> const>; //! Get this bus's protocol facet, if present. @@ -40,6 +47,10 @@ namespace kapi::devices //! @return this bus's protocol facet if it has one, nullptr otherwise. [[nodiscard]] virtual auto protocol() -> struct bus_protocol *; + protected: + //! All busses have the "bus" facet. + auto query_interface(interface_id interface) -> void * override; + private: kstd::vector<kstd::shared_ptr<device>> m_devices; }; diff --git a/kernel/kapi/devices/bus.cpp b/kernel/kapi/devices/bus.cpp index 1b3ad4bf..a9bba4fb 100644 --- a/kernel/kapi/devices/bus.cpp +++ b/kernel/kapi/devices/bus.cpp @@ -42,4 +42,14 @@ namespace kapi::devices return nullptr; } + auto bus::query_interface(interface_id interface) -> void * + { + if (interface == bus::id) + { + return this; + } + + return device::query_interface(interface); + } + } // namespace kapi::devices
\ No newline at end of file |
