Subject: Splitting struct device and softc
To: None <tech-kern@netbsd.org>
From: Joerg Sonnenberger <joerg@britannica.bec.de>
List: tech-kern
Date: 09/23/2007 17:21:15
--Yylu36WmvOXNoKYn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi all,
I'd like to commit the attached patch to allow converting drivers on a
case-by-case base to not depend on struct device being the first field.
if_bge is included as sample. CFATTACH_DECL*_NEW is meant as a temporary
interface until all drivers are converted and should be removed after
that. This is a first and critical step to completely remove the public
definition of struct device (and make it an abstract interface thereby).

Joerg

--Yylu36WmvOXNoKYn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="softc-sep.diff"

Index: sys/device.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/sys/sys/device.h,v
retrieving revision 1.97
diff -u -r1.97 device.h
--- sys/device.h	26 Aug 2007 18:20:57 -0000	1.97
+++ sys/device.h	22 Sep 2007 22:29:11 -0000
@@ -120,12 +120,14 @@
 	device_t	dv_parent;	/* pointer to parent device
 					   (NULL if pseudo- or root node) */
 	int		dv_flags;	/* misc. flags; see below */
+	void		*dv_private;	/* this device's private storage */
 	int		*dv_locators;	/* our actual locators (optional) */
 	prop_dictionary_t dv_properties;/* properties dictionary */
 };
 
 /* dv_flags */
 #define	DVF_ACTIVE	0x0001		/* device is activated */
+#define	DVF_PRIV_ALLOC	0x0002		/* device private storage != device */
 
 TAILQ_HEAD(devicelist, device);
 
@@ -214,6 +216,7 @@
 	const char *ca_name;		/* name of attachment */
 	LIST_ENTRY(cfattach) ca_list;	/* link on cfdriver's list */
 	size_t	  ca_devsize;		/* size of dev data (for malloc) */
+	int	  ca_flags;		/* flags for driver allocation etc */
 	int	(*ca_match)(device_t, cfdata_t, void *);
 	void	(*ca_attach)(device_t, device_t, void *);
 	int	(*ca_detach)(device_t, int);
@@ -225,21 +228,28 @@
 };
 LIST_HEAD(cfattachlist, cfattach);
 
-#define	CFATTACH_DECL(name, ddsize, matfn, attfn, detfn, actfn)		\
+#define	CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, \
+	rescanfn, chdetfn) \
 struct cfattach __CONCAT(name,_ca) = {					\
 	.ca_name		= ___STRING(name),			\
 	.ca_devsize		= ddsize,				\
-	.ca_match		= matfn,				\
+	.ca_match 		= matfn,				\
 	.ca_attach		= attfn,				\
 	.ca_detach		= detfn,				\
 	.ca_activate		= actfn,				\
+	.ca_rescan		= rescanfn,				\
+	.ca_childdetached	= chdetfn,				\
 }
 
-#define	CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, \
+#define	CFATTACH_DECL(name, ddsize, matfn, attfn, detfn, actfn)		\
+	CFATTACH_DECL2(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL)
+
+#define	CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, \
 	rescanfn, chdetfn) \
 struct cfattach __CONCAT(name,_ca) = {					\
 	.ca_name		= ___STRING(name),			\
 	.ca_devsize		= ddsize,				\
+	.ca_flags		= DVF_PRIV_ALLOC,			\
 	.ca_match 		= matfn,				\
 	.ca_attach		= attfn,				\
 	.ca_detach		= detfn,				\
@@ -248,6 +258,9 @@
 	.ca_childdetached	= chdetfn,				\
 }
 
+#define	CFATTACH_DECL_NEW(name, ddsize, matfn, attfn, detfn, actfn)		\
+	CFATTACH_DECL2_NEW(name, ddsize, matfn, attfn, detfn, actfn, NULL, NULL)
+
 /* Flags given to config_detach(), and the ca_detach function. */
 #define	DETACH_FORCE	0x01		/* force detachment; hardware gone */
 #define	DETACH_QUIET	0x02		/* don't print a notice */
Index: kern/subr_autoconf.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/sys/kern/subr_autoconf.c,v
retrieving revision 1.119
diff -u -r1.119 subr_autoconf.c
--- kern/subr_autoconf.c	20 Jul 2007 22:15:47 -0000	1.119
+++ kern/subr_autoconf.c	22 Sep 2007 22:28:26 -0000
@@ -1075,6 +1075,7 @@
 	int myunit;
 	char num[10];
 	device_t dev;
+	void *dev_private;
 	const struct cfiattrdata *ia;
 
 	cd = config_cfdriver_lookup(cf->cf_name);
@@ -1085,7 +1086,8 @@
 	if (ca == NULL)
 		return (NULL);
 
-	if (ca->ca_devsize < sizeof(struct device))
+	if ((ca->ca_flags & DVF_PRIV_ALLOC) == 0 &&
+	    ca->ca_devsize < sizeof(struct device))
 		panic("config_devalloc");
 
 #ifndef __BROKEN_CONFIG_UNIT_USAGE
@@ -1114,19 +1116,30 @@
 		panic("config_devalloc: device name too long");
 
 	/* get memory for all device vars */
-	dev = (device_t)malloc(ca->ca_devsize, M_DEVBUF,
-			       M_ZERO | (cold ? M_NOWAIT : M_WAITOK));
-	if (!dev)
+	dev_private = malloc(ca->ca_devsize, M_DEVBUF,
+			     M_ZERO | (cold ? M_NOWAIT : M_WAITOK));
+	if (dev_private == NULL)
 		panic("config_devalloc: memory allocation for device softc failed");
+
+	if ((ca->ca_flags & DVF_PRIV_ALLOC) != 0) {
+		dev = malloc(sizeof(struct device), M_DEVBUF, 
+			     M_ZERO | (cold ? M_NOWAIT : M_WAITOK));
+	} else {
+		dev = dev_private;
+	}
+	if (dev == NULL)
+		panic("config_devalloc: memory allocation for device_t failed");
 	dev->dv_class = cd->cd_class;
 	dev->dv_cfdata = cf;
 	dev->dv_cfdriver = cd;
 	dev->dv_cfattach = ca;
 	dev->dv_unit = myunit;
+	dev->dv_private = dev_private;
 	memcpy(dev->dv_xname, cd->cd_name, lname);
 	memcpy(dev->dv_xname + lname, xunit, lunit);
 	dev->dv_parent = parent;
 	dev->dv_flags = DVF_ACTIVE;	/* always initially active */
+	dev->dv_flags |= ca->ca_flags;	/* inherit flags from class */
 	if (locs) {
 		KASSERT(parent); /* no locators at root */
 		ia = cfiattr_lookup(cf->cf_pspec->cfp_iattr,
@@ -1151,6 +1164,9 @@
 	if (dev->dv_locators)
 		free(dev->dv_locators, M_DEVBUF);
 
+	if ((dev->dv_flags & DVF_PRIV_ALLOC) != 0)
+		free(dev->dv_private, M_DEVBUF);
+
 	free(dev, M_DEVBUF);
 }
 
@@ -1690,11 +1706,7 @@
 device_private(device_t dev)
 {
 
-	/*
-	 * For now, at least, "struct device" is the first thing in
-	 * the driver's private data.  So, we just return ourselves.
-	 */
-	return (dev);
+	return (dev->dv_private);
 }
 
 prop_dictionary_t
Index: dev/pci/if_bge.c
===================================================================
RCS file: /home/joerg/repo/netbsd/src/sys/dev/pci/if_bge.c,v
retrieving revision 1.137
diff -u -r1.137 if_bge.c
--- dev/pci/if_bge.c	29 Aug 2007 22:33:42 -0000	1.137
+++ dev/pci/if_bge.c	22 Sep 2007 22:46:47 -0000
@@ -290,7 +290,7 @@
 #define BGE_QUIRK_5700_COMMON \
 	(BGE_QUIRK_5700_SMALLDMA|BGE_QUIRK_PRODUCER_BUG)
 
-CFATTACH_DECL(bge, sizeof(struct bge_softc),
+CFATTACH_DECL_NEW(bge, sizeof(struct bge_softc),
     bge_probe, bge_attach, NULL, NULL);
 
 static u_int32_t
@@ -350,7 +350,7 @@
 	}
 
 	if (i == BGE_TIMEOUT) {
-		printf("%s: VPD read timed out\n", sc->bge_dev.dv_xname);
+		printf("%s: VPD read timed out\n", device_xname(sc->bge_dev));
 		return(0);
 	}
 
@@ -387,7 +387,7 @@
 
 	if (res.vr_id != VPD_RES_ID) {
 		printf("%s: bad VPD resource id: expected %x got %x\n",
-			sc->bge_dev.dv_xname, VPD_RES_ID, res.vr_id);
+			device_xname(sc->bge_dev), VPD_RES_ID, res.vr_id);
 		return;
 	}
 
@@ -404,7 +404,7 @@
 
 	if (res.vr_id != VPD_RES_READ) {
 		printf("%s: bad VPD resource id: expected %x got %x\n",
-		    sc->bge_dev.dv_xname, VPD_RES_READ, res.vr_id);
+		    device_xname(sc->bge_dev), VPD_RES_READ, res.vr_id);
 		return;
 	}
 
@@ -451,7 +451,7 @@
 	}
 
 	if (i == BGE_TIMEOUT) {
-		printf("%s: eeprom read timed out\n", sc->bge_dev.dv_xname);
+		printf("%s: eeprom read timed out\n", device_xname(sc->bge_dev));
 		return(0);
 	}
 
@@ -486,7 +486,7 @@
 static int
 bge_miibus_readreg(device_t dev, int phy, int reg)
 {
-	struct bge_softc *sc = (struct bge_softc *)dev;
+	struct bge_softc *sc = device_private(dev);
 	u_int32_t val;
 	u_int32_t saved_autopoll;
 	int i;
@@ -517,7 +517,7 @@
 	}
 
 	if (i == BGE_TIMEOUT) {
-		printf("%s: PHY read timed out\n", sc->bge_dev.dv_xname);
+		printf("%s: PHY read timed out\n", device_xname(sc->bge_dev));
 		val = 0;
 		goto done;
 	}
@@ -539,7 +539,7 @@
 static void
 bge_miibus_writereg(device_t dev, int phy, int reg, int val)
 {
-	struct bge_softc *sc = (struct bge_softc *)dev;
+	struct bge_softc *sc = device_private(dev);
 	u_int32_t saved_autopoll;
 	int i;
 
@@ -567,14 +567,14 @@
 	}
 
 	if (i == BGE_TIMEOUT) {
-		printf("%s: PHY read timed out\n", sc->bge_dev.dv_xname);
+		printf("%s: PHY read timed out\n", device_xname(sc->bge_dev));
 	}
 }
 
 static void
 bge_miibus_statchg(device_t dev)
 {
-	struct bge_softc *sc = (struct bge_softc *)dev;
+	struct bge_softc *sc = device_private(dev);
 	struct mii_data *mii = &sc->bge_mii;
 
 	/*
@@ -695,7 +695,7 @@
 	/* Grab a big chunk o' storage. */
 	if (bus_dmamem_alloc(sc->bge_dmatag, BGE_JMEM, PAGE_SIZE, 0,
 	     &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
-		printf("%s: can't alloc rx buffers\n", sc->bge_dev.dv_xname);
+		printf("%s: can't alloc rx buffers\n", device_xname(sc->bge_dev));
 		return ENOBUFS;
 	}
 
@@ -703,7 +703,7 @@
 	if (bus_dmamem_map(sc->bge_dmatag, &seg, rseg, BGE_JMEM, (void **)&kva,
 	    BUS_DMA_NOWAIT)) {
 		printf("%s: can't map DMA buffers (%d bytes)\n",
-		    sc->bge_dev.dv_xname, (int)BGE_JMEM);
+		    device_xname(sc->bge_dev), (int)BGE_JMEM);
 		error = ENOBUFS;
 		goto out;
 	}
@@ -711,7 +711,7 @@
 	state = 2;
 	if (bus_dmamap_create(sc->bge_dmatag, BGE_JMEM, 1, BGE_JMEM, 0,
 	    BUS_DMA_NOWAIT, &sc->bge_cdata.bge_rx_jumbo_map)) {
-		printf("%s: can't create DMA map\n", sc->bge_dev.dv_xname);
+		printf("%s: can't create DMA map\n", device_xname(sc->bge_dev));
 		error = ENOBUFS;
 		goto out;
 	}
@@ -719,7 +719,7 @@
 	state = 3;
 	if (bus_dmamap_load(sc->bge_dmatag, sc->bge_cdata.bge_rx_jumbo_map,
 	    kva, BGE_JMEM, NULL, BUS_DMA_NOWAIT)) {
-		printf("%s: can't load DMA map\n", sc->bge_dev.dv_xname);
+		printf("%s: can't load DMA map\n", device_xname(sc->bge_dev));
 		error = ENOBUFS;
 		goto out;
 	}
@@ -743,7 +743,7 @@
 		    M_DEVBUF, M_NOWAIT);
 		if (entry == NULL) {
 			printf("%s: no memory for jumbo buffer queue!\n",
-			    sc->bge_dev.dv_xname);
+			    device_xname(sc->bge_dev));
 			error = ENOBUFS;
 			goto out;
 		}
@@ -784,7 +784,7 @@
 	entry = SLIST_FIRST(&sc->bge_jfree_listhead);
 
 	if (entry == NULL) {
-		printf("%s: no free jumbo buffers\n", sc->bge_dev.dv_xname);
+		printf("%s: no free jumbo buffers\n", device_xname(sc->bge_dev));
 		return(NULL);
 	}
 
@@ -917,7 +917,7 @@
 		if (buf == NULL) {
 			m_freem(m_new);
 			printf("%s: jumbo allocation failed "
-			    "-- packet dropped!\n", sc->bge_dev.dv_xname);
+			    "-- packet dropped!\n", device_xname(sc->bge_dev));
 			return(ENOBUFS);
 		}
 
@@ -1116,7 +1116,7 @@
 		dma = malloc(sizeof(*dma), M_DEVBUF, M_NOWAIT);
 		if (dma == NULL) {
 			printf("%s: can't alloc txdmamap_pool_entry\n",
-			    sc->bge_dev.dv_xname);
+			    device_xname(sc->bge_dev));
 			bus_dmamap_destroy(sc->bge_dmatag, dmamap);
 			return (ENOMEM);
 		}
@@ -1236,7 +1236,7 @@
 	 */
 	if (CSR_READ_4(sc, BGE_RXCPU_MODE) & BGE_RXCPUMODE_ROMFAIL) {
 		printf("%s: RX CPU self-diagnostics failed!\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return(ENODEV);
 	}
 
@@ -1261,7 +1261,7 @@
 
 		/* From FreeBSD */
 		DPRINTFN(4, ("(%s: PCI-Express DMA setting)\n",
-		    sc->bge_dev.dv_xname));
+		    device_xname(sc->bge_dev)));
 		dma_rw_ctl = (BGE_PCI_READ_CMD | BGE_PCI_WRITE_CMD |
 		    (0xf << BGE_PCIDMARWCTL_RD_WAT_SHIFT) |
 		    (0x2 << BGE_PCIDMARWCTL_WR_WAT_SHIFT));
@@ -1273,7 +1273,7 @@
 		dma_rw_ctl =   0x76000000; /* XXX XXX XXX */;
 		device_ctl = pci_conf_read(pa->pa_pc, pa->pa_tag,
 					   BGE_PCI_CONF_DEV_CTRL);
-		aprint_debug("%s: pcie mode=0x%x\n", sc->bge_dev.dv_xname,
+		aprint_debug("%s: pcie mode=0x%x\n", device_xname(sc->bge_dev),
 		    device_ctl);
 
 		if ((device_ctl & 0x00e0) && 0) {
@@ -1291,7 +1291,7 @@
 	} else if (pci_conf_read(pa->pa_pc, pa->pa_tag,BGE_PCI_PCISTATE) &
 	    BGE_PCISTATE_PCI_BUSMODE) {
 		/* Conventional PCI bus */
-	  	DPRINTFN(4, ("(%s: PCI 2.2 DMA setting)\n", sc->bge_dev.dv_xname));
+	  	DPRINTFN(4, ("(%s: PCI 2.2 DMA setting)\n", device_xname(sc->bge_dev)));
 		dma_rw_ctl = (BGE_PCI_READ_CMD | BGE_PCI_WRITE_CMD |
 		   (0x7 << BGE_PCIDMARWCTL_RD_WAT_SHIFT) |
 		   (0x7 << BGE_PCIDMARWCTL_WR_WAT_SHIFT));
@@ -1299,7 +1299,7 @@
 			dma_rw_ctl |= 0x0F;
 		}
 	} else {
-	  	DPRINTFN(4, ("(:%s: PCI-X DMA setting)\n", sc->bge_dev.dv_xname));
+	  	DPRINTFN(4, ("(:%s: PCI-X DMA setting)\n", device_xname(sc->bge_dev)));
 		/* PCI-X bus */
 		dma_rw_ctl = BGE_PCI_READ_CMD|BGE_PCI_WRITE_CMD |
 		    (0x3 << BGE_PCIDMARWCTL_RD_WAT_SHIFT) |
@@ -1386,7 +1386,7 @@
 			if (bootverbose)
 				printf("%s: cache line size %d not "
 				    "supported; disabling PCI MWI\n",
-				    sc->bge_dev.dv_xname, cachesize);
+				    device_xname(sc->bge_dev), cachesize);
 #endif
 			PCI_CLRBIT(pa->pa_pc, pa->pa_tag, BGE_PCI_CMD,
 			    PCIM_CMD_MWIEN);
@@ -1502,7 +1502,7 @@
 
 	if (i == BGE_TIMEOUT) {
 		printf("%s: buffer manager failed to start\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return(ENXIO);
 	}
 
@@ -1519,7 +1519,7 @@
 
 	if (i == BGE_TIMEOUT) {
 		printf("%s: flow-through queue init failed\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return(ENXIO);
 	}
 
@@ -1705,7 +1705,7 @@
 
 	if (i == BGE_TIMEOUT) {
 		printf("%s: host coalescing engine failed to idle\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return(ENXIO);
 	}
 
@@ -2390,7 +2390,7 @@
 	 * for all supported OEM cards, states D1-D3 are  unsupported.
 	 */
 	printf("%s: power state %d unimplemented; check GPIO pins\n",
-	       sc->bge_dev.dv_xname, powerlevel);
+	       device_xname(sc->bge_dev), powerlevel);
 #endif
 	return EOPNOTSUPP;
 }
@@ -2418,7 +2418,7 @@
 static void
 bge_attach(device_t parent, device_t self, void *aux)
 {
-	struct bge_softc	*sc = (struct bge_softc *)self;
+	struct bge_softc	*sc = device_private(self);
 	struct pci_attach_args	*pa = aux;
 	const struct bge_product *bp;
 	const struct bge_revision *br;
@@ -2441,6 +2441,7 @@
 	bp = bge_lookup(pa);
 	KASSERT(bp != NULL);
 
+	sc->bge_dev = self;
 	sc->bge_pa = *pa;
 
 	aprint_naive(": Ethernet controller\n");
@@ -2457,7 +2458,7 @@
 
 	if (!(command & PCI_COMMAND_MEM_ENABLE)) {
 		aprint_error("%s: failed to enable memory mapping!\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return;
 	}
 
@@ -2472,14 +2473,14 @@
 			break;
 	default:
 		aprint_error("%s: can't find mem space\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return;
 	}
 
 	DPRINTFN(5, ("pci_intr_map\n"));
 	if (pci_intr_map(pa, &ih)) {
 		aprint_error("%s: couldn't map interrupt\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return;
 	}
 
@@ -2491,14 +2492,14 @@
 
 	if (sc->bge_intrhand == NULL) {
 		aprint_error("%s: couldn't establish interrupt",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		if (intrstr != NULL)
 			aprint_normal(" at %s", intrstr);
 		aprint_normal("\n");
 		return;
 	}
 	aprint_normal("%s: interrupting at %s\n",
-	    sc->bge_dev.dv_xname, intrstr);
+	    device_xname(sc->bge_dev), intrstr);
 
 	/*
 	 * Kludge for 5700 Bx bug: a hardware bug (PCIX byte enable?)
@@ -2537,7 +2538,7 @@
 
 	if (bge_chipinit(sc)) {
 		aprint_error("%s: chip initialization failed\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		bge_release_resources(sc);
 		return;
 	}
@@ -2557,13 +2558,13 @@
 	} else if (bge_read_eeprom(sc, (void *)eaddr,
 	    BGE_EE_MAC_OFFSET + 2, ETHER_ADDR_LEN)) {
 		aprint_error("%s: failed to read station address\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		bge_release_resources(sc);
 		return;
 	}
 
 	br = bge_lookup_rev(sc->bge_chipid);
-	aprint_normal("%s: ", sc->bge_dev.dv_xname);
+	aprint_normal("%s: ", device_xname(sc->bge_dev));
 
 	if (br == NULL) {
 		aprint_normal("unknown ASIC (0x%04x)", sc->bge_chipid >> 16);
@@ -2584,7 +2585,7 @@
 	if (bus_dmamem_alloc(sc->bge_dmatag, sizeof(struct bge_ring_data),
 			     PAGE_SIZE, 0, &seg, 1, &rseg, BUS_DMA_NOWAIT)) {
 		aprint_error("%s: can't alloc rx buffers\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		return;
 	}
 	DPRINTFN(5, ("bus_dmamem_map\n"));
@@ -2592,7 +2593,7 @@
 			   sizeof(struct bge_ring_data), &kva,
 			   BUS_DMA_NOWAIT)) {
 		aprint_error("%s: can't map DMA buffers (%d bytes)\n",
-		    sc->bge_dev.dv_xname, (int)sizeof(struct bge_ring_data));
+		    device_xname(sc->bge_dev), (int)sizeof(struct bge_ring_data));
 		bus_dmamem_free(sc->bge_dmatag, &seg, rseg);
 		return;
 	}
@@ -2601,7 +2602,7 @@
 	    sizeof(struct bge_ring_data), 0,
 	    BUS_DMA_NOWAIT, &sc->bge_ring_map)) {
 		aprint_error("%s: can't create DMA map\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 		bus_dmamem_unmap(sc->bge_dmatag, kva,
 				 sizeof(struct bge_ring_data));
 		bus_dmamem_free(sc->bge_dmatag, &seg, rseg);
@@ -2627,7 +2628,7 @@
 	if ((sc->bge_quirks & BGE_QUIRK_5705_CORE) == 0) {
 		if (bge_alloc_jumbo_mem(sc)) {
 			aprint_error("%s: jumbo buffer allocation failed\n",
-			    sc->bge_dev.dv_xname);
+			    device_xname(sc->bge_dev));
 		} else
 			sc->ethercom.ec_capabilities |= ETHERCAP_JUMBO_MTU;
 	}
@@ -2647,7 +2648,7 @@
 		sc->bge_tx_coal_ticks = (12 * 5);
 		sc->bge_rx_max_coal_bds = (12 * 5);
 			aprint_verbose("%s: setting short Tx thresholds\n",
-			    sc->bge_dev.dv_xname);
+			    device_xname(sc->bge_dev));
 	}
 
 	/* Set up ifnet structure */
@@ -2661,7 +2662,7 @@
 	IFQ_SET_MAXLEN(&ifp->if_snd, max(BGE_TX_RING_CNT - 1, IFQ_MAXLEN));
 	IFQ_SET_READY(&ifp->if_snd);
 	DPRINTFN(5, ("strcpy if_xname\n"));
-	strcpy(ifp->if_xname, sc->bge_dev.dv_xname);
+	strcpy(ifp->if_xname, device_xname(sc->bge_dev));
 
 	if ((sc->bge_quirks & BGE_QUIRK_CSUM_BROKEN) == 0)
 		sc->ethercom.ec_if.if_capabilities |=
@@ -2720,12 +2721,12 @@
 		 */
 		ifmedia_init(&sc->bge_mii.mii_media, 0, bge_ifmedia_upd,
 			     bge_ifmedia_sts);
-		mii_attach(&sc->bge_dev, &sc->bge_mii, 0xffffffff,
+		mii_attach(sc->bge_dev, &sc->bge_mii, 0xffffffff,
 			   MII_PHY_ANY, MII_OFFSET_ANY,
 			   MIIF_FORCEANEG|MIIF_DOPAUSE);
 
 		if (LIST_FIRST(&sc->bge_mii.mii_phys) == NULL) {
-			printf("%s: no PHY found!\n", sc->bge_dev.dv_xname);
+			printf("%s: no PHY found!\n", device_xname(sc->bge_dev));
 			ifmedia_add(&sc->bge_mii.mii_media,
 				    IFM_ETHER|IFM_MANUAL, 0, NULL);
 			ifmedia_set(&sc->bge_mii.mii_media,
@@ -2763,28 +2764,28 @@
 	 * Attach event counters.
 	 */
 	evcnt_attach_dynamic(&sc->bge_ev_intr, EVCNT_TYPE_INTR,
-	    NULL, sc->bge_dev.dv_xname, "intr");
+	    NULL, device_xname(sc->bge_dev), "intr");
 	evcnt_attach_dynamic(&sc->bge_ev_tx_xoff, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "tx_xoff");
+	    NULL, device_xname(sc->bge_dev), "tx_xoff");
 	evcnt_attach_dynamic(&sc->bge_ev_tx_xon, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "tx_xon");
+	    NULL, device_xname(sc->bge_dev), "tx_xon");
 	evcnt_attach_dynamic(&sc->bge_ev_rx_xoff, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "rx_xoff");
+	    NULL, device_xname(sc->bge_dev), "rx_xoff");
 	evcnt_attach_dynamic(&sc->bge_ev_rx_xon, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "rx_xon");
+	    NULL, device_xname(sc->bge_dev), "rx_xon");
 	evcnt_attach_dynamic(&sc->bge_ev_rx_macctl, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "rx_macctl");
+	    NULL, device_xname(sc->bge_dev), "rx_macctl");
 	evcnt_attach_dynamic(&sc->bge_ev_xoffentered, EVCNT_TYPE_MISC,
-	    NULL, sc->bge_dev.dv_xname, "xoffentered");
+	    NULL, device_xname(sc->bge_dev), "xoffentered");
 #endif /* BGE_EVENT_COUNTERS */
 	DPRINTFN(5, ("callout_init\n"));
 	callout_init(&sc->bge_timeout, 0);
 
-	sc->bge_powerhook = powerhook_establish(sc->bge_dev.dv_xname,
+	sc->bge_powerhook = powerhook_establish(device_xname(sc->bge_dev),
 	    bge_powerhook, sc);
 	if (sc->bge_powerhook == NULL)
 		printf("%s: WARNING: unable to establish PCI power hook\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 }
 
 static void
@@ -2902,7 +2903,7 @@
 
 	if (i >= BGE_TIMEOUT) {
 		printf("%s: firmware handshake timed out, val = %x\n",
-		    sc->bge_dev.dv_xname, val);
+		    device_xname(sc->bge_dev), val);
 		/*
 		 * XXX: occasionally fired on bcm5721, but without
 		 * apparent harm.  For now, keep going if we timeout
@@ -2931,7 +2932,7 @@
 	if ((new_pcistate & ~BGE_PCISTATE_RESERVED) !=
 	    (pcistate & ~BGE_PCISTATE_RESERVED)) {
 		printf("%s: pcistate failed to revert\n",
-		    sc->bge_dev.dv_xname);
+		    device_xname(sc->bge_dev));
 	}
 
 	/* XXX: from FreeBSD/Linux; no documentation */
@@ -3229,8 +3230,8 @@
 			/* Clear the interrupt */
 			CSR_WRITE_4(sc, BGE_MAC_EVT_ENB,
 			    BGE_EVTENB_MI_INTERRUPT);
-			bge_miibus_readreg(&sc->bge_dev, 1, BRGPHY_MII_ISR);
-			bge_miibus_writereg(&sc->bge_dev, 1, BRGPHY_MII_IMR,
+			bge_miibus_readreg(sc->bge_dev, 1, BRGPHY_MII_ISR);
+			bge_miibus_writereg(sc->bge_dev, 1, BRGPHY_MII_IMR,
 			    BRGPHY_INTRS);
 		}
 	} else {
@@ -3773,7 +3774,7 @@
 	if (dmamap->dm_nsegs > (BGE_TX_RING_CNT - sc->bge_txcnt - 16)) {
 		BGE_TSO_PRINTF(("%s: "
 		    " dmamap_load_mbuf too close to ring wrap\n",
-		    sc->bge_dev.dv_xname));
+		    device_xname(sc->bge_dev)));
 		goto fail_unload;
 	}
 
@@ -3822,7 +3823,7 @@
 
 	if (i < dmamap->dm_nsegs) {
 		BGE_TSO_PRINTF(("%s: reached %d < dm_nsegs %d\n",
-		    sc->bge_dev.dv_xname, i, dmamap->dm_nsegs));
+		    device_xname(sc->bge_dev), i, dmamap->dm_nsegs));
 		goto fail_unload;
 	}
 
@@ -3831,7 +3832,7 @@
 
 	if (frag == sc->bge_tx_saved_considx) {
 		BGE_TSO_PRINTF(("%s: frag %d = wrapped id %d?\n",
-		    sc->bge_dev.dv_xname, frag, sc->bge_tx_saved_considx));
+		    device_xname(sc->bge_dev), frag, sc->bge_tx_saved_considx));
 
 		goto fail_unload;
 	}
@@ -3956,7 +3957,7 @@
 	 */
 	error = bge_blockinit(sc);
 	if (error != 0) {
-		printf("%s: initialization error %d\n", sc->bge_dev.dv_xname,
+		printf("%s: initialization error %d\n", device_xname(sc->bge_dev),
 		    error);
 		splx(s);
 		return error;
@@ -4186,7 +4187,7 @@
 
 	sc = ifp->if_softc;
 
-	printf("%s: watchdog timeout -- resetting\n", sc->bge_dev.dv_xname);
+	printf("%s: watchdog timeout -- resetting\n", device_xname(sc->bge_dev));
 
 	ifp->if_flags &= ~IFF_RUNNING;
 	bge_init(ifp);
@@ -4210,7 +4211,7 @@
 	}
 
 	printf("%s: block failed to stop: reg 0x%lx, bit 0x%08x\n",
-	    sc->bge_dev.dv_xname, (u_long) reg, bit);
+	    device_xname(sc->bge_dev), (u_long) reg, bit);
 }
 
 /*
Index: dev/pci/if_bgereg.h
===================================================================
RCS file: /home/joerg/repo/netbsd/src/sys/dev/pci/if_bgereg.h,v
retrieving revision 1.43
diff -u -r1.43 if_bgereg.h
--- dev/pci/if_bgereg.h	6 Aug 2007 12:23:08 -0000	1.43
+++ dev/pci/if_bgereg.h	22 Sep 2007 22:34:58 -0000
@@ -2380,7 +2380,7 @@
 #define BGE_JUMBO_RXRING_VALID	0x0004
 
 struct bge_softc {
-	struct device		bge_dev;
+	device_t		bge_dev;
 	struct ethercom		ethercom;		/* interface info */
 	bus_space_handle_t	bge_bhandle;
 	bus_space_tag_t		bge_btag;

--Yylu36WmvOXNoKYn--