Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Un-do a bunch of misguided code sharing. It's not ...



details:   https://anonhg.NetBSD.org/src/rev/eecfa646db81
branches:  trunk
changeset: 959844:eecfa646db81
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Feb 27 02:52:48 2021 +0000

description:
Un-do a bunch of misguided code sharing.  It's not really shared if it's
full of platform-specific #ifdefs:
- ofwoea_batinit() is gone; just do what's needed early in macppc / ofppc
  initppc() functions.
- Get a bunch of Mac-specific stuff out of ofwoea_initppc().

diffstat:

 sys/arch/macppc/include/autoconf.h       |    3 +-
 sys/arch/macppc/macppc/machdep.c         |   58 ++++++++++-
 sys/arch/ofppc/include/autoconf.h        |    3 +-
 sys/arch/ofppc/ofppc/machdep.c           |   87 +++++++++++++++++-
 sys/arch/powerpc/include/ofw_bus.h       |    3 +-
 sys/arch/powerpc/include/ofw_bus_funcs.h |    3 +-
 sys/arch/powerpc/oea/ofwoea_machdep.c    |  147 +-----------------------------
 7 files changed, 145 insertions(+), 159 deletions(-)

diffs (truncated from 474 to 300 lines):

diff -r 1511ed1533ba -r eecfa646db81 sys/arch/macppc/include/autoconf.h
--- a/sys/arch/macppc/include/autoconf.h        Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/macppc/include/autoconf.h        Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.h,v 1.21 2021/02/12 23:38:17 thorpej Exp $    */
+/*     $NetBSD: autoconf.h,v 1.22 2021/02/27 02:52:48 thorpej Exp $    */
 
 /*-
  * Copyright (C) 1998  Internet Research Institute, Inc.
@@ -62,7 +62,6 @@
 
 /* these are in machdep.c */
 void initppc(u_int, u_int, char *);
-void model_init(void);
 paddr_t kvtop(void *);
 void dumpsys(void);
 void copy_disp_props(device_t, int, prop_dictionary_t);
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/macppc/macppc/machdep.c
--- a/sys/arch/macppc/macppc/machdep.c  Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/macppc/macppc/machdep.c  Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.172 2021/01/26 14:49:41 thorpej Exp $    */
+/*     $NetBSD: machdep.c,v 1.173 2021/02/27 02:52:48 thorpej Exp $    */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,13 +32,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.172 2021/01/26 14:49:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.173 2021/02/27 02:52:48 thorpej Exp $");
 
 #include "opt_compat_netbsd.h"
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 #include "opt_altivec.h"
 #include "opt_multiprocessor.h"
+#include "opt_ppcarch.h"
 #include "adb.h"
 #include "zsc.h"
 
@@ -78,6 +79,7 @@
 #include <powerpc/trap.h>
 #include <powerpc/fpu.h>
 #include <powerpc/oea/bat.h>
+#include <powerpc/oea/spr.h>
 #include <powerpc/spr.h>
 #ifdef ALTIVEC
 #include <powerpc/altivec.h>
@@ -124,13 +126,53 @@
 void
 initppc(u_int startkernel, u_int endkernel, char *args)
 {
-       ofwoea_initppc(startkernel, endkernel, args);
-}
+       int node, l;
+
+       node = OF_finddevice("/");
+       if (node != -1) {
+               l = OF_getprop(node, "model", model_name, sizeof(model_name));
+               if (l == -1) {
+                       OF_getprop(node, "name", model_name,
+                           sizeof(model_name));
+               }
+       }
+
+       ofw_quiesce = strncmp(model_name, "PowerMac11,2", 12) == 0 ||
+                     strncmp(model_name, "PowerMac12,1", 12) == 0;
+
+       /* switch CPUs to full speed */
+       if  (strncmp(model_name, "PowerMac7,", 10) == 0) {
+               int clock_ih = OF_open("/u3/i2c/i2c-hwclock");
+               if (clock_ih != 0) {
+                       OF_call_method_1("slew-high", clock_ih, 0);
+               }
+       }
 
