Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc Shuffle around a couple of things that aren...



details:   https://anonhg.NetBSD.org/src/rev/f8702d3b1727
branches:  trunk
changeset: 959566:f8702d3b1727
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Feb 19 05:21:39 2021 +0000

description:
Shuffle around a couple of things that aren't particularly OEA-specific:

- Early bootstrap console initialization moves to ofw_machdep.c, and
  is called a bit earlier, from ofw_bootstrap().

- Decoding the "translations" property from /chosen/mmu is specified
  in the general OpenFirmware PowerPC bindings, and is not specific to
  any particular PowerPC flavor.  It's now decoded a bit earlier in
  ofw_bootstrap().

The *interpretation* of the mode field of a translation is, however,
implementation-specific, so that remains in ofwoea_machdep.c.

diffstat:

 sys/arch/powerpc/include/ofw_machdep.h |   27 +++-
 sys/arch/powerpc/oea/ofw_consinit.c    |   85 +-----------
 sys/arch/powerpc/oea/ofwoea_machdep.c  |   85 +++--------
 sys/arch/powerpc/powerpc/ofw_machdep.c |  222 ++++++++++++++++++++++++++++++--
 4 files changed, 266 insertions(+), 153 deletions(-)

diffs (truncated from 654 to 300 lines):

diff -r 2b3a2cfb7b10 -r f8702d3b1727 sys/arch/powerpc/include/ofw_machdep.h
--- a/sys/arch/powerpc/include/ofw_machdep.h    Fri Feb 19 03:42:02 2021 +0000
+++ b/sys/arch/powerpc/include/ofw_machdep.h    Fri Feb 19 05:21:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_machdep.h,v 1.1 2021/02/18 18:31:22 thorpej Exp $ */
+/* $NetBSD: ofw_machdep.h,v 1.2 2021/02/19 05:21:39 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -32,6 +32,31 @@
 #ifdef _KERNEL
 #include <machine/powerpc.h>
 
+/*
+ * The general format of an OpenFirmware virtual translation record is:
+ *
+ *     cell(s)         virt
+ *     cell(s)         size
+ *     cell(s)         phys
+ *     cell            mode
+ *
+ * "mode" contains PTE WIMG bits.
+ *
+ * We define this structure to describe these translations that's independent
+ * of the number of cells each field consumes.
+ */
+struct OF_translation {
+       vaddr_t         virt;
+       vsize_t         size;
+       paddr_t         phys;
+       uint32_t        mode;
+};
+
+#define        OFW_MAX_TRANSLATIONS    32
+
+extern int ofw_chosen;         /* cached handle for "/chosen" */
+extern struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];
+
 void   ofw_bootstrap(void);
 #endif /* _KERNEL */
 
diff -r 2b3a2cfb7b10 -r f8702d3b1727 sys/arch/powerpc/oea/ofw_consinit.c
--- a/sys/arch/powerpc/oea/ofw_consinit.c       Fri Feb 19 03:42:02 2021 +0000
+++ b/sys/arch/powerpc/oea/ofw_consinit.c       Fri Feb 19 05:21:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_consinit.c,v 1.19 2020/07/06 09:34:17 rin Exp $ */
+/* $NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 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.19 2020/07/06 09:34:17 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.20 2021/02/19 05:21:39 thorpej Exp $");
 
 #include "adb.h"
 #include "adbkbd.h"
@@ -54,6 +54,7 @@
 #include <sys/bus.h>
 
 #include <powerpc/ofw_cons.h>
+#include <powerpc/ofw_machdep.h>
 
 #include <dev/cons.h>
 #include <dev/ofw/openfirm.h>
@@ -88,26 +89,14 @@
 #include <dev/ic/pckbcvar.h>
 #endif
 
-int console_node = 0, console_instance = 0;
+extern int console_node, console_instance;
 
-int chosen, stdin, stdout;
 int ofkbd_ihandle;
 
 static void cninit_kd(void);
-static void ofwoea_bootstrap_console(void);
-static int ofwbootcons_cngetc(dev_t);
-static void ofwbootcons_cnputc(dev_t, int);
 
 /*#define OFDEBUG*/
 
-struct consdev consdev_ofwbootcons = {
-       NULL, NULL,
-       ofwbootcons_cngetc,
-       ofwbootcons_cnputc,
-       nullcnpollc,
-       NULL, NULL, NULL, NODEV, CN_INTERNAL,
-};
-
 #ifdef OFDEBUG
 void ofprint(const char *, ...);
 
@@ -133,11 +122,9 @@
 {
        char name[32];
 
-       ofwoea_bootstrap_console();
-
        OFPRINTF("console node: %08x\n", console_node);
 
-       if (console_node == -1)
+       if (console_node <= 0)
                goto nocons;
 
        memset(name, 0, sizeof(name));
@@ -171,9 +158,7 @@
                return;
 #endif /* NZTTY */
 
-               /* fallback to OFW boot console */
-               cp = &consdev_ofwbootcons;
-               cn_tab = cp;
+               /* fallback to OFW boot console (already set) */
                return;
        }
        else
@@ -207,7 +192,7 @@
        /*
         * We must determine which keyboard type we have.
         */
