PCI: Use pci_update_current_state() in pci_enable_device_flags()
[linux-2.6-microblaze.git] / drivers / pci / pci.c
index 29cb92b..375d298 100644 (file)
@@ -1900,10 +1900,16 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
        int err;
        int i, bars = 0;
 
-       if (atomic_inc_return(&dev->enable_cnt) > 1) {
-               pci_update_current_state(dev, dev->current_state);
+       /*
+        * Power state could be unknown at this point, either due to a fresh
+        * boot or a device removal call.  So get the current power state
+        * so that things like MSI message writing will behave as expected
+        * (e.g. if the device really is in D0 at enable time).
+        */
+       pci_update_current_state(dev, dev->current_state);
+
+       if (atomic_inc_return(&dev->enable_cnt) > 1)
                return 0;               /* already enabled */
-       }
 
        bridge = pci_upstream_bridge(dev);
        if (bridge)
@@ -5038,7 +5044,7 @@ static void pci_dev_lock(struct pci_dev *dev)
 }
 
 /* Return 1 on successful lock, 0 on contention */
-static int pci_dev_trylock(struct pci_dev *dev)
+int pci_dev_trylock(struct pci_dev *dev)
 {
        if (pci_cfg_access_trylock(dev)) {
                if (device_trylock(&dev->dev))
@@ -5048,12 +5054,14 @@ static int pci_dev_trylock(struct pci_dev *dev)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(pci_dev_trylock);
 
-static void pci_dev_unlock(struct pci_dev *dev)
+void pci_dev_unlock(struct pci_dev *dev)
 {
        device_unlock(&dev->dev);
        pci_cfg_access_unlock(dev);
 }
+EXPORT_SYMBOL_GPL(pci_dev_unlock);
 
 static void pci_dev_save_and_disable(struct pci_dev *dev)
 {