Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/sun Use a somewhat more flexible method to hook up t...



details:   https://anonhg.NetBSD.org/src/rev/84427db5a4e6
branches:  trunk
changeset: 483830:84427db5a4e6
user:      pk <pk%NetBSD.org@localhost>
date:      Sun Mar 19 12:50:43 2000 +0000

description:
Use a somewhat more flexible method to hook up the keyboard driver
as the console input device.

diffstat:

 sys/dev/sun/kbd.c       |  51 +++++++++++++++++++++++++-----------------------
 sys/dev/sun/kbd_xlate.h |  12 +----------
 sys/dev/sun/kbd_zs.c    |  24 +++++++++++++++++-----
 sys/dev/sun/kbdvar.h    |  30 ++++++++++++++++++++++++++-
 4 files changed, 74 insertions(+), 43 deletions(-)

diffs (290 lines):

diff -r 4e16a04e4665 -r 84427db5a4e6 sys/dev/sun/kbd.c
--- a/sys/dev/sun/kbd.c Sun Mar 19 12:42:45 2000 +0000
+++ b/sys/dev/sun/kbd.c Sun Mar 19 12:50:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd.c,v 1.22 1999/05/14 06:42:02 mrg Exp $     */
+/*     $NetBSD: kbd.c,v 1.23 2000/03/19 12:50:43 pk Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -128,7 +128,7 @@
                return (EBUSY);
        k->k_events.ev_io = p;
 
-       if ((error = kbd_iopen(unit)) != 0) {
+       if ((error = kbd_iopen(k->k_cc)) != 0) {
                k->k_events.ev_io = NULL;
                return (error);
        }
@@ -213,7 +213,7 @@
 kbdioctl(dev, cmd, data, flag, p)
        dev_t dev;
        u_long cmd;
-       register caddr_t data;
+       caddr_t data;
        int flag;
        struct proc *p;
 {
@@ -498,8 +498,8 @@
  */
 int
 kbd_code_to_keysym(ks, c)
