Date: Tue, 5 Apr 2011 19:43:05 GMT From: John Baldwin <jhb@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 191077 for review Message-ID: <201104051943.p35Jh583020659@skunkworks.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@191077?ac=10 Change 191077 by jhb@jhb_jhbbsd on 2011/04/05 19:42:58 - Add some bootverbose printfs for debugging. - Compile. Affected files ... .. //depot/projects/pci/sys/amd64/pci/pci_bus.c#3 edit .. //depot/projects/pci/sys/dev/acpica/acpi_pcib_acpi.c#3 edit .. //depot/projects/pci/sys/dev/acpica/acpi_pcib_pci.c#2 edit .. //depot/projects/pci/sys/dev/pci/pci_pci.c#8 edit .. //depot/projects/pci/sys/dev/pci/pcib_private.h#6 edit .. //depot/projects/pci/sys/i386/pci/pci_bus.c#3 edit .. //depot/projects/pci/sys/sparc64/pci/apb.c#2 edit .. //depot/projects/pci/sys/sparc64/pci/ofw_pcib.c#2 edit .. //depot/projects/pci/sys/x86/pci/qpi.c#2 edit .. //depot/projects/pci/sys/x86/x86/mptable_pci.c#3 edit Differences ... ==== //depot/projects/pci/sys/amd64/pci/pci_bus.c#3 (text+ko) ==== @@ -35,6 +35,7 @@ #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> +#include <sys/rman.h> #include <sys/sysctl.h> #include <dev/pci/pcivar.h> ==== //depot/projects/pci/sys/dev/acpica/acpi_pcib_acpi.c#3 (text+ko) ==== @@ -34,6 +34,7 @@ #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> +#include <sys/rman.h> #include <sys/sysctl.h> #include <contrib/dev/acpica/include/acpi.h> ==== //depot/projects/pci/sys/dev/acpica/acpi_pcib_pci.c#2 (text+ko) ==== @@ -35,6 +35,7 @@ #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> +#include <sys/rman.h> #include <contrib/dev/acpica/include/acpi.h> #include <contrib/dev/acpica/include/accommon.h> ==== //depot/projects/pci/sys/dev/pci/pci_pci.c#8 (text+ko) ==== @@ -36,14 +36,16 @@ */ #include <sys/param.h> -#include <sys/systm.h> +#include <sys/bus.h> #include <sys/kernel.h> +#include <sys/libkern.h> +#include <sys/malloc.h> #include <sys/module.h> -#include <sys/bus.h> -#include <machine/bus.h> #include <sys/rman.h> #include <sys/sysctl.h> +#include <sys/systm.h> +#include <machine/bus.h> #include <machine/resource.h> #include <dev/pci/pcivar.h> @@ -118,13 +120,13 @@ switch (type) { case SYS_RES_IOPORT: - return (rman_is_region_manager(r, &sc->io_rman)); + return (rman_is_region_manager(r, &sc->io.rman)); case SYS_RES_MEMORY: /* Prefetchable resources may live in either memory rman. */ if (rman_get_flags(r) & RF_PREFETCHABLE && - rman_is_region_manager(r, &sc->pmem_rman)) + rman_is_region_manager(r, &sc->pmem.rman)) return (1); - return (rman_is_region_manager(r, &sc->mem_rman)); + return (rman_is_region_manager(r, &sc->mem.rman)); } return (0); } @@ -138,8 +140,9 @@ static void pcib_alloc_window(struct pcib_softc *sc, struct pcib_window *w, int type, - int flags, const char *name, pci_addr_t max_address) + int flags, pci_addr_t max_address) { + char buf[64]; int error, rid; if (max_address != (u_long)max_address) @@ -147,20 +150,20 @@ w->rman.rm_start = 0; w->rman.rm_end = max_address; w->rman.rm_type = RMAN_ARRAY; - w->rman.rm_descr = malloc(64, M_DEVBUF, M_WAITOK); - snprintf(w->rman.rm_descr, 64, "%s %s window", - device_get_nameunit(sc->dev), name); + snprintf(buf, sizeof(buf), "%s %s window", + device_get_nameunit(sc->dev), w->name); + w->rman.rm_descr = strdup(buf, M_DEVBUF); error = rman_init(&w->rman); if (error) panic("Failed to initialize %s %s rman", - device_get_nameunit(sc->dev), name); + device_get_nameunit(sc->dev), w->name); if (!pcib_is_window_open(w)) return; if (w->base > max_address || w->limit > max_address) { device_printf(sc->dev, - "initial %s window has too many bits, ignoring\n", name); + "initial %s window has too many bits, ignoring\n", w->name); return; } rid = w->reg; @@ -168,15 +171,15 @@ w->limit - w->base + 1, flags); if (w->res == NULL) { device_printf(sc->dev, - "failed to allocate initial %s window: %jx - %jx\n", - name, (uintmax_t)w->base, (uintmax_t)w->limit); + "failed to allocate initial %s window: %#jx-%#jx\n", + w->name, (uintmax_t)w->base, (uintmax_t)w->limit); return; } error = rman_manage_region(&w->rman, rman_get_start(w->res), rman_get_end(w->res)); if (error) - panic("Failed to initialize rman with resource"); + panic("Failed to initialize rman with resource"); } /* @@ -188,7 +191,6 @@ pci_addr_t max; device_t dev; uint32_t val; - int rid; dev = sc->dev; @@ -212,6 +214,7 @@ sc->io.reg = PCIR_IOBASEL_1; sc->io.step = 12; sc->io.mask = WIN_IO; + sc->io.name = "I/O port"; if ((val & PCIM_BRIO_MASK) == PCIM_BRIO_32) { sc->io.base = PCI_PPBIOBASE( pci_read_config(dev, PCIR_IOBASEH_1, 2), val); @@ -225,8 +228,7 @@ pci_read_config(dev, PCIR_IOLIMITL_1, 1)); max = 0xffff; } - pcib_alloc_window(sc, &sc->io, SYS_RES_IOPORT, 0, "I/O port", - max); + pcib_alloc_window(sc, &sc->io, SYS_RES_IOPORT, 0, max); } /* Read the existing memory window. */ @@ -234,12 +236,12 @@ sc->mem.reg = PCIR_MEMBASE_1; sc->mem.step = 20; sc->mem.mask = WIN_MEM; + sc->mem.name = "memory"; sc->mem.base = PCI_PPBMEMBASE(0, pci_read_config(dev, PCIR_MEMBASE_1, 2)); sc->mem.limit = PCI_PPBMEMLIMIT(0, pci_read_config(dev, PCIR_MEMLIMIT_1, 2)); - pcib_alloc_window(sc, &sc->mem, SYS_RES_MEMORY, 0, "memory", - 0xffffffff); + pcib_alloc_window(sc, &sc->mem, SYS_RES_MEMORY, 0, 0xffffffff); /* Determine if the prefetchable memory window is implemented. */ val = pci_read_config(dev, PCIR_PMBASEL_1, 2); @@ -260,22 +262,23 @@ if (sc->pmem.valid) { sc->pmem.reg = PCIR_PMBASEL_1; sc->pmem.step = 20; - sc->omem.mask = WIN_PMEM; + sc->pmem.mask = WIN_PMEM; + sc->pmem.name = "prefetch"; if ((val & PCIM_BRPM_MASK) == PCIM_BRPM_64) { sc->pmem.base = PCI_PPBMEMBASE( - pci_read_config(dev, PCIR_PMBASEH_1, 4), pmemlow); + pci_read_config(dev, PCIR_PMBASEH_1, 4), val); sc->pmem.limit = PCI_PPBMEMLIMIT( pci_read_config(dev, PCIR_PMLIMITH_1, 4), pci_read_config(dev, PCIR_PMLIMITL_1, 2)); max = 0xffffffffffffffff; } else { - sc->pmem.base = PCI_PPBMEMBASE(0, pmemlow); + sc->pmem.base = PCI_PPBMEMBASE(0, val); sc->pmem.limit = PCI_PPBMEMLIMIT(0, pci_read_config(dev, PCIR_PMLIMITL_1, 2)); max = 0xffffffff; } pcib_alloc_window(sc, &sc->pmem, SYS_RES_MEMORY, - RF_PREFETCHABLE, "prefetchable memory", max); + RF_PREFETCHABLE, max); } } @@ -616,7 +619,7 @@ sc->flags |= PCIB_SUBTRACTIVE; #ifdef NEW_PCIB - pcib_probe_windows(); + pcib_probe_windows(sc); #endif if (bootverbose) { device_printf(dev, " domain %d\n", sc->domain); @@ -745,6 +748,18 @@ } #ifdef NEW_PCIB +static const char * +pcib_child_name(device_t child) +{ + static char buf[64]; + + if (device_get_nameunit(child) != NULL) + return (device_get_nameunit(child)); + snprintf(buf, sizeof(buf), "pci%d:%d:%d:%d", pci_get_domain(child), + pci_get_bus(child), pci_get_slot(child), pci_get_function(child)); + return (buf); +} + /* * Attempt to allocate a resource from the existing resources assigned * to a window. @@ -759,11 +774,16 @@ if (!pcib_is_window_open(w)) return (NULL); - res = rman_reserve_resource(&w->rm, start, end, count, + res = rman_reserve_resource(&w->rman, start, end, count, flags & ~RF_ACTIVE, child); if (res == NULL) return (NULL); + if (bootverbose) + device_printf(sc->dev, + "allocated %s range (%#lx-%#lx) for rid %x of %s\n", + w->name, rman_get_start(res), rman_get_end(res), *rid, + pcib_child_name(child)); rman_set_rid(res, *rid); /* @@ -796,8 +816,10 @@ * Clamp the desired resource range to the maximum address * this window supports. Reject impossible requests. */ - if (end > w->max_address) - end = w->max_address; + if (!w->valid) + return (EINVAL); + if (end > w->rman.rm_end) + end = w->rman.rm_end; if (start + count > end || start + count < start) return (EINVAL); @@ -819,6 +841,11 @@ count, flags); if (w->res == NULL) return (ENXIO); + if (bootverbose) + device_printf(sc->dev, + "allocated initial %s window of %#lx-%#lx\n", + w->name, rman_get_start(w->res), + rman_get_end(w->res)); goto updatewin; } @@ -836,9 +863,13 @@ * request size is larger than w->res, we should find the * optimal aligned buffer containing w->res and allocate that. */ - align = 1ul << RF_ALIGNMENT_MASK(flags); + if (bootverbose) + device_printf(sc->dev, + "attempting to grow %s window for (%#lx-%#lx,%#lx)\n", + w->name, start, end, count); + align = 1ul << RF_ALIGNMENT(flags); if (start < rman_get_start(w->res)) { - if (rman_first_free_region(&w->rm, &start_free, &end_free) != + if (rman_first_free_region(&w->rman, &start_free, &end_free) != 0 || start_free != rman_get_start(w->res)) end_free = rman_get_start(w->res) - 1; if (end_free > end) @@ -855,6 +886,9 @@ * ok, ensure it is properly aligned for this window. */ if (front >= start) { + if (bootverbose) + printf("\tfront candidate range: %#lx-%#lx\n", + front, end_free); front &= (1ul << w->step) - 1; front = rman_get_start(w->res) - front; } else @@ -862,12 +896,12 @@ } else front = 0; if (end > rman_get_end(w->res)) { - if (rman_last_free_region(&w->rm, &start_free, &end_free) != + if (rman_last_free_region(&w->rman, &start_free, &end_free) != 0 || end_free != rman_get_end(w->res)) start_free = rman_get_end(w->res) + 1; if (start_free < start) start_free = start; - + /* Move start_free up until it is properly aligned. */ start_free = roundup2(start_free, align); back = start_free + count; @@ -879,6 +913,9 @@ * ok, ensure it is properly aligned for this window. */ if (back <= end) { + if (bootverbose) + printf("\tback candidate range: %#lx-%#lx\n", + start_free, back); back = roundup2(back, w->step) - 1; back -= rman_get_end(w->res); } else @@ -893,14 +930,14 @@ error = ENOSPC; while (front != 0 || back != 0) { if (front != 0 && (front <= back || back == 0)) { - error = bus_adjust_resource(sc->dev, w->type, w->res, + error = bus_adjust_resource(sc->dev, type, w->res, rman_get_start(w->res) - front, rman_get_end(w->res)); if (error == 0) break; front = 0; } else { - error = bus_adjust_resource(sc->dev, w->type, w->res, + error = bus_adjust_resource(sc->dev, type, w->res, rman_get_start(w->res), rman_get_end(w->res) + back); if (error == 0) @@ -911,6 +948,9 @@ if (error) return (error); + if (bootverbose) + device_printf(sc->dev, "grew %s window to %#lx-%#lx\n", + w->name, rman_get_start(w->res), rman_get_end(w->res)); updatewin: /* Save the new window. */ @@ -918,7 +958,7 @@ w->limit = rman_get_end(w->res); KASSERT((w->base & ((1ul << w->step) - 1)) == 0, ("start address is not aligned")); - KASSERT((w->end & ((1ul << w->step) - 1)) == (1ul << w->step) - 1, + KASSERT((w->limit & ((1ul << w->step) - 1)) == (1ul << w->step) - 1, ("end address is not aligned")); pcib_write_windows(sc, w->mask); return (0); @@ -929,7 +969,7 @@ * is set up to, or capable of handling them. */ struct resource * -pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, +pcib_alloc_resource(device_t dev, device_t child, int type, int *rid, u_long start, u_long end, u_long count, u_int flags) { struct pcib_softc *sc; @@ -942,8 +982,8 @@ * the bridge control register. VGA resources do not fall into * the resource windows and are passed up to the parent. */ - if (type == SYS_RES_IOPORT && pci_is_vga_ioport_range(start, end) || - type == SYS_RES_MEMORY && pci_is_vga_memory_range(start, end)) { + if ((type == SYS_RES_IOPORT && pci_is_vga_ioport_range(start, end)) || + (type == SYS_RES_MEMORY && pci_is_vga_memory_range(start, end))) { if (sc->bridgectl & PCIB_BCR_VGA_ENABLE) return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); @@ -956,8 +996,8 @@ * ISA enable bit. */ #ifdef notyet - if (type == SYS_RES_IOPORT && pci_is_isa_ioport_range(start, end) || - type == SYS_RES_MEMORY && pci_is_isa_memory_range(start, end)) { + if ((type == SYS_RES_IOPORT && pci_is_isa_ioport_range(start, end)) || + (type == SYS_RES_MEMORY && pci_is_isa_memory_range(start, end))) { if (sc->bridgectl & PCIB_BCR_ISA_ENABLE) return (bus_generic_alloc_resource(dev, child, type, rid, start, end, count, flags)); @@ -972,7 +1012,7 @@ */ if (sc->flags & PCIB_SUBTRACTIVE) return (bus_generic_alloc_resource(dev, child, type, rid, - stat, end, count, flags)); + start, end, count, flags)); #endif switch (type) { @@ -983,7 +1023,8 @@ break; #ifdef SUBTRACTIVE_WITH_WINDOWS if (sc->flags & PCIB_SUBTRACTIVE) - break; + return (bus_generic_alloc_resource(dev, child, type, + rid, start, end, count, flags)); #endif if (pcib_grow_window(sc, &sc->io, type, start, end, count, flags) == 0) @@ -1011,7 +1052,8 @@ break; #ifdef SUBTRACTIVE_WITH_WINDOWS if (sc->flags & PCIB_SUBTRACTIVE) - break; + return (bus_generic_alloc_resource(dev, child, type, + rid, start, end, count, flags)); #endif if (flags & RF_PREFETCHABLE) { if (pcib_grow_window(sc, &sc->pmem, type, start, end, @@ -1029,7 +1071,7 @@ break; default: return (bus_generic_alloc_resource(dev, child, type, rid, - stat, end, count, flags)); + start, end, count, flags)); } return (r); } ==== //depot/projects/pci/sys/dev/pci/pcib_private.h#6 (text+ko) ==== @@ -53,6 +53,7 @@ int valid; int mask; /* WIN_* bitmask of this window */ int step; /* log_2 of window granularity */ + const char *name; }; #endif ==== //depot/projects/pci/sys/i386/pci/pci_bus.c#3 (text+ko) ==== @@ -35,6 +35,7 @@ #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> +#include <sys/rman.h> #include <sys/sysctl.h> #include <dev/pci/pcivar.h> ==== //depot/projects/pci/sys/sparc64/pci/apb.c#2 (text+ko) ==== @@ -48,6 +48,7 @@ #include <sys/kernel.h> #include <sys/module.h> #include <sys/bus.h> +#include <sys/rman.h> #include <dev/ofw/ofw_bus.h> #include <dev/ofw/openfirm.h> ==== //depot/projects/pci/sys/sparc64/pci/ofw_pcib.c#2 (text+ko) ==== @@ -42,6 +42,7 @@ #include <sys/kernel.h> #include <sys/libkern.h> #include <sys/module.h> +#include <sys/rman.h> #include <dev/ofw/ofw_bus.h> #include <dev/ofw/openfirm.h> ==== //depot/projects/pci/sys/x86/pci/qpi.c#2 (text+ko) ==== @@ -40,6 +40,7 @@ #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/module.h> +#include <sys/rman.h> #include <sys/systm.h> #include <machine/cputypes.h> ==== //depot/projects/pci/sys/x86/x86/mptable_pci.c#3 (text+ko) ==== @@ -40,6 +40,7 @@ #include <sys/bus.h> #include <sys/kernel.h> #include <sys/module.h> +#include <sys/rman.h> #include <dev/pci/pcireg.h> #include <dev/pci/pcivar.h>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104051943.p35Jh583020659>
