@@ -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 */
@@ -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
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 <yinghai@kernel.org> --- drivers/pci/probe.c | 9 +++++++++ include/linux/pci.h | 2 ++ 2 files changed, 11 insertions(+)