Module Name: src
Committed By: thorpej
Date: Thu Feb 18 18:31:22 UTC 2021
Modified Files:
src/sys/arch/powerpc/oea: ofw_subr.S
src/sys/arch/powerpc/powerpc: ofw_machdep.c
Added Files:
src/sys/arch/powerpc/include: ofw_machdep.h
Log Message:
Add an ofw_bootstrap() function, called during early bootstrap from
ofwinit() to perform additional early initialization in C code. Use
this to get the memory config while we're still running in the OpenFirmware
client environment, rather than waiting until we've started fiddling with
the system state.
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/arch/powerpc/include/ofw_machdep.h
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/powerpc/oea/ofw_subr.S
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/powerpc/powerpc/ofw_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/oea/ofw_subr.S
diff -u src/sys/arch/powerpc/oea/ofw_subr.S:1.14 src/sys/arch/powerpc/oea/ofw_subr.S:1.15
--- src/sys/arch/powerpc/oea/ofw_subr.S:1.14 Thu Feb 18 16:29:12 2021
+++ src/sys/arch/powerpc/oea/ofw_subr.S Thu Feb 18 18:31:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_subr.S,v 1.14 2021/02/18 16:29:12 thorpej Exp $ */
+/* $NetBSD: ofw_subr.S,v 1.15 2021/02/18 18:31:22 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -113,7 +113,13 @@ ENTRY_NOPROFILE(ofwinit)
lis %r9,_C_LABEL(OF_buf)@ha
stw %r8,_C_LABEL(OF_buf)@l(%r9)
- /* XXX Do other stuff in C code. */
+ /*
+ * Call into C code to perform additional early initialization.
+ */
+ lis %r8,_C_LABEL(ofw_bootstrap)@ha
+ addi %r8,%r8,_C_LABEL(ofw_bootstrap)@l
+ mtctr %r8
+ bctrl
/*
* Jump off the trampoline for all subsequent calls
Index: src/sys/arch/powerpc/powerpc/ofw_machdep.c
diff -u src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.26 src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.27
--- src/sys/arch/powerpc/powerpc/ofw_machdep.c:1.26 Wed Jan 27 03:17:24 2021
+++ src/sys/arch/powerpc/powerpc/ofw_machdep.c Thu Feb 18 18:31:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $ */
+/* $NetBSD: ofw_machdep.c,v 1.27 2021/02/18 18:31:22 thorpej Exp $ */
/*
* Copyright (C) 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.26 2021/01/27 03:17:24 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_machdep.c,v 1.27 2021/02/18 18:31:22 thorpej Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -50,6 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_machdep.
#include <machine/powerpc.h>
#include <machine/autoconf.h>
+#include <powerpc/ofw_machdep.h>
+
#ifdef DEBUG
#define DPRINTF aprint_error
#else
@@ -59,15 +61,8 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_machdep.
#define OFMEM_REGIONS 32
static struct mem_region OFmem[OFMEM_REGIONS + 1], OFavail[OFMEM_REGIONS + 3];
-/*
- * This is called during initppc, before the system is really initialized.
- * It shall provide the total and the available regions of RAM.
- * Both lists must have a zero-size entry as terminator.
- * The available regions need not take the kernel into account, but needs
- * to provide space for two additional entry beyond the terminating one.
- */
-void
-mem_regions(struct mem_region **memp, struct mem_region **availp)
+static void
+ofw_bootstrap_get_memory(void)
{
const char *macrisc[] = {"MacRISC", "MacRISC2", "MacRISC4", NULL};
int hroot, hmem, i, cnt, memcnt, regcnt, acells, scells;
@@ -225,8 +220,6 @@ mem_regions(struct mem_region **memp, st
}
}
- *memp = OFmem;
- *availp = OFavail;
return;
error:
@@ -239,14 +232,40 @@ error:
OFavail[0].start = 0x3000;
OFavail[0].size = 0x20000000 - 0x3000;
- *memp = OFmem;
- *availp = OFavail;
#else
panic("no memory?");
#endif
return;
}
+/*
+ * Called from ofwinit() very early in bootstrap. We are still
+ * running on the stack provided by OpenFirmware and in the same
+ * OpenFirmware client environment as the boot loader. Our calls
+ * to OpenFirmware are direct, and not via the trampoline that
+ * saves / restores kernel state.
+ */
+void
+ofw_bootstrap(void)
+{
+ /* Get the system memory configuration. */
+ ofw_bootstrap_get_memory();
+}
+
+/*
+ * This is called during initppc, before the system is really initialized.
+ * It shall provide the total and the available regions of RAM.
+ * Both lists must have a zero-size entry as terminator.
+ * The available regions need not take the kernel into account, but needs
+ * to provide space for two additional entry beyond the terminating one.
+ */
+void
+mem_regions(struct mem_region **memp, struct mem_region **availp)
+{
+ *memp = OFmem;
+ *availp = OFavail;
+}
+
void
ppc_exit(void)
{
Added files:
Index: src/sys/arch/powerpc/include/ofw_machdep.h
diff -u /dev/null src/sys/arch/powerpc/include/ofw_machdep.h:1.1
--- /dev/null Thu Feb 18 18:31:22 2021
+++ src/sys/arch/powerpc/include/ofw_machdep.h Thu Feb 18 18:31:22 2021
@@ -0,0 +1,38 @@
+/* $NetBSD: ofw_machdep.h,v 1.1 2021/02/18 18:31:22 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _POWERPC_OFW_MACHDEP_H_
+#define _POWERPC_OFW_MACHDEP_H_
+
+#ifdef _KERNEL
+#include <machine/powerpc.h>
+
+void ofw_bootstrap(void);
+#endif /* _KERNEL */
+
+#endif /* _POWERPC_OFW_MACHDEP_H_ */