-/* perform model-specific actions at initppc() */
-void
-model_init(void)
-{
+       /*
+        * Initialize BAT mappings for our I/O regions.  Note,
+        * on the 601, we use segment mappings under the covers.
+        */
+#ifdef PPC_OEA601
+       if ((mfpvr() >> 16 ) == MPC601) {
+               oea_batinit(
+                   0x80000000, BAT_BL_256M,
+                   0x90000000, BAT_BL_256M,
+                   0xa0000000, BAT_BL_256M,
+                   0xb0000000, BAT_BL_256M,
+                   0xf0000000, BAT_BL_256M,
+                   0);
+       } else
+#endif /* PPC_OEA601 */
+       {
+               oea_batinit(
+                   0x80000000, BAT_BL_1G,
+                   0xf0000000, BAT_BL_128M,
+                   0xf8000000, BAT_BL_64M,
+                   0xfe000000, BAT_BL_8M,      /* Grackle IO */
+                   0);
+       }
+
+       ofwoea_initppc(startkernel, endkernel, args);
 }
 
 void
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/ofppc/include/autoconf.h
--- a/sys/arch/ofppc/include/autoconf.h Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/ofppc/include/autoconf.h Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: autoconf.h,v 1.17 2020/07/07 02:33:54 rin Exp $        */
+/*     $NetBSD: autoconf.h,v 1.18 2021/02/27 02:52:48 thorpej Exp $    */
 
 #ifndef _OFPPC_AUTOCONF_H_
 #define _OFPPC_AUTOCONF_H_
@@ -37,7 +37,6 @@
 
 #ifdef _KERNEL
 void initppc(u_int, u_int, char *);
-void model_init(void);
 void strayintr(int);
 void dumpsys(void);
 
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/ofppc/ofppc/machdep.c
--- a/sys/arch/ofppc/ofppc/machdep.c    Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/ofppc/ofppc/machdep.c    Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.117 2014/03/26 17:38:09 christos Exp $   */
+/*     $NetBSD: machdep.c,v 1.118 2021/02/27 02:52:49 thorpej Exp $    */
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -29,7 +29,9 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.117 2014/03/26 17:38:09 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.118 2021/02/27 02:52:49 thorpej Exp $");
+
+#include "opt_ofwoea.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -74,15 +76,94 @@
 #endif
 
 struct model_data modeldata;
