diff -ur dev/cardbus/cardbus.c /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus.c --- dev/cardbus/cardbus.c Wed Dec 28 18:43:47 2005 +++ /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus.c Wed Dec 28 17:39:36 2005 @@ -71,18 +71,13 @@ #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_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 +86,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 == PCIR_BIOS) - testval = PCIM_BIOS_ADDR_MASK; - 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,7 +94,7 @@ cardbus_probe(device_t cbdev) { device_set_desc(cbdev, "CardBus bus"); - return 0; + return (0); } static int @@ -410,7 +104,7 @@ sc->sc_dev = cbdev; cardbus_device_create(sc); - return 0; + return (0); } static int @@ -420,12 +114,13 @@ cardbus_detach_card(cbdev); cardbus_device_destroy(sc); - return 0; + return (0); } static int cardbus_suspend(device_t self) { + cardbus_detach_card(self); return (0); } @@ -433,6 +128,7 @@ static int cardbus_resume(device_t self) { + return (0); } @@ -501,13 +197,14 @@ pci_freecfg((struct pci_devinfo *)dinfo); continue; } - cardbus_pickup_maps(cbdev, child); - cardbus_alloc_resources(cbdev, child); + pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 0); + pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci); + pci_add_resources(cbdev, child, 1, dinfo->mprefetchable); pci_print_verbose(&dinfo->pci); - if (device_probe_and_attach(child) != 0) - cardbus_release_all_resources(cbdev, dinfo); - else + if (device_probe_and_attach(child) == 0) cardattached++; + else + pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 1); } if (cardattached > 0) return (0); @@ -575,12 +272,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); } @@ -594,8 +288,8 @@ 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. " + device_printf(cbdev, "Bug: Resource still " + "owned by child. " "(type=%d, rid=%d, addr=%lx)\n", rle->type, rle->rid, rman_get_start(rle->res)); @@ -670,7 +364,8 @@ }; 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; diff -ur dev/cardbus/cardbus_cis.c /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus_cis.c --- dev/cardbus/cardbus_cis.c Wed Dec 28 18:43:47 2005 +++ /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus_cis.c Tue Dec 27 20:44:14 2005 @@ -316,7 +316,7 @@ if (type == SYS_RES_MEMORY) { if (reg & TPL_BAR_REG_PREFETCHABLE) - dinfo->mprefetchable |= BARBIT(bar); + dinfo->mprefetchable |= PCI_RID2BAR(bar); #if 0 /* * XXX: It appears from a careful reading of the spec @@ -338,7 +338,7 @@ * correctness. */ if (reg & TPL_BAR_REG_BELOW1MB) - dinfo->mbelow1mb |= BARBIT(bar); + dinfo->mbelow1mb |= PCI_RID2BAR(bar); #endif } @@ -360,9 +360,9 @@ 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)) ? + (type == SYS_RES_MEMORY && dinfo->mprefetchable & PCI_RID2BAR(bar)) ? " (Prefetchable)" : "", type == SYS_RES_MEMORY ? - ((dinfo->mbelow1mb & BARBIT(bar)) ? " (Below 1Mb)" : "") : "")); + ((dinfo->mbelow1mb & PCI_RID2BAR(bar)) ? " (Below 1Mb)" : "") : "")); resource_list_add(&dinfo->pci.resources, type, bar, 0UL, ~0UL, len); Only in dev/cardbus: cardbus_cis.c.orig Only in /dell/imp/p4/newcard/src/sys/dev/cardbus: cardbus_cis.c~ diff -ur dev/cardbus/cardbus_device.c /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus_device.c --- dev/cardbus/cardbus_device.c Wed Dec 28 18:43:47 2005 +++ /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbus_device.c Wed Sep 21 04:56:33 2005 @@ -26,7 +26,7 @@ * */ #include -__FBSDID("$FreeBSD: src/sys/dev/cardbus/cardbus_device.c,v 1.1 2005/12/29 01:43:47 imp Exp $"); +__FBSDID("$FreeBSD$"); #include #include diff -ur dev/cardbus/cardbusvar.h /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbusvar.h --- dev/cardbus/cardbusvar.h Wed Dec 28 18:43:47 2005 +++ /dell/imp/p4/newcard/src/sys/dev/cardbus/cardbusvar.h Tue Dec 27 20:44:15 2005 @@ -35,7 +35,6 @@ 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)-PCIR_BARS)/4)) uint16_t mfrid; /* manufacturer id */ uint16_t prodid; /* product id */ u_int funcid; /* function id */ diff -ur dev/pccbb/pccbb.c /dell/imp/p4/newcard/src/sys/dev/pccbb/pccbb.c --- dev/pccbb/pccbb.c Tue Dec 27 12:18:11 2005 +++ /dell/imp/p4/newcard/src/sys/dev/pccbb/pccbb.c Wed Dec 28 17:39:40 2005 @@ -485,7 +485,7 @@ */ mtx_lock(&Giant); status = cbb_get(sc, CBB_SOCKET_STATE); - DPRINTF(("Status is 0x%x\n", status)); + DPRINTF(("Status is 0x%x %x\n", status, sc->bsh)); if (!CBB_CARD_PRESENT(status)) { not_a_card = 0; /* We know card type */ cbb_removal(sc); @@ -1034,21 +1034,20 @@ return (0); } -/* - * XXX The following function belongs in the pci bus layer. - */ +#define START_NONE 0xffffffff +#define END_NONE 0 + static void cbb_cardbus_auto_open(struct cbb_softc *sc, int type) { uint32_t starts[2]; uint32_t ends[2]; struct cbb_reslist *rle; - int align; - int prefetchable[2]; + int align, i; uint32_t reg; - starts[0] = starts[1] = 0xffffffff; - ends[0] = ends[1] = 0; + starts[0] = starts[1] = START_NONE; + ends[0] = ends[1] = END_NONE; if (type == SYS_RES_MEMORY) align = CBB_MEMALIGN; @@ -1057,115 +1056,68 @@ else align = 1; - /* - * This looks somewhat bogus, and doesn't seem to really respect - * alignment. The alignment stuff is happening too late (it - * should happen at allocation time, not activation time) and - * this code looks generally to be too complex for the purpose - * it surves. - */ SLIST_FOREACH(rle, &sc->rl, link) { if (rle->type != type) - ; - else if (rle->res == NULL) { - device_printf(sc->dev, "WARNING: Resource not reserved? " - "(type=%d, addr=%lx)\n", - rle->type, rman_get_start(rle->res)); - } else if (!(rman_get_flags(rle->res) & RF_ACTIVE)) { - /* XXX */ - } else if (starts[0] == 0xffffffff) { - starts[0] = rman_get_start(rle->res); - ends[0] = rman_get_end(rle->res); - prefetchable[0] = - rman_get_flags(rle->res) & RF_PREFETCHABLE; - } else if (rman_get_end(rle->res) > ends[0] && - rman_get_start(rle->res) - ends[0] < - CBB_AUTO_OPEN_SMALLHOLE && prefetchable[0] == - (rman_get_flags(rle->res) & RF_PREFETCHABLE)) { - ends[0] = rman_get_end(rle->res); - } else if (rman_get_start(rle->res) < starts[0] && - starts[0] - rman_get_end(rle->res) < - CBB_AUTO_OPEN_SMALLHOLE && prefetchable[0] == - (rman_get_flags(rle->res) & RF_PREFETCHABLE)) { - starts[0] = rman_get_start(rle->res); - } else if (starts[1] == 0xffffffff) { - starts[1] = rman_get_start(rle->res); - ends[1] = rman_get_end(rle->res); - prefetchable[1] = - rman_get_flags(rle->res) & RF_PREFETCHABLE; - } else if (rman_get_end(rle->res) > ends[1] && - rman_get_start(rle->res) - ends[1] < - CBB_AUTO_OPEN_SMALLHOLE && prefetchable[1] == - (rman_get_flags(rle->res) & RF_PREFETCHABLE)) { - ends[1] = rman_get_end(rle->res); - } else if (rman_get_start(rle->res) < starts[1] && - starts[1] - rman_get_end(rle->res) < - CBB_AUTO_OPEN_SMALLHOLE && prefetchable[1] == - (rman_get_flags(rle->res) & RF_PREFETCHABLE)) { - starts[1] = rman_get_start(rle->res); + continue; + if (rle->res == NULL) + continue; + if (!(rman_get_flags(rle->res) & RF_ACTIVE)) + continue; + if (rman_get_flags(rle->res) & RF_PREFETCHABLE) + i = 1; + else + i = 0; + if (rman_get_start(rle->res) < starts[i]) + starts[i] = rman_get_start(rle->res); + if (rman_get_end(rle->res) > ends[i]) + ends[i] = rman_get_end(rle->res); + } + for (i = 0; i < 2; i++) { + if (starts[i] == START_NONE) + continue; + starts[i] &= ~(align - 1); + ends[i] = ((ends[i] + align - 1) & ~(align - 1)) - 1; + } + if (starts[0] != START_NONE && starts[1] != START_NONE) { + if (starts[0] < starts[1]) { + if (ends[0] > starts[1]) { + device_printf(sc->dev, "Overlapping ranges" + " for prefetch and non-prefetch memory\n"); + return; + } } else { - uint32_t diffs[2]; - int win; - - diffs[0] = diffs[1] = 0xffffffff; - if (rman_get_start(rle->res) > ends[0]) - diffs[0] = rman_get_start(rle->res) - ends[0]; - else if (rman_get_end(rle->res) < starts[0]) - diffs[0] = starts[0] - rman_get_end(rle->res); - if (rman_get_start(rle->res) > ends[1]) - diffs[1] = rman_get_start(rle->res) - ends[1]; - else if (rman_get_end(rle->res) < starts[1]) - diffs[1] = starts[1] - rman_get_end(rle->res); - - win = (diffs[0] <= diffs[1])?0:1; - if (rman_get_start(rle->res) > ends[win]) - ends[win] = rman_get_end(rle->res); - else if (rman_get_end(rle->res) < starts[win]) - starts[win] = rman_get_start(rle->res); - if (!(rman_get_flags(rle->res) & RF_PREFETCHABLE)) - prefetchable[win] = 0; + if (ends[1] > starts[0]) { + device_printf(sc->dev, "Overlapping ranges" + " for prefetch and non-prefetch memory\n"); + return; + } } - - if (starts[0] != 0xffffffff) - starts[0] -= starts[0] % align; - if (starts[1] != 0xffffffff) - starts[1] -= starts[1] % align; - if (ends[0] % align != 0) - ends[0] += align - ends[0] % align - 1; - if (ends[1] % align != 0) - ends[1] += align - ends[1] % align - 1; } if (type == SYS_RES_MEMORY) { cbb_cardbus_mem_open(sc->dev, 0, starts[0], ends[0]); cbb_cardbus_mem_open(sc->dev, 1, starts[1], ends[1]); reg = pci_read_config(sc->dev, CBBR_BRIDGECTRL, 2); - reg &= ~(CBBM_BRIDGECTRL_PREFETCH_0| + reg &= ~(CBBM_BRIDGECTRL_PREFETCH_0 | CBBM_BRIDGECTRL_PREFETCH_1); - reg |= (prefetchable[0]?CBBM_BRIDGECTRL_PREFETCH_0:0)| - (prefetchable[1]?CBBM_BRIDGECTRL_PREFETCH_1:0); + if (starts[1] != START_NONE) + reg |= CBBM_BRIDGECTRL_PREFETCH_1; pci_write_config(sc->dev, CBBR_BRIDGECTRL, reg, 2); - if (cbb_debug) { - if (starts[0] != 0xffffffff) - device_printf(sc->dev, "Memory window 0:" - " %#x-%#x%s\n", starts[0], ends[0], - prefetchable[0] ? " prefetch" : ""); - if (starts[1] != 0xffffffff) - device_printf(sc->dev, "Memory window 1:" - " %#x-%#x%s\n", starts[1], ends[1], - prefetchable[1] ? " prefetch" : ""); + if (bootverbose) { + device_printf(sc->dev, "Opening memory:\n"); + if (starts[0] != START_NONE) + device_printf(sc->dev, "Normal: %#x-%#x\n", + starts[0], ends[0]); + if (starts[1] != START_NONE) + device_printf(sc->dev, "Prefetch: %#x-%#x\n", + starts[1], ends[1]); } } else if (type == SYS_RES_IOPORT) { cbb_cardbus_io_open(sc->dev, 0, starts[0], ends[0]); cbb_cardbus_io_open(sc->dev, 1, starts[1], ends[1]); - if (cbb_debug) { - if (starts[0] != 0xffffffff) - device_printf(sc->dev, "I/O window 0:" - " %#x-%#x\n", starts[0], ends[0]); - if (starts[1] != 0xffffffff) - device_printf(sc->dev, "I/O window 1:" - " %#x-%#x\n", starts[1], ends[1]); - } + if (bootverbose && starts[0] != START_NONE) + device_printf(sc->dev, "Opening I/O: %#x-%#x\n", + starts[0], ends[0]); } } @@ -1228,6 +1180,7 @@ rman_make_alignment_flags(count); break; case SYS_RES_MEMORY: + printf("start %#lx end %#lx\n", start, end); if (start <= cbb_start_mem) start = cbb_start_mem; if (end < start) @@ -1241,7 +1194,8 @@ rman_make_alignment_flags(align); break; } - + device_printf(brdev, "Alignment flags are %x count %ld\n", + RF_ALIGNMENT(flags), count); res = BUS_ALLOC_RESOURCE(device_get_parent(brdev), child, type, rid, start, end, count, flags & ~RF_ACTIVE); if (res == NULL) { diff -ur dev/pci/pci.c /dell/imp/p4/newcard/src/sys/dev/pci/pci.c --- dev/pci/pci.c Tue Dec 27 21:04:42 2005 +++ /dell/imp/p4/newcard/src/sys/dev/pci/pci.c Tue Dec 27 20:42:03 2005 @@ -80,9 +80,7 @@ int force_route); static int pci_add_map(device_t pcib, device_t bus, device_t dev, int b, int s, int f, int reg, - struct resource_list *rl); -static void pci_add_resources(device_t pcib, device_t bus, - device_t dev); + struct resource_list *rl, int force, int prefetch); static int pci_probe(device_t dev); static int pci_attach(device_t dev); static void pci_load_vendor_data(void); @@ -830,7 +828,8 @@ */ static int pci_add_map(device_t pcib, device_t bus, device_t dev, - int b, int s, int f, int reg, struct resource_list *rl) + int b, int s, int f, int reg, struct resource_list *rl, int force, + int prefetch) { uint32_t map; uint64_t base; @@ -841,6 +840,7 @@ uint16_t cmd; int type; int barlen; + struct resource *res; map = PCIB_READ_CONFIG(pcib, b, s, f, reg, 4); PCIB_WRITE_CONFIG(pcib, b, s, f, reg, 0xffffffff, 4); @@ -889,14 +889,20 @@ /* * If base is 0, then we have problems. It is best to ignore * such entries for the moment. These will be allocated later if - * the driver specifically requests them. + * the driver specifically requests them. However, some + * removable busses look better when all resources are allocated, + * so allow '0' to be overriden. * * Similarly treat maps whose values is the same as the test value * read back. These maps have had all f's written to them by the * BIOS in an attempt to disable the resources. */ - if (base == 0 || map == testval) + if (!force && (base == 0 || map == testval)) { + if (bootverbose) + printf("ignored rid %#x: base %#llx map %#x testval %#x\n", + reg, base, map, testval); return (barlen); + } /* * This code theoretically does the right thing, but has @@ -924,16 +930,28 @@ return (barlen); } - start = base; - end = base + (1 << ln2size) - 1; count = 1 << ln2size; + if (base == 0 || base == pci_mapbase(testval)) { + start = 0; /* Let the parent deside */ + end = ~0ULL; + } else { + start = base; + end = base + (1 << ln2size) - 1; + } resource_list_add(rl, type, reg, start, end, count); /* * Not quite sure what to do on failure of allocating the resource * since I can postulate several right answers. */ - resource_list_alloc(rl, bus, dev, type, ®, start, end, count, 0); + res = resource_list_alloc(rl, bus, dev, type, ®, start, end, count, + prefetch ? RF_PREFETCHABLE : 0); + if (res == NULL) + printf("alloc failed\n"); + else + printf("Allocated for %#x: start %#lx end %#lx\n", reg, rman_get_start(res), rman_get_end(res)); + if (res != NULL) + pci_write_config(dev, reg, rman_get_start(res), 4); return (barlen); } @@ -946,7 +964,7 @@ */ static void pci_ata_maps(device_t pcib, device_t bus, device_t dev, int b, - int s, int f, struct resource_list *rl) + int s, int f, struct resource_list *rl, int force, uint32_t prefetchmask) { int rid, type, progif; #if 0 @@ -963,29 +981,39 @@ progif = pci_read_config(dev, PCIR_PROGIF, 1); type = SYS_RES_IOPORT; if (progif & PCIP_STORAGE_IDE_MODEPRIM) { - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(0), rl); - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(1), rl); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(0), rl, force, + prefetchmask & (1 << 0)); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(1), rl, force, + prefetchmask & (1 << 1)); } else { rid = PCIR_BAR(0); resource_list_add(rl, type, rid, 0x1f0, 0x1f7, 8); - resource_list_alloc(rl, bus, dev, type, &rid, 0x1f0, 0x1f7,8,0); + resource_list_alloc(rl, bus, dev, type, &rid, 0x1f0, 0x1f7, 8, + 0); rid = PCIR_BAR(1); resource_list_add(rl, type, rid, 0x3f6, 0x3f6, 1); - resource_list_alloc(rl, bus, dev, type, &rid, 0x3f6, 0x3f6,1,0); + resource_list_alloc(rl, bus, dev, type, &rid, 0x3f6, 0x3f6, 1, + 0); } if (progif & PCIP_STORAGE_IDE_MODESEC) { - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(2), rl); - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(3), rl); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(2), rl, force, + prefetchmask & (1 << 2)); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(3), rl, force, + prefetchmask & (1 << 3)); } else { rid = PCIR_BAR(2); resource_list_add(rl, type, rid, 0x170, 0x177, 8); - resource_list_alloc(rl, bus, dev, type, &rid, 0x170, 0x177,8,0); + resource_list_alloc(rl, bus, dev, type, &rid, 0x170, 0x177, 8, + 0); rid = PCIR_BAR(3); resource_list_add(rl, type, rid, 0x376, 0x376, 1); - resource_list_alloc(rl, bus, dev, type, &rid, 0x376, 0x376,1,0); + resource_list_alloc(rl, bus, dev, type, &rid, 0x376, 0x376, 1, + 0); } - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(4), rl); - pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(5), rl); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(4), rl, force, + prefetchmask & (1 << 4)); + pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(5), rl, force, + prefetchmask & (1 << 5)); } static void @@ -1035,15 +1063,18 @@ resource_list_add(&dinfo->resources, SYS_RES_IRQ, 0, irq, irq, 1); } -static void -pci_add_resources(device_t pcib, device_t bus, device_t dev) +void +pci_add_resources(device_t bus, device_t dev, int force, uint32_t prefetchmask) { + device_t pcib; struct pci_devinfo *dinfo = device_get_ivars(dev); pcicfgregs *cfg = &dinfo->cfg; struct resource_list *rl = &dinfo->resources; struct pci_quirk *q; int b, i, f, s; + pcib = device_get_parent(bus); + b = cfg->bus; s = cfg->slot; f = cfg->func; @@ -1052,16 +1083,20 @@ if ((pci_get_class(dev) == PCIC_STORAGE) && (pci_get_subclass(dev) == PCIS_STORAGE_IDE) && (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV)) - pci_ata_maps(pcib, bus, dev, b, s, f, rl); + pci_ata_maps(pcib, bus, dev, b, s, f, rl, force, prefetchmask); else for (i = 0; i < cfg->nummaps;) i += pci_add_map(pcib, bus, dev, b, s, f, PCIR_BAR(i), - rl); + rl, force, prefetchmask & (1 << i)); + /* + * Add additional, quirked resources. + */ for (q = &pci_quirks[0]; q->devid; q++) { if (q->devid == ((cfg->device << 16) | cfg->vendor) && q->type == PCI_QUIRK_MAP_REG) - pci_add_map(pcib, bus, dev, b, s, f, q->arg1, rl); + pci_add_map(pcib, bus, dev, b, s, f, q->arg1, rl, + force, 0); } if (cfg->intpin > 0 && PCI_INTERRUPT_VALID(cfg->intline)) { @@ -1115,16 +1150,13 @@ void pci_add_child(device_t bus, struct pci_devinfo *dinfo) { - device_t pcib; - - pcib = device_get_parent(bus); dinfo->cfg.dev = device_add_child(bus, NULL, -1); device_set_ivars(dinfo->cfg.dev, dinfo); resource_list_init(&dinfo->resources); pci_cfg_save(dinfo->cfg.dev, dinfo, 0); pci_cfg_restore(dinfo->cfg.dev, dinfo); pci_print_verbose(dinfo); - pci_add_resources(pcib, bus, dinfo->cfg.dev); + pci_add_resources(bus, dinfo->cfg.dev, 0, 0); } static int @@ -1784,6 +1816,7 @@ count = 1 << mapsize; if (RF_ALIGNMENT(flags) < mapsize) flags = (flags & ~RF_ALIGNMENT_MASK) | RF_ALIGNMENT_LOG2(mapsize); + printf("Alignment flags are %x\n", RF_ALIGNMENT(flags)); /* * Allocate enough resource, and then write back the Only in dev/pci: pci.c.orig Only in /dell/imp/p4/newcard/src/sys/dev/pci: pci.c~ diff -ur dev/pci/pci_pci.c /dell/imp/p4/newcard/src/sys/dev/pci/pci_pci.c --- dev/pci/pci_pci.c Sun Aug 28 17:45:00 2005 +++ /dell/imp/p4/newcard/src/sys/dev/pci/pci_pci.c Mon Dec 26 23:27:45 2005 @@ -385,6 +385,8 @@ if (pcib_is_prefetch_open(sc)) ok = ok || (start >= sc->pmembase && end <= sc->pmemlimit); + if (bootverbose) + printf("start: %#lx end: %#lx membase %#x memlimit %#x pmembase %#x pmemlimit %#x\n", start, end, sc->membase, sc->memlimit, sc->pmembase, sc->pmemlimit); /* * Make sure we allow access to VGA memory addresses when the * bridge has the "VGA Enable" bit set. diff -ur dev/pci/pci_private.h /dell/imp/p4/newcard/src/sys/dev/pci/pci_private.h --- dev/pci/pci_private.h Tue Dec 27 21:04:42 2005 +++ /dell/imp/p4/newcard/src/sys/dev/pci/pci_private.h Tue Dec 27 20:42:03 2005 @@ -41,6 +41,8 @@ void pci_add_children(device_t dev, int busno, size_t dinfo_size); void pci_add_child(device_t bus, struct pci_devinfo *dinfo); +void pci_add_resources(device_t bus, device_t dev, int force, + uint32_t prefetchmask); void pci_driver_added(device_t dev, driver_t *driver); int pci_print_child(device_t dev, device_t child); void pci_probe_nomatch(device_t dev, device_t child); diff -ur dev/pci/pcireg.h /dell/imp/p4/newcard/src/sys/dev/pci/pcireg.h --- dev/pci/pcireg.h Tue Dec 27 21:04:42 2005 +++ /dell/imp/p4/newcard/src/sys/dev/pci/pcireg.h Tue Dec 27 12:06:48 2005 @@ -116,6 +116,7 @@ #define PCIR_BARS 0x10 #define PCIR_BAR(x) (PCIR_BARS + (x) * 4) +#define PCI_RID2BAR(rid) (1<<(((rid)-PCIR_BARS)/4)) #define PCIR_CIS 0x28 #define PCIM_CIS_ASI_MASK 0x7 #define PCIM_CIS_ASI_TUPLE 0