[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
This commit is contained in:
Michael Zhilin 2016-07-24 08:35:45 +00:00
parent 285e3c3ea9
commit 334453c5a9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303258
4 changed files with 208 additions and 82 deletions

View File

@ -86,6 +86,7 @@ crypto/blowfish/bf_enc.c optional crypto | ipsec
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

View File

@ -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, device_t parent)
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;
/*
* Please ensure that your implementation of NVRAM->ENV specifies
* bus tag
*/
if (sc->bst == NULL)
return (ENXIO);
if (resource_int_value("nvram", device_get_unit(dev), "maxsize",
&sc->maxsize) != 0 || sc->maxsize == 0)
sc->maxsize = NVRAM_MAX_SIZE;
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 (resource_int_value("nvram", device_get_unit(dev), "flags",
&sc->flags) != 0 || sc->flags == 0)
sc->flags = NVRAM_FLAGS_GENERIC;
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;
sc->addr = ivar;
break;
default:
break;
}
if (sc->addr == 0)
continue;
if (bootverbose)
device_printf(dev, "base=0x%08x sig=0x%08x "
@ -172,15 +150,6 @@ nvram2env_probe(device_t dev)
}
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_softc * sc, int offset)
}
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;

View File

@ -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_ */

View File

@ -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);