7526601a84a4311a9b2a551b1734bc7ad2d3adb1
[lunaix-os.git] / lunaix-os / kernel / device / builtin / devrand.c
1 #include <hal/rnd.h>
2 #include <lunaix/device.h>
3 #include <lunaix/syslog.h>
4
5 LOG_MODULE("rand")
6
7 int
8 __rand_rd_pg(struct device* dev, void* buf, size_t offset)
9 {
10     rnd_fill(buf, PG_SIZE);
11     return PG_SIZE;
12 }
13
14 int
15 __rand_rd(struct device* dev, void* buf, size_t offset, size_t len)
16 {
17     rnd_fill(buf, len);
18     return len;
19 }
20
21 void
22 devbuiltin_init_rand()
23 {
24     if (!rnd_is_supported()) {
25         kprintf(KWARN "not supported.\n");
26         return;
27     }
28     struct device* devrand = device_addseq(NULL, NULL, "rand");
29     devrand->read = __rand_rd;
30     devrand->read_page = __rand_rd_pg;
31 }