feat: add support for process to conduct Intel x87 and MMX related task.
[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     uint32_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 (*exec_cmd)(struct device* dev, uint32_t req, va_list args);
34 };
35
36 struct device*
37 device_add(struct device* parent,
38            void* underlay,
39            char* name_fmt,
40            uint32_t type,
41            va_list args);
42
43 struct device*
44 device_addseq(struct device* parent, void* underlay, char* name_fmt, ...);
45
46 struct device*
47 device_addvol(struct device* parent, void* underlay, char* name_fmt, ...);
48
49 struct device*
50 device_addcat(struct device* parent, char* name_fmt, ...);
51
52 void
53 device_remove(struct device* dev);
54
55 struct device*
56 device_getbyid(struct llist_header* devlist, dev_t id);
57
58 struct device*
59 device_getbyhname(struct device* root_dev, struct hstr* name);
60
61 struct device*
62 device_getbyname(struct device* root_dev, const char* name, size_t len);
63
64 struct device*
65 device_getbyoffset(struct device* root_dev, int pos);
66
67 #endif /* __LUNAIX_DEVICE_H */