From: Heiner Kallweit <hkallweit1@gmail.com>
To: Bjorn Helgaas <bhelgaas@google.com>,
Realtek linux nic maintainers <nic_swsd@realtek.com>,
Paolo Abeni <pabeni@redhat.com>, Jakub Kicinski <kuba@kernel.org>,
Eric Dumazet <edumazet@google.com>,
David Miller <davem@davemloft.net>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: [PATCH 1/2] PCI: Add pcim_iomap_region
Date: Wed, 27 Mar 2024 12:53:18 +0100 [thread overview]
Message-ID: <b5ebb7e2-7c94-4111-8e10-cf162547f466@gmail.com> (raw)
In-Reply-To: <982b02cb-a095-4131-84a7-24817ac68857@gmail.com>
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(+)
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
next prev parent reply other threads:[~2024-03-27 11:53 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-27 11:52 [PATCH 0/2] PCI: Add and use pcim_iomap_region() Heiner Kallweit
2024-03-27 11:53 ` Heiner Kallweit [this message]
2024-03-27 11:54 ` [PATCH 2/2] r8169: use new function pcim_iomap_region() Heiner Kallweit
2024-03-27 13:35 ` Philipp Stanner
2024-03-27 13:20 ` [PATCH 0/2] PCI: Add and use pcim_iomap_region() Philipp Stanner
2024-03-28 17:35 ` Heiner Kallweit
2024-03-28 22:03 ` Heiner Kallweit
2024-04-02 13:17 ` Philipp Stanner
2024-04-02 13:54 ` Heiner Kallweit
2024-04-02 14:11 ` Philipp Stanner
2024-04-02 19:06 ` Heiner Kallweit
2024-04-02 13:40 ` Philipp Stanner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5ebb7e2-7c94-4111-8e10-cf162547f466@gmail.com \
--to=hkallweit1@gmail.com \
--cc=bhelgaas@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nic_swsd@realtek.com \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox