[Midnightbsd-cvs] src: dev/cardbus: cardbus sync

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sun Nov 30 11:10:30 EST 2008


Log Message:
-----------
cardbus sync

Modified Files:
--------------
    src/sys/dev/cardbus:
        cardbus.c (r1.2 -> r1.3)
        cardbus_cis.c (r1.2 -> r1.3)
        cardbus_device.c (r1.1.1.1 -> r1.2)
        cardbusreg.h (r1.2 -> r1.3)
        cardbusvar.h (r1.2 -> r1.3)

-------------- next part --------------
Index: cardbus.c
===================================================================
RCS file: /home/cvs/src/sys/dev/cardbus/cardbus.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/cardbus/cardbus.c -L sys/dev/cardbus/cardbus.c -u -r1.2 -r1.3
--- sys/dev/cardbus/cardbus.c
+++ sys/dev/cardbus/cardbus.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus.c,v 1.52.2.3 2006/03/01 18:19:33 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus.c,v 1.66 2007/09/30 11:05:14 marius Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,18 +71,12 @@
 #define	DPRINTF(a) if (cardbus_debug) printf a
 #define	DEVPRINTF(x) if (cardbus_debug) device_printf x
 
-
-static void	cardbus_add_map(device_t cbdev, device_t child, int reg);
-static int	cardbus_alloc_resources(device_t cbdev, device_t child);
 static int	cardbus_attach(device_t cbdev);
 static int	cardbus_attach_card(device_t cbdev);
-static int	cardbus_barsort(const void *a, const void *b);
 static int	cardbus_detach(device_t cbdev);
 static int	cardbus_detach_card(device_t cbdev);
-static void	cardbus_device_setup_regs(device_t brdev, int b, int s, int f,
-		    pcicfgregs *cfg);
+static void	cardbus_device_setup_regs(pcicfgregs *cfg);
 static void	cardbus_driver_added(device_t cbdev, driver_t *driver);
-static void	cardbus_pickup_maps(device_t cbdev, device_t child);
 static int	cardbus_probe(device_t cbdev);
 static int	cardbus_read_ivar(device_t cbdev, device_t child, int which,
 		    uintptr_t *result);
@@ -91,307 +85,6 @@
 static int	cardbus_write_ivar(device_t cbdev, device_t child, int which,
 		    uintptr_t value);
 
-/*
- * Resource allocation
- */
-/*
- * Adding a memory/io resource (sans CIS)
- */
-
-static void
-cardbus_add_map(device_t cbdev, device_t child, int reg)
-{
-	struct cardbus_devinfo *dinfo = device_get_ivars(child);
-	struct resource_list_entry *rle;
-	uint32_t size;
-	uint32_t testval;
-	int type;
-
-	STAILQ_FOREACH(rle, &dinfo->pci.resources, link) {
-		if (rle->rid == reg)
-			return;
-	}
-
-	if (reg == CARDBUS_ROM_REG)
-		testval = CARDBUS_ROM_ADDRMASK;
-	else
-		testval = ~0;
-
-	pci_write_config(child, reg, testval, 4);
-	testval = pci_read_config(child, reg, 4);
-
-	if (testval == ~0 || testval == 0)
-		return;
-
-	if ((testval & 1) == 0)
-		type = SYS_RES_MEMORY;
-	else
-		type = SYS_RES_IOPORT;
-
-	size = CARDBUS_MAPREG_MEM_SIZE(testval);
-	device_printf(cbdev, "Resource not specified in CIS: id=%x, size=%x\n",
-	    reg, size);
-	resource_list_add(&dinfo->pci.resources, type, reg, 0UL, ~0UL, size);
-}
-
-static void
-cardbus_pickup_maps(device_t cbdev, device_t child)
-{
-	struct cardbus_devinfo *dinfo = device_get_ivars(child);
-	int reg;
-
-	/*
-	 * Try to pick up any resources that was not specified in CIS.
-	 * Maybe this isn't any longer necessary now that we have fixed
-	 * CIS parsing and we should filter things here?  XXX
-	 */
-	for (reg = 0; reg < dinfo->pci.cfg.nummaps; reg++)
-		cardbus_add_map(cbdev, child, PCIR_BAR(reg));
-}
-
-static int
-cardbus_barsort(const void *a, const void *b)
-{
-	return ((*(const struct resource_list_entry * const *)b)->count -
-	    (*(const struct resource_list_entry * const *)a)->count);
-}
-
-/* XXX this function is too long */
-static int
-cardbus_alloc_resources(device_t cbdev, device_t child)
-{
-	struct cardbus_devinfo *dinfo = device_get_ivars(child);
-	int count;
-	struct resource_list_entry *rle;
-	struct resource_list_entry **barlist;
-	int tmp;
-	uint32_t mem_psize = 0, mem_nsize = 0, io_size = 0;
-	struct resource *res;
-	uint32_t start,end;
-	int rid, flags;
-
-	count = 0;
-	STAILQ_FOREACH(rle, &dinfo->pci.resources, link) {
-		count++;
-	}
-	if (count == 0)
-		return (0);
-	barlist = malloc(sizeof(struct resource_list_entry*) * count, M_DEVBUF,
-	    M_WAITOK);
-	count = 0;
-	STAILQ_FOREACH(rle, &dinfo->pci.resources, link) {
-		barlist[count] = rle;
-		if (rle->type == SYS_RES_IOPORT) {
-			io_size += rle->count;
-		} else if (rle->type == SYS_RES_MEMORY) {
-			if (dinfo->mprefetchable & BARBIT(rle->rid))
-				mem_psize += rle->count;
-			else
-				mem_nsize += rle->count;
-		}
-		count++;
-	}
-
-	/*
-	 * We want to allocate the largest resource first, so that our
-	 * allocated memory is packed.
-	 */
-	qsort(barlist, count, sizeof(struct resource_list_entry *),
-	    cardbus_barsort);
-
-	/* Allocate prefetchable memory */
-	flags = 0;
-	for (tmp = 0; tmp < count; tmp++) {
-		rle = barlist[tmp];
-		if (rle->res == NULL &&
-		    rle->type == SYS_RES_MEMORY &&
-		    dinfo->mprefetchable & BARBIT(rle->rid)) {
-			flags = rman_make_alignment_flags(rle->count);
-			break;
-		}
-	}
-	if (flags > 0) { /* If any prefetchable memory is requested... */
-		/*
-		 * First we allocate one big space for all resources of this
-		 * type.  We do this because our parent, pccbb, needs to open
-		 * a window to forward all addresses within the window, and
-		 * it would be best if nobody else has resources allocated
-		 * within the window.
-		 * (XXX: Perhaps there might be a better way to do this?)
-		 */
-		rid = 0;
-		res = bus_alloc_resource(cbdev, SYS_RES_MEMORY, &rid, 0,
-		    (dinfo->mprefetchable & dinfo->mbelow1mb)?0xFFFFF:~0UL,
-		    mem_psize, flags);
-		if (res == NULL) {
-			device_printf(cbdev,
-			    "Can't get memory for prefetch mem\n");
-			free(barlist, M_DEVBUF);
-			return (EIO);
-		}
-		start = rman_get_start(res);
-		end = rman_get_end(res);
-		DEVPRINTF((cbdev, "Prefetchable memory at %x-%x\n", start, end));
-		/*
-		 * Now that we know the region is free, release it and hand it
-		 * out piece by piece.
-		 */
-		bus_release_resource(cbdev, SYS_RES_MEMORY, rid, res);
-		for (tmp = 0; tmp < count; tmp++) {
-			rle = barlist[tmp];
-			if (rle->type == SYS_RES_MEMORY &&
-			    dinfo->mprefetchable & BARBIT(rle->rid)) {
-				rle->res = bus_alloc_resource(cbdev,
-				    rle->type, &rle->rid, start, end,
-				    rle->count,
-				    rman_make_alignment_flags(rle->count));
-				if (rle->res != NULL) {
-					rle->start = rman_get_start(rle->res);
-					rle->end = rman_get_end(rle->res);
-					pci_write_config(child,
-					    rle->rid, rle->start, 4);
-				}
-			}
-		}
-	}
-
-	/* Allocate non-prefetchable memory */
-	flags = 0;
-	for (tmp = 0; tmp < count; tmp++) {
-		rle = barlist[tmp];
-		if (rle->type == SYS_RES_MEMORY &&
-		    (dinfo->mprefetchable & BARBIT(rle->rid)) == 0) {
-			flags = rman_make_alignment_flags(rle->count);
-			break;
-		}
-	}
-	if (flags > 0) { /* If any non-prefetchable memory is requested... */
-		/*
-		 * First we allocate one big space for all resources of this
-		 * type.  We do this because our parent, pccbb, needs to open
-		 * a window to forward all addresses within the window, and
-		 * it would be best if nobody else has resources allocated
-		 * within the window.
-		 * (XXX: Perhaps there might be a better way to do this?)
-		 */
-		rid = 0;
-		res = bus_alloc_resource(cbdev, SYS_RES_MEMORY, &rid, 0,
-		    ((~dinfo->mprefetchable) & dinfo->mbelow1mb)?0xFFFFF:~0UL,
-		    mem_nsize, flags);
-		if (res == NULL) {
-			device_printf(cbdev,
-			    "Can't get memory for non-prefetch mem\n");
-			free(barlist, M_DEVBUF);
-			return (EIO);
-		}
-		start = rman_get_start(res);
-		end = rman_get_end(res);
-		DEVPRINTF((cbdev, "Non-prefetchable memory at %x-%x\n",
-		    start, end));
-		/*
-		 * Now that we know the region is free, release it and hand it
-		 * out piece by piece.
-		 */
-		bus_release_resource(cbdev, SYS_RES_MEMORY, rid, res);
-		for (tmp = 0; tmp < count; tmp++) {
-			rle = barlist[tmp];
-			if (rle->type == SYS_RES_MEMORY &&
-			    (dinfo->mprefetchable & BARBIT(rle->rid)) == 0) {
-				rle->res = bus_alloc_resource(cbdev,
-				    rle->type, &rle->rid, start, end,
-				    rle->count,
-				    rman_make_alignment_flags(rle->count));
-				if (rle->res == NULL) {
-					DEVPRINTF((cbdev, "Cannot pre-allocate "
-					    "memory for cardbus device\n"));
-					free(barlist, M_DEVBUF);
-					return (ENOMEM);
-				}
-				rle->start = rman_get_start(rle->res);
-				rle->end = rman_get_end(rle->res);
-				pci_write_config(child,
-				    rle->rid, rle->start, 4);
-			}
-		}
-	}
-
-	/* Allocate IO ports */
-	flags = 0;
-	for (tmp = 0; tmp < count; tmp++) {
-		rle = barlist[tmp];
-		if (rle->type == SYS_RES_IOPORT) {
-			flags = rman_make_alignment_flags(rle->count);
-			break;
-		}
-	}
-	if (flags > 0) { /* If any IO port is requested... */
-		/*
-		 * First we allocate one big space for all resources of this
-		 * type.  We do this because our parent, pccbb, needs to open
-		 * a window to forward all addresses within the window, and
-		 * it would be best if nobody else has resources allocated
-		 * within the window.
-		 * (XXX: Perhaps there might be a better way to do this?)
-		 */
-		rid = 0;
-		res = bus_alloc_resource(cbdev, SYS_RES_IOPORT, &rid, 0,
-		    (dinfo->ibelow1mb)?0xFFFFF:~0UL, io_size, flags);
-		if (res == NULL) {
-			device_printf(cbdev,
-			    "Can't get memory for IO ports\n");
-			free(barlist, M_DEVBUF);
-			return (EIO);
-		}
-		start = rman_get_start(res);
-		end = rman_get_end(res);
-		DEVPRINTF((cbdev, "IO port at %x-%x\n", start, end));
-		/*
-		 * Now that we know the region is free, release it and hand it
-		 * out piece by piece.
-		 */
-		bus_release_resource(cbdev, SYS_RES_IOPORT, rid, res);
-		for (tmp = 0; tmp < count; tmp++) {
-			rle = barlist[tmp];
-			if (rle->type == SYS_RES_IOPORT) {
-				rle->res = bus_alloc_resource(cbdev,
-				    rle->type, &rle->rid, start, end,
-				    rle->count,
-				    rman_make_alignment_flags(rle->count));
-				if (rle->res == NULL) {
-					DEVPRINTF((cbdev, "Cannot pre-allocate "
-					    "IO port for cardbus device\n"));
-					free(barlist, M_DEVBUF);
-					return (ENOMEM);
-				}
-				rle->start = rman_get_start(rle->res);
-				rle->end = rman_get_end(rle->res);
-				pci_write_config(child,
-				    rle->rid, rle->start, 4);
-			}
-		}
-	}
-
-	/* Allocate IRQ */
-	rid = 0;
-	res = bus_alloc_resource_any(cbdev, SYS_RES_IRQ, &rid, RF_SHAREABLE);
-	if (res == NULL) {
-		device_printf(cbdev, "Can't get memory for irq\n");
-		free(barlist, M_DEVBUF);
-		return (EIO);
-	}
-	start = rman_get_start(res);
-	end = rman_get_end(res);
-	resource_list_add(&dinfo->pci.resources, SYS_RES_IRQ, rid, start, end,
-	    1);
-	rle = resource_list_find(&dinfo->pci.resources, SYS_RES_IRQ, rid);
-	rle->res = res;
-	dinfo->pci.cfg.intline = start;
-	pci_write_config(child, PCIR_INTLINE, start, 1);
-
-	free(barlist, M_DEVBUF);
-	return (0);
-}
-
 /************************************************************************/
 /* Probe/Attach								*/
 /************************************************************************/
@@ -400,25 +93,33 @@
 cardbus_probe(device_t cbdev)
 {
 	device_set_desc(cbdev, "CardBus bus");
-	return 0;
+	return (0);
 }
 
 static int
 cardbus_attach(device_t cbdev)
 {
-	return 0;
+	struct cardbus_softc *sc = device_get_softc(cbdev);
+
+	sc->sc_dev = cbdev;
+	cardbus_device_create(sc);
+	return (0);
 }
 
 static int
 cardbus_detach(device_t cbdev)
 {
+	struct cardbus_softc *sc = device_get_softc(cbdev);
+
 	cardbus_detach_card(cbdev);
-	return 0;
+	cardbus_device_destroy(sc);
+	return (0);
 }
 
 static int
 cardbus_suspend(device_t self)
 {
+
 	cardbus_detach_card(self);
 	return (0);
 }
@@ -426,6 +127,7 @@
 static int
 cardbus_resume(device_t self)
 {
+
 	return (0);
 }
 
@@ -434,23 +136,25 @@
 /************************************************************************/
 
 static void
-cardbus_device_setup_regs(device_t brdev, int b, int s, int f, pcicfgregs *cfg)
+cardbus_device_setup_regs(pcicfgregs *cfg)
 {
-	PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_INTLINE,
-	    pci_get_irq(device_get_parent(brdev)), 1);
-	cfg->intline = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_INTLINE, 1);
-
-	PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_CACHELNSZ, 0x08, 1);
-	cfg->cachelnsz = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_CACHELNSZ, 1);
-
-	PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_LATTIMER, 0xa8, 1);
-	cfg->lattimer = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_LATTIMER, 1);
+	device_t dev = cfg->dev;
+	int i;
 
-	PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_MINGNT, 0x14, 1);
-	cfg->mingnt = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_MINGNT, 1);
+	/*
+	 * Some cards power up with garbage in their BARs.  This
+	 * code clears all that junk out.
+	 */
+	for (i = 0; i < PCI_MAX_BAR_0; i++)
+		pci_write_config(dev, PCIR_BAR(i), 0, 4);
 
-	PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_MAXLAT, 0x14, 1);
-	cfg->maxlat = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_MAXLAT, 1);
+	cfg->intline =
+	    pci_get_irq(device_get_parent(device_get_parent(dev)));
+	pci_write_config(dev, PCIR_INTLINE, cfg->intline, 1);
+	pci_write_config(dev, PCIR_CACHELNSZ, 0x08, 1);
+	pci_write_config(dev, PCIR_LATTIMER, 0xa8, 1);
+	pci_write_config(dev, PCIR_MINGNT, 0x14, 1);
+	pci_write_config(dev, PCIR_MAXLAT, 0x14, 1);
 }
 
 static int
@@ -458,52 +162,48 @@
 {
 	device_t brdev = device_get_parent(cbdev);
 	device_t child;
+	int bus, domain, slot, func;
 	int cardattached = 0;
-	int bus, slot, func;
+	int cardbusfunchigh = 0;
 
 	cardbus_detach_card(cbdev); /* detach existing cards */
 	POWER_ENABLE_SOCKET(brdev, cbdev);
+	domain = pcib_get_domain(cbdev);
 	bus = pcib_get_bus(cbdev);
+	slot = 0;
 	/* For each function, set it up and try to attach a driver to it */
-	for (slot = 0; slot <= CARDBUS_SLOTMAX; slot++) {
-		int cardbusfunchigh = 0;
-		for (func = 0; func <= cardbusfunchigh; func++) {
-			struct cardbus_devinfo *dinfo;
-
-			dinfo = (struct cardbus_devinfo *)
-			    pci_read_device(brdev, bus, slot, func,
-				sizeof(struct cardbus_devinfo));
-			if (dinfo == NULL)
-				continue;
-			if (dinfo->pci.cfg.mfdev)
-				cardbusfunchigh = CARDBUS_FUNCMAX;
-
-			cardbus_device_setup_regs(brdev, bus, slot, func,
-			    &dinfo->pci.cfg);
-			child = device_add_child(cbdev, NULL, -1);
-			if (child == NULL) {
-				DEVPRINTF((cbdev, "Cannot add child!\n"));
-				pci_freecfg((struct pci_devinfo *)dinfo);
-				continue;
-			}
-			dinfo->pci.cfg.dev = child;
-			resource_list_init(&dinfo->pci.resources);
-			device_set_ivars(child, dinfo);
-			if (cardbus_do_cis(cbdev, child) != 0) {
-				DEVPRINTF((cbdev, "Can't parse cis\n"));
-				pci_freecfg((struct pci_devinfo *)dinfo);
-				continue;
-			}
-			cardbus_pickup_maps(cbdev, child);
-			cardbus_alloc_resources(cbdev, child);
-			pci_print_verbose(&dinfo->pci);
-			if (device_probe_and_attach(child) != 0)
-				cardbus_release_all_resources(cbdev, dinfo);
-			else
-				cardattached++;
+	for (func = 0; func <= cardbusfunchigh; func++) {
+		struct cardbus_devinfo *dinfo;
+
+		dinfo = (struct cardbus_devinfo *)
+		    pci_read_device(brdev, domain, bus, slot, func,
+			sizeof(struct cardbus_devinfo));
+		if (dinfo == NULL)
+			continue;
+		if (dinfo->pci.cfg.mfdev)
+			cardbusfunchigh = PCI_FUNCMAX;
+
+		child = device_add_child(cbdev, NULL, -1);
+		if (child == NULL) {
+			DEVPRINTF((cbdev, "Cannot add child!\n"));
+			pci_freecfg((struct pci_devinfo *)dinfo);
+			continue;
 		}
+		dinfo->pci.cfg.dev = child;
+		resource_list_init(&dinfo->pci.resources);
+		device_set_ivars(child, dinfo);
+		if (cardbus_do_cis(cbdev, child) != 0)
+			DEVPRINTF((cbdev, "Warning: Bogus CIS ignored\n"));
+		pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 0);
+		pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci);
+		cardbus_device_setup_regs(&dinfo->pci.cfg);
+		pci_add_resources(cbdev, child, 1, dinfo->mprefetchable);
+		pci_print_verbose(&dinfo->pci);
+		if (device_probe_and_attach(child) == 0)
+			cardattached++;
+		else
+			pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 1);
 	}
-
 	if (cardattached > 0)
 		return (0);
 	POWER_DISABLE_SOCKET(brdev, cbdev);
@@ -518,7 +218,8 @@
 	int tmp;
 	int err = 0;
 
