New device attachment scheme:

- split softc size and match/attach out from cfdriver into
	  a new struct cfattach.

	- new "attach" directive for files.*.  May specify the name of
	  the cfattach structure, so that devices may be easily attached
	  to parents with different autoconfiguration semantics.
This commit is contained in:
thorpej 1996-03-17 00:53:54 +00:00
parent 6d9ea4cf59
commit de7c200585
14 changed files with 157 additions and 89 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.146 1996/03/01 04:08:51 mycroft Exp $ */
/* $NetBSD: wd.c,v 1.147 1996/03/17 00:54:01 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
@ -138,15 +138,23 @@ struct wdc_softc {
int wdcprobe __P((struct device *, void *, void *));
void wdcattach __P((struct device *, struct device *, void *));
struct cfdriver wdccd = {
NULL, "wdc", wdcprobe, wdcattach, DV_DULL, sizeof(struct wdc_softc)
struct cfattach wdc_ca = {
sizeof(struct wdc_softc), wdcprobe, wdcattach
};
struct cfdriver wdc_cd = {
NULL, "wdc", DV_DULL
};
int wdprobe __P((struct device *, void *, void *));
void wdattach __P((struct device *, struct device *, void *));
struct cfdriver wdcd = {
NULL, "wd", wdprobe, wdattach, DV_DISK, sizeof(struct wd_softc)
struct cfattach wd_ca = {
sizeof(struct wd_softc), wdprobe, wdattach
};
struct cfdriver wd_cd = {
NULL, "wd", DV_DISK
};
void wdgetdisklabel __P((struct wd_softc *));
@ -353,7 +361,7 @@ void
wdstrategy(bp)
struct buf *bp;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(bp->b_dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(bp->b_dev)];
int s;
/* Valid request? */
@ -888,9 +896,9 @@ wdopen(dev, flag, fmt)
int error;
unit = WDUNIT(dev);
if (unit >= wdcd.cd_ndevs)
if (unit >= wd_cd.cd_ndevs)
return ENXIO;
wd = wdcd.cd_devs[unit];
wd = wd_cd.cd_devs[unit];
if (wd == 0)
return ENXIO;
@ -962,7 +970,7 @@ wdclose(dev, flag, fmt)
dev_t dev;
int flag, fmt;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
int part = WDPART(dev);
int error;
@ -1307,7 +1315,7 @@ wdioctl(dev, cmd, addr, flag, p)
int flag;
struct proc *p;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
int error;
if ((wd->sc_flags & WDF_LOADED) == 0)
@ -1423,7 +1431,7 @@ wdsize(dev)
if (wdopen(dev, 0, S_IFBLK) != 0)
return -1;
wd = wdcd.cd_devs[WDUNIT(dev)];
wd = wd_cd.cd_devs[WDUNIT(dev)];
part = WDPART(dev);
if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
@ -1462,9 +1470,9 @@ wddump(dev, blkno, va, size)
wddoingadump = 1;
unit = WDUNIT(dev);
if (unit >= wdcd.cd_ndevs)
if (unit >= wd_cd.cd_ndevs)
return ENXIO;
wd = wdcd.cd_devs[unit];
wd = wd_cd.cd_devs[unit];
if (wd == 0)
return ENXIO;
@ -1656,8 +1664,8 @@ wdcunwedge(wdc)
(void) wdcreset(wdc);
/* Schedule recalibrate for all drives on this controller. */
for (unit = 0; unit < wdcd.cd_ndevs; unit++) {
struct wd_softc *wd = wdcd.cd_devs[unit];
for (unit = 0; unit < wd_cd.cd_ndevs; unit++) {
struct wd_softc *wd = wd_cd.cd_devs[unit];
if (!wd || (void *)wd->sc_dev.dv_parent != wdc)
continue;
if (wd->sc_state > RECAL)

View File

@ -303,8 +303,12 @@ int seaprobe __P((struct device *, void *, void *));
void seaattach __P((struct device *, struct device *, void *));
int seaprint __P((void *, char *));
struct cfdriver seacd = {
NULL, "sea", seaprobe, seaattach, DV_DULL, sizeof(struct sea_softc)
struct cfattach sea_ca = {
sizeof(struct sea_softc), seaprobe, seaattach
};
struct cfdriver sea_cd = {
NULL, "sea", DV_DULL
};
#ifdef SEA_DEBUGQUEUE
@ -685,8 +689,8 @@ sea_main()
*/
loop:
done = 1;
for (unit = 0; unit < seacd.cd_ndevs; unit++) {
sea = seacd.cd_devs[unit];
for (unit = 0; unit < sea_cd.cd_ndevs; unit++) {
sea = sea_cd.cd_devs[unit];
if (!sea)
continue;
s = splbio();

View File

@ -1,4 +1,4 @@
/* $NetBSD: ultra14f.c,v 1.62 1996/02/24 05:27:49 mycroft Exp $ */
/* $NetBSD: ultra14f.c,v 1.63 1996/03/17 00:53:58 thorpej Exp $ */
/*
* Copyright (c) 1994 Charles Hannum. All rights reserved.
@ -326,8 +326,12 @@ int uhaprobe __P((struct device *, void *, void *));
void uhaattach __P((struct device *, struct device *, void *));
int uhaprint __P((void *, char *));
struct cfdriver uhacd = {
NULL, "uha", uhaprobe, uhaattach, DV_DULL, sizeof(struct uha_softc)
struct cfattach uha_ca = {
sizeof(struct uha_softc), uhaprobe, uhaattach
};
struct cfdriver uha_cd = {
NULL, "uha", DV_DULL
};
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: wd.c,v 1.146 1996/03/01 04:08:51 mycroft Exp $ */
/* $NetBSD: wd.c,v 1.147 1996/03/17 00:54:01 thorpej Exp $ */
/*
* Copyright (c) 1994, 1995 Charles M. Hannum. All rights reserved.
@ -138,15 +138,23 @@ struct wdc_softc {
int wdcprobe __P((struct device *, void *, void *));
void wdcattach __P((struct device *, struct device *, void *));
struct cfdriver wdccd = {
NULL, "wdc", wdcprobe, wdcattach, DV_DULL, sizeof(struct wdc_softc)
struct cfattach wdc_ca = {
sizeof(struct wdc_softc), wdcprobe, wdcattach
};
struct cfdriver wdc_cd = {
NULL, "wdc", DV_DULL
};
int wdprobe __P((struct device *, void *, void *));
void wdattach __P((struct device *, struct device *, void *));
struct cfdriver wdcd = {
NULL, "wd", wdprobe, wdattach, DV_DISK, sizeof(struct wd_softc)
struct cfattach wd_ca = {
sizeof(struct wd_softc), wdprobe, wdattach
};
struct cfdriver wd_cd = {
NULL, "wd", DV_DISK
};
void wdgetdisklabel __P((struct wd_softc *));
@ -353,7 +361,7 @@ void
wdstrategy(bp)
struct buf *bp;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(bp->b_dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(bp->b_dev)];
int s;
/* Valid request? */
@ -888,9 +896,9 @@ wdopen(dev, flag, fmt)
int error;
unit = WDUNIT(dev);
if (unit >= wdcd.cd_ndevs)
if (unit >= wd_cd.cd_ndevs)
return ENXIO;
wd = wdcd.cd_devs[unit];
wd = wd_cd.cd_devs[unit];
if (wd == 0)
return ENXIO;
@ -962,7 +970,7 @@ wdclose(dev, flag, fmt)
dev_t dev;
int flag, fmt;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
int part = WDPART(dev);
int error;
@ -1307,7 +1315,7 @@ wdioctl(dev, cmd, addr, flag, p)
int flag;
struct proc *p;
{
struct wd_softc *wd = wdcd.cd_devs[WDUNIT(dev)];
struct wd_softc *wd = wd_cd.cd_devs[WDUNIT(dev)];
int error;
if ((wd->sc_flags & WDF_LOADED) == 0)
@ -1423,7 +1431,7 @@ wdsize(dev)
if (wdopen(dev, 0, S_IFBLK) != 0)
return -1;
wd = wdcd.cd_devs[WDUNIT(dev)];
wd = wd_cd.cd_devs[WDUNIT(dev)];
part = WDPART(dev);
if (wd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
size = -1;
@ -1462,9 +1470,9 @@ wddump(dev, blkno, va, size)
wddoingadump = 1;
unit = WDUNIT(dev);
if (unit >= wdcd.cd_ndevs)
if (unit >= wd_cd.cd_ndevs)
return ENXIO;
wd = wdcd.cd_devs[unit];
wd = wd_cd.cd_devs[unit];
if (wd == 0)
return ENXIO;
@ -1656,8 +1664,8 @@ wdcunwedge(wdc)
(void) wdcreset(wdc);
/* Schedule recalibrate for all drives on this controller. */
for (unit = 0; unit < wdcd.cd_ndevs; unit++) {
struct wd_softc *wd = wdcd.cd_devs[unit];
for (unit = 0; unit < wd_cd.cd_ndevs; unit++) {
struct wd_softc *wd = wd_cd.cd_devs[unit];
if (!wd || (void *)wd->sc_dev.dv_parent != wdc)
continue;
if (wd->sc_state > RECAL)

View File

@ -1,4 +1,4 @@
/* $NetBSD: wss.c,v 1.9 1996/02/16 08:18:36 mycroft Exp $ */
/* $NetBSD: wss.c,v 1.10 1996/03/17 00:54:03 thorpej Exp $ */
/*
* Copyright (c) 1994 John Brezak
@ -164,8 +164,12 @@ struct audio_hw_if wss_hw_if = {
int wssprobe __P((struct device *, void *, void *));
void wssattach __P((struct device *, struct device *, void *));
struct cfdriver wsscd = {
NULL, "wss", wssprobe, wssattach, DV_DULL, sizeof(struct wss_softc)
struct cfattach wss_ca = {
sizeof(struct wss_softc), wssprobe, wssattach
};
struct cfdriver wss_cd = {
NULL, "wss", DV_DULL
};
/*
@ -304,10 +308,10 @@ wssopen(dev, flags)
struct wss_softc *sc;
int unit = AUDIOUNIT(dev);
if (unit >= wsscd.cd_ndevs)
if (unit >= wss_cd.cd_ndevs)
return ENODEV;
sc = wsscd.cd_devs[unit];
sc = wss_cd.cd_devs[unit];
if (!sc)
return ENXIO;

View File

@ -1,4 +1,4 @@
/* $NetBSD: wt.c,v 1.29 1996/03/01 04:08:40 mycroft Exp $ */
/* $NetBSD: wt.c,v 1.30 1996/03/17 00:54:05 thorpej Exp $ */
/*
* Streamer tape driver.
@ -167,8 +167,12 @@ int wtprobe __P((struct device *, void *, void *));
void wtattach __P((struct device *, struct device *, void *));
int wtintr __P((void *sc));
struct cfdriver wtcd = {
NULL, "wt", wtprobe, wtattach, DV_TAPE, sizeof(struct wt_softc)
struct cfattach wt_ca = {
sizeof(struct wt_softc), wtprobe, wtattach
};
struct cfdriver wt_cd = {
NULL, "wt", DV_TAPE
};
/*
@ -286,9 +290,9 @@ wtopen(dev, flag)
struct wt_softc *sc;
int error;
if (unit >= wtcd.cd_ndevs)
if (unit >= wt_cd.cd_ndevs)
return ENXIO;
sc = wtcd.cd_devs[unit];
sc = wt_cd.cd_devs[unit];
if (!sc)
return ENXIO;
@ -371,7 +375,7 @@ wtclose(dev)
dev_t dev;
{
int unit = minor(dev) & T_UNIT;
struct wt_softc *sc = wtcd.cd_devs[unit];
struct wt_softc *sc = wt_cd.cd_devs[unit];
/* If rewind is pending, do nothing */
if (sc->flags & TPREW)
@ -425,7 +429,7 @@ wtioctl(dev, cmd, addr, flag)
int flag;
{
int unit = minor(dev) & T_UNIT;
struct wt_softc *sc = wtcd.cd_devs[unit];
struct wt_softc *sc = wt_cd.cd_devs[unit];
int error, count, op;
switch (cmd) {
@ -525,7 +529,7 @@ wtstrategy(bp)
struct buf *bp;
{
int unit = minor(bp->b_dev) & T_UNIT;
struct wt_softc *sc = wtcd.cd_devs[unit];
struct wt_softc *sc = wt_cd.cd_devs[unit];
int s;
bp->b_resid = bp->b_bcount;

View File

@ -1,4 +1,4 @@
/* $NetBSD: aic7870.c,v 1.7 1996/03/04 19:30:50 cgd Exp $ */
/* $NetBSD: aic7870.c,v 1.8 1996/03/17 00:55:23 thorpej Exp $ */
/*
* Product specific probe and attach routines for:
@ -45,9 +45,12 @@
static int aic7870_probe __P((struct device *, void *, void *));
static void aic7870_attach __P((struct device *, struct device *, void *));
struct cfdriver ahccd = {
NULL, "ahc", aic7870_probe, aic7870_attach, DV_DULL,
sizeof(struct ahc_softc)
struct cfattach ahc_ca = {
sizeof(struct ahc_softc), aic7870_probe, aic7870_attach
};
struct cfdriver ahc_cd = {
NULL, "ahc", DV_DULL
};
int ahcintr __P((void *));

View File

@ -1,29 +1,35 @@
# $NetBSD: files.pci,v 1.12 1996/03/04 03:29:19 cgd Exp $
# $NetBSD: files.pci,v 1.13 1996/03/17 00:55:24 thorpej Exp $
#
# Config.new file and device description for machine-independent PCI code.
# Included by ports that need it. Requires that the SCSI files be
# defined first.
device pci at pcibus {[dev = -1], [function = -1]}
device pci {[dev = -1], [function = -1]}
attach pci at pcibus
file dev/pci/pci.c pci needs-flag
file dev/pci/pci_subr.c pci
# Adaptec 7870 chips
device ahc at pci: scsi, aic7xxx
device ahc: scsi, aic7xxx
attach ahc at pci
file dev/pci/aic7870.c ahc
# Ethernet driver for DC21040-based boards
device de at pci: ether, ifnet
device de: ether, ifnet
attach de at pci
file dev/pci/if_de.c de
# Digital DEFPA PCI FDDI Controller
device fpa at pci: pdq, fddi, ifnet
device fpa: pdq, fddi, ifnet
attach fpa at pci
file dev/pci/if_fpa.c fpa
# NCR 53c8xx SCSI chips
device ncr at pci: scsi
device ncr: scsi
attach ncr at pci
file dev/pci/ncr.c ncr
# PCI-PCI bridge chips
device ppb at pci: pcibus
device ppb: pcibus
attach ppb at pci
file dev/pci/ppb.c ppb

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_de.c,v 1.13 1996/03/14 03:04:17 cgd Exp $ */
/* $NetBSD: if_de.c,v 1.14 1996/03/17 00:55:27 thorpej Exp $ */
/*-
* Copyright (c) 1994, 1995 Matt Thomas (matt@lkg.dec.com)
@ -384,8 +384,9 @@ extern struct cfdriver decd;
#if defined(__NetBSD__)
typedef void ifnet_ret_t;
typedef u_long ioctl_cmd_t;
extern struct cfdriver decd;
#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) decd.cd_devs[unit])
extern struct cfattach de_ca;
extern struct cfdriver de_cd;
#define TULIP_UNIT_TO_SOFTC(unit) ((tulip_softc_t *) de_cd.cd_devs[unit])
#endif
#ifndef TULIP_BURSTSIZE
@ -2405,8 +2406,12 @@ tulip_pci_probe(
static void tulip_pci_attach(TULIP_PCI_ATTACH_ARGS);
struct cfdriver decd = {
0, "de", tulip_pci_probe, tulip_pci_attach, DV_IFNET, sizeof(tulip_softc_t)
struct cfattach de_ca = {
sizeof(tulip_softc_t), tulip_pci_probe, tulip_pci_attach
};
struct cfdriver de_cd = {
0, "de", DV_IFNET
};
#endif /* __NetBSD__ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_fpa.c,v 1.6 1996/03/14 03:04:19 cgd Exp $ */
/* $NetBSD: if_fpa.c,v 1.7 1996/03/17 00:55:30 thorpej Exp $ */
/*-
* Copyright (c) 1995 Matt Thomas (thomas@lkg.dec.com)
@ -179,11 +179,17 @@ static pdq_softc_t *pdqs_pci[NFPA];
#define PDQ_PCI_UNIT_TO_SOFTC(unit) (pdqs_pci[unit])
#endif /* __FreeBSD__ */
#if defined(__bsdi__) || defined(__NetBSD__)
#if defined(__bsdi__)
extern struct cfdriver fpacd;
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpacd.cd_devs[unit])
#endif
#if defined(__NetBSD__)
extern struct cfattach fpa_ca;
extern struct cfdriver fpa_cd;
#define PDQ_PCI_UNIT_TO_SOFTC(unit) ((pdq_softc_t *)fpa_cd.cd_devs[unit])
#endif
static ifnet_ret_t
pdq_pci_ifinit(
int unit)
@ -455,7 +461,11 @@ pdq_pci_attach(
#endif
}
struct cfdriver fpacd = {
0, "fpa", pdq_pci_probe, pdq_pci_attach, DV_IFNET, sizeof(pdq_softc_t)
struct cfattach fpa_ca = {
sizeof(pdq_softc_t), pdq_pci_probe, pdq_pci_attach
};
struct cfdriver fpa_cd = {
0, "fpa", DV_IFNET
};
#endif /* __NetBSD__ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ncr.c,v 1.29 1996/03/14 05:21:20 cgd Exp $ */
/* $NetBSD: ncr.c,v 1.30 1996/03/17 00:55:32 thorpej Exp $ */
/**************************************************************************
**
@ -1319,7 +1319,7 @@ static void ncr_attach (pcici_t tag, int unit);
static char ident[] =
"\n$NetBSD: ncr.c,v 1.29 1996/03/14 05:21:20 cgd Exp $\n";
"\n$NetBSD: ncr.c,v 1.30 1996/03/17 00:55:32 thorpej Exp $\n";
u_long ncr_version = NCR_VERSION * 11
+ (u_long) sizeof (struct ncb) * 7
@ -1356,8 +1356,12 @@ int ncr_cache; /* to be aligned _NOT_ static */
#ifdef __NetBSD__
struct cfdriver ncrcd = {
NULL, "ncr", ncr_probe, ncr_attach, DV_DULL, sizeof(struct ncb)
struct cfattach ncr_ca = {
sizeof(struct ncb), ncr_probe, ncr_attach
};
struct cfdriver ncr_cd = {
NULL, "ncr", DV_DULL
};
#else /* !__NetBSD__ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ncrstat.c,v 1.6 1995/01/27 05:44:31 cgd Exp $ */
/* $NetBSD: ncrstat.c,v 1.7 1996/03/17 00:55:36 thorpej Exp $ */
/**************************************************************************
**
@ -92,7 +92,7 @@ struct nlist nl[] = {
{ "_ncr_version" },
#ifdef __NetBSD__
#define N_NCRCD 1
{ "_ncrcd" },
{ "_ncr_cd" },
#else
#define N_NCRP 1
{ "_ncrp" },
@ -114,7 +114,7 @@ u_long ccb_base;
u_long ncr_unit;
#ifdef __NetBSD__
struct cfdriver ncrcd;
struct cfdriver ncr_cd;
#else
u_long ncr_units;
#endif
@ -224,20 +224,20 @@ void open_kvm(int flags)
if (!KVM_READ (
nl[N_NCRCD].n_value,
&ncrcd,
sizeof (ncrcd))) {
&ncr_cd,
sizeof (ncr_cd))) {
fprintf (stderr, "%s: bad kvm read.\n", prog);
exit (1);
};
if (ncr_unit >= ncrcd.cd_ndevs){
if (ncr_unit >= ncr_cd.cd_ndevs){
fprintf (stderr, "%s: bad unit number (valid range: 0-%d).\n",
prog, ncrcd.cd_ndevs-1);
prog, ncr_cd.cd_ndevs-1);
exit (1);
};
if (!KVM_READ (
ncrcd.cd_devs+4*ncr_unit,
ncr_cd.cd_devs+4*ncr_unit,
&ncr_base,
sizeof (ncr_base))) {
fprintf (stderr, "%s: bad kvm read.\n", prog);

View File

@ -1,4 +1,4 @@
/* $NetBSD: pci.c,v 1.15 1996/03/14 04:03:01 cgd Exp $ */
/* $NetBSD: pci.c,v 1.16 1996/03/17 00:55:38 thorpej Exp $ */
/*
* Copyright (c) 1995, 1996 Christopher G. Demetriou. All rights reserved.
@ -44,8 +44,12 @@
int pcimatch __P((struct device *, void *, void *));
void pciattach __P((struct device *, struct device *, void *));
struct cfdriver pcicd = {
NULL, "pci", pcimatch, pciattach, DV_DULL, sizeof(struct device)
struct cfattach pci_ca = {
sizeof(struct device), pcimatch, pciattach
};
struct cfdriver pci_cd = {
NULL, "pci", DV_DULL
};
int pciprint __P((void *, char *));
@ -153,5 +157,5 @@ pcisubmatch(parent, match, aux)
if (cf->pcicf_function != PCI_UNK_FUNCTION &&
cf->pcicf_function != pa->pa_function)
return 0;
return ((*cf->cf_driver->cd_match)(parent, match, aux));
return ((*cf->cf_attach->ca_match)(parent, match, aux));
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ppb.c,v 1.4 1996/03/14 04:03:03 cgd Exp $ */
/* $NetBSD: ppb.c,v 1.5 1996/03/17 00:55:39 thorpej Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@ -52,8 +52,12 @@
int ppbmatch __P((struct device *, void *, void *));
void ppbattach __P((struct device *, struct device *, void *));
struct cfdriver ppbcd = {
NULL, "ppb", ppbmatch, ppbattach, DV_DULL, sizeof(struct device)
struct cfattach ppb_ca = {
sizeof(struct device), ppbmatch, ppbattach
};
struct cfdriver ppb_cd = {
NULL, "ppb", DV_DULL
};
static int ppbprint __P((void *, char *pnp));