From owner-p4-projects@FreeBSD.ORG Mon Apr 4 13:27:23 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 6377A106566C; Mon, 4 Apr 2011 13:27:23 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 264AB1065672 for ; Mon, 4 Apr 2011 13:27:23 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id 115028FC13 for ; Mon, 4 Apr 2011 13:27:23 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id p34DRMfr068933 for ; Mon, 4 Apr 2011 13:27:22 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p34DRMrh068930 for perforce@freebsd.org; Mon, 4 Apr 2011 13:27:22 GMT (envelope-from jhb@freebsd.org) Date: Mon, 4 Apr 2011 13:27:22 GMT Message-Id: <201104041327.p34DRMrh068930@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 191022 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Apr 2011 13:27:23 -0000 http://p4web.freebsd.org/@@191022?ac=10 Change 191022 by jhb@jhb_jhbbsd on 2011/04/04 13:26:40 Cleanups, fully handle the 'valid' member of pcib_window. Affected files ... .. //depot/projects/pci/sys/dev/pci/pci_pci.c#5 edit Differences ... ==== //depot/projects/pci/sys/dev/pci/pci_pci.c#5 (text+ko) ==== @@ -139,12 +139,12 @@ pcib_is_window_open(struct pcib_window *pw) { - return (pw->base > 0 && pw->base < pw->limit); + return (pw->valid && pw->base < pw->limit); } static void -pcib_alloc_window(struct pcib_softc *sc, struct pcib_window *w, int type, int reg, - int flags, const char *name, pci_addr_t max_address) +pcib_alloc_window(struct pcib_softc *sc, struct pcib_window *w, int type, + int reg, int flags, const char *name, pci_addr_t max_address) { int error, rid; @@ -154,32 +154,33 @@ 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(w->rman.rm_descr, 64, "%s %s window", + device_get_nameunit(sc->dev), name); error = rman_init(&w->rman); if (error) - panic("Failed to initialize %s %s rman", device_get_nameunit(sc->dev), - name); + panic("Failed to initialize %s %s rman", + device_get_nameunit(sc->dev), 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); - w->base = 0; + device_printf(sc->dev, + "initial %s window has too many bits, ignoring\n", name); return; } rid = reg; - w->res = bus_alloc_resource(sc->dev, type, &rid, w->base, w->limit, w->limit - - w->base + 1, flags); + w->res = bus_alloc_resource(sc->dev, type, &rid, w->base, w->limit, + w->limit - w->base + 1, flags); if (w->res == NULL) { - device_printf(sc->dev, "failed to allocate initial %s window: %jx - %jx\n", + device_printf(sc->dev, + "failed to allocate initial %s window: %jx - %jx\n", name, (uintmax_t)w->base, (uintmax_t)w->limit); - w->base = 0; return; } - error = rman_manage_region(&w->rman, rman_get_start(w->res), rman_get_end(w->res)); + 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"); } @@ -200,7 +201,10 @@ /* Determine if the I/O port window is implemented. */ val = pci_read_config(dev, PCIR_IOBASEL_1, 1); if (val == 0) { - /* If 'val' is zero, then only 16-bits of I/O space are supported. */ + /* + * If 'val' is zero, then only 16-bits of I/O space + * are supported. + */ pci_write_config(dev, PCIR_IOBASEL_1, 0xff, 1); if (pci_read_config(dev, PCIR_IOBASEL_1, 1) != 0) { sc->io.valid = 1; @@ -224,21 +228,26 @@ pci_read_config(dev, PCIR_IOLIMITL_1, 1)); max = 0xffff; } - pcib_alloc_window(sc, &sc->io, SYS_RES_IOPORT, PCIR_IOBASEL_1, 0, - "I/O port", max); + pcib_alloc_window(sc, &sc->io, SYS_RES_IOPORT, PCIR_IOBASEL_1, + 0, "I/O port", max); } /* Read the existing memory window. */ sc->mem.valid = 1; - 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, PCIR_MEMBASE_1, 0, "memory", - 0xffffffff); + 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, PCIR_MEMBASE_1, 0, + "memory", 0xffffffff); /* Determine if the prefetchable memory window is implemented. */ val = pci_read_config(dev, PCIR_PMBASEL_1, 2); if (val == 0) { - /* If 'val' is zero, then only 32-bits of memory space are supported. */ + /* + * If 'val' is zero, then only 32-bits of memory space + * are supported. + */ pci_write_config(dev, PCIR_PMBASEL_1, 0xffff, 2); if (pci_read_config(dev, PCIR_PMBASEL_1, 2) != 0) { sc->pmem.valid = 1; @@ -274,11 +283,13 @@ uint32_t val; dev = sc->dev; - if (mask & WIN_IO) { + if (sc->io.valid && mask & WIN_IO) { val = pci_read_config(dev, PCIR_IOBASEL_1, 1); if ((val & PCIM_BRIO_MASK) == PCIM_BRIO_32) { - pci_write_config(dev, PCIR_IOBASEH_1, sc->io.base >> 16, 2); - pci_write_config(dev, PCIR_IOLIMITH_1, sc->io.limit >> 16, 2); + pci_write_config(dev, PCIR_IOBASEH_1, + sc->io.base >> 16, 2); + pci_write_config(dev, PCIR_IOLIMITH_1, + sc->io.limit >> 16, 2); } pci_write_config(dev, PCIR_IOBASEL_1, sc->io.base >> 8, 1); pci_write_config(dev, PCIR_IOLIMITL_1, sc->io.limit >> 8, 1); @@ -289,11 +300,13 @@ pci_write_config(dev, PCIR_MEMLIMIT_1, sc->mem.limit >> 16, 2); } - if (mask & WIN_PMEM) { + if (sc->pmem.valid && mask & WIN_PMEM) { val = pci_read_config(dev, PCIR_PMBASEL_1, 2); if ((val & PCIM_BRPM_MASK) == PCIM_BRPM_64) { - pci_write_config(dev, PCIR_PMBASEH_1, sc->pmem.base >> 32, 4); - pci_write_config(dev, PCIR_PMLIMITH_1, sc->pmem.limit >> 32, 4); + pci_write_config(dev, PCIR_PMBASEH_1, + sc->pmem.base >> 32, 4); + pci_write_config(dev, PCIR_PMLIMITH_1, + sc->pmem.limit >> 32, 4); } pci_write_config(dev, PCIR_PMBASEL_1, sc->pmem.base >> 16, 2); pci_write_config(dev, PCIR_PMLIMITL_1, sc->pmem.limit >> 16, 2); @@ -607,7 +620,7 @@ device_printf(dev, " secondary bus %d\n", sc->secbus); device_printf(dev, " subordinate bus %d\n", sc->subbus); #ifdef NEW_PCIB - if (pcib_is_window_open(&sc->io) + if (pcib_is_window_open(&sc->io)) device_printf(dev, " I/O decode 0x%jx-0x%jx\n", (uintmax_t)sc->io.base, (uintmax_t)sc->io.limit); if (pcib_is_window_open(&sc->mem)) @@ -618,7 +631,8 @@ (uintmax_t)sc->pmem.base, (uintmax_t)sc->pmem.limit); #else if (pcib_is_io_open(sc)) - device_printf(dev, " I/O decode 0x%x-0x%x\n", sc->iobase, sc->iolimit); + device_printf(dev, " I/O decode 0x%x-0x%x\n", + sc->iobase, sc->iolimit); if (pcib_is_nonprefetch_open(sc)) device_printf(dev, " memory decode 0x%jx-0x%jx\n", (uintmax_t)sc->membase, (uintmax_t)sc->memlimit); @@ -729,19 +743,21 @@ #ifdef NEW_PCIB /* - * Attempt to allocate a resource from the existing resources assigned to a window. + * Attempt to allocate a resource from the existing resources assigned + * to a window. */ static struct resource * -pcib_suballoc_resource(struct pcib_softc *sc, struct pcib_window *w, device_t child, - int type, int *rid, u_long start, u_long end, u_long count, u_int flags) +pcib_suballoc_resource(struct pcib_softc *sc, struct pcib_window *w, + device_t child, int type, int *rid, u_long start, u_long end, u_long count, + u_int flags) { struct resource *res; if (!pcib_is_window_open(w)) return (NULL); - res = rman_reserve_resource(&w->rm, start, end, count, flags & ~RF_ACTIVE, - child); + res = rman_reserve_resource(&w->rm, start, end, count, + flags & ~RF_ACTIVE, child); if (res == NULL) return (NULL);