refactor: elf parsing utility and exec related
[lunaix-os.git] / lunaix-os / includes / lunaix / device.h
1 #ifndef __LUNAIX_DEVICE_H
2 #define __LUNAIX_DEVICE_H
3
4 #define DEVICE_NAME_SIZE 32
5
6 #include <lunaix/ds/hstr.h>
7 #include <lunaix/ds/llist.h>
8 #include <lunaix/types.h>
9
10 #define DEV_STRUCT_MAGIC 0x5645444c
11
12 #define DEV_MSKIF 0x00000003
13
14 #define DEV_IFVOL 0x0 // volumetric (block) device
15 #define DEV_IFSEQ 0x1 // sequential (character) device
16 #define DEV_IFCAT 0x2 // a device category (as device groupping)
17
18 typedef unsigned int dev_t;
19
20 struct device
21 {
22     u32_t magic;
23     struct llist_header siblings;
24     struct llist_header children;
25     struct device* parent;
26     struct hstr name;
27     dev_t dev_id;
28     int dev_type;
29     char name_val[DEVICE_NAME_SIZE];
30     void* underlay;
31     int (*read)(struct device* dev, void* buf, size_t offset, size_t len);
32     int (*write)(struct device* dev, void* buf, size_t offset, size_t len);
33     int (*read_page)(struct device* dev, void* buf, size_t offset);
34     int (*write_page)(struct device* dev, void* buf, size_t offset);
35     int (*exec_cmd)(struct device* dev, u32_t req, va_list args);
36 };
37
38 struct device*
39 device_add(struct device* parent,
40            void* underlay,
41            char* name_fmt,
42            u32_t type,
43            va_list args);
44
45 struct device*
46 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
47
48 struct device*
49 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
50
51 struct device*
52 device_addcat(struct device* parent, char* name_fmt, ...);
53
54 void
55 device_remove(struct device* dev);
56
57 struct device*
58 device_getbyid(struct llist_header* devlist, dev_t id);
59
60 struct device*
61 device_getbyhname(struct device* root_dev, struct hstr* name);
62
63 struct device*
64 device_getbyname(struct device* root_dev, const char* name, size_t len);
65
66 struct device*
67 device_getbyoffset(struct device* root_dev, int pos);
68
69 void
70 device_init_builtin();
71
72 #endif /* __LUNAIX_DEVICE_H */