-	device_get_children(cbdev, &devlist, &numdevs);
+	if (device_get_children(cbdev, &devlist, &numdevs) != 0)
+		return (ENOENT);
 
 	if (numdevs == 0) {
 		free(devlist, M_TEMP);
@@ -552,7 +253,9 @@
 	struct cardbus_devinfo *dinfo;
 
 	DEVICE_IDENTIFY(driver, cbdev);
-	device_get_children(cbdev, &devlist, &numdevs);
+	if (device_get_children(cbdev, &devlist, &numdevs) != 0)
+		return;
+
 	/*
 	 * If there are no drivers attached, but there are children,
 	 * then power the card up.
@@ -570,12 +273,9 @@
 			continue;
 		dinfo = device_get_ivars(dev);
 		pci_print_verbose(&dinfo->pci);
-		resource_list_init(&dinfo->pci.resources);
-		cardbus_do_cis(cbdev, dev);
-		cardbus_pickup_maps(cbdev, dev);
-		cardbus_alloc_resources(cbdev, dev);
+		pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci);
 		if (device_probe_and_attach(dev) != 0)
-			cardbus_release_all_resources(cbdev, dinfo);
+			pci_cfg_save(dev, &dinfo->pci, 1);
 	}
 	free(devlist, M_TEMP);
 }
@@ -588,18 +288,13 @@
 	/* Free all allocated resources */
 	STAILQ_FOREACH(rle, &dinfo->pci.resources, link) {
 		if (rle->res) {
-			if (rman_get_device(rle->res) != cbdev)
-				device_printf(cbdev, "release_all_resource: "
-				    "Resource still owned by child, oops. "
-				    "(type=%d, rid=%d, addr=%lx)\n",
-				    rle->type, rle->rid,
-				    rman_get_start(rle->res));
 			BUS_RELEASE_RESOURCE(device_get_parent(cbdev),
 			    cbdev, rle->type, rle->rid, rle->res);
 			rle->res = NULL;
 			/*
 			 * zero out config so the card won't acknowledge
-			 * access to the space anymore
+			 * access to the space anymore. XXX doesn't handle
+			 * 64-bit bars.
 			 */
 			pci_write_config(dinfo->pci.cfg.dev, rle->rid, 0, 4);
 		}
@@ -664,8 +359,8 @@
 	{0,0}
 };
 
-DECLARE_CLASS(pci_driver);
-DEFINE_CLASS_1(cardbus, cardbus_driver, cardbus_methods, 0, pci_driver);
+DEFINE_CLASS_1(cardbus, cardbus_driver, cardbus_methods,
+    sizeof(struct cardbus_softc), pci_driver);
 
 static devclass_t cardbus_devclass;
 
Index: cardbusvar.h
===================================================================
RCS file: /home/cvs/src/sys/dev/cardbus/cardbusvar.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/cardbus/cardbusvar.h -L sys/dev/cardbus/cardbusvar.h -u -r1.2 -r1.3
--- sys/dev/cardbus/cardbusvar.h
+++ sys/dev/cardbus/cardbusvar.h
@@ -23,18 +23,18 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/cardbus/cardbusvar.h,v 1.11.2.2 2006/03/01 18:19:33 imp Exp $
+ * $FreeBSD: src/sys/dev/cardbus/cardbusvar.h,v 1.14 2005/12/29 23:41:29 imp Exp $
  */
 
 /*
  * Structure definitions for the Cardbus Bus driver
  */
-struct cardbus_devinfo {
+struct cardbus_devinfo
+{
 	struct pci_devinfo pci;
 	uint8_t        mprefetchable; /* bit mask of prefetchable BARs */
 	uint8_t        mbelow1mb; /* bit mask of BARs which require below 1Mb */
 	uint8_t        ibelow1mb; /* bit mask of BARs which require below 1Mb */
-#define        BARBIT(RID) (1<<(((RID)-CARDBUS_BASE0_REG)/4))
 	uint16_t	mfrid;		/* manufacturer id */
 	uint16_t	prodid;		/* product id */
 	u_int		funcid;		/* function id */
@@ -45,3 +45,35 @@
 	} funce;
 	uint32_t	fepresent;	/* bit mask of funce values present */
 };
+
+struct cis_buffer
+{
+	size_t	len;			/* Actual length of the CIS */
+	uint8_t buffer[2040];		/* small enough to be 2k */
+};
+
+struct cardbus_softc 
+{
+	/* XXX need mutex XXX */
+	device_t	sc_dev;
+	struct cdev 	*sc_cisdev;
+	struct cis_buffer *sc_cis;
+	int		sc_cis_open;
+};
+
+struct tuple_callbacks;
+
+typedef int (tuple_cb) (device_t cbdev, device_t child, int id, int len,
+		 uint8_t *tupledata, uint32_t start, uint32_t *off,
+		 struct tuple_callbacks *info, void *);
+
+struct tuple_callbacks {
+	int	id;
+	char	*name;
+	tuple_cb *func;
+};
+
+int	cardbus_device_create(struct cardbus_softc *);
+int	cardbus_device_destroy(struct cardbus_softc *);
+int	cardbus_parse_cis(device_t cbdev, device_t child,
+	    struct tuple_callbacks *callbacks, void *);
Index: cardbus_cis.c
===================================================================
RCS file: /home/cvs/src/sys/dev/cardbus/cardbus_cis.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/cardbus/cardbus_cis.c -L sys/dev/cardbus/cardbus_cis.c -u -r1.2 -r1.3
--- sys/dev/cardbus/cardbus_cis.c
+++ sys/dev/cardbus/cardbus_cis.c
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus_cis.c,v 1.50.2.2 2006/03/01 18:19:33 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus_cis.c,v 1.62 2007/06/08 04:03:57 imp Exp $");
 
 /*
  * CIS Handling for the Cardbus Bus
@@ -58,45 +58,35 @@
 #define	DPRINTF(a) if (cardbus_cis_debug) printf a
 #define	DEVPRINTF(x) if (cardbus_cis_debug) device_printf x
 
-struct tuple_callbacks;
-
-typedef int (tuple_cb) (device_t cbdev, device_t child, int id, int len,
-		 uint8_t *tupledata, uint32_t start, uint32_t *off,
-		 struct tuple_callbacks *info);
-
-struct tuple_callbacks {
-	int	id;
-	char	*name;
-	tuple_cb *func;
-};
+#define CIS_CONFIG_SPACE	(struct resource *)~0UL
 
 static int decode_tuple_generic(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_linktarget(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_vers_1(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_funcid(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_manfid(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_funce(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_bar(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_unhandled(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 static int decode_tuple_end(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info);
+    struct tuple_callbacks *info, void *);
 
 static int	cardbus_read_tuple_conf(device_t cbdev, device_t child,
 		    uint32_t start, uint32_t *off, int *tupleid, int *len,
@@ -113,9 +103,8 @@
 		    uint32_t *start, int *rid);
 static int	decode_tuple(device_t cbdev, device_t child, int tupleid,
 		    int len, uint8_t *tupledata, uint32_t start,
-		    uint32_t *off, struct tuple_callbacks *callbacks);
-static int	cardbus_parse_cis(device_t cbdev, device_t child,
-		    struct tuple_callbacks *callbacks);
+		    uint32_t *off, struct tuple_callbacks *callbacks,
+		    void *);
 
 #define	MAKETUPLE(NAME,FUNC) { CISTPL_ ## NAME, #NAME, decode_tuple_ ## FUNC }
 
@@ -139,7 +128,7 @@
 static int
 decode_tuple_generic(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	int i;
 
@@ -162,7 +151,7 @@
 static int
 decode_tuple_linktarget(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	int i;
 
@@ -180,7 +169,7 @@
 	    tupledata[2] != 'S') {
 		printf("Invalid data for CIS Link Target!\n");
 		decode_tuple_generic(cbdev, child, id, len, tupledata,
-		    start, off, info);
+		    start, off, info, argp);
 		return (EINVAL);
 	}
 	return (0);
@@ -189,7 +178,7 @@
 static int
 decode_tuple_vers_1(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	int i;
 
@@ -212,7 +201,7 @@
 static int
 decode_tuple_funcid(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	struct cardbus_devinfo *dinfo = device_get_ivars(child);
 	int numnames = sizeof(funcnames) / sizeof(funcnames[0]);
@@ -225,7 +214,7 @@
 				printf("%s", funcnames[tupledata[i]]);
 			else
 				printf("Unknown(%d)", tupledata[i]);
-			if (i < len-1)
+			if (i < len - 1)
 				printf(", ");
 		}
 		printf("\n");
@@ -238,7 +227,7 @@
 static int
 decode_tuple_manfid(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	struct cardbus_devinfo *dinfo = device_get_ivars(child);
 	int i;
@@ -260,7 +249,7 @@
 static int
 decode_tuple_funce(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	struct cardbus_devinfo *dinfo = device_get_ivars(child);
 	int type, i;
@@ -295,12 +284,12 @@
 static int
 decode_tuple_bar(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	struct cardbus_devinfo *dinfo = device_get_ivars(child);
 	int type;
 	uint8_t reg;
-	uint32_t bar, pci_bar;
+	uint32_t bar;
 
 	if (len != 6) {
 		device_printf(cbdev, "CIS BAR length not 6 (%d)\n", len);
@@ -309,11 +298,10 @@
 
 	reg = *tupledata;
 	len = le32toh(*(uint32_t*)(tupledata + 2));
-	if (reg & TPL_BAR_REG_AS) {
+	if (reg & TPL_BAR_REG_AS)
 		type = SYS_RES_IOPORT;
-	} else {
+	else
 		type = SYS_RES_MEMORY;
-	}
 
 	bar = reg & TPL_BAR_REG_ASI_MASK;
 	if (bar == 0) {
@@ -325,11 +313,11 @@
 	}
 
 	/* Convert from BAR type to BAR offset */
-	bar = CARDBUS_BASE0_REG + (bar - 1) * 4;
+	bar = PCIR_BAR(bar - 1);
 
 	if (type == SYS_RES_MEMORY) {
 		if (reg & TPL_BAR_REG_PREFETCHABLE)
-			dinfo->mprefetchable |= BARBIT(bar);
+			dinfo->mprefetchable |= (1 << PCI_RID2BAR(bar));
 #if 0
 		/*
 		 * XXX: It appears from a careful reading of the spec
@@ -351,56 +339,27 @@
 		 * correctness.
 		 */
 		if (reg & TPL_BAR_REG_BELOW1MB)
-			dinfo->mbelow1mb |= BARBIT(bar);
+			dinfo->mbelow1mb |= (1 << PCI_RID2BAR(bar));
 #endif
 	}
 
-	/*
-	 * Sanity check the BAR length reported in the CIS with the length
-	 * encoded in the PCI BAR.  The latter seems to be more reliable.
-	 * XXX - This probably belongs elsewhere.
-	 */
-	pci_write_config(child, bar, 0xffffffff, 4);
-	pci_bar = pci_read_config(child, bar, 4);
-	if ((pci_bar != 0x0) && (pci_bar != 0xffffffff)) {
-		if (type == SYS_RES_MEMORY) {
-			pci_bar &= ~0xf;
-		} else {
-			pci_bar &= ~0x3;
-		}
-		len = 1 << (ffs(pci_bar) - 1);
-	}
-
-	DEVPRINTF((cbdev, "Opening BAR: type=%s, bar=%02x, len=%04x%s%s\n",
-	    (type == SYS_RES_MEMORY) ? "MEM" : "IO", bar, len,
-	    (type == SYS_RES_MEMORY && dinfo->mprefetchable & BARBIT(bar)) ?
-	    " (Prefetchable)" : "", type == SYS_RES_MEMORY ?
-	    ((dinfo->mbelow1mb & BARBIT(bar)) ? " (Below 1Mb)" : "") : ""));
-
-	resource_list_add(&dinfo->pci.resources, type, bar, 0UL, ~0UL, len);
-
-	/*
-	 * Mark the appropriate bit in the PCI command register so that
-	 * device drivers will know which type of BARs can be used.
-	 */
-	pci_enable_io(child, type);
 	return (0);
 }
 
 static int
 decode_tuple_unhandled(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	/* Make this message suck less XXX */
 	printf("TUPLE: %s [%d] is unhandled! Bailing...", info->name, len);
-	return (-1);
+	return (EINVAL);
 }
 
 static int
 decode_tuple_end(device_t cbdev, device_t child, int id,
     int len, uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *info)
