@@ -343,6 +343,34 @@ void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr)
}
EXPORT_SYMBOL(pcim_iounmap);
+/**
+ * pcim_iomap_region - Request and iomap a PCI BAR
+ * @pdev: PCI device to map IO resources for
+ * @bar: BAR to request and iomap
+ * @name: Name used when requesting regions
+ *
+ * Request and iomap a region specified by @bar.
+ */
+void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar, const char *name)
+{
+ void __iomem *addr;
+ int rc;
+
+ if (bar >= DEVICE_COUNT_RESOURCE)
+ return NULL;
+
+ rc = pci_request_region(pdev, bar, name);
+ if (rc)
+ return NULL;
+
+ addr = pcim_iomap(pdev, bar, 0);
+ if (!addr)
+ pci_release_region(pdev, bar);
+
+ return addr;
+}
+EXPORT_SYMBOL_GPL(pcim_iomap_region);
+
/**
* pcim_iomap_regions - Request and iomap PCI BARs
* @pdev: PCI device to map IO resources for
@@ -2323,6 +2323,8 @@ static inline void pci_fixup_device(enum pci_fixup_pass pass,
void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
+void __iomem *pcim_iomap_region(struct pci_dev *pdev, int bar,
+ const char *name);
int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name);
int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask,
const char *name);
Several drivers use the following sequence for a single BAR: rc = pcim_iomap_regions(pdev, BIT(bar), name); if (rc) error; addr = pcim_iomap_table(pdev)[bar]; Let's create a simpler (from implementation and usage perspective) pcim_iomap_region() for this use case. Note: The check for !pci_resource_len() is included in pcim_iomap(), so we don't have to duplicate it. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> --- drivers/pci/devres.c | 28 ++++++++++++++++++++++++++++ include/linux/pci.h | 2 ++ 2 files changed, 30 insertions(+)