Commit 7f375f32 authored by Tejun Heo's avatar Tejun Heo Committed by Greg Kroah-Hartman

PCI: allow multiple calls to pcim_pin_device()

Sanity check in pcim_pin_device() was too restrictive in that it didn't
allow multiple calls to the function, which is against the devres
philosohpy of fire-and-forget.  Track pinned status separately and allow
pinning multiple times.
Signed-off-by: default avatarTejun Heo <htejun@gmail.com>
Acked-by: default avatarIan McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent a967e127
...@@ -757,7 +757,8 @@ int pci_enable_device(struct pci_dev *dev) ...@@ -757,7 +757,8 @@ int pci_enable_device(struct pci_dev *dev)
* when a device is enabled using managed PCI device enable interface. * when a device is enabled using managed PCI device enable interface.
*/ */
struct pci_devres { struct pci_devres {
unsigned int disable:1; unsigned int enabled:1;
unsigned int pinned:1;
unsigned int orig_intx:1; unsigned int orig_intx:1;
unsigned int restore_intx:1; unsigned int restore_intx:1;
u32 region_mask; u32 region_mask;
...@@ -781,7 +782,7 @@ static void pcim_release(struct device *gendev, void *res) ...@@ -781,7 +782,7 @@ static void pcim_release(struct device *gendev, void *res)
if (this->restore_intx) if (this->restore_intx)
pci_intx(dev, this->orig_intx); pci_intx(dev, this->orig_intx);
if (this->disable) if (this->enabled && !this->pinned)
pci_disable_device(dev); pci_disable_device(dev);
} }
...@@ -820,12 +821,12 @@ int pcim_enable_device(struct pci_dev *pdev) ...@@ -820,12 +821,12 @@ int pcim_enable_device(struct pci_dev *pdev)
dr = get_pci_dr(pdev); dr = get_pci_dr(pdev);
if (unlikely(!dr)) if (unlikely(!dr))
return -ENOMEM; return -ENOMEM;
WARN_ON(!!dr->disable); WARN_ON(!!dr->enabled);
rc = pci_enable_device(pdev); rc = pci_enable_device(pdev);
if (!rc) { if (!rc) {
pdev->is_managed = 1; pdev->is_managed = 1;
dr->disable = 1; dr->enabled = 1;
} }
return rc; return rc;
} }
...@@ -843,9 +844,9 @@ void pcim_pin_device(struct pci_dev *pdev) ...@@ -843,9 +844,9 @@ void pcim_pin_device(struct pci_dev *pdev)
struct pci_devres *dr; struct pci_devres *dr;
dr = find_pci_dr(pdev); dr = find_pci_dr(pdev);
WARN_ON(!dr || !dr->disable); WARN_ON(!dr || !dr->enabled);
if (dr) if (dr)
dr->disable = 0; dr->pinned = 1;
} }
/** /**
...@@ -876,7 +877,7 @@ pci_disable_device(struct pci_dev *dev) ...@@ -876,7 +877,7 @@ pci_disable_device(struct pci_dev *dev)
dr = find_pci_dr(dev); dr = find_pci_dr(dev);
if (dr) if (dr)
dr->disable = 0; dr->enabled = 0;
if (atomic_sub_return(1, &dev->enable_cnt) != 0) if (atomic_sub_return(1, &dev->enable_cnt) != 0)
return; return;
......
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