From 02a0c882275959c0fbd58754418ecc1218821e76 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Fri, 18 Jun 2021 22:30:25 +0200 Subject: Renamed device prefix from 'io_' to 'dev_' --- kernel/Makefile | 2 +- kernel/drivers/bga.c | 8 +- kernel/drivers/ps2/keyboard.c | 8 +- kernel/drivers/ps2/mouse.c | 8 +- kernel/drivers/timer.c | 6 +- kernel/drivers/vbe.c | 8 +- kernel/drivers/vmware.c | 8 +- kernel/features/bus.c | 29 +++-- kernel/features/dev.c | 244 ++++++++++++++++++++++++++++++++++++++++++ kernel/features/io.c | 244 ------------------------------------------ kernel/features/logger.c | 6 +- kernel/features/syscall.c | 26 ++--- kernel/inc/dev.h | 32 ++++++ kernel/inc/fs.h | 4 +- kernel/inc/io.h | 32 ------ kernel/main.c | 4 +- 16 files changed, 334 insertions(+), 335 deletions(-) create mode 100644 kernel/features/dev.c delete mode 100644 kernel/features/io.c create mode 100644 kernel/inc/dev.h delete mode 100644 kernel/inc/io.h (limited to 'kernel') diff --git a/kernel/Makefile b/kernel/Makefile index 7107e14..9fed3f1 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -22,7 +22,7 @@ COBJS = entry_asm.o \ drivers/ps2/keyboard.o \ features/mm.o \ features/fs.o \ - features/io.o \ + features/dev.o \ features/bus.o \ features/fb.o \ features/logger.o \ diff --git a/kernel/drivers/bga.c b/kernel/drivers/bga.c index 2f3b1fa..cc93b75 100644 --- a/kernel/drivers/bga.c +++ b/kernel/drivers/bga.c @@ -2,11 +2,11 @@ #include #include +#include #include #include #include #include -#include #include #include @@ -75,7 +75,7 @@ static res bga_control(u32 request, void *arg1, void *arg2, void *arg3) UNUSED(arg3); switch (request) { - case IOCTL_FB_GET: { + case DEVCTL_FB_GET: { if (!generic.fb) return -ENOENT; @@ -121,7 +121,7 @@ CLEAR void bga_install(void) { bga_enable(1920, 1200, 32); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->control = bga_control; - io_add(IO_FRAMEBUFFER, dev); + dev_add(DEV_FRAMEBUFFER, dev); } diff --git a/kernel/drivers/ps2/keyboard.c b/kernel/drivers/ps2/keyboard.c index 3516a7e..b16f4b2 100644 --- a/kernel/drivers/ps2/keyboard.c +++ b/kernel/drivers/ps2/keyboard.c @@ -1,11 +1,11 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include +#include #include #include #include #include -#include #include #include #include @@ -43,7 +43,7 @@ static void keyboard_handler(void) state = 0; merged = 0; - io_unblock(IO_KEYBOARD); + dev_unblock(DEV_KEYBOARD); } static res keyboard_read(void *buf, u32 offset, u32 count) @@ -75,8 +75,8 @@ CLEAR void ps2_keyboard_install(u8 device) int_event_handler_add(1, keyboard_handler); queue = stack_new(); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->read = keyboard_read; dev->ready = keyboard_ready; - io_add(IO_KEYBOARD, dev); + dev_add(DEV_KEYBOARD, dev); } diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c index ab20c90..086f522 100644 --- a/kernel/drivers/ps2/mouse.c +++ b/kernel/drivers/ps2/mouse.c @@ -1,11 +1,11 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include +#include #include #include #include #include -#include #include #include #include @@ -33,7 +33,7 @@ static void mouse_finish(void) event->but.middle = (mouse_byte[0] >> 2) & 1; stack_push_bot(queue, event); mouse_cycle = 0; - io_unblock(IO_MOUSE); + dev_unblock(DEV_MOUSE); } static void mouse_handler(void) @@ -141,8 +141,8 @@ CLEAR void ps2_mouse_install(u8 device) int_event_handler_add(12, mouse_handler); queue = stack_new(); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->read = mouse_read; dev->ready = mouse_ready; - io_add(IO_MOUSE, dev); + dev_add(DEV_MOUSE, dev); } diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 44d66f3..977647c 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -1,11 +1,11 @@ // MIT License, Copyright (c) 2020 Marvin Borner #include +#include #include #include #include #include -#include #include #include @@ -70,7 +70,7 @@ CLEAR void timer_install(void) timer_phase(1000); int_event_handler_add(0, timer_handler); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->read = timer_read; - io_add(IO_TIMER, dev); + dev_add(DEV_TIMER, dev); } diff --git a/kernel/drivers/vbe.c b/kernel/drivers/vbe.c index fd91062..2ba9fb1 100644 --- a/kernel/drivers/vbe.c +++ b/kernel/drivers/vbe.c @@ -2,11 +2,11 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -31,7 +31,7 @@ static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3) UNUSED(arg3); switch (request) { - case IOCTL_FB_GET: { + case DEVCTL_FB_GET: { if (!generic.fb) return -ENOENT; @@ -67,7 +67,7 @@ CLEAR void vbe_install(u32 data) generic.fb = vbe->fb; fb_protect(&generic); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->control = vbe_control; - io_add(IO_FRAMEBUFFER, dev); + dev_add(DEV_FRAMEBUFFER, dev); } diff --git a/kernel/drivers/vmware.c b/kernel/drivers/vmware.c index 24f56a0..b2069b6 100644 --- a/kernel/drivers/vmware.c +++ b/kernel/drivers/vmware.c @@ -2,10 +2,10 @@ // VMWare extensions/backdoors for better VM integration #include +#include #include #include #include -#include #include #include #include @@ -125,7 +125,7 @@ static void vmware_mouse_handler(void) event->but.right = (buttons & VMMOUSE_RIGHT_CLICK) != 0; event->but.middle = (buttons & VMMOUSE_MIDDLE_CLICK) != 0; stack_push_bot(queue, event); - io_unblock(IO_MOUSE); + dev_unblock(DEV_MOUSE); } static res vmware_mouse_ready(void) @@ -152,8 +152,8 @@ CLEAR void vmware_mouse_install(u8 device) int_event_handler_add(12, vmware_mouse_handler); queue = stack_new(); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->read = vmware_mouse_read; dev->ready = vmware_mouse_ready; - io_add(IO_MOUSE, dev); + dev_add(DEV_MOUSE, dev); } diff --git a/kernel/features/bus.c b/kernel/features/bus.c index 3757a3a..ad7352f 100644 --- a/kernel/features/bus.c +++ b/kernel/features/bus.c @@ -4,9 +4,9 @@ #include #include #include +#include #include #include -#include #include #include #include @@ -36,8 +36,8 @@ struct bus { u32 hash; }; -PROTECTED struct list *bus_list = NULL; -PROTECTED struct list *bus_conns = NULL; +PROTECTED static struct list *bus_list = NULL; +PROTECTED static struct list *bus_conns = NULL; static u32 conn_cnt = 1; // 0 is reserved static struct bus *bus_find_bus(u32 hash) @@ -104,7 +104,10 @@ static res bus_register(const char *name) u32 hash = crc32_user(0, name, len); if (bus_find_bus(hash)) - return -EBUSY; + return -EINVAL; + + if (bus_find_owner(proc_current()->pid)) + return -EEXIST; struct bus *bus = zalloc(sizeof(*bus)); strlcpy_user(bus->name, name, sizeof(bus->name)); @@ -182,10 +185,10 @@ static res bus_send(u32 conn, const void *buf, u32 count) if (bus->pid == proc_current()->pid) { stack_push_bot(bus_conn->out, msg); - io_unblock_pid(bus_conn->pid); + dev_unblock_pid(bus_conn->pid); } else { stack_push_bot(bus_conn->in, msg); - io_unblock_pid(bus->pid); + dev_unblock_pid(bus->pid); } return count; @@ -229,8 +232,6 @@ static res bus_receive(void *buf, u32 offset, u32 count) if (!bus_owner && !bus_conn) return -ENOENT; - // TODO: Better round-robin - if (bus_owner) { struct node *iterator = bus_conns->head; while (iterator) { @@ -257,13 +258,13 @@ static res bus_control(u32 request, void *arg1, void *arg2, void *arg3) UNUSED(arg3); switch (request) { - case IOCTL_BUS_CONNECT_BUS: { + case DEVCTL_BUS_CONNECT_BUS: { return bus_connect_bus(arg1, arg2); } - case IOCTL_BUS_CONNECT_CONN: { + case DEVCTL_BUS_CONNECT_CONN: { return bus_connect_conn((u32)arg1); } - case IOCTL_BUS_REGISTER: { + case DEVCTL_BUS_REGISTER: { return bus_register(arg1); } default: { @@ -307,8 +308,6 @@ static res bus_ready(void) if (!bus_owner && !bus_conn) return -ENOENT; - // TODO: Better round-robin - if (bus_owner) { struct node *iterator = bus_conns->head; while (iterator) { @@ -331,10 +330,10 @@ CLEAR void bus_install(void) bus_list = list_new(); bus_conns = list_new(); - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->control = bus_control; dev->read = bus_read; dev->ready = bus_ready; dev->write = bus_write; - io_add(IO_BUS, dev); + dev_add(DEV_BUS, dev); } diff --git a/kernel/features/dev.c b/kernel/features/dev.c new file mode 100644 index 0000000..ecc3f0c --- /dev/null +++ b/kernel/features/dev.c @@ -0,0 +1,244 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct dev_listener { + u32 group; + struct proc *proc; +}; + +PROTECTED static struct dev_dev *dev_mappings[DEV_MAX] = { 0 }; +PROTECTED static struct list *dev_listeners[DEV_MAX] = { 0 }; + +static u32 group_id = 0; + +static u8 dev_type_valid(enum dev_type type) +{ + return type > DEV_MIN && type < DEV_MAX; +} + +static struct dev_dev *dev_get(enum dev_type type) +{ + if (!dev_type_valid(type)) + return NULL; + + return dev_mappings[type]; +} + +// TODO: Efficiency +static void dev_remove_group(u32 group) +{ + for (u32 dev = DEV_MIN; dev < DEV_MAX; dev++) { + struct node *iterator = dev_listeners[dev]->head; + while (iterator) { + struct dev_listener *listener = iterator->data; + struct node *next = iterator->next; + if (listener->group == group) + list_remove(dev_listeners[dev], iterator); + iterator = next; + } + } + + if (group + 1 == group_id) + group_id--; +} + +CLEAR void dev_add(enum dev_type type, struct dev_dev *dev) +{ + assert(dev_type_valid(type) && !dev_mappings[type]); + dev_mappings[type] = dev; +} + +res dev_poll(u32 *devs) +{ + if (!memory_readable(devs)) + return -EFAULT; + + u32 group = group_id++; + + for (u32 *p = devs; p && memory_readable(p); p++) { + stac(); + enum dev_type type = *p; + clac(); + + if (!type) + break; + + struct dev_dev *dev = dev_get(type); + if (!dev || !dev->read) { + dev_remove_group(group); + return -ENOENT; + } + + if (dev->ready) { + res ready = dev->ready(); + if (ready == EOK) { + dev_remove_group(group); + return type; + } else if (ready != -EAGAIN) { + return ready; + } + } + + struct dev_listener *listener = zalloc(sizeof(*listener)); + listener->group = group; + listener->proc = proc_current(); + list_add(dev_listeners[type], listener); + } + + proc_state(proc_current(), PROC_BLOCKED); + proc_yield(); + return dev_poll(devs); +} + +res dev_control(enum dev_type type, u32 request, void *arg1, void *arg2, void *arg3) +{ + struct dev_dev *dev; + if (!(dev = dev_get(type)) || !dev->control) + return -ENOENT; + + return dev->control(request, arg1, arg2, arg3); +} + +res dev_write(enum dev_type type, const void *buf, u32 offset, u32 count) +{ + if (!memory_readable_range(memory_range(buf, count))) + return -EFAULT; + + struct dev_dev *dev; + if (!(dev = dev_get(type)) || !dev->write) + return -ENOENT; + + return dev->write(buf, offset, count); +} + +res dev_read(enum dev_type type, void *buf, u32 offset, u32 count) +{ + if (!memory_writable_range(memory_range(buf, count))) + return -EFAULT; + + struct dev_dev *dev; + if (!(dev = dev_get(type)) || !dev->read) + return -ENOENT; + + if (dev->ready && dev->ready() != EOK) + return -EAGAIN; + + return dev->read(buf, offset, count); +} + +res dev_ready(enum dev_type type) +{ + struct dev_dev *dev; + if (!(dev = dev_get(type))) + return -ENOENT; + + if (dev->ready && dev->ready() != EOK) + return -EAGAIN; + + return EOK; +} + +void dev_block(enum dev_type type, struct proc *proc) +{ + assert(dev_type_valid(type)); + struct dev_listener *listener = zalloc(sizeof(*listener)); + listener->group = group_id++; + listener->proc = proc; + list_add(dev_listeners[type], listener); + proc_state(proc_current(), PROC_BLOCKED); + proc_yield(); +} + +void dev_unblock(enum dev_type type) +{ + assert(dev_type_valid(type)); + struct node *iterator = dev_listeners[type]->head; + while (iterator) { + struct dev_listener *listener = iterator->data; + struct proc *proc = listener->proc; + proc_state(proc, PROC_RUNNING); + struct node *next = iterator->next; + dev_remove_group(listener->group); + free(listener); + iterator = next; + } + + if (proc_idle()) + proc_yield(); +} + +void dev_unblock_pid(u32 pid) +{ + for (u32 type = DEV_MIN; type < DEV_MAX; type++) { + struct node *iterator = dev_listeners[type]->head; + while (iterator) { + struct dev_listener *listener = iterator->data; + struct proc *proc = listener->proc; + proc_state(proc, PROC_RUNNING); + struct node *next = iterator->next; + if (proc->pid == pid) { + list_remove(dev_listeners[type], iterator); + free(listener); + } + iterator = next; + } + } + + if (proc_idle()) + proc_yield(); +} + +CLEAR void dev_install(void) +{ + for (u32 i = 0; i < DEV_MAX; i++) + dev_listeners[i] = list_new(); + + /** + * Keyboard & mouse detection + */ + + ps2_detect(); + + u8 ps2_keyboard = ps2_keyboard_detect(); + if (ps2_keyboard != U8_MAX) { + ps2_keyboard_install(ps2_keyboard); + } + + u8 ps2_mouse = ps2_mouse_detect(); + if (ps2_mouse != U8_MAX) { + if (vmware_detect() && vmware_mouse_detect()) + vmware_mouse_install(ps2_mouse); + else + ps2_mouse_install(ps2_mouse); + } + + /** + * Other devices + */ + + fb_install(); + timer_install(); + logger_install(); + bus_install(); +} diff --git a/kernel/features/io.c b/kernel/features/io.c deleted file mode 100644 index 8126ccf..0000000 --- a/kernel/features/io.c +++ /dev/null @@ -1,244 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -struct io_listener { - u32 group; - struct proc *proc; -}; - -PROTECTED static struct io_dev *io_mappings[IO_MAX] = { 0 }; -PROTECTED static struct list *io_listeners[IO_MAX] = { 0 }; - -static u32 group_id = 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]; -} - -// TODO: Efficiency -static void io_remove_group(u32 group) -{ - for (u32 io = IO_MIN; io < IO_MAX; io++) { - struct node *iterator = io_listeners[io]->head; - while (iterator) { - struct io_listener *listener = iterator->data; - struct node *next = iterator->next; - if (listener->group == group) - list_remove(io_listeners[io], iterator); - iterator = next; - } - } - - if (group + 1 == group_id) - group_id--; -} - -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_poll(u32 *devs) -{ - if (!memory_readable(devs)) - return -EFAULT; - - u32 group = group_id++; - - for (u32 *p = devs; p && memory_readable(p); p++) { - stac(); - enum io_type io = *p; - clac(); - - if (!io) - break; - - struct io_dev *dev = io_get(io); - if (!dev || !dev->read) { - io_remove_group(group); - return -ENOENT; - } - - if (dev->ready) { - res ready = dev->ready(); - if (ready == EOK) { - io_remove_group(group); - return io; - } else if (ready != -EAGAIN) { - return ready; - } - } - - struct io_listener *listener = zalloc(sizeof(*listener)); - listener->group = group; - listener->proc = proc_current(); - list_add(io_listeners[io], listener); - } - - proc_state(proc_current(), PROC_BLOCKED); - proc_yield(); - return io_poll(devs); -} - -res io_control(enum io_type io, u32 request, void *arg1, void *arg2, void *arg3) -{ - struct io_dev *dev; - if (!(dev = io_get(io)) || !dev->control) - return -ENOENT; - - return dev->control(request, arg1, arg2, arg3); -} - -res io_write(enum io_type io, const void *buf, u32 offset, u32 count) -{ - if (!memory_readable_range(memory_range(buf, count))) - return -EFAULT; - - struct io_dev *dev; - if (!(dev = io_get(io)) || !dev->write) - return -ENOENT; - - return dev->write(buf, offset, count); -} - -res io_read(enum io_type io, void *buf, u32 offset, u32 count) -{ - if (!memory_writable_range(memory_range(buf, count))) - return -EFAULT; - - struct io_dev *dev; - if (!(dev = io_get(io)) || !dev->read) - return -ENOENT; - - if (dev->ready && dev->ready() != EOK) - return -EAGAIN; - - return dev->read(buf, offset, count); -} - -res io_ready(enum io_type io) -{ - struct io_dev *dev; - if (!(dev = io_get(io))) - return -ENOENT; - - if (dev->ready && dev->ready() != EOK) - return -EAGAIN; - - return EOK; -} - -void io_block(enum io_type io, struct proc *proc) -{ - assert(io_type_valid(io)); - struct io_listener *listener = zalloc(sizeof(*listener)); - listener->group = group_id++; - listener->proc = proc; - list_add(io_listeners[io], listener); - proc_state(proc_current(), PROC_BLOCKED); - proc_yield(); -} - -void io_unblock(enum io_type io) -{ - assert(io_type_valid(io)); - struct node *iterator = io_listeners[io]->head; - while (iterator) { - struct io_listener *listener = iterator->data; - struct proc *proc = listener->proc; - proc_state(proc, PROC_RUNNING); - struct node *next = iterator->next; - io_remove_group(listener->group); - free(listener); - iterator = next; - } - - if (proc_idle()) - proc_yield(); -} - -void io_unblock_pid(u32 pid) -{ - for (u32 io = IO_MIN; io < IO_MAX; io++) { - struct node *iterator = io_listeners[io]->head; - while (iterator) { - struct io_listener *listener = iterator->data; - struct proc *proc = listener->proc; - proc_state(proc, PROC_RUNNING); - struct node *next = iterator->next; - if (proc->pid == pid) { - list_remove(io_listeners[io], iterator); - free(listener); - } - iterator = next; - } - } - - if (proc_idle()) - proc_yield(); -} - -CLEAR void io_install(void) -{ - for (u32 i = 0; i < IO_MAX; i++) - io_listeners[i] = list_new(); - - /** - * Keyboard & mouse detection - */ - - ps2_detect(); - - u8 ps2_keyboard = ps2_keyboard_detect(); - if (ps2_keyboard != U8_MAX) { - ps2_keyboard_install(ps2_keyboard); - } - - u8 ps2_mouse = ps2_mouse_detect(); - if (ps2_mouse != U8_MAX) { - if (vmware_detect() && vmware_mouse_detect()) - vmware_mouse_install(ps2_mouse); - else - ps2_mouse_install(ps2_mouse); - } - - /** - * Other devices - */ - - fb_install(); - timer_install(); - logger_install(); - bus_install(); -} diff --git a/kernel/features/logger.c b/kernel/features/logger.c index fd5d730..4385408 100644 --- a/kernel/features/logger.c +++ b/kernel/features/logger.c @@ -1,10 +1,10 @@ // MIT License, Copyright (c) 2021 Marvin Borner #include +#include #include #include #include -#include #include #include #include @@ -36,7 +36,7 @@ static res logger_write(const void *buf, u32 offset, u32 count) void logger_install(void) { - struct io_dev *dev = zalloc(sizeof(*dev)); + struct dev_dev *dev = zalloc(sizeof(*dev)); dev->write = logger_write; - io_add(IO_LOGGER, dev); + dev_add(DEV_LOGGER, dev); } diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c index 6e43caa..997fa96 100644 --- a/kernel/features/syscall.c +++ b/kernel/features/syscall.c @@ -1,11 +1,11 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include #include #include #include #include #include -#include #include #include #include @@ -57,29 +57,29 @@ static u32 syscall_handler(u32 esp) break; } - // I/O operations - case SYS_IOPOLL: { - frame->eax = io_poll((void *)frame->ebx); + // Device operations + case SYS_DEV_POLL: { + frame->eax = dev_poll((void *)frame->ebx); break; } - case SYS_IOREAD: { - res ready = io_ready(frame->ebx); + case SYS_DEV_READ: { + res ready = dev_ready(frame->ebx); if (ready == -EAGAIN) { - io_block(frame->ebx, proc_current()); + dev_block(frame->ebx, proc_current()); } else if (ready != EOK) { frame->eax = ready; break; } - frame->eax = io_read(frame->ebx, (void *)frame->ecx, frame->edx, frame->esi); + frame->eax = dev_read(frame->ebx, (void *)frame->ecx, frame->edx, frame->esi); break; } - case SYS_IOWRITE: { - frame->eax = io_write(frame->ebx, (void *)frame->ecx, frame->edx, frame->esi); + case SYS_DEV_WRITE: { + frame->eax = dev_write(frame->ebx, (void *)frame->ecx, frame->edx, frame->esi); break; } - case SYS_IOCONTROL: { - frame->eax = io_control(frame->ebx, frame->ecx, (void *)frame->edx, - (void *)frame->esi, (void *)frame->edi); + case SYS_DEV_CONTROL: { + frame->eax = dev_control(frame->ebx, frame->ecx, (void *)frame->edx, + (void *)frame->esi, (void *)frame->edi); break; } diff --git a/kernel/inc/dev.h b/kernel/inc/dev.h new file mode 100644 index 0000000..fc5e424 --- /dev/null +++ b/kernel/inc/dev.h @@ -0,0 +1,32 @@ +// MIT License, Copyright (c) 2021 Marvin Borner + +#ifndef dev_H +#define dev_H + +#include +#include +#include +#include + +struct dev_dev { + res (*read)(void *buf, u32 offset, u32 count) NONNULL; + res (*write)(const void *buf, u32 offset, u32 count) NONNULL; + res (*control)(u32 request, void *arg1, void *arg2, void *arg3); + res (*ready)(void); +}; + +void dev_install(void); +void dev_add(enum dev_type type, struct dev_dev *dev) NONNULL; + +// No NONNULL on syscalls +res dev_control(enum dev_type type, u32 request, void *arg1, void *arg2, void *arg3); +res dev_write(enum dev_type type, const void *buf, u32 offset, u32 count); +res dev_read(enum dev_type type, void *buf, u32 offset, u32 count); +res dev_poll(u32 *devs); +res dev_ready(enum dev_type type); + +void dev_block(enum dev_type type, struct proc *proc) NONNULL; +void dev_unblock(enum dev_type type); +void dev_unblock_pid(u32 pid); + +#endif diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h index 1ea4b21..42cf21a 100644 --- a/kernel/inc/fs.h +++ b/kernel/inc/fs.h @@ -11,12 +11,12 @@ * Device */ -enum dev_type { DEV_BLOCK, DEV_CHAR }; +enum vfs_dev_type { DEV_BLOCK, DEV_CHAR }; struct vfs_dev { u32 id; char name[8]; - enum dev_type type; + enum vfs_dev_type type; struct vfs *vfs; void *data; res (*read)(void *buf, u32 offset, u32 count, struct vfs_dev *dev) NONNULL; diff --git a/kernel/inc/io.h b/kernel/inc/io.h deleted file mode 100644 index c20a6f7..0000000 --- a/kernel/inc/io.h +++ /dev/null @@ -1,32 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner - -#ifndef IO_H -#define IO_H - -#include -#include -#include -#include - -struct io_dev { - res (*read)(void *buf, u32 offset, u32 count) NONNULL; - res (*write)(const void *buf, u32 offset, u32 count) NONNULL; - res (*control)(u32 request, void *arg1, void *arg2, void *arg3); - res (*ready)(void); -}; - -void io_install(void); -void io_add(enum io_type io, struct io_dev *dev) NONNULL; - -// No NONNULL on syscalls -res io_control(enum io_type io, u32 request, void *arg1, void *arg2, void *arg3); -res io_write(enum io_type io, const void *buf, u32 offset, u32 count); -res io_read(enum io_type io, void *buf, u32 offset, u32 count); -res io_poll(u32 *devs); -res io_ready(enum io_type io); - -void io_block(enum io_type io, struct proc *proc) NONNULL; -void io_unblock(enum io_type io); -void io_unblock_pid(u32 pid); - -#endif diff --git a/kernel/main.c b/kernel/main.c index d6e7727..e7daf16 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,5 +1,6 @@ // MIT License, Copyright (c) 2020 Marvin Borner +#include #include #include #include @@ -9,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -42,7 +42,7 @@ int kernel_main(u32 magic, u32 addr, u32 esp) pci_install(); pic_install(); idt_install(); - io_install(); + dev_install(); syscall_init(); proc_init(); -- cgit v1.2.3