Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Sep 2016 02:28:39 +0000 (UTC)
From:      Justin Hibbits <jhibbits@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r306065 - in head/sys: dev/ofw powerpc/ofw powerpc/powerpc
Message-ID:  <201609210228.u8L2Sdfn015537@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhibbits
Date: Wed Sep 21 02:28:39 2016
New Revision: 306065
URL: https://svnweb.freebsd.org/changeset/base/306065

Log:
  Add a ofw_parse_bootargs function, and use it for powerpc
  
  Summary:
  If the environment variable is set, U-boot adds a 'bootargs' property to
  /chosen.  This is already handled by ARM and MIPS, but should be handled in a
  central location.  For now, ofw_subr.c is a good place until we determine if it
  should be moved to init_main.c, or somewhere more central to all architectures.
  
  Eventually arm and mips should be modified to use ofw_parse_bootargs() as well,
  rather than using the duplicate code already.
  
  Reviewed By: adrian
  Differential Revision: https://reviews.freebsd.org/D7846

Modified:
  head/sys/dev/ofw/ofw_subr.c
  head/sys/dev/ofw/ofw_subr.h
  head/sys/powerpc/ofw/ofw_machdep.c
  head/sys/powerpc/powerpc/machdep.c

Modified: head/sys/dev/ofw/ofw_subr.c
==============================================================================
--- head/sys/dev/ofw/ofw_subr.c	Wed Sep 21 02:27:23 2016	(r306064)
+++ head/sys/dev/ofw/ofw_subr.c	Wed Sep 21 02:28:39 2016	(r306065)
@@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/param.h>
 #include <sys/bus.h>
 #include <sys/libkern.h>
+#include <sys/reboot.h>
 #include <sys/rman.h>
 
 #include <machine/bus.h>
@@ -180,3 +181,64 @@ ofw_reg_to_paddr(phandle_t dev, int regn
 
 	return (0);
 }
+
+/* Parse cmd line args as env - copied from xlp_machdep. */
+/* XXX-BZ this should really be centrally provided for all (boot) code. */
+static void
+_parse_bootargs(char *cmdline)
+{
+	char *n, *v;
+
+	while ((v = strsep(&cmdline, " \n")) != NULL) {
+		if (*v == '\0')
+			continue;
+		if (*v == '-') {
+			while (*v != '\0') {
+				v++;
+				switch (*v) {
+				case 'a': boothowto |= RB_ASKNAME; break;
+				/* Someone should simulate that ;-) */
+				case 'C': boothowto |= RB_CDROM; break;
+				case 'd': boothowto |= RB_KDB; break;
+				case 'D': boothowto |= RB_MULTIPLE; break;
+				case 'm': boothowto |= RB_MUTE; break;
+				case 'g': boothowto |= RB_GDB; break;
+				case 'h': boothowto |= RB_SERIAL; break;
+				case 'p': boothowto |= RB_PAUSE; break;
+				case 'r': boothowto |= RB_DFLTROOT; break;
+				case 's': boothowto |= RB_SINGLE; break;
+				case 'v': boothowto |= RB_VERBOSE; break;
+				}
+			}
+		} else {
+			n = strsep(&v, "=");
+			if (v == NULL)
+				kern_setenv(n, "1");
+			else
+				kern_setenv(n, v);
+		}
+	}
+}
+
+/*
+ * This is intended to be called early on, right after the OF system is
+ * initialized, so pmap may not be up yet.
+ */
+int
+ofw_parse_bootargs(void)
+{
+	phandle_t chosen;
+	char buf[2048];		/* early stack supposedly big enough */
+	int err;
+
+	chosen = OF_finddevice("/chosen");
+	if (chosen <= 0)
+		return (chosen);
+
+	if ((err = OF_getprop(chosen, "bootargs", buf, sizeof(buf))) != -1) {
+		_parse_bootargs(buf);
+		return (0);
+	}
+
+	return (err);
+}

