Module Name: src
Committed By: thorpej
Date: Fri Mar 5 18:10:07 UTC 2021
Modified Files:
src/sys/arch/powerpc/include: ofw_cons.h
src/sys/arch/powerpc/oea: ofw_consinit.c ofwoea_machdep.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/include/ofw_cons.h
cvs rdiff -u -r1.23 -r1.24 src/sys/arch/powerpc/oea/ofw_consinit.c
cvs rdiff -u -r1.58 -r1.59 src/sys/arch/powerpc/oea/ofwoea_machdep.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/powerpc/include/ofw_cons.h
diff -u src/sys/arch/powerpc/include/ofw_cons.h:1.2 src/sys/arch/powerpc/include/ofw_cons.h:1.3
--- src/sys/arch/powerpc/include/ofw_cons.h:1.2 Wed Oct 17 19:56:41 2007
+++ src/sys/arch/powerpc/include/ofw_cons.h Fri Mar 5 18:10:06 2021
@@ -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_ */
Index: src/sys/arch/powerpc/oea/ofw_consinit.c
diff -u src/sys/arch/powerpc/oea/ofw_consinit.c:1.23 src/sys/arch/powerpc/oea/ofw_consinit.c:1.24
--- src/sys/arch/powerpc/oea/ofw_consinit.c:1.23 Fri Feb 19 18:05:42 2021
+++ src/sys/arch/powerpc/oea/ofw_consinit.c Fri Mar 5 18:10:06 2021
@@ -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 struct consdev consdev_zs;
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 @@ void ofprint(const char *blah, ...)
#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 @@ cninit(void)
/* 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 @@ cninit_kd(void)
#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 @@ cninit_kd(void)
#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 @@ cninit_kd(void)
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 @@ cninit_kd(void)
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 @@ cninit_kd(void)
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 @@ cninit_kd(void)
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 @@ cninit_kd(void)
*/
printf("defaulting to USB...");
printf("console keyboard type: USB\n");
- ukbd_cnattach();
+ selected_keyboard = ukbd_cnattach;
goto kbd_found;
#endif
@@ -359,17 +363,8 @@ cninit_kd(void)
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 @@ ofkbd_cngetc(dev_t dev)
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 @@ ofkbd_cngetc(dev_t dev)
}
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)();
+
+#if NWSDISPLAY > 0
+ /*
+ * XXX This is a little gross, but we don't get to call
+ * XXX wskbd_cnattach() twice.
+ */
+ wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
+#endif
+ }
+}
+
+void
ofwoea_consinit(void)
{
static int initted = 0;
Index: src/sys/arch/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.58 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.59
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.58 Fri Mar 5 02:58:13 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c Fri Mar 5 18:10:06 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.59 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: ofwoea_machdep.c,v 1.58 2021/03/05 02:58:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.59 2021/03/05 18:10:06 thorpej Exp $");
#include "ksyms.h"
#include "wsdisplay.h"
@@ -177,10 +177,8 @@ ofwoea_initppc(u_int startkernel, u_int
/* Get the timebase frequency from the firmware. */
get_timebase_frequency();
- /* Initialize bus_space */
- ofwoea_bus_space_init();
-
- ofwoea_consinit();
+ /* Probe for the console device; it's initialized later. */
+ ofwoea_cnprobe();
if (ofw_quiesce)
OF_quiesce();
@@ -194,6 +192,12 @@ ofwoea_initppc(u_int startkernel, u_int
*/
ofwmsr &= ~PSL_IP;
+ /* Initialize bus_space */
+ ofwoea_bus_space_init();
+
+ /* Initialize the console device. */
+ ofwoea_consinit();
+
uvm_md_init();
pmap_bootstrap(startkernel, endkernel);