Module Name: src
Committed By: thorpej
Date: Sat Feb 27 02:52:49 UTC 2021
Modified Files:
src/sys/arch/macppc/include: autoconf.h
src/sys/arch/macppc/macppc: machdep.c
src/sys/arch/ofppc/include: autoconf.h
src/sys/arch/ofppc/ofppc: machdep.c
src/sys/arch/powerpc/include: ofw_bus.h ofw_bus_funcs.h
src/sys/arch/powerpc/oea: ofwoea_machdep.c
Log Message:
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().
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/macppc/include/autoconf.h
cvs rdiff -u -r1.172 -r1.173 src/sys/arch/macppc/macppc/machdep.c
cvs rdiff -u -r1.17 -r1.18 src/sys/arch/ofppc/include/autoconf.h
cvs rdiff -u -r1.117 -r1.118 src/sys/arch/ofppc/ofppc/machdep.c
cvs rdiff -u -r1.4 -r1.5 src/sys/arch/powerpc/include/ofw_bus.h
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/powerpc/include/ofw_bus_funcs.h
cvs rdiff -u -r1.55 -r1.56 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/macppc/include/autoconf.h
diff -u src/sys/arch/macppc/include/autoconf.h:1.21 src/sys/arch/macppc/include/autoconf.h:1.22
--- src/sys/arch/macppc/include/autoconf.h:1.21 Fri Feb 12 23:38:17 2021
+++ src/sys/arch/macppc/include/autoconf.h Sat Feb 27 02:52:48 2021
@@ -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 @@ void identifycpu(char *);
/* 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);
Index: src/sys/arch/macppc/macppc/machdep.c
diff -u src/sys/arch/macppc/macppc/machdep.c:1.172 src/sys/arch/macppc/macppc/machdep.c:1.173
--- src/sys/arch/macppc/macppc/machdep.c:1.172 Tue Jan 26 14:49:41 2021
+++ src/sys/arch/macppc/macppc/machdep.c Sat Feb 27 02:52:48 2021
@@ -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 @@ __KERNEL_RCSID(0, "$NetBSD: machdep.c,v
#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 @@ static int of_upd_brightness(void *, int
void
initppc(u_int startkernel, u_int endkernel, char *args)
{
- ofwoea_initppc(startkernel, endkernel, args);
-}
+ int node, l;
-/* perform model-specific actions at initppc() */
-void
-model_init(void)
-{
+ 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);
+ }
+ }
+
+ /*
+ * 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
Index: src/sys/arch/ofppc/include/autoconf.h
diff -u src/sys/arch/ofppc/include/autoconf.h:1.17 src/sys/arch/ofppc/include/autoconf.h:1.18
--- src/sys/arch/ofppc/include/autoconf.h:1.17 Tue Jul 7 02:33:54 2020
+++ src/sys/arch/ofppc/include/autoconf.h Sat Feb 27 02:52:48 2021
@@ -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 @@ extern char model_name[64];
#ifdef _KERNEL
void initppc(u_int, u_int, char *);
-void model_init(void);
void strayintr(int);
void dumpsys(void);
Index: src/sys/arch/ofppc/ofppc/machdep.c
diff -u src/sys/arch/ofppc/ofppc/machdep.c:1.117 src/sys/arch/ofppc/ofppc/machdep.c:1.118
--- src/sys/arch/ofppc/ofppc/machdep.c:1.117 Wed Mar 26 17:38:09 2014
+++ src/sys/arch/ofppc/ofppc/machdep.c Sat Feb 27 02:52:49 2021
@@ -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 @@ extern int machine_has_rtas;
#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;
Index: src/sys/arch/powerpc/include/ofw_bus.h
diff -u src/sys/arch/powerpc/include/ofw_bus.h:1.4 src/sys/arch/powerpc/include/ofw_bus.h:1.5
--- src/sys/arch/powerpc/include/ofw_bus.h:1.4 Fri Jun 4 20:31:58 2010
+++ src/sys/arch/powerpc/include/ofw_bus.h Sat Feb 27 02:52:48 2021
@@ -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 @@ extern struct powerpc_bus_space genppc_i
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
Index: src/sys/arch/powerpc/include/ofw_bus_funcs.h
diff -u src/sys/arch/powerpc/include/ofw_bus_funcs.h:1.1 src/sys/arch/powerpc/include/ofw_bus_funcs.h:1.2
--- src/sys/arch/powerpc/include/ofw_bus_funcs.h:1.1 Fri Jul 1 17:29:39 2011
+++ src/sys/arch/powerpc/include/ofw_bus_funcs.h Sat Feb 27 02:52:48 2021
@@ -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 @@ extern struct powerpc_bus_space genppc_i
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
Index: src/sys/arch/powerpc/oea/ofwoea_machdep.c
diff -u src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.55 src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.56
--- src/sys/arch/powerpc/oea/ofwoea_machdep.c:1.55 Sat Feb 27 01:22:18 2021
+++ src/sys/arch/powerpc/oea/ofwoea_machdep.c Sat Feb 27 02:52:48 2021
@@ -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 @@ extern volatile u_int cpu_spinstart_ack;
void
ofwoea_initppc(u_int startkernel, u_int endkernel, char *args)
{
- int node, l;
register_t scratch;
-#if defined(MULTIPROCESSOR) && defined(ofppc)
- char cpupath[32];
- int i;
-#endif
-
- /* initialze bats */
- if ((oeacpufeat & OEACPU_NOBAT) == 0)
- ofwoea_batinit();
-
#if NKSYMS || defined(DDB) || defined(MODULAR)
/* get info of kernel symbol table from bootloader */
memcpy(&startsym, args + strlen(args) + 1, sizeof(startsym));
@@ -166,29 +156,6 @@ ofwoea_initppc(u_int startkernel, u_int
startsym = endsym = NULL;
#endif
- /* get model name and perform model-specific actions */
- memset(model_name, 0, sizeof(model_name));
- 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));
- model_init();
- }
-
- if (strncmp(model_name, "PowerMac11,2", 12) == 0 ||
- strncmp(model_name, "PowerMac12,1", 12) == 0)
- ofw_quiesce = 1;
-
- /* 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);
- }
- }
-
/* Initialize bus_space */
ofwoea_bus_space_init();
@@ -198,14 +165,17 @@ ofwoea_initppc(u_int startkernel, u_int
OF_quiesce();
#if defined(MULTIPROCESSOR) && defined(ofppc)
- for (i=1; i < CPU_MAXNUM; i++) {
+ char cpupath[32];
+ int i, l, node;
+
+ for (i = 1; i < CPU_MAXNUM; i++) {
snprintf(cpupath, sizeof(cpupath), "/cpus/@%x", i);
node = OF_finddevice(cpupath);
if (node <= 0)
continue;
aprint_verbose("Starting up CPU %d %s\n", i, cpupath);
OF_start_cpu(node, (u_int)cpu_spinstart, i);
- for (l=0; l < 100000000; l++) {
+ for (l = 0; l < 100000000; l++) {
if (cpu_spinstart_ack == i) {
aprint_verbose("CPU %d spun up.\n", i);
break;
@@ -427,109 +397,6 @@ restore_ofmap(void)
pmap_update(&ofw_pmap);
}
-
-
-/*
- * Scan the device tree for ranges, and return them as bitmap 0..15
- */
-#if !defined(macppc) && defined(PPC_OEA)
-static u_int16_t
-ranges_bitmap(int node, u_int16_t bitmap)
-{
- int child, mlen, acells, scells, reclen, i, j;
- u_int32_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;
-
-#ifdef ofppc
- reclen = acells + modeldata.ranges_offset + scells;
-#else
- reclen = acells + 1 + scells;
-#endif
-
- 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;
-}
-#endif /* !macppc && PPC_OEA */
-
-void
-ofwoea_batinit(void)
-{
-#if defined (PPC_OEA)
-
-#ifdef macppc
- /*
- * cover PCI and register space but not the firmware ROM
- */
-#ifdef PPC_OEA601
-
- /*
- * use segment registers for the 601
- */
- 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 */
- /*
- * map to bats
- */
- oea_batinit(0x80000000, BAT_BL_1G,
- 0xf0000000, BAT_BL_128M,
- 0xf8000000, BAT_BL_64M,
- 0xfe000000, BAT_BL_8M, /* Grackle IO */
- 0);
-#else /* ! macppc */
- uint16_t bitmap;
- int node, i;
-
- 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);
- }
- }
-#endif /* macppc */
-#endif /* OEA */
-}
-
-
/* we define these partially, as we will fill the rest in later */
struct powerpc_bus_space genppc_isa_io_space_tag = {
.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,