From owner-svn-src-head@freebsd.org Wed Sep 21 02:28:40 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E3FE4BE0990; Wed, 21 Sep 2016 02:28:40 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A57989AA; Wed, 21 Sep 2016 02:28:40 +0000 (UTC) (envelope-from jhibbits@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u8L2SdFV015541; Wed, 21 Sep 2016 02:28:39 GMT (envelope-from jhibbits@FreeBSD.org) Received: (from jhibbits@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u8L2Sdfn015537; Wed, 21 Sep 2016 02:28:39 GMT (envelope-from jhibbits@FreeBSD.org) Message-Id: <201609210228.u8L2Sdfn015537@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhibbits set sender to jhibbits@FreeBSD.org using -f From: Justin Hibbits Date: Wed, 21 Sep 2016 02:28:39 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Sep 2016 02:28:41 -0000 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 #include #include +#include #include #include @@ -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 #include +#include 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 */