X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/b3b42765712afed5a35c9be5c832f4a06bd85e7a..f6ab9c9ababa2cf6e5c723b83ffb9362094054e8:/lunaix-os/includes/lunaix/device.h diff --git a/lunaix-os/includes/lunaix/device.h b/lunaix-os/includes/lunaix/device.h index 8171600..2634d81 100644 --- a/lunaix-os/includes/lunaix/device.h +++ b/lunaix-os/includes/lunaix/device.h @@ -4,38 +4,63 @@ #define DEVICE_NAME_SIZE 32 #include +#include #include +#include #include +/** + * @brief Export pseudo device + * + */ +#define EXPORT_PSEUDODEV(id, init_fn) \ + export_ldga_el(pseudo_dev, id, ptr_t, init_fn) + +#define DEV_STRUCT_MAGIC 0x5645444c + #define DEV_MSKIF 0x00000003 #define DEV_IFVOL 0x0 // volumetric (block) device #define DEV_IFSEQ 0x1 // sequential (character) device #define DEV_IFCAT 0x2 // a device category (as device groupping) +#define DEV_IFSYS 0x3 // a system device typedef unsigned int dev_t; struct device { + u32_t magic; struct llist_header siblings; struct llist_header children; struct device* parent; + // TODO investigate event polling + struct hstr name; dev_t dev_id; int dev_type; char name_val[DEVICE_NAME_SIZE]; void* underlay; - int (*read)(struct device* dev, void* buf, size_t offset, size_t len); - int (*write)(struct device* dev, void* buf, size_t offset, size_t len); + + struct + { + int (*read)(struct device* dev, void* buf, size_t offset, size_t len); + int (*write)(struct device* dev, void* buf, size_t offset, size_t len); + int (*read_page)(struct device* dev, void* buf, size_t offset); + int (*write_page)(struct device* dev, void* buf, size_t offset); + int (*exec_cmd)(struct device* dev, u32_t req, va_list args); + } ops; }; struct device* device_add(struct device* parent, void* underlay, char* name_fmt, - uint32_t type, + u32_t type, va_list args); +struct device* +device_addsys(struct device* parent, void* underlay, char* name_fmt, ...); + struct device* device_addseq(struct device* parent, void* underlay, char* name_fmt, ...); @@ -52,12 +77,15 @@ struct device* device_getbyid(struct llist_header* devlist, dev_t id); struct device* -device_getbyhname(struct llist_header* devlist, struct hstr* name); +device_getbyhname(struct device* root_dev, struct hstr* name); struct device* -device_getbyname(struct llist_header* devlist, const char* name, size_t len); +device_getbyname(struct device* root_dev, const char* name, size_t len); struct device* -device_getbyoffset(struct llist_header* devlist, int pos); +device_getbyoffset(struct device* root_dev, int pos); + +void +device_install_pseudo(); #endif /* __LUNAIX_DEVICE_H */