- Don't expose dev_propdb directly -- provide devprop_*() wrappers instead.

- Rework the ARMADILLO / epe device properties interaction so that it actually
  associates the MAC address property with the epe device instance.
This commit is contained in:
thorpej 2006-02-18 05:04:11 +00:00
parent 8c30474280
commit 680d9eea68
15 changed files with 123 additions and 52 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.7 2006/02/16 18:20:31 thorpej Exp $ */
/* $NetBSD: autoconf.c,v 1.8 2006/02/18 05:04:11 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.7 2006/02/16 18:20:31 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.8 2006/02/18 05:04:11 thorpej Exp $");
#include "opt_algor_p4032.h"
#include "opt_algor_p5064.h"
@ -107,7 +107,7 @@ device_register(struct device *dev, void *aux)
struct pci_attach_args *pa = aux;
if (BUILTIN_ETHERNET_P(pa)) {
if (prop_set(dev_propdb, dev, "mac-addr",
if (devprop_set(dev, "mac-addr",
algor_ethaddr,
sizeof(algor_ethaddr), 0, 0) != 0) {
printf("WARNING: unable to set mac-addr "

View File

@ -1,4 +1,4 @@
/* $NetBSD: epe.c,v 1.5 2005/12/24 20:06:52 perry Exp $ */
/* $NetBSD: epe.c,v 1.6 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (c) 2004 Jesse Off
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: epe.c,v 1.5 2005/12/24 20:06:52 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: epe.c,v 1.6 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/types.h>
#include <sys/param.h>
@ -159,7 +159,7 @@ epe_attach(struct device *parent, struct device *self, void *aux)
panic("%s: Cannot map registers", self->dv_xname);
/* Fetch the Ethernet address from property if set. */
if (prop_get(dev_propdb, 0, "mac-addr", sc->sc_enaddr,
if (devprop_get(self, "mac-addr", sc->sc_enaddr,
ETHER_ADDR_LEN, NULL) == ETHER_ADDR_LEN) {
bus_space_write_4(sc->sc_iot, sc->sc_ioh, EPE_AFP, 0);
bus_space_write_region_1(sc->sc_iot, sc->sc_ioh, EPE_IndAd,

View File

@ -1,4 +1,4 @@
/* $NetBSD: armadillo9_iic.c,v 1.1 2005/11/13 06:33:05 hamajima Exp $ */
/* $NetBSD: armadillo9_iic.c,v 1.2 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (c) 2005 HAMAJIMA Katsuomi. All rights reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: armadillo9_iic.c,v 1.1 2005/11/13 06:33:05 hamajima Exp $");
__KERNEL_RCSID(0, "$NetBSD: armadillo9_iic.c,v 1.2 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -37,6 +37,7 @@ __KERNEL_RCSID(0, "$NetBSD: armadillo9_iic.c,v 1.1 2005/11/13 06:33:05 hamajima
#include <dev/i2c/i2c_bitbang.h>
#include <arm/ep93xx/epsocvar.h>
#include <arm/ep93xx/epgpiovar.h>
#include <evbarm/armadillo/armadillo9var.h>
#include "seeprom.h"
#if NSEEPROM > 0
@ -93,7 +94,6 @@ armadillo9iic_attach(struct device *parent, struct device *self, void *aux)
struct i2cbus_attach_args iba;
#if NSEEPROM > 0
struct epgpio_attach_args *ga = aux;
u_int8_t enaddr[ETHER_ADDR_LEN];
#endif
lockinit(&sc->sc_buslock, PRIBIO|PCATCH, "armadillo9iiclk", 0, 0);
@ -128,13 +128,12 @@ armadillo9iic_attach(struct device *parent, struct device *self, void *aux)
config_found(&sc->sc_dev, &iba, iicbus_print);
#if NSEEPROM > 0
/* read and set mac address */
if (!seeprom_bootstrap_read(&sc->sc_i2c, 0x50, 0x00, 128,
(uint8_t *)enaddr, ETHER_ADDR_LEN)
&& (prop_set(dev_propdb, 0, "mac-addr",
enaddr, ETHER_ADDR_LEN, PROP_ARRAY, 0) != 0)) {
printf("WARNING: unable to set mac-addr property for %s\n",
sc->sc_dev.dv_xname);
/* read mac address */
/* XXX This should probably be done elsewhere, earlier in bootstrap. */
if (seeprom_bootstrap_read(&sc->sc_i2c, 0x50, 0x00, 128,
armadillo9_ethaddr, ETHER_ADDR_LEN) != 0) {
printf("%s: WARNING: unable to read MAC address from SEEPROM\n",
sc->sc_dev.dv_xname);
}
#endif
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: armadillo9_machdep.c,v 1.4 2006/02/13 12:24:21 hamajima Exp $ */
/* $NetBSD: armadillo9_machdep.c,v 1.5 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
@ -110,7 +110,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.4 2006/02/13 12:24:21 hamajima Exp $");
__KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.5 2006/02/18 05:04:11 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_kgdb.h"
@ -127,6 +127,9 @@ __KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.4 2006/02/13 12:24:21 hamaj
#include <sys/termios.h>
#include <sys/ksyms.h>
#include <net/if.h>
#include <net/if_ether.h>
#include <uvm/uvm_extern.h>
#include <dev/cons.h>
@ -137,6 +140,7 @@ __KERNEL_RCSID(0, "$NetBSD: armadillo9_machdep.c,v 1.4 2006/02/13 12:24:21 hamaj
#define DRAM_BLOCKS 4
#include <machine/bootconfig.h>
#include <machine/autoconf.h>
#include <machine/bus.h>
#include <machine/cpu.h>
#include <machine/frame.h>
@ -304,6 +308,25 @@ int kgdb_devrate = KGDB_DEVRATE;
int kgdb_devmode = KGDB_DEVMODE;
#endif /* KGDB */
/*
* MAC address for the built-in Ethernet.
*/
uint8_t armadillo9_ethaddr[ETHER_ADDR_LEN];
static void
armadillo9_device_register(device_t dev, void *aux)
{
/* MAC address for the built-in Ethernet. */
if (strcmp(dev->dv_cfdata->cf_name, "epe") == 0) {
if (devprop_set(dev, "mac-addr", armadillo9_ethaddr,
ETHER_ADDR_LEN, PROP_ARRAY, 0) != 0) {
printf("WARNING: unable to set mac-addr property "
"for %s\n", dev->dv_xname);
}
}
}
/*
* void cpu_reboot(int howto, char *bootstr)
*
@ -877,6 +900,9 @@ initarm(void *arg)
Debugger();
#endif
/* We have our own device_register() */
evbarm_device_register = armadillo9_device_register;
/* We return the new stack pointer address */
return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: armadillo9var.h,v 1.1 2006/02/13 12:24:21 hamajima Exp $ */
/* $NetBSD: armadillo9var.h,v 1.2 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (c) 2006 HAMAJIMA Katsuomi. All rights reserved.
@ -74,4 +74,6 @@ struct bootparam_tag {
extern char bootparam[];
extern uint8_t armadillo9_ethaddr[];
#endif /* _ARMADILLO9VAR_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.9 2005/12/11 12:17:11 christos Exp $ */
/* $NetBSD: autoconf.c,v 1.10 2006/02/18 05:04:11 thorpej Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.9 2005/12/11 12:17:11 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -117,7 +117,7 @@ device_register(struct device *dev, void *aux)
*/
ethaddr[4] += 0x10;
}
if (prop_set(dev_propdb, dev, "mac-addr",
if (devprop_set(dev, "mac-addr",
ethaddr, sizeof(ethaddr), 0, 0) != 0) {
printf("WARNING: unable to set mac-addr "
"property for %s\n", dev->dv_xname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.9 2005/12/24 22:45:35 perry Exp $ */
/* $NetBSD: autoconf.c,v 1.10 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.9 2005/12/24 22:45:35 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.10 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -100,7 +100,7 @@ device_register(struct device *dev, void *aux)
/* Set the frequency of the on-chip UART. */
int freq = COM_FREQ * 6;
if (prop_set(dev_propdb, dev, "frequency",
if (devprop_set(dev, "frequency",
&freq, sizeof(freq), PROP_INT, 0) != 0)
printf("WARNING: unable to set frequency "
"property for %s\n", dev->dv_xname);
@ -111,7 +111,7 @@ device_register(struct device *dev, void *aux)
strcmp(parent->dv_cfdata->cf_name, "opb") == 0) {
/* Set the mac-addr of the on-chip Ethernet. */
/* XXX 405GP only has one; what about CPUs with two? */
if (prop_set(dev_propdb, dev, "mac-addr",
if (devprop_set(dev, "mac-addr",
&board_data.mac_address_local,
sizeof(board_data.mac_address_local),
PROP_CONST, 0) != 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_aumac.c,v 1.13 2005/12/08 22:41:44 yamt Exp $ */
/* $NetBSD: if_aumac.c,v 1.14 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright (c) 2001 Wasabi Systems, Inc.
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_aumac.c,v 1.13 2005/12/08 22:41:44 yamt Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_aumac.c,v 1.14 2006/02/18 05:04:11 thorpej Exp $");
#include "bpfilter.h"
@ -235,7 +235,7 @@ aumac_attach(struct device *parent, struct device *self, void *aux)
sc->sc_st = aa->aa_st;
/* Get the MAC address. */
if (prop_get(dev_propdb, &sc->sc_dev, "mac-addr", enaddr,
if (devprop_get(&sc->sc_dev, "mac-addr", enaddr,
sizeof(enaddr), NULL) != sizeof(enaddr)) {
printf("%s: unable to get mac-addr property\n",
sc->sc_dev.dv_xname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: com_opb.c,v 1.13 2005/12/11 12:18:42 christos Exp $ */
/* $NetBSD: com_opb.c,v 1.14 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: com_opb.c,v 1.13 2005/12/11 12:18:42 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: com_opb.c,v 1.14 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -119,7 +119,7 @@ com_opb_attach(struct device *parent, struct device *self, void *aux)
bus_space_map(sc->sc_iot, oaa->opb_addr, COM_NPORTS, 0,
&sc->sc_ioh);
if (prop_get(dev_propdb, &sc->sc_dev, "frequency",
if (devprop_get(&sc->sc_dev, "frequency",
&sc->sc_frequency, sizeof(sc->sc_frequency), NULL) == -1) {
printf(": unable to get frequency property\n");
return;
@ -169,7 +169,7 @@ com_opb_device_register(struct device *dev, int frequency)
int com_freq = frequency;
/* Set the frequency of the on-chip UART. */
if (prop_set(dev_propdb, dev, "frequency",
if (devprop_set(dev, "frequency",
&com_freq, sizeof(com_freq), PROP_INT, 0) != 0)
printf("WARNING: unable to set frequency "
"property for %s\n", dev->dv_xname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_emac.c,v 1.23 2005/12/11 12:18:42 christos Exp $ */
/* $NetBSD: if_emac.c,v 1.24 2006/02/18 05:04:11 thorpej Exp $ */
/*
* Copyright 2001, 2002 Wasabi Systems, Inc.
@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.23 2005/12/11 12:18:42 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_emac.c,v 1.24 2006/02/18 05:04:11 thorpej Exp $");
#include "bpfilter.h"
@ -397,7 +397,7 @@ emac_attach(struct device *parent, struct device *self, void *aux)
emac_reset(sc);
/* Fetch the Ethernet address. */
if (prop_get(dev_propdb, &sc->sc_dev, "mac-addr", enaddr,
if (devprop_get(&sc->sc_dev, "mac-addr", enaddr,
sizeof(enaddr), NULL) != sizeof(enaddr)) {
printf("%s: unable to get mac-addr property\n",
sc->sc_dev.dv_xname);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ibm4xx_autoconf.c,v 1.3 2005/12/11 12:18:42 christos Exp $ */
/* $NetBSD: ibm4xx_autoconf.c,v 1.4 2006/02/18 05:04:11 thorpej Exp $ */
/* Original Tag: ibm4xxgpx_autoconf.c,v 1.2 2004/10/23 17:12:22 thorpej Exp $ */
/*
@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoconf.c,v 1.3 2005/12/11 12:18:42 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ibm4xx_autoconf.c,v 1.4 2006/02/18 05:04:11 thorpej Exp $");
#include <sys/param.h>
#include <sys/conf.h>
@ -58,6 +58,8 @@ ibm4xx_device_register(struct device *dev, void *aux)
uint8_t enaddr[ETHER_ADDR_LEN];
unsigned char prop_name[15];
/* XXX dv_unit abuse */
/* XXX Should be using index / offset */
snprintf(prop_name, sizeof(prop_name),
"emac%d-mac-addr", dev->dv_unit);
@ -68,7 +70,7 @@ ibm4xx_device_register(struct device *dev, void *aux)
return;
}
if (prop_set(dev_propdb, dev, "mac-addr",
if (devprop_set(dev, "mac-addr",
enaddr, sizeof(enaddr),
PROP_ARRAY, 0) != 0)
printf("WARNING: unable to set mac-addr "

View File

@ -1,4 +1,4 @@
/* $NetBSD: lm75.c,v 1.3 2005/12/11 12:21:22 christos Exp $ */
/* $NetBSD: lm75.c,v 1.4 2006/02/18 05:04:12 thorpej Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@ -120,7 +120,7 @@ lmtemp_attach(struct device *parent, struct device *self, void *aux)
sc->sc_sensor[0].warnflags = ENVSYS_WARN_OK;
sc->sc_sensor[0].units = sc->sc_info[0].units = ENVSYS_STEMP;
if (prop_get(dev_propdb, &sc->sc_dev, "description",
if (devprop_get(&sc->sc_dev, "description",
sc->sc_info[0].desc, sizeof(sc->sc_info[0].desc),
&ptype) < 1 ||
ptype != PROP_STRING)

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_tlp_pci.c,v 1.85 2006/02/16 18:20:31 thorpej Exp $ */
/* $NetBSD: if_tlp_pci.c,v 1.86 2006/02/18 05:04:12 thorpej Exp $ */
/*-
* Copyright (c) 1998, 1999, 2000, 2002 The NetBSD Foundation, Inc.
@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_tlp_pci.c,v 1.85 2006/02/16 18:20:31 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_tlp_pci.c,v 1.86 2006/02/18 05:04:12 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -632,9 +632,8 @@ tlp_pci_attach(struct device *parent, struct device *self, void *aux)
* XXX logic, and for now we can at least remove a machine-
* XXX dependent wart from the PCI front-end.
*/
if (prop_get(dev_propdb, &sc->sc_dev, "mac-addr",
enaddr, sizeof(enaddr), NULL) ==
sizeof(enaddr)) {
if (devprop_get(&sc->sc_dev, "mac-addr",
enaddr, sizeof(enaddr), NULL) == sizeof(enaddr)) {
extern int tlp_srom_debug;
sc->sc_srom_addrbits = 6;
sc->sc_srom = malloc(TULIP_ROM_SIZE(6), M_DEVBUF,

View File

@ -1,4 +1,4 @@
/* $NetBSD: subr_autoconf.c,v 1.103 2005/12/24 19:12:23 perry Exp $ */
/* $NetBSD: subr_autoconf.c,v 1.104 2006/02/18 05:04:13 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.103 2005/12/24 19:12:23 perry Exp $");
__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.104 2006/02/18 05:04:13 thorpej Exp $");
#include "opt_ddb.h"
@ -89,6 +89,7 @@ __KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.103 2005/12/24 19:12:23 perry Ex
#include <sys/errno.h>
#include <sys/proc.h>
#include <sys/reboot.h>
#include <sys/properties.h>
#include <machine/limits.h>
#include "opt_userconf.h"
@ -129,7 +130,7 @@ static struct cftable initcftable;
/*
* Database of device properties.
*/
propdb_t dev_propdb;
static propdb_t dev_propdb;
#define ROOT ((device_t)NULL)
@ -1467,3 +1468,41 @@ config_finalize(void)
}
}
/*
* Wrappers around prop_*() for handling device properties.
*/
int
devprop_set(device_t dev, const char *name, void *val, size_t len,
int type, int wait)
{
return (prop_set(dev_propdb, dev, name, val, len, type, wait));
}
size_t
devprop_list(device_t dev, char *names, size_t len)
{
return (prop_list(dev_propdb, dev, names, len));
}
size_t
devprop_get(device_t dev, const char *name, void *val, size_t len, int *typep)
{
return (prop_get(dev_propdb, dev, name, val, len, typep));
}
int
devprop_delete(device_t dev, const char *name)
{
return (prop_delete(dev_propdb, dev, name));
}
int
devprop_copy(device_t from, device_t to, int wait)
{
return (prop_copy(dev_propdb, from, to, wait));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: device.h,v 1.84 2005/12/24 19:01:28 perry Exp $ */
/* $NetBSD: device.h,v 1.85 2006/02/18 05:04:13 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@ -303,8 +303,6 @@ extern int booted_partition; /* or the partition on that device */
extern volatile int config_pending; /* semaphore for mountroot */
extern propdb_t dev_propdb; /* device properties database */
void config_init(void);
void configure(void);
@ -354,6 +352,12 @@ void config_finalize(void);
void device_register(device_t, void *);
#endif
int devprop_set(device_t, const char *, void *, size_t, int, int);
size_t devprop_list(device_t, char *, size_t);
size_t devprop_get(device_t, const char *, void *, size_t, int *);
int devprop_delete(device_t, const char *);
int devprop_copy(device_t, device_t, int);
/* convenience definitions */
#define device_lookup(cfd, unit) \
(((unit) < (cfd)->cd_ndevs) ? (cfd)->cd_devs[(unit)] : NULL)