From patchwork Wed Mar 13 23:27:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yinghai Lu X-Patchwork-Id: 2266451 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 08336DF215 for ; Wed, 13 Mar 2013 23:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S964987Ab3CMXaG (ORCPT ); Wed, 13 Mar 2013 19:30:06 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:51624 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964822Ab3CMXaE (ORCPT ); Wed, 13 Mar 2013 19:30:04 -0400 Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r2DNSMh3026434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 13 Mar 2013 23:28:22 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r2DNSLvS019135 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 13 Mar 2013 23:28:21 GMT Received: from abhmt103.oracle.com (abhmt103.oracle.com [141.146.116.55]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r2DNSLJt025978; Wed, 13 Mar 2013 18:28:21 -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:21 -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 01/27] PCI: Add pci_dev_resource_n() Date: Wed, 13 Mar 2013 16:27:56 -0700 Message-Id: <1363217302-14383-2-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: acsinet22.oracle.com [141.146.126.238] Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Now pci device resource iteration is done via "for (i=0...)" open code. That make code hard to read esp when only bridge or sriov resources are involved. We want to replace those open code with for_each_pci_resource(). Also want to add addon_resource handling, and need to make addon resource to be treated as normal PCI resources during iteration. Add pci_device_resource_n() instead of using dev->resources[n]. Use it with for_each_pci_resource macro and addon_resource support. -v2: Add EXPORT_SYMBOL to find building error found by Gary Hade Signed-off-by: Yinghai Lu --- drivers/pci/probe.c | 9 +++++++++ include/linux/pci.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b494066..9cb3eb3 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -105,6 +105,15 @@ static int __init pcibus_class_init(void) } postcore_initcall(pcibus_class_init); +struct resource *pci_dev_resource_n(struct pci_dev *dev, int n) +{ + if (n >= 0 && n < PCI_NUM_RESOURCES) + return &dev->resource[n]; + + return NULL; +} +EXPORT_SYMBOL(pci_dev_resource_n); + static u64 pci_size(u64 base, u64 maxbase, u64 mask) { u64 size = mask & maxbase; /* Find the significant bits */ diff --git a/include/linux/pci.h b/include/linux/pci.h index 2461033a..00d5367 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -338,6 +338,8 @@ struct pci_dev { size_t romlen; /* Length of ROM if it's not from the BAR */ }; +struct resource *pci_dev_resource_n(struct pci_dev *dev, int n); + static inline struct pci_dev *pci_physfn(struct pci_dev *dev) { #ifdef CONFIG_PCI_IOV