1 #ifndef __LUNAIX_DEVICE_H
2 #define __LUNAIX_DEVICE_H
4 #define DEVICE_NAME_SIZE 32
6 #include <lunaix/ds/hstr.h>
7 #include <lunaix/ds/ldga.h>
8 #include <lunaix/ds/llist.h>
9 #include <lunaix/ds/semaphore.h>
10 #include <lunaix/types.h>
13 * @brief Export pseudo device
16 #define EXPORT_PSEUDODEV(id, init_fn) \
17 export_ldga_el(pseudo_dev, id, ptr_t, init_fn)
19 #define DEV_STRUCT_MAGIC 0x5645444c
21 #define DEV_MSKIF 0x00000003
23 #define DEV_IFVOL 0x0 // volumetric (block) device
24 #define DEV_IFSEQ 0x1 // sequential (character) device
25 #define DEV_IFCAT 0x2 // a device category (as device groupping)
26 #define DEV_IFSYS 0x3 // a system device
28 typedef unsigned int dev_t;
33 struct llist_header siblings;
34 struct llist_header children;
35 struct device* parent;
36 // TODO investigate event polling
41 char name_val[DEVICE_NAME_SIZE];
46 int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
47 int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
48 int (*read_page)(struct device* dev, void* buf, size_t offset);
49 int (*write_page)(struct device* dev, void* buf, size_t offset);
50 int (*exec_cmd)(struct device* dev, u32_t req, va_list args);
55 device_add(struct device* parent,
62 device_addsys(struct device* parent, void* underlay, char* name_fmt, ...);
65 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
68 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
71 device_addcat(struct device* parent, char* name_fmt, ...);
74 device_remove(struct device* dev);
77 device_getbyid(struct llist_header* devlist, dev_t id);
80 device_getbyhname(struct device* root_dev, struct hstr* name);
83 device_getbyname(struct device* root_dev, const char* name, size_t len);
86 device_getbyoffset(struct device* root_dev, int pos);
89 device_install_pseudo();
91 #endif /* __LUNAIX_DEVICE_H */