+    struct tuple_callbacks *info, void *argp)
 {
 	if (cardbus_cis_debug)
 		printf("CIS reading done\n");
@@ -464,23 +423,22 @@
     uint32_t start, uint32_t *off, int *tupleid, int *len,
     uint8_t *tupledata)
 {
-	if (res == (struct resource*)~0UL) {
+	if (res == CIS_CONFIG_SPACE)
 		return (cardbus_read_tuple_conf(cbdev, child, start, off,
 		    tupleid, len, tupledata));
-	} else {
-		return (cardbus_read_tuple_mem(cbdev, res, start, off,
-		    tupleid, len, tupledata));
-	}
+	return (cardbus_read_tuple_mem(cbdev, res, start, off, tupleid, len,
+	    tupledata));
 }
 
 static void
 cardbus_read_tuple_finish(device_t cbdev, device_t child, int rid,
     struct resource *res)
 {
-	if (res != (struct resource*)~0UL) {
-		bus_release_resource(cbdev, SYS_RES_MEMORY, rid, res);
-		pci_write_config(child, rid, 0, 4);
-		PCI_DISABLE_IO(cbdev, child, SYS_RES_MEMORY);
+	if (res != CIS_CONFIG_SPACE) {
+		bus_release_resource(child, SYS_RES_MEMORY, rid, res);
+		if (rid == PCIM_CIS_ASI_ROM)
+			pci_write_config(child, rid, pci_read_config(child,
+			    rid, 4) & ~PCIR_BIOS, 4);
 	}
 }
 
@@ -488,71 +446,51 @@
 cardbus_read_tuple_init(device_t cbdev, device_t child, uint32_t *start,
     int *rid)
 {
-	uint32_t testval;
-	uint32_t size;
 	struct resource *res;
+	uint32_t space;
 
-	switch (CARDBUS_CIS_SPACE(*start)) {
-	case CARDBUS_CIS_ASI_TUPLE:
+	space = *start & PCIM_CIS_ASI_MASK;
+	switch (space) {
+	case PCIM_CIS_ASI_CONFIG:
+		if (cardbus_cis_debug)
+			device_printf(cbdev, "CIS in PCI config space\n");
 		/* CIS in PCI config space need no initialization */
-		return ((struct resource*)~0UL);
-	case CARDBUS_CIS_ASI_BAR0:
-	case CARDBUS_CIS_ASI_BAR1:
-	case CARDBUS_CIS_ASI_BAR2:
-	case CARDBUS_CIS_ASI_BAR3:
-	case CARDBUS_CIS_ASI_BAR4:
-	case CARDBUS_CIS_ASI_BAR5:
-		*rid = CARDBUS_BASE0_REG + (CARDBUS_CIS_SPACE(*start) - 1) * 4;
+		return (CIS_CONFIG_SPACE);
+	case PCIM_CIS_ASI_BAR0:
+	case PCIM_CIS_ASI_BAR1:
+	case PCIM_CIS_ASI_BAR2:
+	case PCIM_CIS_ASI_BAR3:
+	case PCIM_CIS_ASI_BAR4:
+	case PCIM_CIS_ASI_BAR5:
+		*rid = PCIR_BAR(space - PCIM_CIS_ASI_BAR0);
+		if (cardbus_cis_debug)
+			device_printf(cbdev, "CIS in BAR %#x\n", *rid);
 		break;
-	case CARDBUS_CIS_ASI_ROM:
-		*rid = CARDBUS_ROM_REG;
-#if 0
-		/*
-		 * This mask doesn't contain the bit that actually enables
-		 * the Option ROM.
-		 */
-		pci_write_config(child, *rid, CARDBUS_ROM_ADDRMASK, 4);
-#endif
+	case PCIM_CIS_ASI_ROM:
+		*rid = PCIR_BIOS;
+		if (cardbus_cis_debug)
+			device_printf(cbdev, "CIS in option rom\n");
 		break;
 	default:
 		device_printf(cbdev, "Unable to read CIS: Unknown space: %d\n",
-		    CARDBUS_CIS_SPACE(*start));
-		return (NULL);
-	}
-
-	/* figure out how much space we need */
-	pci_write_config(child, *rid, 0xffffffff, 4);
-	testval = pci_read_config(child, *rid, 4);
-
-	/*
-	 * This bit has a different meaning depending if we are dealing
-	 * with a normal BAR or an Option ROM BAR.
-	 */
-	if (((testval & 0x1) == 0x1) && (*rid != CARDBUS_ROM_REG)) {
-		device_printf(cbdev, "CIS Space is IO, expecting memory.\n");
+		    space);
 		return (NULL);
 	}
 
-	size = CARDBUS_MAPREG_MEM_SIZE(testval);
-	/* XXX Is this some kind of hack? */
-	if (size < 4096)
-		size = 4096;
 	/* allocate the memory space to read CIS */
-	res = bus_alloc_resource(cbdev, SYS_RES_MEMORY, rid, 0, ~0, size,
-	    rman_make_alignment_flags(size) | RF_ACTIVE);
+	res = bus_alloc_resource(child, SYS_RES_MEMORY, rid, 0, ~0, 1,
+	    rman_make_alignment_flags(4096) | RF_ACTIVE);
 	if (res == NULL) {
 		device_printf(cbdev, "Unable to allocate resource "
 		    "to read CIS.\n");
 		return (NULL);
 	}
-	pci_write_config(child, *rid,
-	    rman_get_start(res) | ((*rid == CARDBUS_ROM_REG)?
-		CARDBUS_ROM_ENABLE : 0),
-	    4);
-	PCI_ENABLE_IO(cbdev, child, SYS_RES_MEMORY);
+	if (*rid == PCIR_BIOS)
+		pci_write_config(child, *rid,
+		    rman_get_start(res) | PCIM_BIOS_ENABLE, 4);
 
 	/* Flip to the right ROM image if CIS is in ROM */
-	if (CARDBUS_CIS_SPACE(*start) == CARDBUS_CIS_ASI_ROM) {
+	if (space == PCIM_CIS_ASI_ROM) {
 		bus_space_tag_t bt;
 		bus_space_handle_t bh;
 		uint32_t imagesize;
@@ -565,7 +503,7 @@
 		bt = rman_get_bustag(res);
 		bh = rman_get_bushandle(res);
 
-		imagenum = CARDBUS_CIS_ASI_ROM_IMAGE(*start);
+		imagenum = (*start & PCIM_CIS_ROM_MASK) >> 28;
 		for (romnum = 0;; romnum++) {
 			romsig = bus_space_read_2(bt, bh,
 			    imagebase + CARDBUS_EXROM_SIGNATURE);
@@ -617,9 +555,9 @@
 			}
 			imagebase += imagesize;
 		}
-		*start = imagebase + CARDBUS_CIS_ADDR(*start);
+		*start = imagebase + (*start & PCIM_CIS_ADDR_MASK);
 	} else {
-		*start = CARDBUS_CIS_ADDR(*start);
+		*start = *start & PCIM_CIS_ADDR_MASK;
 	}
 
 	return (res);
@@ -632,24 +570,24 @@
 static int
 decode_tuple(device_t cbdev, device_t child, int tupleid, int len,
     uint8_t *tupledata, uint32_t start, uint32_t *off,
-    struct tuple_callbacks *callbacks)
+    struct tuple_callbacks *callbacks, void *argp)
 {
 	int i;
 	for (i = 0; callbacks[i].id != CISTPL_GENERIC; i++) {
 		if (tupleid == callbacks[i].id)
 			return (callbacks[i].func(cbdev, child, tupleid, len,
-			    tupledata, start, off, &callbacks[i]));
+			    tupledata, start, off, &callbacks[i], argp));
 	}
 	return (callbacks[i].func(cbdev, child, tupleid, len,
-	    tupledata, start, off, NULL));
+	    tupledata, start, off, NULL, argp));
 }
 
