diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-04-06 18:13:21 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-04-06 18:13:21 +0200 |
| commit | 8d08b3b905d211e989848e1abf3a8ff2535836c8 (patch) | |
| tree | 4bccad5a277a841d970929d70024a6f552468bcd /kapi | |
| parent | f456f1674d48932846eb7b5ec1df630ad67e7e3d (diff) | |
| download | teachos-8d08b3b905d211e989848e1abf3a8ff2535836c8.tar.xz teachos-8d08b3b905d211e989848e1abf3a8ff2535836c8.zip | |
kapi: extract more code to the kernel
Diffstat (limited to 'kapi')
| -rw-r--r-- | kapi/include/kapi/devices/bus.hpp | 54 | ||||
| -rw-r--r-- | kapi/include/kapi/devices/device.hpp | 28 |
2 files changed, 12 insertions, 70 deletions
diff --git a/kapi/include/kapi/devices/bus.hpp b/kapi/include/kapi/devices/bus.hpp index a384291..7b2d41f 100644 --- a/kapi/include/kapi/devices/bus.hpp +++ b/kapi/include/kapi/devices/bus.hpp @@ -4,23 +4,19 @@ // IWYU pragma: private, include "kapi/devices.hpp" #include "kapi/devices/device.hpp" -#include "kapi/devices/manager.hpp" -#include "kapi/system.hpp" #include <kstd/memory> #include <kstd/print> #include <kstd/string> #include <kstd/vector> -#include <algorithm> #include <atomic> #include <cstddef> -#include <utility> namespace kapi::devices { - //! @addtogroup kapi-devices + //! @addtogroup kapi-devices-kernel-defined //! @{ //! A bus device that represents a logical/physical tree of devices and busses. @@ -31,65 +27,27 @@ namespace kapi::devices //! @param major The major number of the bus. //! @param minor The minor number of the bus. //! @param name The name of the bus. - bus(std::size_t major, std::size_t minor, kstd::string const & name) - : device(major, minor, name) - {} + bus(std::size_t major, std::size_t minor, kstd::string const & name); //! Initialize the bus and all of its children. //! //! @return true iff. the bus and all of its children are healthy, false otherwise. - auto init() -> bool final - { - if (m_initialized.test_and_set()) - { - return true; - } - - if (!probe()) - { - return false; - } - - return std::ranges::fold_left(m_devices, true, [&](bool acc, auto & child) -> bool { - kstd::println("[kAPI:BUS] Initializing child device {}@{}", child->name(), name()); - return child->init() && acc; - }); - } + auto init() -> bool final; //! Attach a child device to this bus. //! //! Whenever a device is attached to a bus, the bus takes sole ownership of the device. //! //! @param child The child device to attach. - auto add_child(kstd::unique_ptr<device> child) -> void - { - auto observer = m_observers.emplace_back(child.get()); - m_devices.push_back(std::move(child)); - kapi::devices::register_device(*observer); - - if (m_initialized.test()) - { - kstd::println("[kAPI:BUS] Initializing child device {}@{}", observer->name(), name()); - if (!observer->init()) - { - kapi::system::panic("[kAPI:BUS] Failed to initialize child device"); - } - } - } + auto add_child(kstd::unique_ptr<device> child) -> void; - [[nodiscard]] auto children() const -> kstd::vector<kstd::observer_ptr<device>> const & - { - return m_observers; - } + [[nodiscard]] auto children() const -> kstd::vector<kstd::observer_ptr<device>> const &; protected: //! Probe the bus hardware state. //! //! @return true iff. the bus hardware is healthy, false otherwise. - auto virtual probe() -> bool - { - return true; - } + auto virtual probe() -> bool; private: kstd::vector<kstd::unique_ptr<device>> m_devices; diff --git a/kapi/include/kapi/devices/device.hpp b/kapi/include/kapi/devices/device.hpp index ca5033e..b3647da 100644 --- a/kapi/include/kapi/devices/device.hpp +++ b/kapi/include/kapi/devices/device.hpp @@ -10,7 +10,7 @@ namespace kapi::devices { - //! @addtogroup kapi-devices + //! @addtogroup kapi-devices-kernel-defined //! @{ /** @@ -24,11 +24,7 @@ namespace kapi::devices * @param minor Device minor number. * @param name Device name. */ - device(size_t major, size_t minor, kstd::string const & name) - : m_major(major) - , m_minor(minor) - , m_name(name) - {} + device(size_t major, size_t minor, kstd::string const & name); /** * @brief Virtual destructor for device. @@ -45,37 +41,25 @@ namespace kapi::devices * @brief Returns the major number of the device. * @return Device major number. */ - [[nodiscard]] auto major() const -> size_t - { - return m_major; - } + [[nodiscard]] auto major() const -> size_t; /** * @brief Returns the minor number of the device. * @return Device minor number. */ - [[nodiscard]] auto minor() const -> size_t - { - return m_minor; - } + [[nodiscard]] auto minor() const -> size_t; /** * @brief Returns the name of the device. * @return Device name. */ - [[nodiscard]] auto name() const -> kstd::string const & - { - return m_name; - } + [[nodiscard]] auto name() const -> kstd::string const &; /** * @brief Check if the device is a block device. * @return true if this device is a block device, false otherwise. */ - [[nodiscard]] virtual auto is_block_device() const -> bool - { - return false; - } + [[nodiscard]] virtual auto is_block_device() const -> bool; private: size_t m_major; |
