[PATCH 1/2] PCI: Add pcim_iomap_region

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 drivers/pci/devres.c | 28 ++++++++++++++++++++++++++++
 include/linux/pci.h  |  2 ++
 2 files changed, 30 insertions(+)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 2c562b9ea..afbb8860b 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -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
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 16493426a..751ffe8c4 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -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);
-- 
2.44.0






[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux