X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/c4510182f3c02e390184bee518940e325f064b20..f6ab9c9ababa2cf6e5c723b83ffb9362094054e8:/lunaix-os/kernel/device/device.c?ds=sidebyside diff --git a/lunaix-os/kernel/device/device.c b/lunaix-os/kernel/device/device.c index beb1f18..979b461 100644 --- a/lunaix-os/kernel/device/device.c +++ b/lunaix-os/kernel/device/device.c @@ -1,8 +1,12 @@ #include #include +#include #include +#include #include #include +#include +#include static DEFINE_LLIST(root_list); @@ -12,7 +16,7 @@ struct device* device_add(struct device* parent, void* underlay, char* name_fmt, - uint32_t type, + u32_t type, va_list args) { struct device* dev = vzalloc(sizeof(struct device)); @@ -27,6 +31,7 @@ device_add(struct device* parent, size_t strlen = __ksprintf_internal(dev->name_val, name_fmt, DEVICE_NAME_SIZE, args); + dev->magic = DEV_STRUCT_MAGIC; dev->dev_id = devid++; dev->name = HSTR(dev->name_val, strlen); dev->parent = parent; @@ -39,6 +44,19 @@ device_add(struct device* parent, return dev; } +struct device* +device_addsys(struct device* parent, void* underlay, char* name_fmt, ...) +{ + va_list args; + va_start(args, name_fmt); + + struct device* dev = + device_add(parent, underlay, name_fmt, DEV_IFSEQ, args); + + va_end(args); + return dev; +} + struct device* device_addseq(struct device* parent, void* underlay, char* name_fmt, ...) { @@ -136,4 +154,29 @@ device_getbyoffset(struct device* root_dev, int offset) } } return NULL; +} + +__DEFINE_LXSYSCALL3(int, ioctl, int, fd, int, req, va_list, args) +{ + int errno; + struct v_fd* fd_s; + if ((errno = vfs_getfd(fd, &fd_s))) { + goto done; + } + + struct device* dev = (struct device*)fd_s->file->inode->data; + if (dev->magic != DEV_STRUCT_MAGIC) { + errno = ENODEV; + goto done; + } + + if (!dev->ops.exec_cmd) { + errno = ENOTSUP; + goto done; + } + + errno = dev->ops.exec_cmd(dev, req, args); + +done: + return DO_STATUS_OR_RETURN(errno); } \ No newline at end of file