Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
ioforge_usb.c
Go to the documentation of this file.
1
3#include "ioforge/ioforge.h"
4#include "libk/serial.h"
5#include "memory/kalloc.h"
7#include <type.h>
8
10 switch (type) {
11 case IOFORGE_ROOT:
13 return true;
14 default:
15 return false;
16 }
17}
18
20 struct ioforge_device* root, uint16_t devclass,
21 ioforge_usb_visitor_fn callback, void* ctx) {
22
23 if (!root)
24 return;
25
26#define MAX_USB_NODES 64
27 struct ioforge_device** stack =
28 (struct ioforge_device**) kalloc(sizeof(void*) * MAX_USB_NODES);
29 if (!stack)
30 return;
31
32 int top = 0;
33 stack[top++] = root;
34
35 while (top > 0) {
36 struct ioforge_device* node = stack[--top];
37 if (!node)
38 continue;
40 continue;
41
42 if (node->type == IOFORGE_USB_DEVICE) {
43 struct ioforge_usb_device* usb =
44 (struct ioforge_usb_device*) node;
45 if (usb->class_code == devclass) {
46 callback(usb, ctx);
47 }
48 }
49
50 struct ioforge_device* child = node->first_child;
51 while (child) {
52 if (top >= MAX_USB_NODES) {
53 // log warning: node truncated
54 serial_printf("[ioforge] WARNING: USB "
55 "traversal stack full, "
56 "some devices may be skipped\n");
57 break;
58 }
59 stack[top++] = child;
60 child = child->next_sibling;
61 }
62 }
63
64 kfree(stack, sizeof(void*) * MAX_USB_NODES);
65}
uint64_t stack
Definition thread.h:13
static struct ioforge_device * root
Definition ioforge.c:25
void serial_printf(const char *fmt,...)
IoForgeType
Definition ioforge.h:10
@ IOFORGE_ROOT
Definition ioforge.h:11
@ IOFORGE_USB_DEVICE
Definition ioforge.h:15
static bool ioforge_can_contain_usb_device(IoForgeType type)
Definition ioforge_usb.c:9
#define MAX_USB_NODES
void(* ioforge_usb_visitor_fn)(struct ioforge_usb_device *dev, void *ctx)
Definition ioforge_usb.h:61
void ioforge_find_usb_device_by_devclass(struct ioforge_device *node, uint16_t devclass, ioforge_usb_visitor_fn callback, void *ctx)
void kfree(void *ptr, size_t size)
void * kalloc(size_t size)
struct ioforge_device * first_child
Definition ioforge.h:36
struct ioforge_device * next_sibling
Definition ioforge.h:37
IoForgeType type
Definition ioforge.h:31
unsigned short uint16_t
Definition type.h:13
#define KERNEL_API
Definition type.h:93
uint8_t type
Definition vnode.h:2