aboutsummaryrefslogtreecommitdiff
path: root/kapi
diff options
context:
space:
mode:
authorFelix Morgner <felix.morgner@ost.ch>2026-07-16 21:55:48 +0200
committerFelix Morgner <felix.morgner@ost.ch>2026-07-16 21:55:48 +0200
commit14685093004d767669fcfecaad875f7ab2aae76d (patch)
treea54cd8612d0c31007565d6a92edc4a2fd13e5e60 /kapi
parent9589e79e9990054e8bba08f183dd7b72819d6078 (diff)
downloadkernel-14685093004d767669fcfecaad875f7ab2aae76d.tar.xz
kernel-14685093004d767669fcfecaad875f7ab2aae76d.zip
kapi: add character device capability
Diffstat (limited to 'kapi')
-rw-r--r--kapi/kapi/devices.hpp1
-rw-r--r--kapi/kapi/devices/block_device.hpp4
-rw-r--r--kapi/kapi/devices/character_device.hpp39
3 files changed, 42 insertions, 2 deletions
diff --git a/kapi/kapi/devices.hpp b/kapi/kapi/devices.hpp
index 989ca0fa..e86e9ee7 100644
--- a/kapi/kapi/devices.hpp
+++ b/kapi/kapi/devices.hpp
@@ -3,6 +3,7 @@
#include <kapi/devices/block_device.hpp> // IWYU pragma: export
#include <kapi/devices/bus.hpp> // IWYU pragma: export
+#include <kapi/devices/character_device.hpp> // IWYU pragma: export
#include <kapi/devices/cpu.hpp> // IWYU pragma: export
#include <kapi/devices/device.hpp> // IWYU pragma: export
#include <kapi/devices/interface.hpp> // IWYU pragma: export
diff --git a/kapi/kapi/devices/block_device.hpp b/kapi/kapi/devices/block_device.hpp
index 4b3eab61..dfd08899 100644
--- a/kapi/kapi/devices/block_device.hpp
+++ b/kapi/kapi/devices/block_device.hpp
@@ -1,5 +1,5 @@
-#ifndef TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP
-#define TEACHOS_KAPI_DEVICES_BLOCK_INTERFACE_HPP
+#ifndef TEACHOS_KAPI_DEVICES_BLOCK_DEVICE_HPP
+#define TEACHOS_KAPI_DEVICES_BLOCK_DEVICE_HPP
// IWYU pragma: private, include <kapi/devices.hpp>
diff --git a/kapi/kapi/devices/character_device.hpp b/kapi/kapi/devices/character_device.hpp
new file mode 100644
index 00000000..7e7e8d6d
--- /dev/null
+++ b/kapi/kapi/devices/character_device.hpp
@@ -0,0 +1,39 @@
+#ifndef TEACHOS_KAPI_DEVICES_CHARACTER_DEVICE_HPP
+#define TEACHOS_KAPI_DEVICES_CHARACTER_DEVICE_HPP
+
+// IWYU pragma: private, include <kapi/devices.hpp>
+
+#include <kapi/devices/interface.hpp>
+
+#include <kstd/result.hpp>
+#include <kstd/units.hpp>
+
+#include <cstddef>
+#include <span>
+
+namespace kapi::devices
+{
+
+ struct character_device
+ {
+ constexpr auto static id = interface{"char"};
+
+ //! Virtual destructor to enable clean deletes through base pointers.
+ virtual ~character_device() = default;
+
+ //! Read data from the stream into a given buffer.
+ //!
+ //! @param buffer The buffer to read into.
+ //! @return The number of bytes read on success, an error otherwise.
+ [[nodiscard]] auto virtual read(std::span<std::byte> buffer) const -> kstd::result<kstd::units::bytes> = 0;
+
+ //! Write data from a buffer into the stream.
+ //!
+ //! @param buffer The buffer to write from.
+ //! @return The number of bytes written on success, an error otherwise.
+ auto virtual write_block(std::span<std::byte const> buffer) -> kstd::result<kstd::units::bytes> = 0;
+ };
+
+} // namespace kapi::devices
+
+#endif \ No newline at end of file