Commit f748a07a authored by Philipp Stanner's avatar Philipp Stanner Committed by Bjorn Helgaas

PCI: Remove legacy pcim_release()

Thanks to preceding cleanup steps, pcim_release() is now not needed
anymore and can be replaced by pcim_disable_device(), which is the exact
counterpart to pcim_enable_device().

This permits removing further parts of the old PCI devres implementation.

Replace pcim_release() with pcim_disable_device().  Remove the now unused
function get_pci_dr().  Remove the struct pci_devres from pci.h.

Link: https://lore.kernel.org/r/20240613115032.29098-12-pstanner@redhat.comSigned-off-by: default avatarPhilipp Stanner <pstanner@redhat.com>
Signed-off-by: default avatarKrzysztof Wilczyński <kwilczynski@kernel.org>
Signed-off-by: default avatarBjorn Helgaas <bhelgaas@google.com>
parent 25216afc
...@@ -477,48 +477,45 @@ int pcim_intx(struct pci_dev *pdev, int enable) ...@@ -477,48 +477,45 @@ int pcim_intx(struct pci_dev *pdev, int enable)
return 0; return 0;
} }
static void pcim_release(struct device *gendev, void *res) static void pcim_disable_device(void *pdev_raw)
{ {
struct pci_dev *dev = to_pci_dev(gendev); struct pci_dev *pdev = pdev_raw;
if (pci_is_enabled(dev) && !dev->pinned)
pci_disable_device(dev);
}
static struct pci_devres *get_pci_dr(struct pci_dev *pdev)
{
struct pci_devres *dr, *new_dr;
dr = devres_find(&pdev->dev, pcim_release, NULL, NULL);
if (dr)
return dr;
new_dr = devres_alloc(pcim_release, sizeof(*new_dr), GFP_KERNEL); if (!pdev->pinned)
if (!new_dr) pci_disable_device(pdev);
return NULL;
return devres_get(&pdev->dev, new_dr, NULL, NULL);
} }
/** /**
* pcim_enable_device - Managed pci_enable_device() * pcim_enable_device - Managed pci_enable_device()
* @pdev: PCI device to be initialized * @pdev: PCI device to be initialized
* *
* Managed pci_enable_device(). * Returns: 0 on success, negative error code on failure.
*
* Managed pci_enable_device(). Device will automatically be disabled on
* driver detach.
*/ */
int pcim_enable_device(struct pci_dev *pdev) int pcim_enable_device(struct pci_dev *pdev)
{ {
struct pci_devres *dr; int ret;
int rc;
dr = get_pci_dr(pdev); ret = devm_add_action(&pdev->dev, pcim_disable_device, pdev);
if (unlikely(!dr)) if (ret != 0)
return -ENOMEM; return ret;
rc = pci_enable_device(pdev); /*
if (!rc) * We prefer removing the action in case of an error over
pdev->is_managed = 1; * devm_add_action_or_reset() because the latter could theoretically be
* disturbed by users having pinned the device too soon.
*/
ret = pci_enable_device(pdev);
if (ret != 0) {
devm_remove_action(&pdev->dev, pcim_disable_device, pdev);
return ret;
}
return rc; pdev->is_managed = true;
return ret;
} }
EXPORT_SYMBOL(pcim_enable_device); EXPORT_SYMBOL(pcim_enable_device);
......
...@@ -810,22 +810,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) ...@@ -810,22 +810,6 @@ static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
} }
#endif #endif
/*
* Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X
* on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so
* there's no need to track it separately. pci_devres is initialized
* when a device is enabled using managed PCI device enable interface.
*
* TODO: Struct pci_devres only needs to be here because they're used in pci.c.
* Port or move these functions to devres.c and then remove them from here.
*/
struct pci_devres {
/*
* TODO:
* This struct is now surplus. Remove it by refactoring pci/devres.c
*/
};
int pcim_intx(struct pci_dev *dev, int enable); int pcim_intx(struct pci_dev *dev, int enable);
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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment