Commit f3ec4f87 authored by Alan Stern's avatar Alan Stern Committed by Jesse Barnes

PCI: change device runtime PM settings for probe and remove

This patch (as1388) changes the way the PCI core handles runtime PM
settings when probing or unbinding drivers.  Now the core will make
sure the device is enabled for runtime PM, with a usage count >= 1,
when a driver is probed.  It does the same when calling a driver's
remove method.

If the driver wants to use runtime PM, all it has to do is call
pm_runtime_pu_noidle() near the end of its probe routine (to cancel
the core's usage increment) and pm_runtime_get_noresume() near the
start of its remove routine (to restore the usage count).  It does not
need to mess around with setting the runtime state to enabled,
disabled, active, or suspended.

The patch updates e1000e and r8169, the only PCI drivers that already
use the existing runtime PM interface.
Signed-off-by: default avatarAlan Stern <stern@rowland.harvard.edu>
Acked-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: default avatarJesse Barnes <jbarnes@virtuousgeek.org>
parent a2dccdb2
...@@ -5721,11 +5721,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev, ...@@ -5721,11 +5721,8 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
e1000_print_device_info(adapter); e1000_print_device_info(adapter);
if (pci_dev_run_wake(pdev)) { if (pci_dev_run_wake(pdev))
pm_runtime_set_active(&pdev->dev); pm_runtime_put_noidle(&pdev->dev);
pm_runtime_enable(&pdev->dev);
}
pm_schedule_suspend(&pdev->dev, MSEC_PER_SEC);
return 0; return 0;
...@@ -5771,8 +5768,6 @@ static void __devexit e1000_remove(struct pci_dev *pdev) ...@@ -5771,8 +5768,6 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
struct e1000_adapter *adapter = netdev_priv(netdev); struct e1000_adapter *adapter = netdev_priv(netdev);
bool down = test_bit(__E1000_DOWN, &adapter->state); bool down = test_bit(__E1000_DOWN, &adapter->state);
pm_runtime_get_sync(&pdev->dev);
/* /*
* flush_scheduled work may reschedule our watchdog task, so * flush_scheduled work may reschedule our watchdog task, so
* explicitly disable watchdog tasks from being rescheduled * explicitly disable watchdog tasks from being rescheduled
...@@ -5797,11 +5792,8 @@ static void __devexit e1000_remove(struct pci_dev *pdev) ...@@ -5797,11 +5792,8 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
clear_bit(__E1000_DOWN, &adapter->state); clear_bit(__E1000_DOWN, &adapter->state);
unregister_netdev(netdev); unregister_netdev(netdev);
if (pci_dev_run_wake(pdev)) { if (pci_dev_run_wake(pdev))
pm_runtime_disable(&pdev->dev); pm_runtime_get_noresume(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
}
pm_runtime_put_noidle(&pdev->dev);
/* /*
* Release control of h/w to f/w. If f/w is AMT enabled, this * Release control of h/w to f/w. If f/w is AMT enabled, this
......
...@@ -3219,11 +3219,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) ...@@ -3219,11 +3219,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL);
if (pci_dev_run_wake(pdev)) { if (pci_dev_run_wake(pdev))
pm_runtime_set_active(&pdev->dev); pm_runtime_put_noidle(&pdev->dev);
pm_runtime_enable(&pdev->dev);
}
pm_runtime_idle(&pdev->dev);
out: out:
return rc; return rc;
...@@ -3246,17 +3243,12 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev) ...@@ -3246,17 +3243,12 @@ static void __devexit rtl8169_remove_one(struct pci_dev *pdev)
struct net_device *dev = pci_get_drvdata(pdev); struct net_device *dev = pci_get_drvdata(pdev);
struct rtl8169_private *tp = netdev_priv(dev); struct rtl8169_private *tp = netdev_priv(dev);
pm_runtime_get_sync(&pdev->dev);
flush_scheduled_work(); flush_scheduled_work();
unregister_netdev(dev); unregister_netdev(dev);
if (pci_dev_run_wake(pdev)) { if (pci_dev_run_wake(pdev))
pm_runtime_disable(&pdev->dev); pm_runtime_get_noresume(&pdev->dev);
pm_runtime_set_suspended(&pdev->dev);
}
pm_runtime_put_noidle(&pdev->dev);
/* restore original MAC address */ /* restore original MAC address */
rtl_rar_set(tp, dev->perm_addr); rtl_rar_set(tp, dev->perm_addr);
......
...@@ -289,8 +289,26 @@ struct drv_dev_and_id { ...@@ -289,8 +289,26 @@ struct drv_dev_and_id {
static long local_pci_probe(void *_ddi) static long local_pci_probe(void *_ddi)
{ {
struct drv_dev_and_id *ddi = _ddi; struct drv_dev_and_id *ddi = _ddi;
struct device *dev = &ddi->dev->dev;
return ddi->drv->probe(ddi->dev, ddi->id); int rc;
/* Unbound PCI devices are always set to disabled and suspended.
* During probe, the device is set to enabled and active and the
* usage count is incremented. If the driver supports runtime PM,
* it should call pm_runtime_put_noidle() in its probe routine and
* pm_runtime_get_noresume() in its remove routine.
*/
pm_runtime_get_noresume(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
rc = ddi->drv->probe(ddi->dev, ddi->id);
if (rc) {
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
pm_runtime_put_noidle(dev);
}
return rc;
} }
static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev, static int pci_call_probe(struct pci_driver *drv, struct pci_dev *dev,
...@@ -369,11 +387,19 @@ static int pci_device_remove(struct device * dev) ...@@ -369,11 +387,19 @@ static int pci_device_remove(struct device * dev)
struct pci_driver * drv = pci_dev->driver; struct pci_driver * drv = pci_dev->driver;
if (drv) { if (drv) {
if (drv->remove) if (drv->remove) {
pm_runtime_get_sync(dev);
drv->remove(pci_dev); drv->remove(pci_dev);
pm_runtime_put_noidle(dev);
}
pci_dev->driver = NULL; pci_dev->driver = NULL;
} }
/* Undo the runtime PM settings in local_pci_probe() */
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
pm_runtime_put_noidle(dev);
/* /*
* If the device is still on, set the power state as "unknown", * If the device is still on, set the power state as "unknown",
* since it might change by the next time we load the driver. * since it might change by the next time we load the driver.
......
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