Unit testing framework and devicetree framework refactoring (#50)
[lunaix-os.git] / lunaix-os / hal / char / devnull.c
1 #include <lunaix/device.h>
2 #include <lunaix/mm/pagetable.h>
3
4 static int
5 __null_wr_pg(struct device* dev, void* buf, size_t offset)
6 {
7     // do nothing
8     return PAGE_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_create(struct device_def* def, morph_t* obj)
34 {
35     struct device* devnull = device_allocseq(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     register_device(devnull, &def->class, "null");
42
43     return 0;
44 }
45
46 static struct device_def devnull_def = {
47     def_device_name("edendi"),
48     def_device_class(LUNAIX, PSEUDO, NIHIL),
49     def_on_create(pdev_nulldev_create)
50 };
51 EXPORT_DEVICE(nulldev, &devnull_def, load_onboot);