Use deviter(9) instead of accessing alldevs directly. Untested.

This commit is contained in:
dyoung 2009-11-05 18:11:09 +00:00
parent fbe2bb0ace
commit b504b9ff0b
7 changed files with 114 additions and 72 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: obsled.c,v 1.6 2006/03/28 17:38:24 thorpej Exp $ */
/* $NetBSD: obsled.c,v 1.7 2009/11/05 18:16:00 dyoung Exp $ */
/*
* Copyright (c) 2004 Shigeyuki Fukushima.
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obsled.c,v 1.6 2006/03/28 17:38:24 thorpej Exp $");
__KERNEL_RCSID(0, "$NetBSD: obsled.c,v 1.7 2009/11/05 18:16:00 dyoung Exp $");
#include <sys/param.h>
#include <sys/device.h>
@ -178,19 +178,21 @@ obsled_set_state(struct obsled_softc *sc)
void
obs266_led_set(int led)
{
struct device *dp = NULL;
struct devicelist *dlp = &alldevs;
device_t dv;
deviter_t di;
/*
* Sarching "obsled" devices from device tree.
* Do you have something better idea?
*/
for (dp = TAILQ_FIRST(dlp); dp != NULL; dp = TAILQ_NEXT(dp, dv_list)) {
if (device_is_a(dp, "obsles")) {
struct obsled_softc *sc = (struct obsled_softc *)dp;
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST); dv != NULL;
dv = deviter_next(&di)) {
if (device_is_a(dv, "obsles")) {
struct obsled_softc *sc = device_private(dv);
sc->sc_led_state =
(led & (1 << device_unit(dp))) >> device_unit(dp);
(led & (1 << device_unit(dv))) >> device_unit(dv);
obsled_set_state(sc);
}
}
deviter_release(&di);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.4 2008/04/28 20:23:26 martin Exp $ */
/* $NetBSD: autoconf.c,v 1.5 2009/11/05 18:15:17 dyoung Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.4 2008/04/28 20:23:26 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.5 2009/11/05 18:15:17 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -60,7 +60,7 @@ cpu_configure(void)
}
static int
is_valid_disk(struct device *dv)
is_valid_disk(device_t dv)
{
const char *name;
@ -78,7 +78,7 @@ is_valid_disk(struct device *dv)
* Return non-zero if disk device matches bootinfo.
*/
static int
match_bootdisk(struct device *dv, struct btinfo_bootdisk *bid)
match_bootdisk(device_t dv, struct btinfo_bootdisk *bid)
{
struct vnode *tmpvn;
int error;
@ -153,7 +153,8 @@ static void
findroot(void)
{
struct btinfo_bootdisk *bid;
struct device *dv;
device_t dv;
deviter_t di;
if (booted_device)
return;
@ -166,8 +167,9 @@ findroot(void)
* because lower device numbers are more likely to be the
* boot device.
*/
for (dv = TAILQ_FIRST(&alldevs); dv != NULL;
dv = TAILQ_NEXT(dv, dv_list)) {
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dv != NULL;
dv = deviter_next(&di)) {
if (dv->dv_class != DV_DISK)
continue;
@ -188,6 +190,7 @@ bootdisk_found:
booted_device = dv;
booted_partition = bid->partition;
}
deviter_release(&di);
if (booted_device)
return;

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.21 2009/03/18 10:22:32 cegger Exp $ */
/* $NetBSD: autoconf.c,v 1.22 2009/11/05 18:14:21 dyoung Exp $ */
/*
* Copyright (c) 1992, 1993
@ -85,7 +85,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.21 2009/03/18 10:22:32 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2009/11/05 18:14:21 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -111,7 +111,7 @@ int cpuspeed = 25; /* approx # instr per usec. */
extern int initcpu(void); /*XXX*/
void findroot(struct device **, int *);
void findroot(device_t *, int *);
struct mipsco_intrhand intrtab[MAX_INTR_COOKIES];
@ -154,18 +154,24 @@ int boot_id, boot_lun, boot_part;
* Attempt to find the device from which we were booted.
*/
void
findroot(struct device **devpp, int *partp)
findroot(device_t *devpp, int *partp)
{
struct device *dv;
device_t dv;
deviter_t di;
for (dv = TAILQ_FIRST(&alldevs); dv; dv = TAILQ_NEXT(dv, dv_list)) {
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dv != NULL;
dv = deviter_next(&di)) {
if (device_class(dv) == boot_class &&
/* XXX device_unit() abuse */
device_unit(dv) == boot_id) {
*devpp = dv;
*partp = boot_part;
return;
}
device_unit(dv) == boot_id)
break;
}
deviter_release(&di);
if (dv != NULL) {
*devpp = dv;
*partp = boot_part;
return;
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: nextdma.c,v 1.44 2008/12/17 17:12:52 cegger Exp $ */
/* $NetBSD: nextdma.c,v 1.45 2009/11/05 18:11:09 dyoung Exp $ */
/*
* Copyright (c) 1998 Darrin B. Jewell
* All rights reserved.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nextdma.c,v 1.44 2008/12/17 17:12:52 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: nextdma.c,v 1.45 2009/11/05 18:11:09 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -137,17 +137,22 @@ static int attached = 0;
struct nextdma_softc *
nextdma_findchannel(const char *name)
{
struct device *dev = TAILQ_FIRST(&alldevs);
device_t dev;
deviter_t di;
while (dev != NULL) {
if (!strncmp(dev->dv_xname, "nextdma", 7)) {
struct nextdma_softc *nsc = (struct nextdma_softc *)dev;
if (!strcmp (nsc->sc_chan->nd_name, name))
return (nsc);
for (dev = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dev != NULL;
dev = deviter_next(&di)) {
if (strncmp(dev->dv_xname, "nextdma", 7) == 0) {
struct nextdma_softc *nsc = device_private(dev);
if (strcmp(nsc->sc_chan->nd_name, name) == 0)
break;
}
dev = TAILQ_NEXT(dev, dv_list);
}
return (NULL);
deviter_release(&di);
if (dev == NULL)
return NULL;
return device_private(dev);
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.22 2008/04/28 20:23:33 martin Exp $ */
/* $NetBSD: autoconf.c,v 1.23 2009/11/05 18:12:31 dyoung Exp $ */
/*-
* Copyright (c) 2006 The NetBSD Foundation, Inc.
@ -34,7 +34,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.22 2008/04/28 20:23:33 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.23 2009/11/05 18:12:31 dyoung Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -253,26 +253,30 @@ gen_fwpath(struct device *dev)
static void
build_fwpath(void)
{
struct device *dev, *d;
device_t dev, d;
deviter_t di, inner_di;
prop_string_t str1;
/* First, find all the PCI busses */
TAILQ_FOREACH(dev, &alldevs, dv_list) {
for (dev = deviter_first(&di, DEVITER_F_ROOT_FIRST); dev != NULL;
dev = deviter_next(&di)) {
if (device_is_a(dev, "pci") || device_is_a(dev, "mainbus") ||
device_is_a(dev, "pcib") || device_is_a(dev, "pceb") ||
device_is_a(dev, "ppb"))
gen_fwpath(dev);
else
continue;
}
deviter_release(&di);
/* Now go find the ISA bus and fix it up */
TAILQ_FOREACH(dev, &alldevs, dv_list) {
for (dev = deviter_first(&di, DEVITER_F_ROOT_FIRST); dev != NULL;
dev = deviter_next(&di)) {
if (device_is_a(dev, "isa"))
gen_fwpath(dev);
else
continue;
}
TAILQ_FOREACH(dev, &alldevs, dv_list) {
deviter_release(&di);
for (dev = deviter_first(&di, DEVITER_F_ROOT_FIRST); dev != NULL;
dev = deviter_next(&di)) {
/* skip the ones we allready computed above */
if (device_is_a(dev, "pci") || device_is_a(dev, "pcib") ||
device_is_a(dev, "pceb") || device_is_a(dev, "isa") ||
@ -280,7 +284,9 @@ build_fwpath(void)
continue;
/* patch in the properties for the pnpbus */
if (device_is_a(dev, "pnpbus")) {
TAILQ_FOREACH(d, &alldevs, dv_list) {
for (d = deviter_first(&inner_di, DEVITER_F_ROOT_FIRST);
d != NULL;
d = deviter_next(&inner_di)) {
if (!device_is_a(d, "isa"))
continue;
str1 = prop_dictionary_get(device_properties(d),
@ -290,9 +296,11 @@ build_fwpath(void)
prop_dictionary_set(device_properties(dev),
"prep-fw-path", str1);
}
deviter_release(&inner_di);
} else
gen_fwpath(dev);
}
deviter_release(&di);
}
@ -303,7 +311,8 @@ build_fwpath(void)
void
findroot(void)
{
struct device *d;
device_t d;
deviter_t di;
char *cp;
prop_string_t str;
size_t len;
@ -321,7 +330,9 @@ findroot(void)
#if defined(NVRAM_DUMP)
printf("Modified bootpath: %s\n", bootpath);
#endif
TAILQ_FOREACH(d, &alldevs, dv_list) {
for (d = deviter_first(&di, DEVITER_F_ROOT_FIRST);
d != NULL;
d = deviter_next(&di)) {
str = prop_dictionary_get(device_properties(d), "prep-fw-path");
if (str == NULL)
continue;
@ -330,10 +341,12 @@ findroot(void)
prop_string_cstring_nocopy(str));
#endif
if (strncmp(prop_string_cstring_nocopy(str), bootpath,
len) == 0) {
booted_device = d;
booted_partition = 0; /* XXX ??? */
return;
}
len) == 0)
break;
}
deviter_release(&di);
if (d != NULL) {
booted_device = d;
booted_partition = 0; /* XXX ??? */
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.64 2009/01/18 05:23:34 isaki Exp $ */
/* $NetBSD: autoconf.c,v 1.65 2009/11/05 18:13:07 dyoung Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.64 2009/01/18 05:23:34 isaki Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.65 2009/11/05 18:13:07 dyoung Exp $");
#include "opt_compat_netbsd.h"
#include "scsibus.h"
@ -170,6 +170,7 @@ scsi_find(dev_t bdev)
int ifid;
char tname[16];
device_t scsibus;
deviter_t di;
struct scsibus_softc *sbsc;
struct scsipi_periph *periph;
@ -196,13 +197,16 @@ scsi_find(dev_t bdev)
sprintf(tname, "%s%" PRIu64,
name_scsiif[ifid], B_X68K_SCSI_IF_UN(bdev));
for (scsibus = TAILQ_FIRST(&alldevs); scsibus;
scsibus = TAILQ_NEXT(scsibus, dv_list))
for (scsibus = deviter_first(&di, DEVITER_F_ROOT_FIRST);
scsibus != NULL;
scsibus = deviter_next(&di)) {
if (device_parent(scsibus)
&& !strcmp(tname, device_xname(device_parent(scsibus))))
&& strcmp(tname, device_xname(device_parent(scsibus))) == 0)
break;
}
deviter_release(&di);
}
if (!scsibus)
if (scsibus == NULL)
return NULL;
sbsc = device_private(scsibus);
periph = scsipi_lookup_periph(sbsc->sc_channel,

View File

@ -1,4 +1,4 @@
/* $NetBSD: autoconf.c,v 1.8 2009/03/11 09:02:05 nonaka Exp $ */
/* $NetBSD: autoconf.c,v 1.9 2009/11/05 18:17:34 dyoung Exp $ */
/*-
* Copyright (c) 2002 The NetBSD Foundation, Inc.
@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.8 2009/03/11 09:02:05 nonaka Exp $");
__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.9 2009/11/05 18:17:34 dyoung Exp $");
#include "opt_md.h"
@ -48,9 +48,9 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.8 2009/03/11 09:02:05 nonaka Exp $");
#include <machine/bootinfo.h>
#include <machine/config_hook.h>
static void handle_wedges(struct device *dv, int par);
static int is_valid_disk(struct device *dv);
static int match_bootdisk(struct device *dv, struct btinfo_bootdisk *bid);
static void handle_wedges(device_t dv, int par);
static int is_valid_disk(device_t dv);
static int match_bootdisk(device_t dv, struct btinfo_bootdisk *bid);
static void findroot(void);
void
@ -70,7 +70,7 @@ cpu_configure(void)
}
static void
handle_wedges(struct device *dv, int par)
handle_wedges(device_t dv, int par)
{
if (config_handle_wedges(dv, par) == 0)
@ -81,7 +81,7 @@ handle_wedges(struct device *dv, int par)
}
static int
is_valid_disk(struct device *dv)
is_valid_disk(device_t dv)
{
if (device_class(dv) != DV_DISK)
@ -98,7 +98,7 @@ is_valid_disk(struct device *dv)
* Return non-zero if disk device matches bootinfo.
*/
static int
match_bootdisk(struct device *dv, struct btinfo_bootdisk *bid)
match_bootdisk(device_t dv, struct btinfo_bootdisk *bid)
{
struct vnode *tmpvn;
int error;
@ -148,12 +148,15 @@ findroot(void)
struct btinfo_rootdevice *biv;
struct btinfo_bootdisk *bid;
device_t dv;
deviter_t di;
if (booted_device)
return;
if ((biv = lookup_bootinfo(BTINFO_ROOTDEVICE)) != NULL) {
TAILQ_FOREACH(dv, &alldevs, dv_list) {
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dv != NULL;
dv = deviter_next(&di)) {
cfdata_t cd;
size_t len;
@ -166,9 +169,12 @@ findroot(void)
if (strncmp(cd->cf_name, biv->devname, len) == 0 &&
biv->devname[len] - '0' == cd->cf_unit) {
handle_wedges(dv, biv->devname[len + 1] - 'a');
return;
break;
}
}
deviter_release(&di);
if (dv != NULL)
return;
}
if ((bid = lookup_bootinfo(BTINFO_BOOTDISK)) != NULL) {
@ -179,7 +185,9 @@ findroot(void)
* because lower device numbers are more likely to be the
* boot device.
*/
TAILQ_FOREACH(dv, &alldevs, dv_list) {
for (dv = deviter_first(&di, DEVITER_F_ROOT_FIRST);
dv != NULL;
dv = deviter_next(&di)) {
if (device_class(dv) != DV_DISK)
continue;
@ -206,6 +214,7 @@ findroot(void)
}
handle_wedges(dv, bid->partition);
}
deviter_release(&di);
if (booted_device)
return;
@ -224,7 +233,7 @@ cpu_rootconf(void)
}
void
device_register(struct device *dev, void *aux)
device_register(device_t dev, void *aux)
{
/* Nothing to do */