Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 24 Jul 2016 08:35:45 +0000 (UTC)
From:      Michael Zhilin <mizhka@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r303258 - in head/sys: conf dev/nvram2env
Message-ID:  <201607240835.u6O8ZjcP078217@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mizhka
Date: Sun Jul 24 08:35:45 2016
New Revision: 303258
URL: https://svnweb.freebsd.org/changeset/base/303258

Log:
  [nvram2env] split implementation into generic & MIPS-based code
  
  Split implementation of nvram2env to generic (MI) & MIPS-based code:
  
   - removed includes like "*siba*", because they are unused
   - added nvram2env_mips.c file with MIPS-specific code, code moved from nvram2env.c
   - added header file to shared defines/structures/function prototypes between MI and MIPS code
  
  Also this fix allows to implement own nvram2env drivers.
  
  Reviewed by:    ray, adrian (mentor)
  Approved by:    adrian (mentor)
  Differential Revision: https://reviews.freebsd.org/D6513

Added:
  head/sys/dev/nvram2env/nvram2env.h   (contents, props changed)
  head/sys/dev/nvram2env/nvram2env_mips.c   (contents, props changed)
Modified:
  head/sys/conf/files.mips
  head/sys/dev/nvram2env/nvram2env.c

Modified: head/sys/conf/files.mips
==============================================================================
--- head/sys/conf/files.mips	Sun Jul 24 08:21:21 2016	(r303257)
+++ head/sys/conf/files.mips	Sun Jul 24 08:35:45 2016	(r303258)
@@ -86,6 +86,7 @@ crypto/blowfish/bf_enc.c		optional	crypt
 crypto/des/des_enc.c			optional	crypto | ipsec | netsmb
 
 # AP common nvram interface MIPS specific, but maybe should be more generic
+dev/nvram2env/nvram2env_mips.c		optional	nvram2env
 dev/nvram2env/nvram2env.c		optional	nvram2env
 
 # hwpmc support

Modified: head/sys/dev/nvram2env/nvram2env.c
==============================================================================
--- head/sys/dev/nvram2env/nvram2env.c	Sun Jul 24 08:21:21 2016	(r303257)
+++ head/sys/dev/nvram2env/nvram2env.c	Sun Jul 24 08:35:45 2016	(r303258)
@@ -46,50 +46,7 @@ __FBSDID("$FreeBSD$");
 
 #include <machine/bus.h>
 
-#include <dev/siba/siba_ids.h>
-#include <dev/siba/sibareg.h>
-#include <dev/siba/sibavar.h>
-
-#define nvram2env_read_1(sc, reg)				\
-	bus_space_read_1((sc)->sc_bt, (sc)->sc_bh,(reg))
-
-#define nvram2env_read_2(sc, reg)				\
-	bus_space_read_2((sc)->sc_bt, (sc)->sc_bh,(reg))
-
-#define nvram2env_read_4(sc, reg)				\
-	bus_space_read_4((sc)->sc_bt, (sc)->sc_bh,(reg))
-
-#define nvram2env_write_1(sc, reg, val)			\
-	bus_space_write_1((sc)->sc_bt, (sc)->sc_bh,	\
-			 (reg), (val))
-
-#define nvram2env_write_2(sc, reg, val)			\
-	bus_space_write_2((sc)->sc_bt, (sc)->sc_bh,	\
-			 (reg), (val))
-
-#define nvram2env_write_4(sc, reg, val)			\
-	bus_space_write_4((sc)->sc_bt, (sc)->sc_bh,	\
-			 (reg), (val))
-
-struct nvram2env_softc {
-	bus_space_tag_t bst;
-	bus_space_handle_t bsh;
-	bus_addr_t addr;
-	int need_swap;
-	uint32_t sig;
-	uint32_t flags;
-#define NVRAM_FLAGS_NOCHECK	0x0001	/* Do not check(CRC or somthing else)*/
-#define NVRAM_FLAGS_GENERIC	0x0002	/* Format Generic, skip 4b and read */
-#define NVRAM_FLAGS_BROADCOM	0x0004	/* Format Broadcom, use struct nvram */
-#define NVRAM_FLAGS_UBOOT	0x0008	/* Format Generic, skip 4b of CRC and read */
-	uint32_t maxsize;
-	uint32_t crc;
-};
-
-static int	nvram2env_attach(device_t);
-static int	nvram2env_probe(device_t);
-
-#define NVRAM_MAX_SIZE 0x10000
+#include "nvram2env.h"
 
 static void
 nvram2env_identify(driver_t * drv, device_t parent)
@@ -100,34 +57,55 @@ nvram2env_identify(driver_t * drv, devic
 		BUS_ADD_CHILD(parent, 0, "nvram2env", i);
 }
 
-static int
+int
 nvram2env_probe(device_t dev)
 {
 	uint32_t i, ivar, sig;
 	struct nvram2env_softc * sc = device_get_softc(dev);
-	sc->bst = mips_bus_space_generic;
 
-	if (resource_int_value("nvram", device_get_unit(dev), "sig",
-	    &sc->sig) != 0 || sc->sig == 0)
-		sc->sig = 0x48534c46;
-
-	if (resource_int_value("nvram", device_get_unit(dev), "maxsize",
-	    &sc->maxsize) != 0 || sc->maxsize == 0)
-		sc->maxsize = NVRAM_MAX_SIZE;
-
-	if (resource_int_value("nvram", device_get_unit(dev), "flags", 
-	    &sc->flags) != 0 || sc->flags == 0)
-		sc->flags = NVRAM_FLAGS_GENERIC;
+	/*
+	 * Please ensure that your implementation of NVRAM->ENV specifies
+	 * bus tag
+	 */
+	if (sc->bst == NULL)
+		return (ENXIO);
+
+	if (sc->sig == 0)
+		if (resource_int_value("nvram", device_get_unit(dev), "sig",
+		    &sc->sig) != 0 || sc->sig == 0)
+			sc->sig = CFE_NVRAM_SIGNATURE;
+
+	if (sc->maxsize == 0)
+		if (resource_int_value("nvram", device_get_unit(dev), "maxsize",
+		    &sc->maxsize) != 0 || sc->maxsize == 0)
+			sc->maxsize = NVRAM_MAX_SIZE;
+
+	if (sc->flags == 0)
+		if (resource_int_value("nvram", device_get_unit(dev), "flags",
+		    &sc->flags) != 0 || sc->flags == 0)
+			sc->flags = NVRAM_FLAGS_GENERIC;
 
 
 	for (i = 0; i < 2; i ++)
 	{
-		if (resource_int_value("nvram", device_get_unit(dev), 
-			(!i)?"base":"fallbackbase", &ivar) != 0 ||
-		    ivar == 0)
-			continue;
+		switch (i) {
+		case 0:
+			break;
+		case 1:
+		case 2:
+			if (resource_int_value("nvram", device_get_unit(dev),
+			    (i == 1) ? "base" : "fallbackbase", &ivar) != 0 ||
+			    ivar == 0)
+				continue;
+
+			sc->addr = ivar;
+			break;
+		default:
+			break;
+		}
 
-		sc->addr = ivar;
+		if (sc->addr == 0)
+			continue;
 
 		if (bootverbose)
 			device_printf(dev, "base=0x%08x sig=0x%08x "
@@ -172,15 +150,6 @@ unmap_done:
 
 }
 
-struct nvram {
-	u_int32_t sig;
-	u_int32_t size;
-	u_int32_t unknown1;
-	u_int32_t unknown2;
-	u_int32_t unknown3;
-	char data[];
-};
-
 static uint32_t read_4(struct nvram2env_softc * sc, int offset) 
 {
 	if (sc->need_swap) 
@@ -190,7 +159,7 @@ static uint32_t read_4(struct nvram2env_
 }
 
 
-static int
+int
 nvram2env_attach(device_t dev)
 {
 	struct nvram2env_softc 	*sc;
@@ -209,10 +178,11 @@ nvram2env_attach(device_t dev)
 
 	sig  = read_4(sc, 0);
 	size = read_4(sc, 4);
-#if 1
+
 	if (bootverbose)
-		device_printf(dev, " size=0x%05x maxsize=0x%05x\n", size, sc->maxsize);
-#endif
+		device_printf(dev, " size=0x%05x maxsize=0x%05x\n", size,
+				sc->maxsize);
+
 	size = (size > sc->maxsize)?sc->maxsize:size;
 
 
@@ -265,12 +235,12 @@ nvram2env_attach(device_t dev)
 			assign = strchr(pair,'=');
 			assign[0] = '\0';
 			value = assign+1;
-#if 1
+
 			if (bootverbose)
-				printf("ENV: %s=%s\n", pair, value);
-#else
-			printf("ENV: %s\n", pair);
-#endif
+				printf("ENV[%p]: %s=%s\n",
+				    (void*)((char*)pair - (char*)nv),
+				    pair, value);
+
 			kern_setenv(pair, value);
 
 			if (strcasecmp(pair, "WAN_MAC_ADDR") == 0) {
@@ -313,12 +283,10 @@ static device_method_t nvram2env_methods
 	DEVMETHOD_END
 };
 
-static driver_t nvram2env_driver = {
+driver_t nvram2env_driver = {
 	"nvram2env",
 	nvram2env_methods,
 	sizeof(struct nvram2env_softc),
 };
-static devclass_t nvram2env_devclass;
-
-DRIVER_MODULE(nvram2env, nexus, nvram2env_driver, nvram2env_devclass, 0, 0);
 
+devclass_t nvram2env_devclass;

Added: head/sys/dev/nvram2env/nvram2env.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/nvram2env/nvram2env.h	Sun Jul 24 08:35:45 2016	(r303258)
@@ -0,0 +1,88 @@
+/*-
+ * Copyright (c) 2010 Aleksandr Rybalko.
+ * Copyright (c) 2016 Michael Zhilin.
+ * 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 AUTHOR 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 AUTHOR 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.
+ * 
+ * $FreeBSD$
+ */
+
+
+#ifndef NVRAM2ENV_NVRAM2ENV_H_
+#define	NVRAM2ENV_NVRAM2ENV_H_
+
+#define	nvram2env_read_1(sc, reg)				\
+	bus_space_read_1((sc)->sc_bt, (sc)->sc_bh,(reg))
+
+#define	nvram2env_read_2(sc, reg)				\
+	bus_space_read_2((sc)->sc_bt, (sc)->sc_bh,(reg))
+
+#define	nvram2env_read_4(sc, reg)				\
+	bus_space_read_4((sc)->sc_bt, (sc)->sc_bh,(reg))
+
+#define	nvram2env_write_1(sc, reg, val)			\
+	bus_space_write_1((sc)->sc_bt, (sc)->sc_bh,	\
+			 (reg), (val))
+
+#define	nvram2env_write_2(sc, reg, val)			\
+	bus_space_write_2((sc)->sc_bt, (sc)->sc_bh,	\
+			 (reg), (val))
+
+#define	nvram2env_write_4(sc, reg, val)			\
+	bus_space_write_4((sc)->sc_bt, (sc)->sc_bh,	\
+			 (reg), (val))
+
+struct nvram2env_softc {
+	bus_space_tag_t bst;
+	bus_space_handle_t bsh;
+	bus_addr_t addr;
+	int need_swap;
+	uint32_t sig;
+	uint32_t flags;
+#define	NVRAM_FLAGS_NOCHECK	0x0001	/* Do not check(CRC or somthing else)*/
+#define	NVRAM_FLAGS_GENERIC	0x0002	/* Format Generic, skip 4b and read */
+#define	NVRAM_FLAGS_BROADCOM	0x0004	/* Format Broadcom, use struct nvram */
+#define	NVRAM_FLAGS_UBOOT	0x0008	/* Format Generic, skip 4b of CRC and read */
+	uint32_t maxsize;
+	uint32_t crc;
+};
+
+#define	NVRAM_MAX_SIZE	0x10000
+#define	CFE_NVRAM_SIGNATURE 0x48534c46
+
+struct nvram {
+	u_int32_t sig;
+	u_int32_t size;
+	u_int32_t unknown1;
+	u_int32_t unknown2;
+	u_int32_t unknown3;
+	char data[];
+};
+
+int		nvram2env_attach(device_t);
+int		nvram2env_probe(device_t);
+
+extern devclass_t	nvram2env_devclass;
+extern driver_t		nvram2env_driver;
+
+#endif /* SYS_DEV_NVRAM2ENV_NVRAM2ENV_H_ */

Added: head/sys/dev/nvram2env/nvram2env_mips.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/nvram2env/nvram2env_mips.c	Sun Jul 24 08:35:45 2016	(r303258)
@@ -0,0 +1,69 @@
+/*-
+ * Copyright (c) 2010 Aleksandr Rybalko.
+ * Copyright (c) 2016 Michael Zhilin.
+ * 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 AUTHOR 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 AUTHOR 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.
+ */
+
+/*
+ * Implementation of pseudo driver for MIPS to copy the NVRAM settings
+ * from various sources into the kernel environment.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+
+#include <machine/bus.h>
+
+#include "nvram2env.h"
+
+static int
+nvram2env_mips_probe(device_t dev)
+{
+	struct nvram2env_softc	*sc;
+
+	sc = device_get_softc(dev);
+	sc->bst = mips_bus_space_generic;
+
+	return (nvram2env_probe(dev));
+}
+
+static device_method_t nvram2env_mips_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_probe,		nvram2env_mips_probe),
+
+	DEVMETHOD_END
+};
+
+DEFINE_CLASS_1(nvram2env, nvram2env_mips_driver, nvram2env_mips_methods,
+		sizeof(struct nvram2env_softc), nvram2env_driver);
+DRIVER_MODULE(nvram2env_mips, nexus, nvram2env_mips_driver, nvram2env_devclass,
+    NULL, NULL);
+
+MODULE_VERSION(nvram2env_mips, 1);
+MODULE_DEPEND(nvram2env_mips, nvram2env, 1, 1, 1);



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