diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-27 12:26:23 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-27 12:26:23 +0200 |
| commit | 1cad7524b291fd7a6f77e01bb90e763e6b557620 (patch) | |
| tree | d1271b3ddd94b32c2a2efbaaa6fde99c0f854afe /kernel/kapi/devices/device.cpp | |
| parent | 12002c540c9de2342d829c5b073c65cfb4549b35 (diff) | |
| download | kernel-1cad7524b291fd7a6f77e01bb90e763e6b557620.tar.xz kernel-1cad7524b291fd7a6f77e01bb90e763e6b557620.zip | |
kapi: add device resources
Diffstat (limited to 'kernel/kapi/devices/device.cpp')
| -rw-r--r-- | kernel/kapi/devices/device.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/kernel/kapi/devices/device.cpp b/kernel/kapi/devices/device.cpp index 9c2d8d40..a05a1653 100644 --- a/kernel/kapi/devices/device.cpp +++ b/kernel/kapi/devices/device.cpp @@ -2,10 +2,18 @@ #include <kapi/devices.hpp> #include <kapi/devices/bus.hpp> +#include <kapi/devices/resource.hpp> #include <kstd/memory.hpp> #include <kstd/mutex.hpp> +#include <kstd/result.hpp> #include <kstd/string.hpp> +#include <kstd/system_error.hpp> +#include <kstd/vector.hpp> + +#include <algorithm> +#include <cstddef> +#include <ranges> namespace kapi::devices { @@ -75,6 +83,36 @@ namespace kapi::devices m_driver_data = data; } + auto device::resources() const -> kstd::vector<resource> + { + auto guard = kstd::lock_guard{m_lock}; + return m_resources; + } + + auto device::request_resource(resource_type type, std::size_t index) const -> kstd::result<resource> + { + auto guard = kstd::lock_guard{m_lock}; + + auto numbered_resources = std::views::enumerate(m_resources); + auto found = std::ranges::find_if(numbered_resources, [&](auto entry) { + auto const & [number, resource] = entry; + return resource.type == type && static_cast<std::size_t>(number) == index; + }); + + if (found != numbered_resources.end()) + { + return kstd::success(*found.base()); + } + + return kstd::failure(make_error_code(kstd::errc::invalid_argument)); + } + + auto device::set_resources(kstd::vector<resource> resources) -> void + { + auto guard = kstd::lock_guard{m_lock}; + m_resources = resources; + } + auto device::query_facet(kapi::capabilities::facet_id) -> void * { return nullptr; |
