refactor: make pci device driver loading passive, pci bus scanner will not load them...
[lunaix-os.git] / lunaix-os / hal / char / devzero.c
1 #include <lunaix/device.h>
2 #include <lunaix/mm/page.h>
3
4 #include <klibc/string.h>
5
6 static int
7 __zero_rd_pg(struct device* dev, void* buf, size_t offset)
8 {
9     memset(&((u8_t*)buf)[offset], 0, PG_SIZE);
10     return PG_SIZE;
11 }
12
13 static int
14 __zero_rd(struct device* dev, void* buf, size_t offset, size_t len)
15 {
16     memset(&((u8_t*)buf)[offset], 0, len);
17     return len;
18 }
19
20 static int
21 pdev_zerodev_init(struct device_def* def)
22 {
23     struct device* devzero = device_allocseq(NULL, NULL);
24     devzero->ops.read_page = __zero_rd_pg;
25     devzero->ops.read = __zero_rd;
26
27     device_register(devzero, &def->class, "zero");
28
29     return 0;
30 }
31
32 static struct device_def devzero_def = {
33     .name = "zero",
34     .class = DEVCLASSV(DEVIF_NON, DEVFN_PSEUDO, DEV_ZERO, DEV_BUILTIN_ZERO),
35     .init = pdev_zerodev_init
36 };
37 EXPORT_DEVICE(zerodev, &devzero_def, load_onboot);