Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Separate probing for the console device and...



details:   https://anonhg.NetBSD.org/src/rev/230a77921a4c
branches:  trunk
changeset: 960027:230a77921a4c
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Mar 05 18:10:06 2021 +0000

description:
Separate probing for the console device and initializing it, so that
ofwoea_initppc() can have more control over which of those steps are
performed during initialization.  Probing happens before setting up
the exception vectors, initializing happens after.

diffstat:

 sys/arch/powerpc/include/ofw_cons.h   |    7 +-
 sys/arch/powerpc/oea/ofw_consinit.c   |  139 ++++++++++++++++++++-------------
 sys/arch/powerpc/oea/ofwoea_machdep.c |   16 ++-
 3 files changed, 96 insertions(+), 66 deletions(-)

diffs (truncated from 358 to 300 lines):

diff -r 6f2f7cf9cc63 -r 230a77921a4c sys/arch/powerpc/include/ofw_cons.h
--- a/sys/arch/powerpc/include/ofw_cons.h       Fri Mar 05 18:08:21 2021 +0000
+++ b/sys/arch/powerpc/include/ofw_cons.h       Fri Mar 05 18:10:06 2021 +0000
@@ -1,9 +1,10 @@
-/* $NetBSD: ofw_cons.h,v 1.2 2007/10/17 19:56:41 garbled Exp $ */
+/* $NetBSD: ofw_cons.h,v 1.3 2021/03/05 18:10:06 thorpej Exp $ */
 
 #ifndef _POWERPC_OFW_CONS_H_
 #define _POWERPC_OFW_CONS_H_
 
-void ofwoea_consinit(void);
-int ofkbd_cngetc(dev_t dev);
+void   ofwoea_cnprobe(void);
+void   ofwoea_consinit(void);
+int    ofkbd_cngetc(dev_t dev);
 
 #endif /* _POWERPC_OFW_CONS_H_ */
diff -r 6f2f7cf9cc63 -r 230a77921a4c sys/arch/powerpc/oea/ofw_consinit.c
--- a/sys/arch/powerpc/oea/ofw_consinit.c       Fri Mar 05 18:08:21 2021 +0000
+++ b/sys/arch/powerpc/oea/ofw_consinit.c       Fri Mar 05 18:10:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.23 2021/02/19 18:05:42 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.24 2021/03/05 18:10:06 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -91,9 +91,9 @@
 
 extern int console_node, console_instance;
 
-int ofkbd_ihandle;
+int ofkbd_ihandle = -1;
 
-static void cninit_kd(void);
+static void ofwoea_cnprobe_keyboard(void);
 
 /*#define OFDEBUG*/
 
@@ -117,39 +117,51 @@
 #define OFPRINTF while(0) printf
 #endif
 
+static bool use_serial_console;
+static struct consdev *selected_serial_consdev;
+
+static int (*selected_keyboard)(void);
+
+/* XXX Gross. */
+#if NPCKBC > 0
+static int
+ofwoea_pckbd_cnattach(void)
+{
+       return pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
+           PCKBC_KBD_SLOT, 0);
+}
+#endif
+
 void
-cninit(void)
+ofwoea_cnprobe(void)
 {
        char name[32];
 
        OFPRINTF("console node: %08x\n", console_node);
 
        if (console_node == -1)
-               goto nocons;
+               return;
 
        memset(name, 0, sizeof(name));
        if (OF_getprop(console_node, "device_type", name, sizeof(name)) == -1)
-               goto nocons;
+               return;
 
        OFPRINTF("console type: %s\n", name);
 
        if (strcmp(name, "serial") == 0) {
+               use_serial_console = true;
 #ifdef PMAC_G5
                /* The MMU hasn't been initialized yet, use failsafe for now */
                extern struct consdev failsafe_cons;
-               cn_tab = &failsafe_cons;
-               (*cn_tab->cn_probe)(cn_tab);
-               (*cn_tab->cn_init)(cn_tab);
-               aprint_verbose("Early G5 console initialized\n");
+               selected_serial_consdev = &failsafe_cons;
+               aprint_verbose("Early G5 console selected\n");
                return;
 #endif /* PMAC_G5 */
 
 #if (NZSTTY > 0) && !defined(MAMBO)
                OF_getprop(console_node, "name", name, sizeof(name));
                if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
-                       cn_tab = &consdev_zs;
-                       (*cn_tab->cn_probe)(cn_tab);
-                       (*cn_tab->cn_init)(cn_tab);
+                       selected_serial_consdev = &consdev_zs;
                }
                return;
 #endif /* NZTTY */
@@ -157,17 +169,24 @@
                /* fallback to OFW boot console (already set) */
                return;
        }
-       else
-               cninit_kd();
-nocons:
-       return;
+
+       /*
+        * We're going to use a display console.  Probe for the keyboard
+        * we'll use.
+        */
+       ofwoea_cnprobe_keyboard();
 }
 
-
+/*
+ * XXX This routine is a complete disaster, filled with platform-specific
+ * XXX stuff.  Fix, plz.
+ */
 static void
-cninit_kd(void)
+ofwoea_cnprobe_keyboard(void)
 {
-       int kstdin, node;
+       extern int ofw_stdin;
+
+       int node, kstdin = ofw_stdin;
        char name[16];
 #if (NAKBD > 0) || (NADBKBD > 0)
        int akbd;
@@ -178,22 +197,8 @@
 #endif
 
        /*
-        * Attach the console output now (so we can see debugging messages,
-        * if any).
-        */
-#if NWSDISPLAY > 0
-       rascons_cnattach();
-#endif
-
-       /*
         * We must determine which keyboard type we have.
         */
-       if (OF_getprop(ofw_chosen, "stdin", &kstdin, sizeof(kstdin))
-           != sizeof(kstdin)) {
-               printf("WARNING: no `stdin' property in /chosen\n");
-               return;
-       }
-
        node = OF_instance_to_package(kstdin);
        memset(name, 0, sizeof(name));
        OF_getprop(node, "name", name, sizeof(name));
@@ -207,22 +212,21 @@
 #if NAKBD > 0
        if (strcmp(name, "adb") == 0) {
                printf("console keyboard type: ADB\n");
-               akbd_cnattach();
+               selected_keyboard = akbd_cnattach;
                goto kbd_found;
        }
 #endif
 #if NADBKBD > 0
        if (strcmp(name, "adb") == 0) {
                printf("console keyboard type: ADB\n");
-               adbkbd_cnattach();
+               selected_keyboard = adbkbd_cnattach;
                goto kbd_found;
        }
 #endif
 #if NPCKBC > 0
        if (strcmp(name, "isa") == 0) {
                printf("console keyboard type: PC Keyboard\n");
-               pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
-                   PCKBC_KBD_SLOT, 0);
+               selected_keyboard = ofwoea_pckbd_cnattach;
                goto kbd_found;
        }
 #endif
@@ -281,17 +285,17 @@
                if (adb_node > 0) {
                        printf("ADB support found\n");
 #if NAKBD > 0
-                       akbd_cnattach();
+                       selected_keyboard = akbd_cnattach;
 #endif
 #if NADBKBD > 0
-                       adbkbd_cnattach();
+                       selected_keyboard = adbkbd_cnattach;
 #endif
                } else {
                        /* must be USB */
                        printf("No ADB support present, assuming USB "
                               "keyboard\n");
 #if NUKBD > 0
-                       ukbd_cnattach();
+                       selected_keyboard = ukbd_cnattach;
 #endif
                }
                goto kbd_found;
@@ -310,7 +314,7 @@
            OF_instance_to_package(ukbds->ihandle) != -1) {
                printf("usb-kbd-ihandles matches\n");
                printf("console keyboard type: USB\n");
-               ukbd_cnattach();
+               selected_keyboard = ukbd_cnattach;
                goto kbd_found;
        }
        /* Try old method name. */
@@ -320,7 +324,7 @@
                printf("usb-kbd-ihandle matches\n");
                printf("console keyboard type: USB\n");
                kstdin = ukbd;
-               ukbd_cnattach();
+               selected_keyboard = ukbd_cnattach;
                goto kbd_found;
        }
 #endif
@@ -333,10 +337,10 @@
                printf("console keyboard type: ADB\n");
                kstdin = akbd;
 #if NAKBD > 0
-               akbd_cnattach();
+               selected_keyboard = akbd_cnattach;
 #endif
 #if NADBKBD > 0
-               adbkbd_cnattach();
+               selected_keyboard = adbkbd_cnattach;
 #endif
                goto kbd_found;
        }
@@ -349,7 +353,7 @@
         */
        printf("defaulting to USB...");
        printf("console keyboard type: USB\n");
-       ukbd_cnattach();
+       selected_keyboard = ukbd_cnattach;
        goto kbd_found;
 #endif
 
@@ -359,17 +363,8 @@
        printf("no console keyboard\n");
        return;
 
-kbd_found:;
-#if NAKBD + NUKBD + NADBKBD + NPCKBC > 0
-       /*
-        * XXX This is a little gross, but we don't get to call
-        * XXX wskbd_cnattach() twice.
-        */
+kbd_found:
        ofkbd_ihandle = kstdin;
-#if NWSDISPLAY > 0
-       wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
-#endif
-#endif
 }
 
 /*
@@ -381,6 +376,8 @@
        u_char c = '\0';
        int len;
 
+       KASSERT(ofkbd_ihandle != -1);
+
        do {
                len = OF_read(ofkbd_ihandle, &c, 1);
        } while (len != 1);
@@ -389,6 +386,34 @@
 }
 
 void
+cninit(void)
+{
+       if (use_serial_console) {
+               if (selected_serial_consdev != NULL) {
+                       cn_tab = selected_serial_consdev;
+                       (*cn_tab->cn_probe)(cn_tab);
+                       (*cn_tab->cn_init)(cn_tab);
+               }
+               return;
+       }
+
+#if NWSDISPLAY > 0
+       rascons_cnattach();
+#endif
+       if (selected_keyboard != NULL) {
+               (*selected_keyboard)();
+



Home | Main Index | Thread Index | Old Index