Modified: head/sys/dev/ofw/ofw_subr.h
==============================================================================
--- head/sys/dev/ofw/ofw_subr.h	Wed Sep 21 02:27:23 2016	(r306064)
+++ head/sys/dev/ofw/ofw_subr.h	Wed Sep 21 02:28:39 2016	(r306065)
@@ -46,4 +46,6 @@
 int ofw_reg_to_paddr(phandle_t _dev, int _regno, bus_addr_t *_paddr,
     bus_size_t *_size, pcell_t *_pci_hi);
 
+int ofw_parse_bootargs(void);
+
 #endif

Modified: head/sys/powerpc/ofw/ofw_machdep.c
==============================================================================
--- head/sys/powerpc/ofw/ofw_machdep.c	Wed Sep 21 02:27:23 2016	(r306064)
+++ head/sys/powerpc/ofw/ofw_machdep.c	Wed Sep 21 02:28:39 2016	(r306065)
@@ -99,6 +99,7 @@ ofw_restore_trap_vec(char *restore_trap_
 /*
  * Saved SPRG0-3 from OpenFirmware. Will be restored prior to the callback.
  */
+#ifndef __powerpc64__
 register_t	ofw_sprg0_save;
 
 static __inline void
@@ -140,6 +141,8 @@ ofw_sprg_restore(void)
 }
 #endif
 
+#endif
+
 static int
 parse_ofw_memory(phandle_t node, const char *prop, struct mem_region *output)
 {
@@ -344,11 +347,12 @@ OF_initial_setup(void *fdt_ptr, void *ju
 	ofmsr[0] = mfmsr();
 	#ifdef __powerpc64__
 	ofmsr[0] &= ~PSL_SF;
-	#endif
+	#else
 	__asm __volatile("mfsprg0 %0" : "=&r"(ofmsr[1]));
 	__asm __volatile("mfsprg1 %0" : "=&r"(ofmsr[2]));
 	__asm __volatile("mfsprg2 %0" : "=&r"(ofmsr[3]));
 	__asm __volatile("mfsprg3 %0" : "=&r"(ofmsr[4]));
+	#endif
 	openfirmware_entry = openfirm;
 
 	if (ofmsr[0] & PSL_DR)
@@ -440,7 +444,9 @@ openfirmware_core(void *args)
 	 */
 	oldmsr = intr_disable();
 
+#ifndef __powerpc64__
 	ofw_sprg_prepare();
+#endif
 
 	/* Save trap vectors */
 	ofw_save_trap_vec(save_trap_of);
@@ -463,7 +469,9 @@ openfirmware_core(void *args)
 	/* Restore trap vecotrs */
 	ofw_restore_trap_vec(save_trap_of);
 
+#ifndef __powerpc64__
 	ofw_sprg_restore();
+#endif
 
 	intr_restore(oldmsr);
 

Modified: head/sys/powerpc/powerpc/machdep.c
==============================================================================
--- head/sys/powerpc/powerpc/machdep.c	Wed Sep 21 02:27:23 2016	(r306064)
+++ head/sys/powerpc/powerpc/machdep.c	Wed Sep 21 02:28:39 2016	(r306065)
@@ -128,6 +128,7 @@ __FBSDID("$FreeBSD$");
 #include <ddb/ddb.h>
 
 #include <dev/ofw/openfirm.h>
+#include <dev/ofw/ofw_subr.h>
 
 int cold = 1;
 #ifdef __powerpc64__
@@ -297,6 +298,8 @@ powerpc_init(vm_offset_t fdt, vm_offset_
 	/* Store boot environment state */
 	OF_initial_setup((void *)fdt, NULL, (int (*)(void *))ofentry);
 
+	ofw_parse_bootargs();
+
 	/*
 	 * Init params/tunables that can be overridden by the loader
 	 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609210228.u8L2Sdfn015537>