Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/atari/dev Add rnd(9) entropy source from keyboard a...



details:   https://anonhg.NetBSD.org/src/rev/7c594a369674
branches:  trunk
changeset: 368142:7c594a369674
user:      tsutsui <tsutsui%NetBSD.org@localhost>
date:      Sat Jun 25 16:09:28 2022 +0000

description:
Add rnd(9) entropy source from keyboard and mouse.

diffstat:

 sys/arch/atari/dev/kbd.c |  28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diffs (88 lines):

diff -r 9288a4682f6d -r 7c594a369674 sys/arch/atari/dev/kbd.c
--- a/sys/arch/atari/dev/kbd.c  Sat Jun 25 15:36:33 2022 +0000
+++ b/sys/arch/atari/dev/kbd.c  Sat Jun 25 16:09:28 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.53 2022/06/25 15:36:33 tsutsui Exp $ */
+/*     $NetBSD: kbd.c,v 1.54 2022/06/25 16:09:28 tsutsui Exp $ */
 
 /*
  * Copyright (c) 1995 Leo Weppelman
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.53 2022/06/25 15:36:33 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kbd.c,v 1.54 2022/06/25 16:09:28 tsutsui Exp $");
 
 #include "mouse.h"
 #include "ite.h"
@@ -48,6 +48,8 @@
 #include <sys/kernel.h>
 #include <sys/signalvar.h>
 #include <sys/syslog.h>
+#include <sys/rndsource.h>
+
 #include <dev/cons.h>
 #include <machine/cpu.h>
 #include <machine/iomap.h>
@@ -93,6 +95,7 @@
        int             sc_pollingmode; /* polling mode on? whatever it is... */
 #endif
        void            *sc_sicookie;   /* softint(9) cookie            */
+       krndsource_t    sc_rndsource;   /* rnd(9) entropy               */
 };
 
 /* WSKBD */
@@ -252,6 +255,8 @@
        kbd_write_poll(kbd_icmd, sizeof(kbd_icmd));
 
        sc->sc_sicookie = softint_establish(SOFTINT_SERIAL, kbdsoft, NULL);
+       rnd_attach_source(&sc->sc_rndsource, device_xname(self),
+           RND_TYPE_TTY, RND_FLAG_DEFAULT);
 
 #if NWSKBD > 0
        if (self != NULL) {
@@ -419,20 +424,24 @@
        /* sr: sr at time of interrupt  */
 {
        struct kbd_softc *sc = &kbd_softc;
-       uint8_t code;
+       uint8_t stat, code;
+       uint32_t rndstat;
        bool got_char = false;
 
        /*
         * There may be multiple keys available. Read them all.
         */
-       while ((KBD->ac_cs & (A_RXRDY | A_OE | A_PE)) != 0) {
+       stat = KBD->ac_cs;
+       rndstat = stat;
+       while ((stat & (A_RXRDY | A_OE | A_PE)) != 0) {
                got_char = true;
                code = KBD->ac_da;
-               if ((KBD->ac_cs & (A_OE | A_PE)) != 0) {
+               if ((stat & (A_OE | A_PE)) == 0) {
+                       kbd_ring[kbd_rbput++ & KBD_RING_MASK] = code;
+               } else {
                        /* Silently ignore errors */
-                       continue;
                }
-               kbd_ring[kbd_rbput++ & KBD_RING_MASK] = code;
+               stat = KBD->ac_cs;
        }
 
        /*
@@ -456,9 +465,12 @@
 
        /*
         * Activate software-level to handle possible input.
+        * Also add status and data to the rnd(9) pool.
         */
-       if (got_char)
+       if (got_char) {
                softint_schedule(sc->sc_sicookie);
+               rnd_add_uint32(&sc->sc_rndsource, (rndstat << 8) | code);
+       }
 }
 
 /*



Home | Main Index | Thread Index | Old Index