123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- #include <types.h>
- #include <kern/errno.h>
- #include <kern/fcntl.h>
- #include <lib.h>
- #include <uio.h>
- #include <vfs.h>
- #include <generic/random.h>
- #include "autoconf.h"
- static struct random_softc *the_random = NULL;
- static
- int
- randopen(struct device *dev, int openflags)
- {
- (void)dev;
- if (openflags != O_RDONLY) {
- return EIO;
- }
- return 0;
- }
- static
- int
- randclose(struct device *dev)
- {
- (void)dev;
- return 0;
- }
- static
- int
- randio(struct device *dev, struct uio *uio)
- {
- struct random_softc *rs = dev->d_data;
- if (uio->uio_rw != UIO_READ) {
- return EIO;
- }
- return rs->rs_read(rs->rs_devdata, uio);
- }
- static
- int
- randioctl(struct device *dev, int op, userptr_t data)
- {
-
- (void)dev;
- (void)op;
- (void)data;
- return EIOCTL;
- }
- int
- config_random(struct random_softc *rs, int unit)
- {
- int result;
-
- if (unit!=0) {
- return ENODEV;
- }
- KASSERT(the_random==NULL);
- the_random = rs;
- rs->rs_dev.d_open = randopen;
- rs->rs_dev.d_close = randclose;
- rs->rs_dev.d_io = randio;
- rs->rs_dev.d_ioctl = randioctl;
- rs->rs_dev.d_blocks = 0;
- rs->rs_dev.d_blocksize = 1;
- rs->rs_dev.d_data = rs;
-
- result = vfs_adddev("random", &rs->rs_dev, 0);
- if (result) {
- return result;
- }
- return 0;
- }
- uint32_t
- random(void)
- {
- if (the_random==NULL) {
- panic("No random device\n");
- }
- return the_random->rs_random(the_random->rs_devdata);
- }
- uint32_t
- randmax(void)
- {
- if (the_random==NULL) {
- panic("No random device\n");
- }
- return the_random->rs_randmax(the_random->rs_devdata);
- }
|