Encapsulate retrieval of properties from the global `options' prom node.
This commit is contained in:
parent
2061ef0c38
commit
7489a68403
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: bsd_openprom.h,v 1.20 2003/08/07 16:29:38 agc Exp $ */
|
||||
/* $NetBSD: bsd_openprom.h,v 1.21 2004/03/16 22:45:18 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -345,9 +345,6 @@ struct nodeops {
|
|||
char *(*no_nextprop) __P((int node, char *name));
|
||||
};
|
||||
|
||||
/* Frequently used options node */
|
||||
extern int optionsnode;
|
||||
|
||||
/*
|
||||
* OBP Module mailbox messages for multi processor machines.
|
||||
*
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: autoconf.c,v 1.201 2003/08/27 15:59:52 mrg Exp $ */
|
||||
/* $NetBSD: autoconf.c,v 1.202 2004/03/16 22:45:18 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996
|
||||
|
@ -48,7 +48,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.201 2003/08/27 15:59:52 mrg Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.202 2004/03/16 22:45:18 pk Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_kgdb.h"
|
||||
|
@ -113,7 +113,6 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.201 2003/08/27 15:59:52 mrg Exp $");
|
|||
* the configuration process, and are used in initializing
|
||||
* the machine.
|
||||
*/
|
||||
int optionsnode; /* node ID of ROM's options */
|
||||
|
||||
#ifdef KGDB
|
||||
extern int kgdb_debug_panic;
|
||||
|
@ -843,8 +842,7 @@ crazymap(prop, map)
|
|||
int *map;
|
||||
{
|
||||
int i;
|
||||
char *propval;
|
||||
char buf[32];
|
||||
char propval[8+1];
|
||||
|
||||
if (!CPU_ISSUN4 && prom_version() < 2) {
|
||||
/*
|
||||
|
@ -852,8 +850,8 @@ crazymap(prop, map)
|
|||
* which contains the mapping for us to use. v2 proms do not
|
||||
* require remapping.
|
||||
*/
|
||||
propval = PROM_getpropstringA(optionsnode, prop, buf, sizeof(buf));
|
||||
if (propval == NULL || strlen(propval) != 8) {
|
||||
if (prom_getoption(prop, propval, sizeof propval) != 0 ||
|
||||
propval[0] == '\0' || strlen(propval) != 8) {
|
||||
build_default_map:
|
||||
printf("WARNING: %s map is bogus, using default\n",
|
||||
prop);
|
||||
|
@ -1232,9 +1230,9 @@ extern struct sparc_bus_space_tag mainbus_space_tag;
|
|||
else
|
||||
openboot_special = openboot_special4c;
|
||||
|
||||
node = findroot();
|
||||
node0 = firstchild(findroot());
|
||||
|
||||
/* the first early device to be configured is the cpu */
|
||||
/* The first early device to be configured is the cpu */
|
||||
if (CPU_ISSUN4M) {
|
||||
const char *cp;
|
||||
int mid, bootnode = 0;
|
||||
|
@ -1244,7 +1242,7 @@ extern struct sparc_bus_space_tag mainbus_space_tag;
|
|||
* Make sure to configure the boot CPU as cpu0.
|
||||
*/
|
||||
rescan:
|
||||
for (node = firstchild(node); node; node = nextsibling(node)) {
|
||||
for (node = node0; node; node = nextsibling(node)) {
|
||||
cp = PROM_getpropstringA(node, "device_type",
|
||||
namebuf, sizeof namebuf);
|
||||
if (strcmp(cp, "cpu") != 0)
|
||||
|
@ -1269,7 +1267,6 @@ extern struct sparc_bus_space_tag mainbus_space_tag;
|
|||
config_found(dev, (void *)&ma, mbprint);
|
||||
if (node == bootnode && bootmid != 0) {
|
||||
/* Re-enter loop to find all remaining CPUs */
|
||||
node = findroot();
|
||||
goto rescan;
|
||||
}
|
||||
}
|
||||
|
@ -1277,20 +1274,11 @@ extern struct sparc_bus_space_tag mainbus_space_tag;
|
|||
bzero(&ma, sizeof(ma));
|
||||
ma.ma_bustag = &mainbus_space_tag;
|
||||
ma.ma_dmatag = &mainbus_dma_tag;
|
||||
ma.ma_node = node;
|
||||
ma.ma_node = findroot();
|
||||
ma.ma_name = "cpu";
|
||||
config_found(dev, (void *)&ma, mbprint);
|
||||
}
|
||||
|
||||
|
||||
node = findroot(); /* re-init root node */
|
||||
|
||||
/* Find the "options" node */
|
||||
node0 = firstchild(node);
|
||||
optionsnode = findnode(node0, "options");
|
||||
if (optionsnode == 0)
|
||||
panic("no options in OPENPROM");
|
||||
|
||||
for (ssp = openboot_special; *(sp = *ssp) != 0; ssp++) {
|
||||
struct openprom_addr romreg;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: openprom.c,v 1.19 2003/08/27 15:59:53 mrg Exp $ */
|
||||
/* $NetBSD: openprom.c,v 1.20 2004/03/16 22:45:18 pk Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
|
@ -41,7 +41,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: openprom.c,v 1.19 2003/08/27 15:59:53 mrg Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: openprom.c,v 1.20 2004/03/16 22:45:18 pk Exp $");
|
||||
|
||||
#include "opt_sparc_arch.h"
|
||||
|
||||
|
@ -68,7 +68,6 @@ const struct cdevsw openprom_cdevsw = {
|
|||
};
|
||||
|
||||
static int lastnode; /* speed hack */
|
||||
extern int optionsnode; /* node ID of ROM's options */
|
||||
|
||||
static int openpromcheckid __P((int, int));
|
||||
static int openpromgetstr __P((int, char *, char **));
|
||||
|
@ -130,9 +129,11 @@ openpromioctl(dev, cmd, data, flags, p)
|
|||
struct proc *p;
|
||||
{
|
||||
struct opiocdesc *op;
|
||||
int node, len, ok, error, s;
|
||||
int node, optionsnode, len, ok, error, s;
|
||||
char *name, *value, *nextprop;
|
||||
|
||||
optionsnode = prom_getoptionsnode();
|
||||
|
||||
/* All too easy... */
|
||||
if (cmd == OPIOCGETOPTNODE) {
|
||||
*(int *)data = optionsnode;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: promlib.c,v 1.25 2004/03/15 23:46:40 pk Exp $ */
|
||||
/* $NetBSD: promlib.c,v 1.26 2004/03/16 22:45:18 pk Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
||||
|
@ -42,7 +42,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.25 2004/03/15 23:46:40 pk Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: promlib.c,v 1.26 2004/03/16 22:45:18 pk Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_sparc_arch.h"
|
||||
|
@ -433,9 +433,44 @@ prom_node_has_property(node, prop)
|
|||
const char *prop;
|
||||
{
|
||||
|
||||
return (PROM_getproplen(node, (caddr_t)prop) != -1);
|
||||
return (PROM_getproplen(node, (char *)prop) != -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the global "options" node Id.
|
||||
*/
|
||||
int prom_getoptionsnode()
|
||||
{
|
||||
static int optionsnode;
|
||||
|
||||
if (optionsnode == 0) {
|
||||
optionsnode = prom_findnode(prom_firstchild(prom_findroot()),
|
||||
"options");
|
||||
}
|
||||
return optionsnode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return a property string value from the global "options" node.
|
||||
*/
|
||||
int prom_getoption(const char *name, char *buf, int buflen)
|
||||
{
|
||||
int node = prom_getoptionsnode();
|
||||
int error, len;
|
||||
|
||||
if (buflen == 0)
|
||||
return (EINVAL);
|
||||
|
||||
if (node == 0)
|
||||
return (ENOENT);
|
||||
|
||||
len = buflen - 1;
|
||||
if ((error = PROM_getprop(node, (char *)name, 1, &len, &buf)) != 0)
|
||||
return error;
|
||||
|
||||
buf[len] = '\0';
|
||||
return (0);
|
||||
}
|
||||
|
||||
void
|
||||
prom_halt()
|
||||
|
@ -654,11 +689,16 @@ obp_v2_getbootargs()
|
|||
return (parse_bootargs(*ba->v2_bootargs));
|
||||
}
|
||||
|
||||
/*
|
||||
* Static storage shared by parse_bootfile() and getbootfile().
|
||||
* Overwritten on each call!
|
||||
*/
|
||||
static char storage[128];
|
||||
|
||||
char *
|
||||
parse_bootfile(args)
|
||||
char *args;
|
||||
{
|
||||
static char storage[128];
|
||||
char *cp, *dp;
|
||||
|
||||
cp = args;
|
||||
|
@ -690,7 +730,7 @@ obp_v2_getbootfile()
|
|||
{
|
||||
struct v2bootargs *ba = promops.po_bootcookie;
|
||||
char *kernel = parse_bootfile(*ba->v2_bootargs);
|
||||
int diagmode, optionsnode;
|
||||
char buf[4+1], *prop;
|
||||
|
||||
if (kernel[0] != '\0')
|
||||
return kernel;
|
||||
|
@ -702,14 +742,16 @@ obp_v2_getbootfile()
|
|||
* then get the `boot-file' value (if any) ourselves.
|
||||
* If the `diag-switch?' PROM variable is set to true, we use
|
||||
* `diag-file' instead.
|
||||
*
|
||||
* Note: PROM_getpropstring() imposes a 31 char size limit.
|
||||
*/
|
||||
optionsnode = findnode(firstchild(findroot()), "options");
|
||||
diagmode = strcmp(PROM_getpropstring(optionsnode, "diag-switch?"),
|
||||
"true") == 0;
|
||||
return PROM_getpropstring(optionsnode,
|
||||
diagmode ? "diag-file" : "boot-file");
|
||||
prop = (prom_getoption("diag-switch?", buf, sizeof buf) != 0 ||
|
||||
strcmp(buf, "true") != 0)
|
||||
? "diag-file"
|
||||
: "boot-file";
|
||||
|
||||
if (prom_getoption(prop, storage, sizeof storage) != 0)
|
||||
return (NULL);
|
||||
|
||||
return (storage);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -922,7 +964,6 @@ prom_makememarr(ap, max, which)
|
|||
return (n);
|
||||
}
|
||||
|
||||
|
||||
static struct idprom idprom;
|
||||
#ifdef _STANDALONE
|
||||
long hostid;
|
||||
|
@ -981,7 +1022,6 @@ void prom_getether(node, cp)
|
|||
u_char *cp;
|
||||
{
|
||||
struct idprom *idp = prom_getidprom();
|
||||
int optionsnode;
|
||||
char buf[6+1], *bp;
|
||||
int nitem;
|
||||
|
||||
|
@ -1009,9 +1049,8 @@ void prom_getether(node, cp)
|
|||
* if we should try to extract the node's "local-mac-address"
|
||||
* property.
|
||||
*/
|
||||
optionsnode = findnode(firstchild(findroot()), "options");
|
||||
if (strcmp(PROM_getpropstring(optionsnode, "local-mac-address?"),
|
||||
"true") != 0)
|
||||
if (prom_getoption("local-mac-address?", buf, sizeof buf) != 0 ||
|
||||
strcmp(buf, "true") != 0)
|
||||
goto read_idprom;
|
||||
|
||||
/* Retrieve the node's "local-mac-address" property, if any */
|
||||
|
|
Loading…
Reference in New Issue