-       register struct kbd_state *ks;
-       register int c;
+       struct kbd_state *ks;
+       int c;
 {
        u_short *km;
        int keysym;
@@ -557,7 +557,7 @@
 {
 
        while (*str) {
-               kd_input(*str);
+               (*k->k_cc->cc_upstream)(*str);
                str++;
        }
 }
@@ -565,9 +565,9 @@
 void
 kbd_input_funckey(k, keysym)
        struct kbd_softc *k;
-       register int keysym;
+       int keysym;
 {
-       register int n;
+       int n;
        char str[12];
 
        /*
@@ -589,10 +589,10 @@
 int
 kbd_input_keysym(k, keysym)
        struct kbd_softc *k;
-       register int keysym;
+       int keysym;
 {
        struct kbd_state *ks = &k->k_state;
-       register int data;
+       int data;
 
        switch (KEYSYM_CLASS(keysym)) {
 
@@ -600,7 +600,7 @@
                data = KEYSYM_DATA(keysym);
                if (ks->kbd_modbits & KBMOD_META_MASK)
                        data |= 0x80;
-               kd_input(data);
+               (*k->k_cc->cc_upstream)(data);
                break;
 
        case KEYSYM_STRING:
@@ -669,7 +669,7 @@
 void
 kbd_input_raw(k, c)
        struct kbd_softc *k;
-       register int c;
+       int c;
 {
        struct kbd_state *ks = &k->k_state;
        struct firm_event *fe;
@@ -721,7 +721,7 @@
         * If /dev/kbd is not connected in event mode, 
         * translate and send upstream (to console).
         */
-       if (!k->k_evmode) {
+       if (!k->k_evmode && k->k_isconsole) {
 
                /* Any input stops auto-repeat (i.e. key release). */
                if (k->k_repeating) {
@@ -792,24 +792,21 @@
  * Called with user context.
  */
 int
-kbd_iopen(unit)
-       int unit;
+kbd_iopen(cc)
+       struct cons_channel *cc;
 {
-       struct kbd_softc *k;
+       struct kbd_softc *k = (struct kbd_softc *)cc->cc_dev;
        struct kbd_state *ks;
        int error, s;
 
-       if (unit >= kbd_cd.cd_ndevs)
-               return (ENXIO);
-       k = kbd_cd.cd_devs[unit];
        if (k == NULL)
                return (ENXIO);
+
        ks = &k->k_state;
-       error = 0;
 
        /* Tolerate extra calls. */
        if (k->k_isopen)
-               return (error);
+               return (0);
 
        s = spltty();
 
@@ -858,7 +855,14 @@
        if (error == 0)
                k->k_isopen = 1;
 
-       return error;
+       return (error);
+}
+
+int
+kbd_iclose(cc)
+       struct cons_channel *cc;
+{
+       /* For now: */ return (0);
 }
 
 /*
@@ -1040,7 +1044,7 @@
     struct kbd_softc *k;
 {
        struct kbd_state *ks = &k->k_state;
-       register char leds;
+       char leds;
 
        leds = ks->kbd_leds;
        leds &= ~(LED_CAPS_LOCK|LED_NUM_LOCK);
@@ -1052,4 +1056,3 @@
 
        kbd_set_leds(k, leds);
 }
-
diff -r 4e16a04e4665 -r 84427db5a4e6 sys/dev/sun/kbd_xlate.h
--- a/sys/dev/sun/kbd_xlate.h   Sun Mar 19 12:42:45 2000 +0000
+++ b/sys/dev/sun/kbd_xlate.h   Sun Mar 19 12:50:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd_xlate.h,v 1.2 1996/12/17 20:46:15 gwr Exp $        */
+/*     $NetBSD: kbd_xlate.h,v 1.3 2000/03/19 12:50:43 pk Exp $ */
 
 /*
  * Copyright (c) 1992, 1993
@@ -80,13 +80,3 @@
 
 extern void kbd_xlate_init __P((struct kbd_state *ks));
 extern int kbd_code_to_keysym __P((struct kbd_state *ks, int c));
-
-/*
- * XXX: kd/kbd interface...  Does this belong elsewhere?
- * This is the only header shared between them...
- */
-
-extern int kbd_iopen __P((int unit));
-extern void kd_init __P((int unit));
-extern void kd_input __P((int c));
-
diff -r 4e16a04e4665 -r 84427db5a4e6 sys/dev/sun/kbd_zs.c
--- a/sys/dev/sun/kbd_zs.c      Sun Mar 19 12:42:45 2000 +0000
+++ b/sys/dev/sun/kbd_zs.c      Sun Mar 19 12:50:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbd_zs.c,v 1.1 1999/05/14 06:42:02 mrg Exp $   */
+/*     $NetBSD: kbd_zs.c,v 1.2 2000/03/19 12:50:43 pk Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -62,6 +62,7 @@
 #include <sys/conf.h>
 #include <sys/device.h>
 #include <sys/kernel.h>
+#include <sys/malloc.h>
 #include <sys/proc.h>
 #include <sys/signal.h>
 #include <sys/signalvar.h>
@@ -142,9 +143,23 @@
        k->k_cs = cs;
        k->k_write_data = kbd_zs_write_data;
 
-       if (args->hwflags & ZS_HWFLAG_CONSOLE) {
+       if ((args->hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
+               /*
+                * Hookup ourselves as the console input channel
+                */
+               struct cons_channel *cc;
+
+               if ((cc = malloc(sizeof *cc, M_DEVBUF, M_NOWAIT)) == NULL)
+                       return;
+
+               cc->cc_dev = self;
+               cc->cc_iopen = kbd_iopen;
+               cc->cc_iclose = kbd_iclose;
+               cc->cc_upstream = NULL;
+               cons_attach_input(cc);
+               k->k_cc = cc;
                k->k_isconsole = 1;
-               printf(" (console)");
+               printf(" (console input)");
        }
        printf("\n");
 
@@ -173,9 +188,6 @@
        /* Magic sequence. */
        k->k_magic1 = KBD_L1;
        k->k_magic2 = KBD_A;
-
-       /* Now attach the (kd) pseudo-driver. */
-       kd_init(kbd_unit);
 }
 
 /*
diff -r 4e16a04e4665 -r 84427db5a4e6 sys/dev/sun/kbdvar.h
--- a/sys/dev/sun/kbdvar.h      Sun Mar 19 12:42:45 2000 +0000
+++ b/sys/dev/sun/kbdvar.h      Sun Mar 19 12:50:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kbdvar.h,v 1.1 1999/05/14 07:07:16 mrg Exp $   */
+/*     $NetBSD: kbdvar.h,v 1.2 2000/03/19 12:50:43 pk Exp $    */
 
 /*
  * Copyright (c) 1992, 1993
@@ -115,14 +115,18 @@
        int     k_repeating;            /* we've called timeout() */
        struct  kbd_state k_state;      /* ASCII translation state */
 
+       /* Console hooks */
+       char k_isconsole;
+       struct cons_channel *k_cc;
+
        /*
         * Magic sequence stuff (L1-A)
         */
-       char k_isconsole;
        char k_magic1_down;
        u_char k_magic1;        /* L1 */
        u_char k_magic2;        /* A */
 
+
        /*
         * The transmit ring buffer.
         */
@@ -143,3 +147,25 @@
 void   kbd_input_raw __P((struct kbd_softc *k, int));
 void   kbd_output(struct kbd_softc *k, int c);
 void   kbd_start_tx(struct kbd_softc *k);
+
+/*
+ * kbd console input channel interface.
+ * XXX - does not belong in this header; but for now, kbd is the only user..
+ */
+struct cons_channel {
+       /* Provided by lower driver */
+       void    *cc_dev;                        /* Lower device private data */
+       int     (*cc_iopen)                     /* Open lower device */
+                       __P((struct cons_channel *));
+       int     (*cc_iclose)                    /* Close lower device */
+                       __P((struct cons_channel *));
+
+       /* Provided by upper driver */
+       void    (*cc_upstream)__P((int));       /* Send a character upstream */
+};
+
+/* Special hook to attach the keyboard driver to the console */
+void   cons_attach_input __P((struct cons_channel *));
+
+int    kbd_iopen __P((struct cons_channel *));
+int    kbd_iclose __P((struct cons_channel *));



Home | Main Index | Thread Index | Old Index