+static void model_init(void);
+
+#ifdef OFWOEA_DEBUG
+#define        DPRINTF printf
+#else
+#define        DPRINTF while (0) printf
+#endif
+
+/*              
+ * Scan the device tree for ranges, and return them as bitmap 0..15
+ */     
+static uint16_t
+ranges_bitmap(int node, uint16_t bitmap)
+{
+       int child, mlen, acells, scells, reclen, i, j;
+       uint32_t addr, len, map[160];
+
+       for (child = OF_child(node); child; child = OF_peer(child)) {
+               mlen = OF_getprop(child, "ranges", map, sizeof(map));
+               if (mlen == -1)
+                       goto noranges;
+
+               j = OF_getprop(child, "#address-cells", &acells,
+                   sizeof(acells));
+               if (j == -1)
+                       goto noranges;
+
+               j = OF_getprop(child, "#size-cells", &scells,
+                   sizeof(scells));
+               if (j == -1)
+                       goto noranges;
+
+               reclen = acells + modeldata.ranges_offset + scells;
+
+               for (i = 0; i < (mlen / 4) / reclen; i++) {
+                       addr = map[reclen * i + acells];
+                       len = map[reclen * i + reclen - 1];
+                       for (j = 0; j < len / 0x10000000; j++)
+                               bitmap |= 1 << ((addr+j*0x10000000) >> 28);
+                       bitmap |= 1 << (addr >> 28);
+               }
+ noranges:
+               bitmap |= ranges_bitmap(child, bitmap);
+               continue;
+       }
+       return bitmap;
+}
 
 void
 initppc(u_int startkernel, u_int endkernel, char *args)
 {
+       int node, i;
+       uint16_t bitmap;
+
+       node = OF_finddevice("/");
+       if (node != -1) {
+               i = OF_getprop(node, "model", model_name, sizeof(model_name));
+               if (i == -1) {
+                       OF_getprop(node, "name", model_name,
+                           sizeof(model_name));
+                       model_init();
+               }
+       }
+
+       if ((oeacpufeat & OEACPU_NOBAT) == 0) {
+               node = OF_finddevice("/");
+
+               bitmap = ranges_bitmap(node, 0);
+               oea_batinit(0);
+
+               for (i = 1; i < 0x10; i++) {
+                       /* skip the three vital SR regions */
+                       if (i == USER_SR || i == KERNEL_SR || i == KERNEL2_SR) {
+                               continue;
+                       }
+                       if (bitmap & (1 << i)) {
+                               oea_iobat_add(0x10000000 * i, BAT_BL_256M);
+                               DPRINTF("Batmapped 256M at 0x%x\n",
+                                   0x10000000 * i);
+                       }
+               }
+       }
+
        ofwoea_initppc(startkernel, endkernel, args);
 }
 
 /* perform model-specific actions at initppc() */
-void
+static void
 model_init(void)
 {
        int qhandle, phandle, j;
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/powerpc/include/ofw_bus.h
--- a/sys/arch/powerpc/include/ofw_bus.h        Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/powerpc/include/ofw_bus.h        Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_bus.h,v 1.4 2010/06/04 20:31:58 chs Exp $ */
+/* $NetBSD: ofw_bus.h,v 1.5 2021/02/27 02:52:48 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -51,7 +51,6 @@
 
 void ofwoea_bus_space_init(void);
 void ofwoea_initppc(u_int, u_int, char *);
-void ofwoea_batinit(void);
 int ofwoea_map_space(int, int, int, struct powerpc_bus_space *, const char *);
 #endif
 
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/powerpc/include/ofw_bus_funcs.h
--- a/sys/arch/powerpc/include/ofw_bus_funcs.h  Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/powerpc/include/ofw_bus_funcs.h  Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_bus_funcs.h,v 1.1 2011/07/01 17:29:39 dyoung Exp $ */
+/* $NetBSD: ofw_bus_funcs.h,v 1.2 2021/02/27 02:52:48 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -40,7 +40,6 @@
 
 void ofwoea_bus_space_init(void);
 void ofwoea_initppc(u_int, u_int, char *);
-void ofwoea_batinit(void);
 int ofwoea_map_space(int, int, int, struct powerpc_bus_space *, const char *);
 #endif
 
diff -r 1511ed1533ba -r eecfa646db81 sys/arch/powerpc/oea/ofwoea_machdep.c
--- a/sys/arch/powerpc/oea/ofwoea_machdep.c     Sat Feb 27 01:31:23 2021 +0000
+++ b/sys/arch/powerpc/oea/ofwoea_machdep.c     Sat Feb 27 02:52:48 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ofwoea_machdep.c,v 1.55 2021/02/27 01:22:18 thorpej Exp $ */
+/* $NetBSD: ofwoea_machdep.c,v 1.56 2021/02/27 02:52:48 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.55 2021/02/27 01:22:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofwoea_machdep.c,v 1.56 2021/02/27 02:52:48 thorpej Exp $");
 
 #include "ksyms.h"
 #include "wsdisplay.h"
@@ -145,18 +145,8 @@
 void
 ofwoea_initppc(u_int startkernel, u_int endkernel, char *args)
 {
-       int node, l;



Home | Main Index | Thread Index | Old Index