1 #include <lunaix/device.h>
2 #include <lunaix/mm/page.h>
5 rng_fill(void* data, size_t len)
12 "jnz 1b" ::"r"((ptr_t)data),
18 __rand_rd_pg(struct device* dev, void* buf, size_t offset)
20 rng_fill(buf, PG_SIZE);
25 __rand_rd(struct device* dev, void* buf, size_t offset, size_t len)
32 pdev_randdev_init(struct device_def* devdef)
34 struct device* devrand = device_allocseq(NULL, NULL);
35 devrand->ops.read = __rand_rd;
36 devrand->ops.read_page = __rand_rd_pg;
38 device_register(devrand, &devdef->class, "rand");
43 static struct device_def devrandx86_def = {
44 .name = "x86 On-Chip RNG",
45 .class = DEVCLASS(DEVIF_SOC, DEVFN_CHAR, DEV_RNG),
46 .init = pdev_randdev_init
48 EXPORT_DEVICE(randdev, &devrandx86_def, load_onboot);