summaryrefslogtreecommitdiffhomepage
path: root/src/loader/dev.c
diff options
context:
space:
mode:
authorMarvin Borner2021-07-12 18:14:44 +0200
committerMarvin Borner2021-07-12 18:15:29 +0200
commit1b429c0fc28e5cd8b474ad5a1de1fa6f3d7c2e2a (patch)
tree593af3e3ec78795bb47553f492db07fb7e87e373 /src/loader/dev.c
parentd414d2f6f46bd425d727af5baae3e2658d6e1384 (diff)
Renamed files to match presentation
Diffstat (limited to 'src/loader/dev.c')
-rw-r--r--src/loader/dev.c84
1 files changed, 0 insertions, 84 deletions
diff --git a/src/loader/dev.c b/src/loader/dev.c
deleted file mode 100644
index 2a57b02..0000000
--- a/src/loader/dev.c
+++ /dev/null
@@ -1,84 +0,0 @@
-// MIT License, Copyright (c) 2021 Marvin Borner
-// Device manager
-
-#include <dev.h>
-#include <lib.h>
-#include <pnc.h>
-
-static struct dev devices[32] = { 0 };
-
-static const char *dev_resolve_type(enum dev_type type)
-{
- switch (type) {
- case DEV_DISK:
- return "Disk";
- case DEV_FB:
- return "Framebuffer";
- case DEV_NONE:
- default:
- return "Unknown";
- }
-}
-
-struct dev *dev_get_by_id(u8 id)
-{
- assert(id < COUNT(devices));
- return &devices[id];
-}
-
-struct dev *dev_get_by_name(const char *name, u32 len)
-{
- if (!name || !name[0])
- return NULL;
-
- for (u8 i = 0; i < COUNT(devices); i++) {
- struct dev *dev = &devices[i];
- if (strncmp(dev->name, name, MIN(sizeof(dev->name), len)) == 0)
- return dev;
- }
-
- return NULL;
-}
-
-void dev_foreach(enum dev_type type, u8 (*cb)(struct dev *))
-{
- for (u8 i = 0; i < COUNT(devices); i++) {
- struct dev *dev = &devices[i];
- if (dev->type == type)
- if (cb(dev))
- break;
- }
-}
-
-u8 dev_register(enum dev_type type, char *name, u32 data,
- s32 (*read)(void *, u32, u32, struct dev *),
- s32 (*write)(const void *, u32, u32, struct dev *))
-{
- static u8 id = 0;
- assert(++id < 0xff);
-
- struct dev *dev = &devices[id];
- dev->id = id;
- dev->type = type;
- dev->read = read;
- dev->write = write;
- dev->data = data;
-
- assert(strlen(name) < sizeof(dev->name));
- memcpy(dev->name, name, sizeof(dev->name));
-
- if (type == DEV_DISK)
- dsk_detect(dev);
-
- return id;
-}
-
-void dev_print(void)
-{
- for (u8 i = 0; i < COUNT(devices); i++) {
- struct dev *dev = &devices[i];
- if (!dev->id)
- continue;
- log("[DEV] %d: %s device: %s\n", dev->id, dev_resolve_type(dev->type), dev->name);
- }
-}