From 9ded3a2bde80eede5fd887812d70c2f834b53c84 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 13 Apr 2021 22:09:23 +0200 Subject: Started IO dev manager --- kernel/features/io.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 kernel/features/io.c (limited to 'kernel/features/io.c') diff --git a/kernel/features/io.c b/kernel/features/io.c new file mode 100644 index 0000000..2bd925b --- /dev/null +++ b/kernel/features/io.c @@ -0,0 +1,67 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include +#include +#include +#include +#include +#include +#include + +PROTECTED static struct io_dev *io_mappings[IO_MAX] = { 0 }; + +static u8 io_type_valid(enum io_type io) +{ + return io > IO_MIN && io < IO_MAX; +} + +static struct io_dev *io_get(enum io_type io) +{ + if (!io_type_valid(io)) + return NULL; + + return io_mappings[io]; +} + +CLEAR void io_add(enum io_type io, struct io_dev *dev) +{ + assert(io_type_valid(io) && !io_mappings[io]); + io_mappings[io] = dev; +} + +res io_control(enum io_type io) +{ + if (!io_get(io)) + return -ENOENT; + + return -ENOENT; +} + +res io_write(enum io_type io, void *buf, u32 offset, u32 count) +{ + if (!memory_readable(buf)) + return -EFAULT; + + if (!io_get(io)) + return -ENOENT; +} + +res io_read(enum io_type io, void *buf, u32 offset, u32 count) +{ + if (!memory_readable(buf)) + return -EFAULT; + + if (!io_get(io)) + return -ENOENT; +} + +res io_poll(enum io_type io) +{ + if (!io_get(io)) + return -ENOENT; +} + +CLEAR void io_install(void) +{ + // TODO: Install I/O devices by selecting best working driver +} -- cgit v1.2.3