-static int
+int
 cardbus_parse_cis(device_t cbdev, device_t child,
-    struct tuple_callbacks *callbacks)
+    struct tuple_callbacks *callbacks, void *argp)
 {
 	uint8_t tupledata[MAXTUPLESIZE];
-	int tupleid;
+	int tupleid = CISTPL_NULL;
 	int len;
 	int expect_linktarget;
 	uint32_t start, off;
@@ -658,10 +596,14 @@
 
 	bzero(tupledata, MAXTUPLESIZE);
 	expect_linktarget = TRUE;
-	if ((start = pci_read_config(child, CARDBUS_CIS_REG, 4)) == 0) {
-		device_printf(cbdev, "CIS pointer is 0!\n");
+	if ((start = pci_read_config(child, PCIR_CIS, 4)) == 0) {
+		if (cardbus_cis_debug)
+			device_printf(cbdev,
+			    "Warning: CIS pointer 0 (no CIS present)\n");
 		return (ENXIO);
 	}
+	if (cardbus_cis_debug)
+		device_printf(cbdev, "CIS pointer is %#x\n", start);
 	off = 0;
 	res = cardbus_read_tuple_init(cbdev, child, &start, &rid);
 	if (res == NULL) {
@@ -670,8 +612,8 @@
 	}
 
 	do {
-		if (0 != cardbus_read_tuple(cbdev, child, res, start, &off,
-		    &tupleid, &len, tupledata)) {
+		if (cardbus_read_tuple(cbdev, child, res, start, &off,
+		    &tupleid, &len, tupledata) != 0) {
 			device_printf(cbdev, "Failed to read CIS.\n");
 			cardbus_read_tuple_finish(cbdev, child, rid, res);
 			return (ENXIO);
@@ -684,7 +626,7 @@
 			return (EINVAL);
 		}
 		expect_linktarget = decode_tuple(cbdev, child, tupleid, len,
-		    tupledata, start, &off, callbacks);
+		    tupledata, start, &off, callbacks, argp);
 		if (expect_linktarget != 0) {
 			device_printf(cbdev, "Parsing failed with %d\n",
 			    expect_linktarget);
@@ -699,7 +641,6 @@
 int
 cardbus_do_cis(device_t cbdev, device_t child)
 {
-	int ret;
 	struct tuple_callbacks init_callbacks[] = {
 		MAKETUPLE(LONGLINK_CB,		unhandled),
 		MAKETUPLE(INDIRECT,		unhandled),
@@ -716,8 +657,5 @@
 		MAKETUPLE(GENERIC,		generic),
 	};
 
-	ret = cardbus_parse_cis(cbdev, child, init_callbacks);
-	if (ret < 0)
-		return (ret);
-	return 0;
+	return (cardbus_parse_cis(cbdev, child, init_callbacks, NULL));
 }
Index: cardbusreg.h
===================================================================
RCS file: /home/cvs/src/sys/dev/cardbus/cardbusreg.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sys/dev/cardbus/cardbusreg.h -L sys/dev/cardbus/cardbusreg.h -u -r1.2 -r1.3
--- sys/dev/cardbus/cardbusreg.h
+++ sys/dev/cardbus/cardbusreg.h
@@ -23,40 +23,13 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/cardbus/cardbusreg.h,v 1.8.2.2 2006/03/01 18:19:33 imp Exp $
+ * $FreeBSD: src/sys/dev/cardbus/cardbusreg.h,v 1.11 2005/10/28 06:03:53 imp Exp $
  */
 
 /*
  * Register definitions for the Cardbus Bus
  */
 
-
-/* Cardbus bus constants */
-#define	CARDBUS_SLOTMAX		0
-#define	CARDBUS_FUNCMAX		7
-
-/* Cardbus configuration header registers */
-#define	CARDBUS_BASE0_REG	0x10
-#define	CARDBUS_BASE1_REG	0x14
-#define	CARDBUS_BASE2_REG	0x18
-#define	CARDBUS_BASE3_REG	0x1C
-#define	CARDBUS_BASE4_REG	0x20
-#define	CARDBUS_BASE5_REG	0x24
-#define	CARDBUS_CIS_REG		0x28
-# define	CARDBUS_CIS_ASIMASK		0x07
-# define	CARDBUS_CIS_ADDRMASK		0x0ffffff8
-# define	CARDBUS_CIS_ASI_TUPLE		0x00
-# define	CARDBUS_CIS_ASI_BAR0		0x01
-# define	CARDBUS_CIS_ASI_BAR1		0x02
-# define	CARDBUS_CIS_ASI_BAR2		0x03
-# define	CARDBUS_CIS_ASI_BAR3		0x04
-# define	CARDBUS_CIS_ASI_BAR4		0x05
-# define	CARDBUS_CIS_ASI_BAR5		0x06
-# define	CARDBUS_CIS_ASI_ROM		0x07
-#define	CARDBUS_ROM_REG		0x30
-# define	CARDBUS_ROM_ENABLE		0x00000001
-# define	CARDBUS_ROM_ADDRMASK		0xfffff800
-
 /* EXROM offsets for reading CIS */
 #define	CARDBUS_EXROM_SIGNATURE	0x00
 #define	CARDBUS_EXROM_DATA_PTR	0x18
@@ -72,16 +45,6 @@
 #define	CARDBUS_EXROM_DATA_CODE_TYPE	0x14 /* Code Type */
 #define	CARDBUS_EXROM_DATA_INDICATOR	0x15 /* Indicator */
 
-/* useful macros */
-#define	CARDBUS_CIS_ADDR(x)						\
-	(CARDBUS_CIS_ADDRMASK & (x))
-#define	CARDBUS_CIS_SPACE(x)						\
-	(CARDBUS_CIS_ASIMASK & (x))
-#define	CARDBUS_CIS_ASI_BAR(x)						\
-	(((CARDBUS_CIS_ASIMASK & (x))-1)*4+0x10)
-#define	CARDBUS_CIS_ASI_ROM_IMAGE(x)					\
-	(((x) >> 28) & 0xf)
-
 #define	CARDBUS_MAPREG_MEM_ADDR_MASK	0x0ffffff0
 #define	CARDBUS_MAPREG_MEM_ADDR(mr)					\
 	((mr) & CARDBUS_MAPREG_MEM_ADDR_MASK)
Index: cardbus_device.c
===================================================================
RCS file: /home/cvs/src/sys/dev/cardbus/cardbus_device.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sys/dev/cardbus/cardbus_device.c -L sys/dev/cardbus/cardbus_device.c -u -r1.1.1.1 -r1.2
--- sys/dev/cardbus/cardbus_device.c
+++ sys/dev/cardbus/cardbus_device.c
@@ -26,7 +26,7 @@
  *
  */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus_device.c,v 1.1.2.1 2006/01/30 20:04:59 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus_device.c,v 1.1 2005/12/29 01:43:47 imp Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>


More information about the Midnightbsd-cvs mailing list