Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756995Ab3DLWqh (ORCPT ); Fri, 12 Apr 2013 18:46:37 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:47569 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756636Ab3DLWqe (ORCPT ); Fri, 12 Apr 2013 18:46:34 -0400 From: Yinghai Lu To: Bjorn Helgaas , Ram Pai Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Yinghai Lu Subject: [PATCH v4 02/29] PCI: Add pci_dev_resource_n() Date: Fri, 12 Apr 2013 15:44:16 -0700 Message-Id: <1365806683-26717-3-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-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1913 Lines: 60 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 bcd9769..ffff013 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -353,6 +353,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 -- 1.8.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/