33 lines
656 B
C
33 lines
656 B
C
#include "device.h"
|
|
#include "libc.h"
|
|
|
|
i32 vm_register_device(VM *vm, const char *path, const char *type, void *data,
|
|
DeviceOps *ops, u32 size) {
|
|
Device *dev;
|
|
|
|
if (vm->dc >= DEVICES_SIZE)
|
|
return -1;
|
|
|
|
dev = &vm->devices[vm->dc];
|
|
dev->handle = vm->dc++;
|
|
|
|
dev->path = path;
|
|
dev->type = type;
|
|
dev->data = data;
|
|
dev->ops = ops;
|
|
dev->size = size;
|
|
dev->flags = 0;
|
|
return dev->handle;
|
|
}
|
|
|
|
/* Find device by path */
|
|
Device *find_device_by_path(VM *vm, const char *path) {
|
|
u32 i;
|
|
for (i = 0; i < vm->dc; i++) {
|
|
if (streq(vm->devices[i].path, path)) {
|
|
return &vm->devices[i];
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|