summaryrefslogtreecommitdiff
path: root/drivers/pci/devres.c
diff options
context:
space:
mode:
authorPhilipp Stanner <pstanner@redhat.com>2024-06-13 14:50:18 +0300
committerKrzysztof Wilczyński <kwilczynski@kernel.org>2024-07-10 07:19:56 +0300
commitd47bde708086c77b1ceeb7643e600089f63dd03b (patch)
treede1b84aa050972d9b757bd9c14a60ad2fb3c952f /drivers/pci/devres.c
parente354bb84a4c1cbb928e052260cc5ce12ec6722ff (diff)
downloadlinux-d47bde708086c77b1ceeb7643e600089f63dd03b.tar.xz
PCI: Add managed pcim_request_region()
These existing functions: pci_request_region() pci_request_selected_regions() pci_request_selected_regions_exclusive() are "hybrid" functions built on __pci_request_region() and are managed if pcim_enable_device() has been called, but unmanaged otherwise. Add these new functions: pcim_request_region() pcim_request_region_exclusive() These are *always* managed and use the new pcim_addr_devres tracking infrastructure instead of find_pci_dr() and struct pci_devres.region_mask. Implement the hybrid functions using the new "pure" functions and remove struct pci_devres.region_mask, which is no longer needed. Link: https://lore.kernel.org/r/20240613115032.29098-6-pstanner@redhat.com Signed-off-by: Philipp Stanner <pstanner@redhat.com> Signed-off-by: Krzysztof Wilczyński <kwilczynski@kernel.org> [bhelgaas: commit log] Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Diffstat (limited to 'drivers/pci/devres.c')
-rw-r--r--drivers/pci/devres.c54
1 files changed, 27 insertions, 27 deletions
diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index a5957b4cbc0e..e4c37fcb12df 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -24,18 +24,16 @@
*
* Consequently, in the new API, region requests performed by the pcim_
* functions are automatically cleaned up through the devres callback
- * pcim_addr_resource_release(), while requests performed by
- * pcim_enable_device() + pci_*region*() are automatically cleaned up
- * through the for-loop in pcim_release().
+ * pcim_addr_resource_release().
*
- * TODO 1:
+ * Users of pcim_enable_device() + pci_*region*() are redirected in
+ * pci.c to the managed functions here in this file. This isn't exactly
+ * perfect, but the only alternative way would be to port ALL drivers
+ * using said combination to pcim_ functions.
+ *
+ * TODO:
* Remove the legacy table entirely once all calls to pcim_iomap_table() in
* the kernel have been removed.
- *
- * TODO 2:
- * Port everyone calling pcim_enable_device() + pci_*region*() to using the
- * pcim_ functions. Then, remove all devres functionality from pci_*region*()
- * functions and remove the associated cleanups described above in point #2.
*/
/*
@@ -402,22 +400,6 @@ static void pcim_release(struct device *gendev, void *res)
{
struct pci_dev *dev = to_pci_dev(gendev);
struct pci_devres *this = res;
- int i;
-
- /*
- * This is legacy code.
- *
- * All regions requested by a pcim_ function do get released through
- * pcim_addr_resource_release(). Thanks to the hybrid nature of the pci_
- * region-request functions, this for-loop has to release the regions
- * if they have been requested by such a function.
- *
- * TODO: Remove this once all users of pcim_enable_device() PLUS
- * pci-region-request-functions have been ported to pcim_ functions.
- */
- for (i = 0; i < DEVICE_COUNT_RESOURCE; i++)
- if (mask_contains_bar(this->region_mask, i))
- pci_release_region(dev, i);
if (this->mwi)
pci_clear_mwi(dev);
@@ -826,12 +808,30 @@ static int _pcim_request_region(struct pci_dev *pdev, int bar, const char *name,
* The region will automatically be released on driver detach. If desired,
* release manually only with pcim_release_region().
*/
-static int pcim_request_region(struct pci_dev *pdev, int bar, const char *name)
+int pcim_request_region(struct pci_dev *pdev, int bar, const char *name)
{
return _pcim_request_region(pdev, bar, name, 0);
}
/**
+ * pcim_request_region_exclusive - Request a PCI BAR exclusively
+ * @pdev: PCI device to requestion region for
+ * @bar: Index of BAR to request
+ * @name: Name associated with the request
+ *
+ * Returns: 0 on success, a negative error code on failure.
+ *
+ * Request region specified by @bar exclusively.
+ *
+ * The region will automatically be released on driver detach. If desired,
+ * release manually only with pcim_release_region().
+ */
+int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, const char *name)
+{
+ return _pcim_request_region(pdev, bar, name, IORESOURCE_EXCLUSIVE);
+}
+
+/**
* pcim_release_region - Release a PCI BAR
* @pdev: PCI device to operate on
* @bar: Index of BAR to release
@@ -839,7 +839,7 @@ static int pcim_request_region(struct pci_dev *pdev, int bar, const char *name)
* Release a region manually that was previously requested by
* pcim_request_region().
*/
-static void pcim_release_region(struct pci_dev *pdev, int bar)
+void pcim_release_region(struct pci_dev *pdev, int bar)
{
struct pcim_addr_devres res_searched;