From patchwork Wed Mar 13 23:28:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2266501 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 45403DF215 for ; Wed, 13 Mar 2013 23:31:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965002Ab3CMX3h (ORCPT ); Wed, 13 Mar 2013 19:29:37 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:51499 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965005Ab3CMX3g (ORCPT ); Wed, 13 Mar 2013 19:29:36 -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 r2DNSU27026512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Mar 2013 23:28:30 GMT Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2DNST5E006945 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Mar 2013 23:28:29 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by acsmt357.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2DNSSwE030547; Wed, 13 Mar 2013 18:28:29 -0500 Received: from linux-siqj.site (/10.132.126.191) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 13 Mar 2013 16:28:28 -0700 From: Yinghai Lu To: Bjorn Helgaas , Ram Pai Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v3 13/27] PCI: Use for_each_pci_resource() with pci bar reassign funcs Date: Wed, 13 Mar 2013 16:28:08 -0700 Message-Id: <1363217302-14383-14-git-send-email-yinghai@kernel.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1363217302-14383-1-git-send-email-yinghai@kernel.org> References: <1363217302-14383-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) {