-       if (OF_getprop(chosen, "stdin", &kstdin, sizeof(kstdin))
+       if (OF_getprop(ofw_chosen, "stdin", &kstdin, sizeof(kstdin))
            != sizeof(kstdin)) {
                printf("WARNING: no `stdin' property in /chosen\n");
                return;
@@ -324,7 +309,7 @@
         */
 
 #if NUKBD > 0
-       if (OF_call_method("`usb-kbd-ihandles", stdin, 0, 1, &ukbds) >= 0 &&
+       if (OF_call_method("`usb-kbd-ihandles", kstdin, 0, 1, &ukbds) >= 0 &&
            ukbds != NULL && ukbds->ihandle != 0 &&
            OF_instance_to_package(ukbds->ihandle) != -1) {
                printf("usb-kbd-ihandles matches\n");
@@ -407,30 +392,6 @@
        return c;
 }
 
-/*
- * Bootstrap console support functions
- */
-
-static int
-ofwbootcons_cngetc(dev_t dev)
-{
-       unsigned char ch = '\0';
-       int l;
-
-       while ((l = OF_read(stdin, &ch, 1)) != 1)
-               if (l != -2 && l != 0)
-                       return -1;
-       return ch;
-}
-
-static void
-ofwbootcons_cnputc(dev_t dev, int c)
-{
-       char ch = c;
-
-       OF_write(stdout, &ch, 1);
-}
-
 void
 ofwoea_consinit(void)
 {
@@ -442,33 +403,3 @@
        initted = 1;
        cninit();
 }
-
-static void
-ofwoea_bootstrap_console(void)
-{
-       int node;
-
-       chosen = OF_finddevice("/chosen");
-       if (chosen == -1)
-               goto nocons;
-
-       if (OF_getprop(chosen, "stdout", &stdout,
-           sizeof(stdout)) != sizeof(stdout))
-               goto nocons;
-       if (OF_getprop(chosen, "stdin", &stdin,
-           sizeof(stdin)) != sizeof(stdin))
-               goto nocons;
-       if (stdout == 0) {
-                /* screen should be console, but it is not open */
-                stdout = OF_open("screen");
-       }
-       node = OF_instance_to_package(stdout);
-       console_node = node;
-       console_instance = stdout;
-
-       return;
-nocons:
-       panic("No /chosen could be found!\n");
-       console_node = -1;
-       return;
-}
diff -r 2b3a2cfb7b10 -r f8702d3b1727 sys/arch/powerpc/oea/ofwoea_machdep.c
--- a/sys/arch/powerpc/oea/ofwoea_machdep.c     Fri Feb 19 03:42:02 2021 +0000
+++ b/sys/arch/powerpc/oea/ofwoea_machdep.c     Fri Feb 19 05:21:39 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.51 2021/02/12 23:40:02 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.52 2021/02/19 05:21:39 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.51 2021/02/12 23:40:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.52 2021/02/19 05:21:39 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -69,6 +69,7 @@
 #include <powerpc/oea/cpufeat.h>
 #include <powerpc/include/oea/spr.h>
 #include <powerpc/ofw_cons.h>
+#include <powerpc/ofw_machdep.h>
 #include <powerpc/spr.h>
 #include <powerpc/pic/picvar.h>
 
@@ -97,19 +98,9 @@
        int type;
 } rangemap_t;
 
-struct ofw_translations {
-       vaddr_t va;
-       int len;
-#if defined (PMAC_G5)
-       register64_t pa;
-#else
-       register_t pa;
-#endif
-       int mode;
-}__attribute__((packed));
+struct OF_translation ofw_translations[OFW_MAX_TRANSLATIONS];
 
 struct pmap ofw_pmap;
-struct ofw_translations ofmap[32];
 char bootpath[256];
 char model_name[64];
 #if NKSYMS || defined(DDB) || defined(MODULAR)
@@ -129,13 +120,11 @@
 int ofw_quiesce;
 
 extern int ofwmsr;
-extern int chosen;
 extern uint32_t ticks_per_sec;
 extern uint32_t ns_per_tick;
 extern uint32_t ticks_per_intr;
 
-static int save_ofmap(struct ofw_translations *, int);
-static void restore_ofmap(struct ofw_translations *, int);
+static void restore_ofmap(void);
 static void set_timebase(void);
 
 extern void cpu_spinstart(u_int);
@@ -144,7 +133,7 @@
 void
 ofwoea_initppc(u_int startkernel, u_int endkernel, char *args)
 {
-       int ofmaplen, node, l;
+       int node, l;
        register_t scratch;
 
 #if defined(MULTIPROCESSOR) && defined(ofppc)
@@ -216,10 +205,6 @@
 
        oea_init(pic_ext_intr);
 
-       ofmaplen = save_ofmap(NULL, 0);
-       if (ofmaplen > 0)
-               save_ofmap(ofmap, ofmaplen);
-
 /*
  * XXX
  * we need to do this here instead of earlier on in ofwinit() for some reason
@@ -305,7 +290,7 @@
            : "=r"(scratch)
            : "K"(PSL_IR|PSL_DR|PSL_ME|PSL_RI));
 
-       restore_ofmap(ofmap, ofmaplen);
+       restore_ofmap();
 
        rascons_finalize();
 
@@ -376,33 +361,11 @@
        mtmsr(msr);
 }
 
-static int
-save_ofmap(struct ofw_translations *map, int maxlen)
+void



Home | Main Index | Thread Index | Old Index