feat: serial device interfacing
[lunaix-os.git] / lunaix-os / hal / char / devnull.c
1 #include <lunaix/device.h>
2 #include <lunaix/mm/page.h>
3
4 static int
5 __null_wr_pg(struct device* dev, void* buf, size_t offset)
6 {
7     // do nothing
8     return PG_SIZE;
9 }
10
11 static int
12 __null_wr(struct device* dev, void* buf, size_t offset, size_t len)
13 {
14     // do nothing
15     return len;
16 }
17
18 static int
19 __null_rd_pg(struct device* dev, void* buf, size_t offset)
20 {
21     // do nothing
22     return 0;
23 }
24
25 static int
26 __null_rd(struct device* dev, void* buf, size_t offset, size_t len)
27 {
28     // do nothing
29     return 0;
30 }
31
32 static int
33 pdev_nulldev_init(struct device_def*)
34 {
35     struct device* devnull = device_addseq(NULL, NULL, "null");
36     devnull->ops.write_page = __null_wr_pg;
37     devnull->ops.write = __null_wr;
38     devnull->ops.read_page = __null_rd_pg;
39     devnull->ops.read = __null_rd;
40
41     return 0;
42 }
43
44 static struct device_def devnull_def = {
45     .name = "null",
46     .class = DEVCLASS(DEVIF_NON, DEVFN_PSEUDO, DEV_BUILTIN, 0),
47     .init = pdev_nulldev_init
48 };
49 EXPORT_DEVICE(nulldev, &devnull_def, load_earlystage);