clang-format
This commit is contained in:
@@ -46,26 +46,21 @@
|
||||
|
||||
static struct beep_softc *the_beep = NULL;
|
||||
|
||||
int
|
||||
config_beep(struct beep_softc *bs, int unit)
|
||||
{
|
||||
/* We use only the first beep device. */
|
||||
if (unit!=0) {
|
||||
return ENODEV;
|
||||
}
|
||||
int config_beep(struct beep_softc *bs, int unit) {
|
||||
/* We use only the first beep device. */
|
||||
if (unit != 0) {
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
KASSERT(the_beep==NULL);
|
||||
the_beep = bs;
|
||||
return 0;
|
||||
KASSERT(the_beep == NULL);
|
||||
the_beep = bs;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
beep(void)
|
||||
{
|
||||
if (the_beep!=NULL) {
|
||||
the_beep->bs_beep(the_beep->bs_devdata);
|
||||
}
|
||||
else {
|
||||
kprintf("beep: Warning: no beep device\n");
|
||||
}
|
||||
void beep(void) {
|
||||
if (the_beep != NULL) {
|
||||
the_beep->bs_beep(the_beep->bs_devdata);
|
||||
} else {
|
||||
kprintf("beep: Warning: no beep device\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@
|
||||
*/
|
||||
|
||||
struct beep_softc {
|
||||
void *bs_devdata;
|
||||
void (*bs_beep)(void *devdata);
|
||||
void *bs_devdata;
|
||||
void (*bs_beep)(void *devdata);
|
||||
};
|
||||
|
||||
#endif /* _GENERIC_BEEP_H_ */
|
||||
|
||||
@@ -79,32 +79,26 @@ static struct lock *con_userlock_write = NULL;
|
||||
* console is set up. Upon console setup they are dumped
|
||||
* to the actual console; thenceforth this space is unused.
|
||||
*/
|
||||
#define DELAYBUFSIZE 1024
|
||||
#define DELAYBUFSIZE 1024
|
||||
static char delayed_outbuf[DELAYBUFSIZE];
|
||||
static size_t delayed_outbuf_pos=0;
|
||||
static size_t delayed_outbuf_pos = 0;
|
||||
|
||||
static
|
||||
void
|
||||
putch_delayed(int ch)
|
||||
{
|
||||
/*
|
||||
* No synchronization needed: called only during system startup
|
||||
* by main thread.
|
||||
*/
|
||||
static void putch_delayed(int ch) {
|
||||
/*
|
||||
* No synchronization needed: called only during system startup
|
||||
* by main thread.
|
||||
*/
|
||||
|
||||
KASSERT(delayed_outbuf_pos < sizeof(delayed_outbuf));
|
||||
delayed_outbuf[delayed_outbuf_pos++] = ch;
|
||||
KASSERT(delayed_outbuf_pos < sizeof(delayed_outbuf));
|
||||
delayed_outbuf[delayed_outbuf_pos++] = ch;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
flush_delay_buf(void)
|
||||
{
|
||||
size_t i;
|
||||
for (i=0; i<delayed_outbuf_pos; i++) {
|
||||
putch(delayed_outbuf[i]);
|
||||
}
|
||||
delayed_outbuf_pos = 0;
|
||||
static void flush_delay_buf(void) {
|
||||
size_t i;
|
||||
for (i = 0; i < delayed_outbuf_pos; i++) {
|
||||
putch(delayed_outbuf[i]);
|
||||
}
|
||||
delayed_outbuf_pos = 0;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
@@ -113,11 +107,8 @@ flush_delay_buf(void)
|
||||
* Print a character, using polling instead of interrupts to wait for
|
||||
* I/O completion.
|
||||
*/
|
||||
static
|
||||
void
|
||||
putch_polled(struct con_softc *cs, int ch)
|
||||
{
|
||||
cs->cs_sendpolled(cs->cs_devdata, ch);
|
||||
static void putch_polled(struct con_softc *cs, int ch) {
|
||||
cs->cs_sendpolled(cs->cs_devdata, ch);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
@@ -125,28 +116,21 @@ putch_polled(struct con_softc *cs, int ch)
|
||||
/*
|
||||
* Print a character, using interrupts to wait for I/O completion.
|
||||
*/
|
||||
static
|
||||
void
|
||||
putch_intr(struct con_softc *cs, int ch)
|
||||
{
|
||||
P(cs->cs_wsem);
|
||||
cs->cs_send(cs->cs_devdata, ch);
|
||||
static void putch_intr(struct con_softc *cs, int ch) {
|
||||
P(cs->cs_wsem);
|
||||
cs->cs_send(cs->cs_devdata, ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* Read a character, using interrupts to wait for I/O completion.
|
||||
*/
|
||||
static
|
||||
int
|
||||
getch_intr(struct con_softc *cs)
|
||||
{
|
||||
unsigned char ret;
|
||||
static int getch_intr(struct con_softc *cs) {
|
||||
unsigned char ret;
|
||||
|
||||
P(cs->cs_rsem);
|
||||
ret = cs->cs_gotchars[cs->cs_gotchars_tail];
|
||||
cs->cs_gotchars_tail =
|
||||
(cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
return ret;
|
||||
P(cs->cs_rsem);
|
||||
ret = cs->cs_gotchars[cs->cs_gotchars_tail];
|
||||
cs->cs_gotchars_tail = (cs->cs_gotchars_tail + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -158,33 +142,29 @@ getch_intr(struct con_softc *cs)
|
||||
* too) would be with a second semaphore used with a nonblocking P,
|
||||
* but we don't have that in OS/161.
|
||||
*/
|
||||
void
|
||||
con_input(void *vcs, int ch)
|
||||
{
|
||||
struct con_softc *cs = vcs;
|
||||
unsigned nexthead;
|
||||
void con_input(void *vcs, int ch) {
|
||||
struct con_softc *cs = vcs;
|
||||
unsigned nexthead;
|
||||
|
||||
nexthead = (cs->cs_gotchars_head + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
if (nexthead == cs->cs_gotchars_tail) {
|
||||
/* overflow; drop character */
|
||||
return;
|
||||
}
|
||||
nexthead = (cs->cs_gotchars_head + 1) % CONSOLE_INPUT_BUFFER_SIZE;
|
||||
if (nexthead == cs->cs_gotchars_tail) {
|
||||
/* overflow; drop character */
|
||||
return;
|
||||
}
|
||||
|
||||
cs->cs_gotchars[cs->cs_gotchars_head] = ch;
|
||||
cs->cs_gotchars_head = nexthead;
|
||||
cs->cs_gotchars[cs->cs_gotchars_head] = ch;
|
||||
cs->cs_gotchars_head = nexthead;
|
||||
|
||||
V(cs->cs_rsem);
|
||||
V(cs->cs_rsem);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called from underlying device when a write-done interrupt occurs.
|
||||
*/
|
||||
void
|
||||
con_start(void *vcs)
|
||||
{
|
||||
struct con_softc *cs = vcs;
|
||||
void con_start(void *vcs) {
|
||||
struct con_softc *cs = vcs;
|
||||
|
||||
V(cs->cs_wsem);
|
||||
V(cs->cs_wsem);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////
|
||||
@@ -197,32 +177,25 @@ con_start(void *vcs)
|
||||
* not, and does not.
|
||||
*/
|
||||
|
||||
void
|
||||
putch(int ch)
|
||||
{
|
||||
struct con_softc *cs = the_console;
|
||||
void putch(int ch) {
|
||||
struct con_softc *cs = the_console;
|
||||
|
||||
if (cs==NULL) {
|
||||
putch_delayed(ch);
|
||||
}
|
||||
else if (curthread->t_in_interrupt ||
|
||||
curthread->t_curspl > 0 ||
|
||||
curcpu->c_spinlocks > 0) {
|
||||
putch_polled(cs, ch);
|
||||
}
|
||||
else {
|
||||
putch_intr(cs, ch);
|
||||
}
|
||||
if (cs == NULL) {
|
||||
putch_delayed(ch);
|
||||
} else if (curthread->t_in_interrupt || curthread->t_curspl > 0 ||
|
||||
curcpu->c_spinlocks > 0) {
|
||||
putch_polled(cs, ch);
|
||||
} else {
|
||||
putch_intr(cs, ch);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
getch(void)
|
||||
{
|
||||
struct con_softc *cs = the_console;
|
||||
KASSERT(cs != NULL);
|
||||
KASSERT(!curthread->t_in_interrupt && curthread->t_iplhigh_count == 0);
|
||||
int getch(void) {
|
||||
struct con_softc *cs = the_console;
|
||||
KASSERT(cs != NULL);
|
||||
KASSERT(!curthread->t_in_interrupt && curthread->t_iplhigh_count == 0);
|
||||
|
||||
return getch_intr(cs);
|
||||
return getch_intr(cs);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -231,107 +204,93 @@ getch(void)
|
||||
* VFS interface functions
|
||||
*/
|
||||
|
||||
static
|
||||
int
|
||||
con_eachopen(struct device *dev, int openflags)
|
||||
{
|
||||
(void)dev;
|
||||
(void)openflags;
|
||||
return 0;
|
||||
static int con_eachopen(struct device *dev, int openflags) {
|
||||
(void)dev;
|
||||
(void)openflags;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
con_io(struct device *dev, struct uio *uio)
|
||||
{
|
||||
int result;
|
||||
char ch;
|
||||
struct lock *lk;
|
||||
static int con_io(struct device *dev, struct uio *uio) {
|
||||
int result;
|
||||
char ch;
|
||||
struct lock *lk;
|
||||
|
||||
(void)dev; // unused
|
||||
(void)dev; // unused
|
||||
|
||||
if (uio->uio_rw==UIO_READ) {
|
||||
lk = con_userlock_read;
|
||||
}
|
||||
else {
|
||||
lk = con_userlock_write;
|
||||
}
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
lk = con_userlock_read;
|
||||
} else {
|
||||
lk = con_userlock_write;
|
||||
}
|
||||
|
||||
KASSERT(lk != NULL);
|
||||
lock_acquire(lk);
|
||||
KASSERT(lk != NULL);
|
||||
lock_acquire(lk);
|
||||
|
||||
while (uio->uio_resid > 0) {
|
||||
if (uio->uio_rw==UIO_READ) {
|
||||
ch = getch();
|
||||
if (ch=='\r') {
|
||||
ch = '\n';
|
||||
}
|
||||
result = uiomove(&ch, 1, uio);
|
||||
if (result) {
|
||||
lock_release(lk);
|
||||
return result;
|
||||
}
|
||||
if (ch=='\n') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = uiomove(&ch, 1, uio);
|
||||
if (result) {
|
||||
lock_release(lk);
|
||||
return result;
|
||||
}
|
||||
if (ch=='\n') {
|
||||
putch('\r');
|
||||
}
|
||||
putch(ch);
|
||||
}
|
||||
}
|
||||
lock_release(lk);
|
||||
return 0;
|
||||
while (uio->uio_resid > 0) {
|
||||
if (uio->uio_rw == UIO_READ) {
|
||||
ch = getch();
|
||||
if (ch == '\r') {
|
||||
ch = '\n';
|
||||
}
|
||||
result = uiomove(&ch, 1, uio);
|
||||
if (result) {
|
||||
lock_release(lk);
|
||||
return result;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
result = uiomove(&ch, 1, uio);
|
||||
if (result) {
|
||||
lock_release(lk);
|
||||
return result;
|
||||
}
|
||||
if (ch == '\n') {
|
||||
putch('\r');
|
||||
}
|
||||
putch(ch);
|
||||
}
|
||||
}
|
||||
lock_release(lk);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
con_ioctl(struct device *dev, int op, userptr_t data)
|
||||
{
|
||||
/* No ioctls. */
|
||||
(void)dev;
|
||||
(void)op;
|
||||
(void)data;
|
||||
return EINVAL;
|
||||
static int con_ioctl(struct device *dev, int op, userptr_t data) {
|
||||
/* No ioctls. */
|
||||
(void)dev;
|
||||
(void)op;
|
||||
(void)data;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
static const struct device_ops console_devops = {
|
||||
.devop_eachopen = con_eachopen,
|
||||
.devop_io = con_io,
|
||||
.devop_ioctl = con_ioctl,
|
||||
.devop_eachopen = con_eachopen,
|
||||
.devop_io = con_io,
|
||||
.devop_ioctl = con_ioctl,
|
||||
};
|
||||
|
||||
static
|
||||
int
|
||||
attach_console_to_vfs(struct con_softc *cs)
|
||||
{
|
||||
struct device *dev;
|
||||
int result;
|
||||
static int attach_console_to_vfs(struct con_softc *cs) {
|
||||
struct device *dev;
|
||||
int result;
|
||||
|
||||
dev = kmalloc(sizeof(*dev));
|
||||
if (dev==NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
dev = kmalloc(sizeof(*dev));
|
||||
if (dev == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
dev->d_ops = &console_devops;
|
||||
dev->d_blocks = 0;
|
||||
dev->d_blocksize = 1;
|
||||
dev->d_data = cs;
|
||||
dev->d_ops = &console_devops;
|
||||
dev->d_blocks = 0;
|
||||
dev->d_blocksize = 1;
|
||||
dev->d_data = cs;
|
||||
|
||||
result = vfs_adddev("con", dev, 0);
|
||||
if (result) {
|
||||
kfree(dev);
|
||||
return result;
|
||||
}
|
||||
result = vfs_adddev("con", dev, 0);
|
||||
if (result) {
|
||||
kfree(dev);
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -340,58 +299,56 @@ attach_console_to_vfs(struct con_softc *cs)
|
||||
* Config routine called by autoconf.c after we are attached to something.
|
||||
*/
|
||||
|
||||
int
|
||||
config_con(struct con_softc *cs, int unit)
|
||||
{
|
||||
struct semaphore *rsem, *wsem;
|
||||
struct lock *rlk, *wlk;
|
||||
int config_con(struct con_softc *cs, int unit) {
|
||||
struct semaphore *rsem, *wsem;
|
||||
struct lock *rlk, *wlk;
|
||||
|
||||
/*
|
||||
* Only allow one system console.
|
||||
* Further devices that could be the system console are ignored.
|
||||
*
|
||||
* Do not hardwire the console to be "con1" instead of "con0",
|
||||
* or these asserts will go off.
|
||||
*/
|
||||
if (unit>0) {
|
||||
KASSERT(the_console!=NULL);
|
||||
return ENODEV;
|
||||
}
|
||||
KASSERT(the_console==NULL);
|
||||
/*
|
||||
* Only allow one system console.
|
||||
* Further devices that could be the system console are ignored.
|
||||
*
|
||||
* Do not hardwire the console to be "con1" instead of "con0",
|
||||
* or these asserts will go off.
|
||||
*/
|
||||
if (unit > 0) {
|
||||
KASSERT(the_console != NULL);
|
||||
return ENODEV;
|
||||
}
|
||||
KASSERT(the_console == NULL);
|
||||
|
||||
rsem = sem_create("console read", 0);
|
||||
if (rsem == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
wsem = sem_create("console write", 1);
|
||||
if (wsem == NULL) {
|
||||
sem_destroy(rsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
rlk = lock_create("console-lock-read");
|
||||
if (rlk == NULL) {
|
||||
sem_destroy(rsem);
|
||||
sem_destroy(wsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
wlk = lock_create("console-lock-write");
|
||||
if (wlk == NULL) {
|
||||
lock_destroy(rlk);
|
||||
sem_destroy(rsem);
|
||||
sem_destroy(wsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
rsem = sem_create("console read", 0);
|
||||
if (rsem == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
wsem = sem_create("console write", 1);
|
||||
if (wsem == NULL) {
|
||||
sem_destroy(rsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
rlk = lock_create("console-lock-read");
|
||||
if (rlk == NULL) {
|
||||
sem_destroy(rsem);
|
||||
sem_destroy(wsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
wlk = lock_create("console-lock-write");
|
||||
if (wlk == NULL) {
|
||||
lock_destroy(rlk);
|
||||
sem_destroy(rsem);
|
||||
sem_destroy(wsem);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
cs->cs_rsem = rsem;
|
||||
cs->cs_wsem = wsem;
|
||||
cs->cs_gotchars_head = 0;
|
||||
cs->cs_gotchars_tail = 0;
|
||||
cs->cs_rsem = rsem;
|
||||
cs->cs_wsem = wsem;
|
||||
cs->cs_gotchars_head = 0;
|
||||
cs->cs_gotchars_tail = 0;
|
||||
|
||||
the_console = cs;
|
||||
con_userlock_read = rlk;
|
||||
con_userlock_write = wlk;
|
||||
the_console = cs;
|
||||
con_userlock_read = rlk;
|
||||
con_userlock_write = wlk;
|
||||
|
||||
flush_delay_buf();
|
||||
flush_delay_buf();
|
||||
|
||||
return attach_console_to_vfs(cs);
|
||||
return attach_console_to_vfs(cs);
|
||||
}
|
||||
|
||||
@@ -40,17 +40,17 @@
|
||||
#define CONSOLE_INPUT_BUFFER_SIZE 32
|
||||
|
||||
struct con_softc {
|
||||
/* initialized by attach routine */
|
||||
void *cs_devdata;
|
||||
void (*cs_send)(void *devdata, int ch);
|
||||
void (*cs_sendpolled)(void *devdata, int ch);
|
||||
/* initialized by attach routine */
|
||||
void *cs_devdata;
|
||||
void (*cs_send)(void *devdata, int ch);
|
||||
void (*cs_sendpolled)(void *devdata, int ch);
|
||||
|
||||
/* initialized by config routine */
|
||||
struct semaphore *cs_rsem;
|
||||
struct semaphore *cs_wsem;
|
||||
unsigned char cs_gotchars[CONSOLE_INPUT_BUFFER_SIZE];
|
||||
unsigned cs_gotchars_head; /* next slot to put a char in */
|
||||
unsigned cs_gotchars_tail; /* next slot to take a char out */
|
||||
/* initialized by config routine */
|
||||
struct semaphore *cs_rsem;
|
||||
struct semaphore *cs_wsem;
|
||||
unsigned char cs_gotchars[CONSOLE_INPUT_BUFFER_SIZE];
|
||||
unsigned cs_gotchars_head; /* next slot to put a char in */
|
||||
unsigned cs_gotchars_tail; /* next slot to take a char out */
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@@ -53,106 +53,90 @@ static struct random_softc *the_random = NULL;
|
||||
* VFS device functions.
|
||||
* open: allow reading only.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randeachopen(struct device *dev, int openflags)
|
||||
{
|
||||
(void)dev;
|
||||
static int randeachopen(struct device *dev, int openflags) {
|
||||
(void)dev;
|
||||
|
||||
if (openflags != O_RDONLY) {
|
||||
return EIO;
|
||||
}
|
||||
if (openflags != O_RDONLY) {
|
||||
return EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* VFS I/O function. Hand off to implementation.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randio(struct device *dev, struct uio *uio)
|
||||
{
|
||||
struct random_softc *rs = dev->d_data;
|
||||
static int randio(struct device *dev, struct uio *uio) {
|
||||
struct random_softc *rs = dev->d_data;
|
||||
|
||||
if (uio->uio_rw != UIO_READ) {
|
||||
return EIO;
|
||||
}
|
||||
if (uio->uio_rw != UIO_READ) {
|
||||
return EIO;
|
||||
}
|
||||
|
||||
return rs->rs_read(rs->rs_devdata, uio);
|
||||
return rs->rs_read(rs->rs_devdata, uio);
|
||||
}
|
||||
|
||||
/*
|
||||
* VFS ioctl function.
|
||||
*/
|
||||
static
|
||||
int
|
||||
randioctl(struct device *dev, int op, userptr_t data)
|
||||
{
|
||||
/*
|
||||
* We don't support any ioctls.
|
||||
*/
|
||||
(void)dev;
|
||||
(void)op;
|
||||
(void)data;
|
||||
return EIOCTL;
|
||||
static int randioctl(struct device *dev, int op, userptr_t data) {
|
||||
/*
|
||||
* We don't support any ioctls.
|
||||
*/
|
||||
(void)dev;
|
||||
(void)op;
|
||||
(void)data;
|
||||
return EIOCTL;
|
||||
}
|
||||
|
||||
static const struct device_ops random_devops = {
|
||||
.devop_eachopen = randeachopen,
|
||||
.devop_io = randio,
|
||||
.devop_ioctl = randioctl,
|
||||
.devop_eachopen = randeachopen,
|
||||
.devop_io = randio,
|
||||
.devop_ioctl = randioctl,
|
||||
};
|
||||
|
||||
/*
|
||||
* Config function.
|
||||
*/
|
||||
int
|
||||
config_random(struct random_softc *rs, int unit)
|
||||
{
|
||||
int result;
|
||||
int config_random(struct random_softc *rs, int unit) {
|
||||
int result;
|
||||
|
||||
/* We use only the first random device. */
|
||||
if (unit!=0) {
|
||||
return ENODEV;
|
||||
}
|
||||
/* We use only the first random device. */
|
||||
if (unit != 0) {
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
KASSERT(the_random==NULL);
|
||||
the_random = rs;
|
||||
KASSERT(the_random == NULL);
|
||||
the_random = rs;
|
||||
|
||||
rs->rs_dev.d_ops = &random_devops;
|
||||
rs->rs_dev.d_blocks = 0;
|
||||
rs->rs_dev.d_blocksize = 1;
|
||||
rs->rs_dev.d_data = rs;
|
||||
rs->rs_dev.d_ops = &random_devops;
|
||||
rs->rs_dev.d_blocks = 0;
|
||||
rs->rs_dev.d_blocksize = 1;
|
||||
rs->rs_dev.d_data = rs;
|
||||
|
||||
/* Add the VFS device structure to the VFS device list. */
|
||||
result = vfs_adddev("random", &rs->rs_dev, 0);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
/* Add the VFS device structure to the VFS device list. */
|
||||
result = vfs_adddev("random", &rs->rs_dev, 0);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Random number functions exported to the rest of the kernel.
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
random(void)
|
||||
{
|
||||
if (the_random==NULL) {
|
||||
panic("No random device\n");
|
||||
}
|
||||
return the_random->rs_random(the_random->rs_devdata);
|
||||
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);
|
||||
uint32_t randmax(void) {
|
||||
if (the_random == NULL) {
|
||||
panic("No random device\n");
|
||||
}
|
||||
return the_random->rs_randmax(the_random->rs_devdata);
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@
|
||||
struct uio;
|
||||
|
||||
struct random_softc {
|
||||
/* Initialized by lower-level attach routine */
|
||||
void *rs_devdata;
|
||||
uint32_t (*rs_random)(void *devdata);
|
||||
uint32_t (*rs_randmax)(void *devdata);
|
||||
int (*rs_read)(void *devdata, struct uio *uio);
|
||||
/* Initialized by lower-level attach routine */
|
||||
void *rs_devdata;
|
||||
uint32_t (*rs_random)(void *devdata);
|
||||
uint32_t (*rs_randmax)(void *devdata);
|
||||
int (*rs_read)(void *devdata, struct uio *uio);
|
||||
|
||||
struct device rs_dev;
|
||||
struct device rs_dev;
|
||||
};
|
||||
|
||||
#endif /* _GENERIC_RANDOM_H_ */
|
||||
|
||||
@@ -49,22 +49,18 @@
|
||||
|
||||
static struct rtclock_softc *the_clock = NULL;
|
||||
|
||||
int
|
||||
config_rtclock(struct rtclock_softc *rtc, int unit)
|
||||
{
|
||||
/* We use only the first clock device. */
|
||||
if (unit!=0) {
|
||||
return ENODEV;
|
||||
}
|
||||
int config_rtclock(struct rtclock_softc *rtc, int unit) {
|
||||
/* We use only the first clock device. */
|
||||
if (unit != 0) {
|
||||
return ENODEV;
|
||||
}
|
||||
|
||||
KASSERT(the_clock==NULL);
|
||||
the_clock = rtc;
|
||||
return 0;
|
||||
KASSERT(the_clock == NULL);
|
||||
the_clock = rtc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
gettime(struct timespec *ts)
|
||||
{
|
||||
KASSERT(the_clock!=NULL);
|
||||
the_clock->rtc_gettime(the_clock->rtc_devdata, ts);
|
||||
void gettime(struct timespec *ts) {
|
||||
KASSERT(the_clock != NULL);
|
||||
the_clock->rtc_gettime(the_clock->rtc_devdata, ts);
|
||||
}
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
struct timespec;
|
||||
|
||||
struct rtclock_softc {
|
||||
void *rtc_devdata;
|
||||
void (*rtc_gettime)(void *devdata, struct timespec *);
|
||||
void *rtc_devdata;
|
||||
void (*rtc_gettime)(void *devdata, struct timespec *);
|
||||
};
|
||||
|
||||
#endif /* _GENERIC_RTCLOCK_H_ */
|
||||
|
||||
Reference in New Issue
Block a user