From patchwork Fri Apr 12 22:44:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2438541 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id A1CF33FD1A for ; Fri, 12 Apr 2013 22:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756701Ab3DLWqg (ORCPT ); Fri, 12 Apr 2013 18:46:36 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:47058 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756630Ab3DLWqd (ORCPT ); Fri, 12 Apr 2013 18:46:33 -0400 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r3CMisSi003900 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 12 Apr 2013 22:44:55 GMT Received: from userz7021.oracle.com (userz7021.oracle.com [156.151.31.85]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3CMiqdf018536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Fri, 12 Apr 2013 22:44:53 GMT Received: from abhmt115.oracle.com (abhmt115.oracle.com [141.146.116.67]) by userz7021.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r3CMiq9J024066; Fri, 12 Apr 2013 22:44:52 GMT Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 12 Apr 2013 15:44:52 -0700 From: Yinghai Lu To: Bjorn Helgaas , Ram Pai Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v4 14/29] PCI: Use for_each_pci_resource() with pci bar reassign funcs Date: Fri, 12 Apr 2013 15:44:28 -0700 Message-Id: <1365806683-26717-15-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1365806683-26717-1-git-send-email-yinghai@kernel.org> References: <1365806683-26717-1-git-send-email-yinghai@kernel.org> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Replace those open code, and make code more readable. Signed-off-by: Yinghai Lu --- drivers/pci/setup-bus.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c index 7e8739e..b23ef4c 100644 --- a/drivers/pci/setup-bus.c +++ b/drivers/pci/setup-bus.c @@ -106,7 +106,7 @@ static resource_size_t get_res_add_size(struct list_head *head, list_for_each_entry(dev_res, head, list) { if (dev_res->res == res) { - int idx = res - &dev_res->dev->resource[0]; + int idx = pci_dev_resource_idx(dev_res->dev, res); dev_printk(KERN_DEBUG, &dev_res->dev->dev, "res[%d]=%pR get_res_add_size add_size %llx\n", @@ -124,15 +124,13 @@ static resource_size_t get_res_add_size(struct list_head *head, static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { struct pci_dev_resource *dev_res, *tmp; resource_size_t r_align; struct list_head *n; - r = &dev->resource[i]; - if (r->flags & IORESOURCE_PCI_FIXED) continue; @@ -237,7 +235,7 @@ static void reassign_resources_sorted(struct list_head *realloc_head, if (!found_match)/* just skip */ continue; - idx = res - &add_res->dev->resource[0]; + idx = pci_dev_resource_idx(add_res->dev, res); add_size = add_res->add_size; if (!resource_size(res)) { res->start = add_res->start; @@ -280,7 +278,7 @@ static void assign_requested_resources_sorted(struct list_head *head, list_for_each_entry(dev_res, head, list) { res = dev_res->res; - idx = res - &dev_res->dev->resource[0]; + idx = pci_dev_resource_idx(dev_res->dev, res); if (resource_size(res) && pci_assign_resource(dev_res->dev, idx)) { if (fail_head) { @@ -757,9 +755,9 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t min_size, io_align = min_align = window_alignment(bus, IORESOURCE_IO); list_for_each_entry(dev, &bus->devices, bus_list) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { unsigned long r_size; if (r->parent || !(r->flags & IORESOURCE_IO)) @@ -870,9 +868,9 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, list_for_each_entry(dev, &bus->devices, bus_list) { int i; + struct resource *r; - for (i = 0; i < PCI_NUM_RESOURCES; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_ALL_RES) { resource_size_t r_size; if (r->parent || (r->flags & mask) != type) @@ -1196,9 +1194,7 @@ static void pci_bridge_release_resources(struct pci_bus *bus, IORESOURCE_PREFETCH; dev = bus->self; - for (idx = PCI_BRIDGE_RESOURCES; idx <= PCI_BRIDGE_RESOURCE_END; - idx++) { - r = &dev->resource[idx]; + for_each_pci_resource(dev, r, idx, PCI_BRIDGE_RES) { if ((r->flags & type_mask) != type) continue; if (!r->parent) @@ -1369,9 +1365,9 @@ static void __init pci_realloc_detect(void) for_each_pci_dev(dev) { int i; + struct resource *r; - for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) { - struct resource *r = &dev->resource[i]; + for_each_pci_resource(dev, r, i, PCI_IOV_RES) { /* Not assigned, or rejected by kernel ? */ if (r->flags && !r->start) {