diff options
| author | Rafael J. Wysocki <rjw@sisk.pl> | 2009-08-18 17:38:32 -0400 |
|---|---|---|
| committer | Rafael J. Wysocki <rjw@sisk.pl> | 2009-08-22 18:04:44 -0400 |
| commit | 5e928f77a09a07f9dd595bb8a489965d69a83458 (patch) | |
| tree | ef53ec90fa3214fd22e36b07c11c06b09e373d8d | |
| parent | 8400146d0dc03590bba051399e4bb7e1cbf1c010 (diff) | |
PM: Introduce core framework for run-time PM of I/O devices (rev. 17)
Introduce a core framework for run-time power management of I/O
devices. Add device run-time PM fields to 'struct dev_pm_info'
and device run-time PM callbacks to 'struct dev_pm_ops'. Introduce
a run-time PM workqueue and define some device run-time PM helper
functions at the core level. Document all these things.
Special thanks to Alan Stern for his help with the design and
multiple detailed reviews of the pereceding versions of this patch
and to Magnus Damm for testing feedback.
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Magnus Damm <damm@igel.co.jp>
| -rw-r--r-- | Documentation/power/runtime_pm.txt | 378 | ||||
| -rw-r--r-- | drivers/base/dd.c | 11 | ||||
| -rw-r--r-- | drivers/base/power/Makefile | 1 | ||||
| -rw-r--r-- | drivers/base/power/main.c | 22 | ||||
| -rw-r--r-- | drivers/base/power/power.h | 31 | ||||
| -rw-r--r-- | drivers/base/power/runtime.c | 1011 | ||||
| -rw-r--r-- | include/linux/pm.h | 101 | ||||
| -rw-r--r-- | include/linux/pm_runtime.h | 114 | ||||
| -rw-r--r-- | kernel/power/Kconfig | 14 | ||||
| -rw-r--r-- | kernel/power/main.c | 17 |
10 files changed, 1689 insertions, 11 deletions
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt new file mode 100644 index 000000000000..f49a33b704d2 --- /dev/null +++ b/Documentation/power/runtime_pm.txt | |||
| @@ -0,0 +1,378 @@ | |||
| 1 | Run-time Power Management Framework for I/O Devices | ||
| 2 | |||
| 3 | (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | ||
| 4 | |||
| 5 | 1. Introduction | ||
| 6 | |||
| 7 | Support for run-time power management (run-time PM) of I/O devices is provided | ||
| 8 | at the power management core (PM core) level by means of: | ||
| 9 | |||
| 10 | * The power management workqueue pm_wq in which bus types and device drivers can | ||
| 11 | put their PM-related work items. It is strongly recommended that pm_wq be | ||
| 12 | used for queuing all work items related to run-time PM, because this allows | ||
| 13 | them to be synchronized with system-wide power transitions (suspend to RAM, | ||
| 14 | hibernation and resume from system sleep states). pm_wq is declared in | ||
| 15 | include/linux/pm_runtime.h and defined in kernel/power/main.c. | ||
| 16 | |||
| 17 | * A number of run-time PM fields in the 'power' member of 'struct device' (which | ||
| 18 | is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can | ||
| 19 | be used for synchronizing run-time PM operations with one another. | ||
| 20 | |||
| 21 | * Three device run-time PM callbacks in 'struct dev_pm_ops' (defined in | ||
| 22 | include/linux/pm.h). | ||
| 23 | |||
| 24 | * A set of helper functions defined in drivers/base/power/runtime.c that can be | ||
| 25 | used for carrying out run-time PM operations in such a way that the | ||
| 26 | synchronization between them is taken care of by the PM core. Bus types and | ||
| 27 | device drivers are encouraged to use these functions. | ||
| 28 | |||
| 29 | The run-time PM callbacks present in 'struct dev_pm_ops', the device run-time PM | ||
| 30 | fields of 'struct dev_pm_info' and the core helper functions provided for | ||
| 31 | run-time PM are described below. | ||
| 32 | |||
| 33 | 2. Device Run-time PM Callbacks | ||
| 34 | |||
| 35 | There are three device run-time PM callbacks defined in 'struct dev_pm_ops': | ||
| 36 | |||
| 37 | struct dev_pm_ops { | ||
| 38 | ... | ||
| 39 | int (*runtime_suspend)(struct device *dev); | ||
| 40 | int (*runtime_resume)(struct device *dev); | ||
| 41 | void (*runtime_idle)(struct device *dev); | ||
| 42 | ... | ||
| 43 | }; | ||
| 44 | |||
| 45 | The ->runtime_suspend() callback is executed by the PM core for the bus type of | ||
| 46 | the device being suspended. The bus type's callback is then _entirely_ | ||
| 47 | _responsible_ for handling the device as appropriate, which may, but need not | ||
| 48 | include executing the device driver's own ->runtime_suspend() callback (from the | ||
| 49 | PM core's point of view it is not necessary to implement a ->runtime_suspend() | ||
| 50 | callback in a device driver as long as the bus type's ->runtime_suspend() knows | ||
| 51 | what to do to handle the device). | ||
| 52 | |||
| 53 | * Once the bus type's ->runtime_suspend() callback has completed successfully | ||
| 54 | for given device, the PM core regards the device as suspended, which need | ||
| 55 | not mean that the device has been put into a low power state. It is | ||
| 56 | supposed to mean, however, that the device will not process data and will | ||
| 57 | not communicate with the CPU(s) and RAM until its bus type's | ||
| 58 | ->runtime_resume() callback is executed for it. The run-time PM status of | ||
| 59 | a device after successful execution of its bus type's ->runtime_suspend() | ||
| 60 | callback is 'suspended'. | ||
| 61 | |||
| 62 | * If the bus type's ->runtime_suspend() callback returns -EBUSY or -EAGAIN, | ||
| 63 | the device's run-time PM status is supposed to be 'active', which means that | ||
| 64 | the device _must_ be fully operational afterwards. | ||
| 65 | |||
| 66 | * If the bus type's ->runtime_suspend() callback returns an error code | ||
| 67 | different from -EBUSY or -EAGAIN, the PM core regards this as a fatal | ||
| 68 | error and will refuse to run the helper functions described in Section 4 | ||
| 69 | for the device, until the status of it is directly set either to 'active' | ||
| 70 | or to 'suspended' (the PM core provides special helper functions for this | ||
| 71 | purpose). | ||
| 72 | |||
| 73 | In particular, if the driver requires remote wakeup capability for proper | ||
| 74 | functioning and device_may_wakeup() returns 'false' for the device, then | ||
| 75 | ->runtime_suspend() should return -EBUSY. On the other hand, if | ||
| 76 | device_may_wakeup() returns 'true' for the device and the device is put | ||
| 77 | into a low power state during the execution of its bus type's | ||
| 78 | ->runtime_suspend(), it is expected that remote wake-up (i.e. hardware mechanism | ||
| 79 | allowing the device to request a change of its power state, such as PCI PME) | ||
| 80 | will be enabled for the device. Generally, remote wake-up should be enabled | ||
| 81 | for all input devices put into a low power state at run time. | ||
| 82 | |||
| 83 | The ->runtime_resume() callback is executed by the PM core for the bus type of | ||
| 84 | the device being woken up. The bus type's callback is then _entirely_ | ||
| 85 | _responsible_ for handling the device as appropriate, which may, but need not | ||
| 86 | include executing the device driver's own ->runtime_resume() callback (from the | ||
| 87 | PM core's point of view it is not necessary to implement a ->runtime_resume() | ||
| 88 | callback in a device driver as long as the bus type's ->runtime_resume() knows | ||
| 89 | what to do to handle the device). | ||
| 90 | |||
| 91 | * Once the bus type's ->runtime_resume() callback has completed successfully, | ||
| 92 | the PM core regards the device as fully operational, which means that the | ||
| 93 | device _must_ be able to complete I/O operations as needed. The run-time | ||
| 94 | PM status of the device is then 'active'. | ||
| 95 | |||
| 96 | * If the bus type's ->runtime_resume() callback returns an error code, the PM | ||
| 97 | core regards this as a fatal error and will refuse to run the helper | ||
| 98 | functions described in Section 4 for the device, until its status is | ||
| 99 | directly set either to 'active' or to 'suspended' (the PM core provides | ||
| 100 | special helper functions for this purpose). | ||
| 101 | |||
| 102 | The ->runtime_idle() callback is executed by the PM core for the bus type of | ||
| 103 | given device whenever the device appears to be idle, which is indicated to the | ||
| 104 | PM core by two counters, the device's usage counter and the counter of 'active' | ||
| 105 | children of the device. | ||
| 106 | |||
| 107 | * If any of these counters is decreased using a helper function provided by | ||
| 108 | the PM core and it turns out to be equal to zero, the other counter is | ||
| 109 | checked. If that counter also is equal to zero, the PM core executes the | ||
| 110 | device bus type's ->runtime_idle() callback (with the device as an | ||
| 111 | argument). | ||
| 112 | |||
| 113 | The action performed by a bus type's ->runtime_idle() callback is totally | ||
| 114 | dependent on the bus type in question, but the expected and recommended action | ||
| 115 | is to check if the device can be suspended (i.e. if all of the conditions | ||
| 116 | necessary for suspending the device are satisfied) and to queue up a suspend | ||
| 117 | request for the device in that case. | ||
| 118 | |||
| 119 | The helper functions provided by the PM core, described in Section 4, guarantee | ||
| 120 | that the following constraints are met with respect to the bus type's run-time | ||
| 121 | PM callbacks: | ||
| 122 | |||
| 123 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute | ||
| 124 | ->runtime_suspend() in parallel with ->runtime_resume() or with another | ||
| 125 | instance of ->runtime_suspend() for the same device) with the exception that | ||
| 126 | ->runtime_suspend() or ->runtime_resume() can be executed in parallel with | ||
| 127 | ->runtime_idle() (although ->runtime_idle() will not be started while any | ||
| 128 | of the other callbacks is being executed for the same device). | ||
| 129 | |||
| 130 | (2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' | ||
| 131 | devices (i.e. the PM core will only execute ->runtime_idle() or | ||
| 132 | ->runtime_suspend() for the devices the run-time PM status of which is | ||
| 133 | 'active'). | ||
| 134 | |||
| 135 | (3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device | ||
| 136 | the usage counter of which is equal to zero _and_ either the counter of | ||
| 137 | 'active' children of which is equal to zero, or the 'power.ignore_children' | ||
| 138 | flag of which is set. | ||
| 139 | |||
| 140 | (4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the | ||
| 141 | PM core will only execute ->runtime_resume() for the devices the run-time | ||
| 142 | PM status of which is 'suspended'). | ||
| 143 | |||
| 144 | Additionally, the helper functions provided by the PM core obey the following | ||
| 145 | rules: | ||
| 146 | |||
| 147 | * If ->runtime_suspend() is about to be executed or there's a pending request | ||
| 148 | to execute it, ->runtime_idle() will not be executed for the same device. | ||
| 149 | |||
| 150 | * A request to execute or to schedule the execution of ->runtime_suspend() | ||
| 151 | will cancel any pending requests to execute ->runtime_idle() for the same | ||
| 152 | device. | ||
| 153 | |||
| 154 | * If ->runtime_resume() is about to be executed or there's a pending request | ||
| 155 | to execute it, the other callbacks will not be executed for the same device. | ||
| 156 | |||
| 157 | * A request to execute ->runtime_resume() will cancel any pending or | ||
| 158 | scheduled requests to execute the other callbacks for the same device. | ||
| 159 | |||
| 160 | 3. Run-time PM Device Fields | ||
| 161 | |||
| 162 | The following device run-time PM fields are present in 'struct dev_pm_info', as | ||
| 163 | defined in include/linux/pm.h: | ||
| 164 | |||
| 165 | struct timer_list suspend_timer; | ||
| 166 | - timer used for scheduling (delayed) suspend request | ||
