diff options
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; |
