diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-07-23 18:52:24 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-07-23 18:52:24 +0200 |
| commit | cb87b4dd8e874d5d7b219487ca38f55756c205df (patch) | |
| tree | 708c018ecf05db1565433b17c69cc40dc4e96680 /kernel | |
| parent | 969c2018d2d3741022818e3bc326b57162748053 (diff) | |
| download | kernel-cb87b4dd8e874d5d7b219487ca38f55756c205df.tar.xz kernel-cb87b4dd8e874d5d7b219487ca38f55756c205df.zip | |
kapi: introduce driver and bus protocol
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | kernel/kapi/devices/driver.cpp | 19 | ||||
| -rw-r--r-- | kernel/kapi/devices/error.cpp | 48 |
3 files changed, 69 insertions, 0 deletions
diff --git a/kernel/CMakeLists.txt b/kernel/CMakeLists.txt index 9d3a83e2..72994449 100644 --- a/kernel/CMakeLists.txt +++ b/kernel/CMakeLists.txt @@ -15,6 +15,8 @@ target_sources("kernel_lib" PRIVATE "kapi/devices/bus.cpp" "kapi/devices/cpu.cpp" "kapi/devices/device.cpp" + "kapi/devices/driver.cpp" + "kapi/devices/error.cpp" "kapi/devices/interface_registry.cpp" "kapi/filesystem.cpp" "kapi/interrupts.cpp" diff --git a/kernel/kapi/devices/driver.cpp b/kernel/kapi/devices/driver.cpp new file mode 100644 index 00000000..c6b5e056 --- /dev/null +++ b/kernel/kapi/devices/driver.cpp @@ -0,0 +1,19 @@ +#include <kapi/devices.hpp> + +#include <cstdint> +#include <optional> + +namespace kapi::devices +{ + + auto driver::claimed_major() const -> std::optional<std::uint8_t> + { + return std::nullopt; + } + + auto driver::query_interface(interface) -> void * + { + return nullptr; + } + +} // namespace kapi::devices diff --git a/kernel/kapi/devices/error.cpp b/kernel/kapi/devices/error.cpp new file mode 100644 index 00000000..9d814fbe --- /dev/null +++ b/kernel/kapi/devices/error.cpp @@ -0,0 +1,48 @@ +#include <kapi/devices/error.hpp> + +#include <kstd/system_error.hpp> + +#include <string_view> +#include <utility> + +namespace kapi::devices +{ + + namespace + { + struct driver_match_category_t final : kstd::error_category + { + [[nodiscard]] auto name() const noexcept -> std::string_view override + { + return "driver_match"; + } + + [[nodiscard]] auto message(int value) const noexcept -> std::string_view override + { + switch (static_cast<driver_match_errc>(value)) + { + case driver_match_errc::no_match: + return "driver does not match this device"; + default: + return "unknown driver matching error"; + } + } + + [[nodiscard]] auto default_error_condition(int value) const noexcept -> kstd::error_condition override + { + if (value == std::to_underlying(driver_match_errc::no_match)) + { + return make_error_condition(kstd::errc::not_supported); + } + return kstd::error_category::default_error_condition(value); + } + + } constexpr driver_match_category_instance{}; + } // namespace + + auto driver_match_category() noexcept -> kstd::error_category const & + { + return driver_match_category_instance; + } + +} // namespace kapi::devices
\ No newline at end of file |
