taskfs fix up, minor refactoring
[lunaix-os.git] / lunaix-os / includes / lunaix / device_num.h
1 #ifndef __LUNAIX_DEVICE_NUM_H
2 #define __LUNAIX_DEVICE_NUM_H
3
4 #include <lunaix/types.h>
5
6 /*
7     Device metadata field (device_def::meta)
8
9     31          16 15           0
10     |  interface  |   function  |
11
12     Where the interface identify how the device is connected with the processor
13     Lunaix identify the following values:
14
15         NON: device do not have hardware interfacing
16
17         SOC: device conntected through some System-on-Chip interconnect bus
18             for example, southbridge on x86 platform, AMBA for ARM's series.
19
20         PCI: device connected through the peripheral component interconnect bus
21             (PCI)
22
23         USB: device connected through the universal serial bus (USB)
24
25         SPI: device connected through the serial peripheral interface (SPI)
26
27         I2C: device connected through the IIC protocol
28
29         FMW: device is a system board firmware
30
31     The function defines the functionality that the device is designated to
32    serve. Lunaix identify the following values:
33
34         PSEDUO: a pseudo device which does not backed by any hardware. (e.g.
35                 /dev/null)
36
37         CHAR: a character device, which support read/write and dealing with
38              characters. Backed hardware might exist.
39
40         SERIAL: a serial interface which talks
41
42         STORAGE: a device that is used for storage of data
43
44         INPUT: a device that accept external input.
45
46         TIME: a device that provides time related services, for example, timing
47              and clocking
48
49         BUSIF: a device that is the interface or HBAs for accessing interconnect
50    bus.
51
52         TTY: a device which can be called as teletypewriter, system can use such
53             device for output into external environment
54
55         CFG: device that provide configuration service to the system or other
56    devices
57
58
59 */
60
61 #define DEV_FNGRP(vendor, function)                                            \
62     (((vendor) & 0xffff) << 16) | ((function) & 0xffff)
63 #define DEV_UNIQUE(devkind, variant)                                           \
64     (((devkind) & 0xffff) << 16) | ((variant) & 0xffff)
65 #define DEV_KIND_FROM(unique) ((unique) >> 16)
66 #define DEV_VAR_FROM(unique) ((unique) & 0xffff)
67
68 #define DEV_VN(fngrp) ((fngrp) >> 16)
69 #define DEV_FN(fngrp) (((fngrp) & 0xffff))
70
71 #define dev_vn(x)      DEVVN_##x
72 #define dev_fn(x)      DEVFN_##x
73 #define dev_id(x)        DEV_##x
74
75 enum devnum_vn
76 {
77     dev_vn(GENERIC),
78     #include <listings/devnum_vn.lst>
79 };
80
81 enum devnum_fn
82 {
83     dev_fn(NON),
84     #include <listings/devnum_fn.lst>
85 };
86
87 enum devnum
88 {
89     dev_id(NON),
90     #include <listings/devnum.lst>
91 };
92
93 struct devident
94 {
95     u32_t fn_grp;
96     u32_t unique;
97 };
98
99 struct devclass
100 {
101     u32_t fn_grp;
102     u32_t device;
103     u32_t variant;
104 };
105
106 static inline int
107 devclass_mkvar(struct devclass* class)
108 {
109     return class->variant++;
110 }
111
112 #endif /* __LUNAIX_DEVICE_NUM_H */