From owner-p4-projects@FreeBSD.ORG Sat Jun 25 12:10:18 2011 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 18177106566C; Sat, 25 Jun 2011 12:10:18 +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 D0948106564A for ; Sat, 25 Jun 2011 12:10:17 +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 BE5878FC12 for ; Sat, 25 Jun 2011 12:10:17 +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 p5PCAHB2054465 for ; Sat, 25 Jun 2011 12:10:17 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id p5PCAHcX054461 for perforce@freebsd.org; Sat, 25 Jun 2011 12:10:17 GMT (envelope-from jhb@freebsd.org) Date: Sat, 25 Jun 2011 12:10:17 GMT Message-Id: <201106251210.p5PCAHcX054461@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 195298 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: Sat, 25 Jun 2011 12:10:18 -0000 http://p4web.freebsd.org/@@195298?ac=10 Change 195298 by jhb@jhb_kavik on 2011/06/25 12:09:14 Move pcib_host_res_* to pci_subr.c. Affected files ... .. //depot/projects/pci/sys/dev/pci/pci_domain.c#13 edit .. //depot/projects/pci/sys/dev/pci/pci_subr.c#2 edit Differences ... ==== //depot/projects/pci/sys/dev/pci/pci_domain.c#13 (text+ko) ==== @@ -109,140 +109,3 @@ return (rman_release_resource(r)); } #endif /* PCI_RES_BUS */ - -#ifdef NEW_PCIB -/* - * Some Host-PCI bridge drivers know which resource ranges they can - * decode and should only allocate subranges to child PCI devices. - * This API provides a way to manage this. The bridge drive should - * initialize this structure during attach and call - * pcib_host_res_decodes() on each resource range it decodes. It can - * then use pcib_host_res_alloc() and pcib_host_res_adjust() as helper - * routines for BUS_ALLOC_RESOURCE() and BUS_ADJUST_RESOURCE(). This - * API assumes that resources for any decoded ranges can be safely - * allocated from the parent via bus_generic_alloc_resource(). - */ -int -pcib_host_res_init(device_t pcib, struct pcib_host_resources *hr) -{ - - hr->hr_pcib = pcib; - resource_list_init(&hr->hr_rl); - return (0); -} - -int -pcib_host_res_free(device_t pcib, struct pcib_host_resources *hr) -{ - - resource_list_free(&hr->hr_rl); - return (0); -} - -int -pcib_host_res_decodes(struct pcib_host_resources *hr, int type, u_long start, - u_long end, u_int flags) -{ - struct resource_list_entry *rle; - int rid; - - if (bootverbose) - device_printf(hr->hr_pcib, "decoding %d %srange %#lx-%#lx\n", - type, flags & RF_PREFETCHABLE ? "prefetchable ": "", start, - end); - rid = resource_list_add_next(&hr->hr_rl, type, start, end, - end - start + 1); - if (flags & RF_PREFETCHABLE) { - KASSERT(type == SYS_RES_MEMORY, - ("only memory is prefetchable")); - rle = resource_list_find(&hr->hr_rl, type, rid); - rle->flags = RLE_PREFETCH; - } - return (0); -} - -struct resource * -pcib_host_res_alloc(struct pcib_host_resources *hr, device_t dev, int type, - int *rid, u_long start, u_long end, u_long count, u_int flags) -{ - struct resource_list_entry *rle; - struct resource *r; - u_long new_start, new_end; - - if (flags & RF_PREFETCHABLE) - KASSERT(type == SYS_RES_MEMORY, - ("only memory is prefetchable")); - - rle = resource_list_find(&hr->hr_rl, type, 0); - if (rle == NULL) { - /* - * No decoding ranges for this resource type, just pass - * the request up to the parent. - */ - return (bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, - start, end, count, flags)); - } - -restart: - /* Try to allocate from each decoded range. */ - for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { - if (rle->type != type) - continue; - if (((flags & RF_PREFETCHABLE) != 0) != - ((rle->flags & RLE_PREFETCH) != 0)) - continue; - new_start = ulmax(start, rle->start); - new_end = ulmin(end, rle->end); - if (new_start > new_end || - new_start + count - 1 > new_end || - new_start + count < new_start) - continue; - r = bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, - new_start, new_end, count, flags); - if (r != NULL) { - if (bootverbose) - device_printf(hr->hr_pcib, - "allocated type %d (%#lx-%#lx) for rid %x of %s\n", - type, rman_get_start(r), rman_get_end(r), - *rid, pcib_child_name(dev)); - return (r); - } - } - - /* - * If we failed to find a prefetch range for a memory - * resource, try again without prefetch. - */ - if (flags & RF_PREFETCHABLE) { - flags &= ~RF_PREFETCHABLE; - rle = resource_list_find(&hr->hr_rl, type, 0); - goto restart; - } - return (NULL); -} - -int -pcib_host_res_adjust(struct pcib_host_resources *hr, device_t dev, int type, - struct resource *r, u_long start, u_long end) -{ - struct resource_list_entry *rle; - - rle = resource_list_find(&hr->hr_rl, type, 0); - if (rle == NULL) { - /* - * No decoding ranges for this resource type, just pass - * the request up to the parent. - */ - return (bus_generic_adjust_resource(hr->hr_pcib, dev, type, r, - start, end)); - } - - /* Only allow adjustments that stay within a decoded range. */ - for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { - if (rle->start <= start && rle->end >= end) - return (bus_generic_adjust_resource(hr->hr_pcib, dev, - type, r, start, end)); - } - return (ERANGE); -} -#endif /* NEW_PCIB */ ==== //depot/projects/pci/sys/dev/pci/pci_subr.c#2 (text+ko) ==== @@ -33,9 +33,10 @@ * provide PCI domains. */ -#include +#include #include #include +#include #include #include @@ -128,3 +129,140 @@ return 1; } + +#ifdef NEW_PCIB +/* + * Some Host-PCI bridge drivers know which resource ranges they can + * decode and should only allocate subranges to child PCI devices. + * This API provides a way to manage this. The bridge drive should + * initialize this structure during attach and call + * pcib_host_res_decodes() on each resource range it decodes. It can + * then use pcib_host_res_alloc() and pcib_host_res_adjust() as helper + * routines for BUS_ALLOC_RESOURCE() and BUS_ADJUST_RESOURCE(). This + * API assumes that resources for any decoded ranges can be safely + * allocated from the parent via bus_generic_alloc_resource(). + */ +int +pcib_host_res_init(device_t pcib, struct pcib_host_resources *hr) +{ + + hr->hr_pcib = pcib; + resource_list_init(&hr->hr_rl); + return (0); +} + +int +pcib_host_res_free(device_t pcib, struct pcib_host_resources *hr) +{ + + resource_list_free(&hr->hr_rl); + return (0); +} + +int +pcib_host_res_decodes(struct pcib_host_resources *hr, int type, u_long start, + u_long end, u_int flags) +{ + struct resource_list_entry *rle; + int rid; + + if (bootverbose) + device_printf(hr->hr_pcib, "decoding %d %srange %#lx-%#lx\n", + type, flags & RF_PREFETCHABLE ? "prefetchable ": "", start, + end); + rid = resource_list_add_next(&hr->hr_rl, type, start, end, + end - start + 1); + if (flags & RF_PREFETCHABLE) { + KASSERT(type == SYS_RES_MEMORY, + ("only memory is prefetchable")); + rle = resource_list_find(&hr->hr_rl, type, rid); + rle->flags = RLE_PREFETCH; + } + return (0); +} + +struct resource * +pcib_host_res_alloc(struct pcib_host_resources *hr, device_t dev, int type, + int *rid, u_long start, u_long end, u_long count, u_int flags) +{ + struct resource_list_entry *rle; + struct resource *r; + u_long new_start, new_end; + + if (flags & RF_PREFETCHABLE) + KASSERT(type == SYS_RES_MEMORY, + ("only memory is prefetchable")); + + rle = resource_list_find(&hr->hr_rl, type, 0); + if (rle == NULL) { + /* + * No decoding ranges for this resource type, just pass + * the request up to the parent. + */ + return (bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, + start, end, count, flags)); + } + +restart: + /* Try to allocate from each decoded range. */ + for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { + if (rle->type != type) + continue; + if (((flags & RF_PREFETCHABLE) != 0) != + ((rle->flags & RLE_PREFETCH) != 0)) + continue; + new_start = ulmax(start, rle->start); + new_end = ulmin(end, rle->end); + if (new_start > new_end || + new_start + count - 1 > new_end || + new_start + count < new_start) + continue; + r = bus_generic_alloc_resource(hr->hr_pcib, dev, type, rid, + new_start, new_end, count, flags); + if (r != NULL) { + if (bootverbose) + device_printf(hr->hr_pcib, + "allocated type %d (%#lx-%#lx) for rid %x of %s\n", + type, rman_get_start(r), rman_get_end(r), + *rid, pcib_child_name(dev)); + return (r); + } + } + + /* + * If we failed to find a prefetch range for a memory + * resource, try again without prefetch. + */ + if (flags & RF_PREFETCHABLE) { + flags &= ~RF_PREFETCHABLE; + rle = resource_list_find(&hr->hr_rl, type, 0); + goto restart; + } + return (NULL); +} + +int +pcib_host_res_adjust(struct pcib_host_resources *hr, device_t dev, int type, + struct resource *r, u_long start, u_long end) +{ + struct resource_list_entry *rle; + + rle = resource_list_find(&hr->hr_rl, type, 0); + if (rle == NULL) { + /* + * No decoding ranges for this resource type, just pass + * the request up to the parent. + */ + return (bus_generic_adjust_resource(hr->hr_pcib, dev, type, r, + start, end)); + } + + /* Only allow adjustments that stay within a decoded range. */ + for (; rle != NULL; rle = STAILQ_NEXT(rle, link)) { + if (rle->start <= start && rle->end >= end) + return (bus_generic_adjust_resource(hr->hr_pcib, dev, + type, r, start, end)); + } + return (ERANGE); +} +#endif /* NEW_PCIB */