diff options
Diffstat (limited to 'Documentation/power/runtime_pm.txt')
-rw-r--r-- | Documentation/power/runtime_pm.txt | 268 |
1 files changed, 179 insertions, 89 deletions
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index 22accb3eb40e..6066e3a6b9a9 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt | |||
@@ -1,39 +1,39 @@ | |||
1 | Run-time Power Management Framework for I/O Devices | 1 | Runtime Power Management Framework for I/O Devices |
2 | 2 | ||
3 | (C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | 3 | (C) 2009-2011 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
4 | (C) 2010 Alan Stern <stern@rowland.harvard.edu> | 4 | (C) 2010 Alan Stern <stern@rowland.harvard.edu> |
5 | 5 | ||
6 | 1. Introduction | 6 | 1. Introduction |
7 | 7 | ||
8 | Support for run-time power management (run-time PM) of I/O devices is provided | 8 | Support for runtime power management (runtime PM) of I/O devices is provided |
9 | at the power management core (PM core) level by means of: | 9 | at the power management core (PM core) level by means of: |
10 | 10 | ||
11 | * The power management workqueue pm_wq in which bus types and device drivers can | 11 | * The power management workqueue pm_wq in which bus types and device drivers can |
12 | put their PM-related work items. It is strongly recommended that pm_wq be | 12 | put their PM-related work items. It is strongly recommended that pm_wq be |
13 | used for queuing all work items related to run-time PM, because this allows | 13 | used for queuing all work items related to runtime PM, because this allows |
14 | them to be synchronized with system-wide power transitions (suspend to RAM, | 14 | them to be synchronized with system-wide power transitions (suspend to RAM, |
15 | hibernation and resume from system sleep states). pm_wq is declared in | 15 | hibernation and resume from system sleep states). pm_wq is declared in |
16 | include/linux/pm_runtime.h and defined in kernel/power/main.c. | 16 | include/linux/pm_runtime.h and defined in kernel/power/main.c. |
17 | 17 | ||
18 | * A number of run-time PM fields in the 'power' member of 'struct device' (which | 18 | * A number of runtime PM fields in the 'power' member of 'struct device' (which |
19 | is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can | 19 | is of the type 'struct dev_pm_info', defined in include/linux/pm.h) that can |
20 | be used for synchronizing run-time PM operations with one another. | 20 | be used for synchronizing runtime PM operations with one another. |
21 | 21 | ||
22 | * Three device run-time PM callbacks in 'struct dev_pm_ops' (defined in | 22 | * Three device runtime PM callbacks in 'struct dev_pm_ops' (defined in |
23 | include/linux/pm.h). | 23 | include/linux/pm.h). |
24 | 24 | ||
25 | * A set of helper functions defined in drivers/base/power/runtime.c that can be | 25 | * A set of helper functions defined in drivers/base/power/runtime.c that can be |
26 | used for carrying out run-time PM operations in such a way that the | 26 | used for carrying out runtime PM operations in such a way that the |
27 | synchronization between them is taken care of by the PM core. Bus types and | 27 | synchronization between them is taken care of by the PM core. Bus types and |
28 | device drivers are encouraged to use these functions. | 28 | device drivers are encouraged to use these functions. |
29 | 29 | ||
30 | The run-time PM callbacks present in 'struct dev_pm_ops', the device run-time PM | 30 | The runtime PM callbacks present in 'struct dev_pm_ops', the device runtime PM |
31 | fields of 'struct dev_pm_info' and the core helper functions provided for | 31 | fields of 'struct dev_pm_info' and the core helper functions provided for |
32 | run-time PM are described below. | 32 | runtime PM are described below. |
33 | 33 | ||
34 | 2. Device Run-time PM Callbacks | 34 | 2. Device Runtime PM Callbacks |
35 | 35 | ||
36 | There are three device run-time PM callbacks defined in 'struct dev_pm_ops': | 36 | There are three device runtime PM callbacks defined in 'struct dev_pm_ops': |
37 | 37 | ||
38 | struct dev_pm_ops { | 38 | struct dev_pm_ops { |
39 | ... | 39 | ... |
@@ -54,11 +54,10 @@ referred to as subsystem-level callbacks in what follows. | |||
54 | By default, the callbacks are always invoked in process context with interrupts | 54 | By default, the callbacks are always invoked in process context with interrupts |
55 | enabled. However, subsystems can use the pm_runtime_irq_safe() helper function | 55 | enabled. However, subsystems can use the pm_runtime_irq_safe() helper function |
56 | to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume() | 56 | to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume() |
57 | callbacks should be invoked in atomic context with interrupts disabled | 57 | callbacks should be invoked in atomic context with interrupts disabled. |
58 | (->runtime_idle() is still invoked the default way). This implies that these | 58 | This implies that these callback routines must not block or sleep, but it also |
59 | callback routines must not block or sleep, but it also means that the | 59 | means that the synchronous helper functions listed at the end of Section 4 can |
60 | synchronous helper functions listed at the end of Section 4 can be used within | 60 | be used within an interrupt handler or in an atomic context. |
61 | an interrupt handler or in an atomic context. | ||
62 | 61 | ||
63 | The subsystem-level suspend callback is _entirely_ _responsible_ for handling | 62 | The subsystem-level suspend callback is _entirely_ _responsible_ for handling |
64 | the suspend of the device as appropriate, which may, but need not include | 63 | the suspend of the device as appropriate, which may, but need not include |
@@ -72,11 +71,11 @@ knows what to do to handle the device). | |||
72 | not mean that the device has been put into a low power state. It is | 71 | not mean that the device has been put into a low power state. It is |
73 | supposed to mean, however, that the device will not process data and will | 72 | supposed to mean, however, that the device will not process data and will |
74 | not communicate with the CPU(s) and RAM until the subsystem-level resume | 73 | not communicate with the CPU(s) and RAM until the subsystem-level resume |
75 | callback is executed for it. The run-time PM status of a device after | 74 | callback is executed for it. The runtime PM status of a device after |
76 | successful execution of the subsystem-level suspend callback is 'suspended'. | 75 | successful execution of the subsystem-level suspend callback is 'suspended'. |
77 | 76 | ||
78 | * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, | 77 | * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, |
79 | the device's run-time PM status is 'active', which means that the device | 78 | the device's runtime PM status is 'active', which means that the device |
80 | _must_ be fully operational afterwards. | 79 | _must_ be fully operational afterwards. |
81 | 80 | ||
82 | * If the subsystem-level suspend callback returns an error code different | 81 | * If the subsystem-level suspend callback returns an error code different |
@@ -104,7 +103,7 @@ the device). | |||
104 | 103 | ||
105 | * Once the subsystem-level resume callback has completed successfully, the PM | 104 | * Once the subsystem-level resume callback has completed successfully, the PM |
106 | core regards the device as fully operational, which means that the device | 105 | core regards the device as fully operational, which means that the device |
107 | _must_ be able to complete I/O operations as needed. The run-time PM status | 106 | _must_ be able to complete I/O operations as needed. The runtime PM status |
108 | of the device is then 'active'. | 107 | of the device is then 'active'. |
109 | 108 | ||
110 | * If the subsystem-level resume callback returns an error code, the PM core | 109 | * If the subsystem-level resume callback returns an error code, the PM core |
@@ -130,7 +129,7 @@ device in that case. The value returned by this callback is ignored by the PM | |||
130 | core. | 129 | core. |
131 | 130 | ||
132 | The helper functions provided by the PM core, described in Section 4, guarantee | 131 | The helper functions provided by the PM core, described in Section 4, guarantee |
133 | that the following constraints are met with respect to the bus type's run-time | 132 | that the following constraints are met with respect to the bus type's runtime |
134 | PM callbacks: | 133 | PM callbacks: |
135 | 134 | ||
136 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute | 135 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute |
@@ -142,7 +141,7 @@ PM callbacks: | |||
142 | 141 | ||
143 | (2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' | 142 | (2) ->runtime_idle() and ->runtime_suspend() can only be executed for 'active' |
144 | devices (i.e. the PM core will only execute ->runtime_idle() or | 143 | devices (i.e. the PM core will only execute ->runtime_idle() or |
145 | ->runtime_suspend() for the devices the run-time PM status of which is | 144 | ->runtime_suspend() for the devices the runtime PM status of which is |
146 | 'active'). | 145 | 'active'). |
147 | 146 | ||
148 | (3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device | 147 | (3) ->runtime_idle() and ->runtime_suspend() can only be executed for a device |
@@ -151,7 +150,7 @@ PM callbacks: | |||
151 | flag of which is set. | 150 | flag of which is set. |
152 | 151 | ||
153 | (4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the | 152 | (4) ->runtime_resume() can only be executed for 'suspended' devices (i.e. the |
154 | PM core will only execute ->runtime_resume() for the devices the run-time | 153 | PM core will only execute ->runtime_resume() for the devices the runtime |
155 | PM status of which is 'suspended'). | 154 | PM status of which is 'suspended'). |
156 | 155 | ||
157 | Additionally, the helper functions provided by the PM core obey the following | 156 | Additionally, the helper functions provided by the PM core obey the following |
@@ -171,9 +170,9 @@ rules: | |||
171 | scheduled requests to execute the other callbacks for the same device, | 170 | scheduled requests to execute the other callbacks for the same device, |
172 | except for scheduled autosuspends. | 171 | except for scheduled autosuspends. |
173 | 172 | ||
174 | 3. Run-time PM Device Fields | 173 | 3. Runtime PM Device Fields |
175 | 174 | ||
176 | The following device run-time PM fields are present in 'struct dev_pm_info', as | 175 | The following device runtime PM fields are present in 'struct dev_pm_info', as |
177 | defined in include/linux/pm.h: | 176 | defined in include/linux/pm.h: |
178 | 177 | ||
179 | struct timer_list suspend_timer; | 178 | struct timer_list suspend_timer; |
@@ -205,7 +204,7 @@ defined in include/linux/pm.h: | |||
205 | 204 | ||
206 | unsigned int disable_depth; | 205 | unsigned int disable_depth; |
207 | - used for disabling the helper funcions (they work normally if this is | 206 | - used for disabling the helper funcions (they work normally if this is |
208 | equal to zero); the initial value of it is 1 (i.e. run-time PM is | 207 | equal to zero); the initial value of it is 1 (i.e. runtime PM is |
209 | initially disabled for all devices) | 208 | initially disabled for all devices) |
210 | 209 | ||
211 | unsigned int runtime_error; | 210 | unsigned int runtime_error; |
@@ -229,10 +228,10 @@ defined in include/linux/pm.h: | |||
229 | suspend to complete; means "start a resume as soon as you've suspended" | 228 | suspend to complete; means "start a resume as soon as you've suspended" |
230 | 229 | ||
231 | unsigned int run_wake; | 230 | unsigned int run_wake; |
232 | - set if the device is capable of generating run-time wake-up events | 231 | - set if the device is capable of generating runtime wake-up events |
233 | 232 | ||
234 | enum rpm_status runtime_status; | 233 | enum rpm_status runtime_status; |
235 | - the run-time PM status of the device; this field's initial value is | 234 | - the runtime PM status of the device; this field's initial value is |
236 | RPM_SUSPENDED, which means that each device is initially regarded by the | 235 | RPM_SUSPENDED, which means that each device is initially regarded by the |
237 | PM core as 'suspended', regardless of its real hardware status | 236 | PM core as 'suspended', regardless of its real hardware status |
238 | 237 | ||
@@ -243,7 +242,7 @@ defined in include/linux/pm.h: | |||
243 | and pm_runtime_forbid() helper functions | 242 | and pm_runtime_forbid() helper functions |
244 | 243 | ||
245 | unsigned int no_callbacks; | 244 | unsigned int no_callbacks; |
246 | - indicates that the device does not use the run-time PM callbacks (see | 245 | - indicates that the device does not use the runtime PM callbacks (see |
247 | Section 8); it may be modified only by the pm_runtime_no_callbacks() | 246 | Section 8); it may be modified only by the pm_runtime_no_callbacks() |
248 | helper function | 247 | helper function |
249 | 248 | ||
@@ -270,16 +269,16 @@ defined in include/linux/pm.h: | |||
270 | 269 | ||
271 | All of the above fields are members of the 'power' member of 'struct device'. | 270 | All of the above fields are members of the 'power' member of 'struct device'. |
272 | 271 | ||
273 | 4. Run-time PM Device Helper Functions | 272 | 4. Runtime PM Device Helper Functions |
274 | 273 | ||
275 | The following run-time PM helper functions are defined in | 274 | The following runtime PM helper functions are defined in |
276 | drivers/base/power/runtime.c and include/linux/pm_runtime.h: | 275 | drivers/base/power/runtime.c and include/linux/pm_runtime.h: |
277 | 276 | ||
278 | void pm_runtime_init(struct device *dev); | 277 | void pm_runtime_init(struct device *dev); |
279 | - initialize the device run-time PM fields in 'struct dev_pm_info' | 278 | - initialize the device runtime PM fields in 'struct dev_pm_info' |
280 | 279 | ||
281 | void pm_runtime_remove(struct device *dev); | 280 | void pm_runtime_remove(struct device *dev); |
282 | - make sure that the run-time PM of the device will be disabled after | 281 | - make sure that the runtime PM of the device will be disabled after |
283 | removing the device from device hierarchy | 282 | removing the device from device hierarchy |
284 | 283 | ||
285 | int pm_runtime_idle(struct device *dev); | 284 | int pm_runtime_idle(struct device *dev); |
@@ -289,9 +288,10 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
289 | 288 | ||
290 | int pm_runtime_suspend(struct device *dev); | 289 | int pm_runtime_suspend(struct device *dev); |
291 | - execute the subsystem-level suspend callback for the device; returns 0 on | 290 | - execute the subsystem-level suspend callback for the device; returns 0 on |
292 | success, 1 if the device's run-time PM status was already 'suspended', or | 291 | success, 1 if the device's runtime PM status was already 'suspended', or |
293 | error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt | 292 | error code on failure, where -EAGAIN or -EBUSY means it is safe to attempt |
294 | to suspend the device again in future | 293 | to suspend the device again in future and -EACCES means that |
294 | 'power.disable_depth' is different from 0 | ||
295 | 295 | ||
296 | int pm_runtime_autosuspend(struct device *dev); | 296 | int pm_runtime_autosuspend(struct device *dev); |
297 | - same as pm_runtime_suspend() except that the autosuspend delay is taken | 297 | - same as pm_runtime_suspend() except that the autosuspend delay is taken |
@@ -301,10 +301,11 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
301 | 301 | ||
302 | int pm_runtime_resume(struct device *dev); | 302 | int pm_runtime_resume(struct device *dev); |
303 | - execute the subsystem-level resume callback for the device; returns 0 on | 303 | - execute the subsystem-level resume callback for the device; returns 0 on |
304 | success, 1 if the device's run-time PM status was already 'active' or | 304 | success, 1 if the device's runtime PM status was already 'active' or |
305 | error code on failure, where -EAGAIN means it may be safe to attempt to | 305 | error code on failure, where -EAGAIN means it may be safe to attempt to |
306 | resume the device again in future, but 'power.runtime_error' should be | 306 | resume the device again in future, but 'power.runtime_error' should be |
307 | checked additionally | 307 | checked additionally, and -EACCES means that 'power.disable_depth' is |
308 | different from 0 | ||
308 | 309 | ||
309 | int pm_request_idle(struct device *dev); | 310 | int pm_request_idle(struct device *dev); |
310 | - submit a request to execute the subsystem-level idle callback for the | 311 | - submit a request to execute the subsystem-level idle callback for the |
@@ -321,7 +322,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
321 | device in future, where 'delay' is the time to wait before queuing up a | 322 | device in future, where 'delay' is the time to wait before queuing up a |
322 | suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work | 323 | suspend work item in pm_wq, in milliseconds (if 'delay' is zero, the work |
323 | item is queued up immediately); returns 0 on success, 1 if the device's PM | 324 | item is queued up immediately); returns 0 on success, 1 if the device's PM |
324 | run-time status was already 'suspended', or error code if the request | 325 | runtime status was already 'suspended', or error code if the request |
325 | hasn't been scheduled (or queued up if 'delay' is 0); if the execution of | 326 | hasn't been scheduled (or queued up if 'delay' is 0); if the execution of |
326 | ->runtime_suspend() is already scheduled and not yet expired, the new | 327 | ->runtime_suspend() is already scheduled and not yet expired, the new |
327 | value of 'delay' will be used as the time to wait | 328 | value of 'delay' will be used as the time to wait |
@@ -329,7 +330,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
329 | int pm_request_resume(struct device *dev); | 330 | int pm_request_resume(struct device *dev); |
330 | - submit a request to execute the subsystem-level resume callback for the | 331 | - submit a request to execute the subsystem-level resume callback for the |
331 | device (the request is represented by a work item in pm_wq); returns 0 on | 332 | device (the request is represented by a work item in pm_wq); returns 0 on |
332 | success, 1 if the device's run-time PM status was already 'active', or | 333 | success, 1 if the device's runtime PM status was already 'active', or |
333 | error code if the request hasn't been queued up | 334 | error code if the request hasn't been queued up |
334 | 335 | ||
335 | void pm_runtime_get_noresume(struct device *dev); | 336 | void pm_runtime_get_noresume(struct device *dev); |
@@ -367,22 +368,32 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
367 | pm_runtime_autosuspend(dev) and return its result | 368 | pm_runtime_autosuspend(dev) and return its result |
368 | 369 | ||
369 | void pm_runtime_enable(struct device *dev); | 370 | void pm_runtime_enable(struct device *dev); |
370 | - enable the run-time PM helper functions to run the device bus type's | 371 | - decrement the device's 'power.disable_depth' field; if that field is equal |
371 | run-time PM callbacks described in Section 2 | 372 | to zero, the runtime PM helper functions can execute subsystem-level |
373 | callbacks described in Section 2 for the device | ||
372 | 374 | ||
373 | int pm_runtime_disable(struct device *dev); | 375 | int pm_runtime_disable(struct device *dev); |
374 | - prevent the run-time PM helper functions from running subsystem-level | 376 | - increment the device's 'power.disable_depth' field (if the value of that |
375 | run-time PM callbacks for the device, make sure that all of the pending | 377 | field was previously zero, this prevents subsystem-level runtime PM |
376 | run-time PM operations on the device are either completed or canceled; | 378 | callbacks from being run for the device), make sure that all of the pending |
379 | runtime PM operations on the device are either completed or canceled; | ||
377 | returns 1 if there was a resume request pending and it was necessary to | 380 | returns 1 if there was a resume request pending and it was necessary to |
378 | execute the subsystem-level resume callback for the device to satisfy that | 381 | execute the subsystem-level resume callback for the device to satisfy that |
379 | request, otherwise 0 is returned | 382 | request, otherwise 0 is returned |
380 | 383 | ||
384 | int pm_runtime_barrier(struct device *dev); | ||
385 | - check if there's a resume request pending for the device and resume it | ||
386 | (synchronously) in that case, cancel any other pending runtime PM requests | ||
387 | regarding it and wait for all runtime PM operations on it in progress to | ||
388 | complete; returns 1 if there was a resume request pending and it was | ||
389 | necessary to execute the subsystem-level resume callback for the device to | ||
390 | satisfy that request, otherwise 0 is returned | ||
391 | |||
381 | void pm_suspend_ignore_children(struct device *dev, bool enable); | 392 | void pm_suspend_ignore_children(struct device *dev, bool enable); |
382 | - set/unset the power.ignore_children flag of the device | 393 | - set/unset the power.ignore_children flag of the device |
383 | 394 | ||
384 | int pm_runtime_set_active(struct device *dev); | 395 | int pm_runtime_set_active(struct device *dev); |
385 | - clear the device's 'power.runtime_error' flag, set the device's run-time | 396 | - clear the device's 'power.runtime_error' flag, set the device's runtime |
386 | PM status to 'active' and update its parent's counter of 'active' | 397 | PM status to 'active' and update its parent's counter of 'active' |
387 | children as appropriate (it is only valid to use this function if | 398 | children as appropriate (it is only valid to use this function if |
388 | 'power.runtime_error' is set or 'power.disable_depth' is greater than | 399 | 'power.runtime_error' is set or 'power.disable_depth' is greater than |
@@ -390,7 +401,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
390 | which is not active and the 'power.ignore_children' flag of which is unset | 401 | which is not active and the 'power.ignore_children' flag of which is unset |
391 | 402 | ||
392 | void pm_runtime_set_suspended(struct device *dev); | 403 | void pm_runtime_set_suspended(struct device *dev); |
393 | - clear the device's 'power.runtime_error' flag, set the device's run-time | 404 | - clear the device's 'power.runtime_error' flag, set the device's runtime |
394 | PM status to 'suspended' and update its parent's counter of 'active' | 405 | PM status to 'suspended' and update its parent's counter of 'active' |
395 | children as appropriate (it is only valid to use this function if | 406 | children as appropriate (it is only valid to use this function if |
396 | 'power.runtime_error' is set or 'power.disable_depth' is greater than | 407 | 'power.runtime_error' is set or 'power.disable_depth' is greater than |
@@ -400,6 +411,9 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
400 | - return true if the device's runtime PM status is 'suspended' and its | 411 | - return true if the device's runtime PM status is 'suspended' and its |
401 | 'power.disable_depth' field is equal to zero, or false otherwise | 412 | 'power.disable_depth' field is equal to zero, or false otherwise |
402 | 413 | ||
414 | bool pm_runtime_status_suspended(struct device *dev); | ||
415 | - return true if the device's runtime PM status is 'suspended' | ||
416 | |||
403 | void pm_runtime_allow(struct device *dev); | 417 | void pm_runtime_allow(struct device *dev); |
404 | - set the power.runtime_auto flag for the device and decrease its usage | 418 | - set the power.runtime_auto flag for the device and decrease its usage |
405 | counter (used by the /sys/devices/.../power/control interface to | 419 | counter (used by the /sys/devices/.../power/control interface to |
@@ -411,14 +425,13 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
411 | effectively prevent the device from being power managed at run time) | 425 | effectively prevent the device from being power managed at run time) |
412 | 426 | ||
413 | void pm_runtime_no_callbacks(struct device *dev); | 427 | void pm_runtime_no_callbacks(struct device *dev); |
414 | - set the power.no_callbacks flag for the device and remove the run-time | 428 | - set the power.no_callbacks flag for the device and remove the runtime |
415 | PM attributes from /sys/devices/.../power (or prevent them from being | 429 | PM attributes from /sys/devices/.../power (or prevent them from being |
416 | added when the device is registered) | 430 | added when the device is registered) |
417 | 431 | ||
418 | void pm_runtime_irq_safe(struct device *dev); | 432 | void pm_runtime_irq_safe(struct device *dev); |
419 | - set the power.irq_safe flag for the device, causing the runtime-PM | 433 | - set the power.irq_safe flag for the device, causing the runtime-PM |
420 | suspend and resume callbacks (but not the idle callback) to be invoked | 434 | callbacks to be invoked with interrupts off |
421 | with interrupts disabled | ||
422 | 435 | ||
423 | void pm_runtime_mark_last_busy(struct device *dev); | 436 | void pm_runtime_mark_last_busy(struct device *dev); |
424 | - set the power.last_busy field to the current time | 437 | - set the power.last_busy field to the current time |
@@ -431,7 +444,7 @@ drivers/base/power/runtime.c and include/linux/pm_runtime.h: | |||
431 | 444 | ||
432 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); | 445 | void pm_runtime_set_autosuspend_delay(struct device *dev, int delay); |
433 | - set the power.autosuspend_delay value to 'delay' (expressed in | 446 | - set the power.autosuspend_delay value to 'delay' (expressed in |
434 | milliseconds); if 'delay' is negative then run-time suspends are | 447 | milliseconds); if 'delay' is negative then runtime suspends are |
435 | prevented | 448 | prevented |
436 | 449 | ||
437 | unsigned long pm_runtime_autosuspend_expiration(struct device *dev); | 450 | unsigned long pm_runtime_autosuspend_expiration(struct device *dev); |
@@ -468,78 +481,95 @@ pm_runtime_suspend() | |||
468 | pm_runtime_autosuspend() | 481 | pm_runtime_autosuspend() |
469 | pm_runtime_resume() | 482 | pm_runtime_resume() |
470 | pm_runtime_get_sync() | 483 | pm_runtime_get_sync() |
484 | pm_runtime_put_sync() | ||
471 | pm_runtime_put_sync_suspend() | 485 | pm_runtime_put_sync_suspend() |
472 | 486 | ||
473 | 5. Run-time PM Initialization, Device Probing and Removal | 487 | 5. Runtime PM Initialization, Device Probing and Removal |
474 | 488 | ||
475 | Initially, the run-time PM is disabled for all devices, which means that the | 489 | Initially, the runtime PM is disabled for all devices, which means that the |
476 | majority of the run-time PM helper funtions described in Section 4 will return | 490 | majority of the runtime PM helper funtions described in Section 4 will return |
477 | -EAGAIN until pm_runtime_enable() is called for the device. | 491 | -EAGAIN until pm_runtime_enable() is called for the device. |
478 | 492 | ||
479 | In addition to that, the initial run-time PM status of all devices is | 493 | In addition to that, the initial runtime PM status of all devices is |
480 | 'suspended', but it need not reflect the actual physical state of the device. | 494 | 'suspended', but it need not reflect the actual physical state of the device. |
481 | Thus, if the device is initially active (i.e. it is able to process I/O), its | 495 | Thus, if the device is initially active (i.e. it is able to process I/O), its |
482 | run-time PM status must be changed to 'active', with the help of | 496 | runtime PM status must be changed to 'active', with the help of |
483 | pm_runtime_set_active(), before pm_runtime_enable() is called for the device. | 497 | pm_runtime_set_active(), before pm_runtime_enable() is called for the device. |
484 | 498 | ||
485 | However, if the device has a parent and the parent's run-time PM is enabled, | 499 | However, if the device has a parent and the parent's runtime PM is enabled, |
486 | calling pm_runtime_set_active() for the device will affect the parent, unless | 500 | calling pm_runtime_set_active() for the device will affect the parent, unless |
487 | the parent's 'power.ignore_children' flag is set. Namely, in that case the | 501 | the parent's 'power.ignore_children' flag is set. Namely, in that case the |
488 | parent won't be able to suspend at run time, using the PM core's helper | 502 | parent won't be able to suspend at run time, using the PM core's helper |
489 | functions, as long as the child's status is 'active', even if the child's | 503 | functions, as long as the child's status is 'active', even if the child's |
490 | run-time PM is still disabled (i.e. pm_runtime_enable() hasn't been called for | 504 | runtime PM is still disabled (i.e. pm_runtime_enable() hasn't been called for |
491 | the child yet or pm_runtime_disable() has been called for it). For this reason, | 505 | the child yet or pm_runtime_disable() has been called for it). For this reason, |
492 | once pm_runtime_set_active() has been called for the device, pm_runtime_enable() | 506 | once pm_runtime_set_active() has been called for the device, pm_runtime_enable() |
493 | should be called for it too as soon as reasonably possible or its run-time PM | 507 | should be called for it too as soon as reasonably possible or its runtime PM |
494 | status should be changed back to 'suspended' with the help of | 508 | status should be changed back to 'suspended' with the help of |
495 | pm_runtime_set_suspended(). | 509 | pm_runtime_set_suspended(). |
496 | 510 | ||
497 | If the default initial run-time PM status of the device (i.e. 'suspended') | 511 | If the default initial runtime PM status of the device (i.e. 'suspended') |
498 | reflects the actual state of the device, its bus type's or its driver's | 512 | reflects the actual state of the device, its bus type's or its driver's |
499 | ->probe() callback will likely need to wake it up using one of the PM core's | 513 | ->probe() callback will likely need to wake it up using one of the PM core's |
500 | helper functions described in Section 4. In that case, pm_runtime_resume() | 514 | helper functions described in Section 4. In that case, pm_runtime_resume() |
501 | should be used. Of course, for this purpose the device's run-time PM has to be | 515 | should be used. Of course, for this purpose the device's runtime PM has to be |
502 | enabled earlier by calling pm_runtime_enable(). | 516 | enabled earlier by calling pm_runtime_enable(). |
503 | 517 | ||
504 | If the device bus type's or driver's ->probe() or ->remove() callback runs | 518 | If the device bus type's or driver's ->probe() callback runs |
505 | pm_runtime_suspend() or pm_runtime_idle() or their asynchronous counterparts, | 519 | pm_runtime_suspend() or pm_runtime_idle() or their asynchronous counterparts, |
506 | they will fail returning -EAGAIN, because the device's usage counter is | 520 | they will fail returning -EAGAIN, because the device's usage counter is |
507 | incremented by the core before executing ->probe() and ->remove(). Still, it | 521 | incremented by the driver core before executing ->probe(). Still, it may be |
508 | may be desirable to suspend the device as soon as ->probe() or ->remove() has | 522 | desirable to suspend the device as soon as ->probe() has finished, so the driver |
509 | finished, so the PM core uses pm_runtime_idle_sync() to invoke the | 523 | core uses pm_runtime_put_sync() to invoke the subsystem-level idle callback for |
510 | subsystem-level idle callback for the device at that time. | 524 | the device at that time. |
525 | |||
526 | Moreover, the driver core prevents runtime PM callbacks from racing with the bus | ||
527 | notifier callback in __device_release_driver(), which is necessary, because the | ||
528 | notifier is used by some subsystems to carry out operations affecting the | ||
529 | runtime PM functionality. It does so by calling pm_runtime_get_sync() before | ||
530 | driver_sysfs_remove() and the BUS_NOTIFY_UNBIND_DRIVER notifications. This | ||
531 | resumes the device if it's in the suspended state and prevents it from | ||
532 | being suspended again while those routines are being executed. | ||
533 | |||
534 | To allow bus types and drivers to put devices into the suspended state by | ||
535 | calling pm_runtime_suspend() from their ->remove() routines, the driver core | ||
536 | executes pm_runtime_put_sync() after running the BUS_NOTIFY_UNBIND_DRIVER | ||
537 | notifications in __device_release_driver(). This requires bus types and | ||
538 | drivers to make their ->remove() callbacks avoid races with runtime PM directly, | ||
539 | but also it allows of more flexibility in the handling of devices during the | ||
540 | removal of their drivers. | ||
511 | 541 | ||
512 | The user space can effectively disallow the driver of the device to power manage | 542 | The user space can effectively disallow the driver of the device to power manage |
513 | it at run time by changing the value of its /sys/devices/.../power/control | 543 | it at run time by changing the value of its /sys/devices/.../power/control |
514 | attribute to "on", which causes pm_runtime_forbid() to be called. In principle, | 544 | attribute to "on", which causes pm_runtime_forbid() to be called. In principle, |
515 | this mechanism may also be used by the driver to effectively turn off the | 545 | this mechanism may also be used by the driver to effectively turn off the |
516 | run-time power management of the device until the user space turns it on. | 546 | runtime power management of the device until the user space turns it on. |
517 | Namely, during the initialization the driver can make sure that the run-time PM | 547 | Namely, during the initialization the driver can make sure that the runtime PM |
518 | status of the device is 'active' and call pm_runtime_forbid(). It should be | 548 | status of the device is 'active' and call pm_runtime_forbid(). It should be |
519 | noted, however, that if the user space has already intentionally changed the | 549 | noted, however, that if the user space has already intentionally changed the |
520 | value of /sys/devices/.../power/control to "auto" to allow the driver to power | 550 | value of /sys/devices/.../power/control to "auto" to allow the driver to power |
521 | manage the device at run time, the driver may confuse it by using | 551 | manage the device at run time, the driver may confuse it by using |
522 | pm_runtime_forbid() this way. | 552 | pm_runtime_forbid() this way. |
523 | 553 | ||
524 | 6. Run-time PM and System Sleep | 554 | 6. Runtime PM and System Sleep |
525 | 555 | ||
526 | Run-time PM and system sleep (i.e., system suspend and hibernation, also known | 556 | Runtime PM and system sleep (i.e., system suspend and hibernation, also known |
527 | as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of | 557 | as suspend-to-RAM and suspend-to-disk) interact with each other in a couple of |
528 | ways. If a device is active when a system sleep starts, everything is | 558 | ways. If a device is active when a system sleep starts, everything is |
529 | straightforward. But what should happen if the device is already suspended? | 559 | straightforward. But what should happen if the device is already suspended? |
530 | 560 | ||
531 | The device may have different wake-up settings for run-time PM and system sleep. | 561 | The device may have different wake-up settings for runtime PM and system sleep. |
532 | For example, remote wake-up may be enabled for run-time suspend but disallowed | 562 | For example, remote wake-up may be enabled for runtime suspend but disallowed |
533 | for system sleep (device_may_wakeup(dev) returns 'false'). When this happens, | 563 | for system sleep (device_may_wakeup(dev) returns 'false'). When this happens, |
534 | the subsystem-level system suspend callback is responsible for changing the | 564 | the subsystem-level system suspend callback is responsible for changing the |
535 | device's wake-up setting (it may leave that to the device driver's system | 565 | device's wake-up setting (it may leave that to the device driver's system |
536 | suspend routine). It may be necessary to resume the device and suspend it again | 566 | suspend routine). It may be necessary to resume the device and suspend it again |
537 | in order to do so. The same is true if the driver uses different power levels | 567 | in order to do so. The same is true if the driver uses different power levels |
538 | or other settings for run-time suspend and system sleep. | 568 | or other settings for runtime suspend and system sleep. |
539 | 569 | ||
540 | During system resume, devices generally should be brought back to full power, | 570 | During system resume, the simplest approach is to bring all devices back to full |
541 | even if they were suspended before the system sleep began. There are several | 571 | power, even if they had been suspended before the system suspend began. There |
542 | reasons for this, including: | 572 | are several reasons for this, including: |
543 | 573 | ||
544 | * The device might need to switch power levels, wake-up settings, etc. | 574 | * The device might need to switch power levels, wake-up settings, etc. |
545 | 575 | ||
@@ -554,18 +584,50 @@ reasons for this, including: | |||
554 | * The device might need to be reset. | 584 | * The device might need to be reset. |
555 | 585 | ||
556 | * Even though the device was suspended, if its usage counter was > 0 then most | 586 | * Even though the device was suspended, if its usage counter was > 0 then most |
557 | likely it would need a run-time resume in the near future anyway. | 587 | likely it would need a runtime resume in the near future anyway. |
558 | |||
559 | * Always going back to full power is simplest. | ||
560 | 588 | ||
561 | If the device was suspended before the sleep began, then its run-time PM status | 589 | If the device had been suspended before the system suspend began and it's |
562 | will have to be updated to reflect the actual post-system sleep status. The way | 590 | brought back to full power during resume, then its runtime PM status will have |
563 | to do this is: | 591 | to be updated to reflect the actual post-system sleep status. The way to do |
592 | this is: | ||
564 | 593 | ||
565 | pm_runtime_disable(dev); | 594 | pm_runtime_disable(dev); |
566 | pm_runtime_set_active(dev); | 595 | pm_runtime_set_active(dev); |
567 | pm_runtime_enable(dev); | 596 | pm_runtime_enable(dev); |
568 | 597 | ||
598 | The PM core always increments the runtime usage counter before calling the | ||
599 | ->suspend() callback and decrements it after calling the ->resume() callback. | ||
600 | Hence disabling runtime PM temporarily like this will not cause any runtime | ||
601 | suspend attempts to be permanently lost. If the usage count goes to zero | ||
602 | following the return of the ->resume() callback, the ->runtime_idle() callback | ||
603 | will be invoked as usual. | ||
604 | |||
605 | On some systems, however, system sleep is not entered through a global firmware | ||
606 | or hardware operation. Instead, all hardware components are put into low-power | ||
607 | states directly by the kernel in a coordinated way. Then, the system sleep | ||
608 | state effectively follows from the states the hardware components end up in | ||
609 | and the system is woken up from that state by a hardware interrupt or a similar | ||
610 | mechanism entirely under the kernel's control. As a result, the kernel never | ||
611 | gives control away and the states of all devices during resume are precisely | ||
612 | known to it. If that is the case and none of the situations listed above takes | ||
613 | place (in particular, if the system is not waking up from hibernation), it may | ||
614 | be more efficient to leave the devices that had been suspended before the system | ||
615 | suspend began in the suspended state. | ||
616 | |||
617 | The PM core does its best to reduce the probability of race conditions between | ||
618 | the runtime PM and system suspend/resume (and hibernation) callbacks by carrying | ||
619 | out the following operations: | ||
620 | |||
621 | * During system suspend it calls pm_runtime_get_noresume() and | ||
622 | pm_runtime_barrier() for every device right before executing the | ||
623 | subsystem-level .suspend() callback for it. In addition to that it calls | ||
624 | pm_runtime_disable() for every device right after executing the | ||
625 | subsystem-level .suspend() callback for it. | ||
626 | |||
627 | * During system resume it calls pm_runtime_enable() and pm_runtime_put_sync() | ||
628 | for every device right before and right after executing the subsystem-level | ||
629 | .resume() callback for it, respectively. | ||
630 | |||
569 | 7. Generic subsystem callbacks | 631 | 7. Generic subsystem callbacks |
570 | 632 | ||
571 | Subsystems may wish to conserve code space by using the set of generic power | 633 | Subsystems may wish to conserve code space by using the set of generic power |
@@ -590,40 +652,68 @@ driver/base/power/generic_ops.c: | |||
590 | callback provided by its driver and return its result, or return 0 if not | 652 | callback provided by its driver and return its result, or return 0 if not |
591 | defined | 653 | defined |
592 | 654 | ||
655 | int pm_generic_suspend_noirq(struct device *dev); | ||
656 | - if pm_runtime_suspended(dev) returns "false", invoke the ->suspend_noirq() | ||
657 | callback provided by the device's driver and return its result, or return | ||
658 | 0 if not defined | ||
659 | |||
593 | int pm_generic_resume(struct device *dev); | 660 | int pm_generic_resume(struct device *dev); |
594 | - invoke the ->resume() callback provided by the driver of this device and, | 661 | - invoke the ->resume() callback provided by the driver of this device and, |
595 | if successful, change the device's runtime PM status to 'active' | 662 | if successful, change the device's runtime PM status to 'active' |
596 | 663 | ||
664 | int pm_generic_resume_noirq(struct device *dev); | ||
665 | - invoke the ->resume_noirq() callback provided by the driver of this device | ||
666 | |||
597 | int pm_generic_freeze(struct device *dev); | 667 | int pm_generic_freeze(struct device *dev); |
598 | - if the device has not been suspended at run time, invoke the ->freeze() | 668 | - if the device has not been suspended at run time, invoke the ->freeze() |
599 | callback provided by its driver and return its result, or return 0 if not | 669 | callback provided by its driver and return its result, or return 0 if not |
600 | defined | 670 | defined |
601 | 671 | ||
672 | int pm_generic_freeze_noirq(struct device *dev); | ||
673 | - if pm_runtime_suspended(dev) returns "false", invoke the ->freeze_noirq() | ||
674 | callback provided by the device's driver and return its result, or return | ||
675 | 0 if not defined | ||
676 | |||
602 | int pm_generic_thaw(struct device *dev); | 677 | int pm_generic_thaw(struct device *dev); |
603 | - if the device has not been suspended at run time, invoke the ->thaw() | 678 | - if the device has not been suspended at run time, invoke the ->thaw() |
604 | callback provided by its driver and return its result, or return 0 if not | 679 | callback provided by its driver and return its result, or return 0 if not |
605 | defined | 680 | defined |
606 | 681 | ||
682 | int pm_generic_thaw_noirq(struct device *dev); | ||
683 | - if pm_runtime_suspended(dev) returns "false", invoke the ->thaw_noirq() | ||
684 | callback provided by the device's driver and return its result, or return | ||
685 | 0 if not defined | ||
686 | |||
607 | int pm_generic_poweroff(struct device *dev); | 687 | int pm_generic_poweroff(struct device *dev); |
608 | - if the device has not been suspended at run time, invoke the ->poweroff() | 688 | - if the device has not been suspended at run time, invoke the ->poweroff() |
609 | callback provided by its driver and return its result, or return 0 if not | 689 | callback provided by its driver and return its result, or return 0 if not |
610 | defined | 690 | defined |
611 | 691 | ||
692 | int pm_generic_poweroff_noirq(struct device *dev); | ||
693 | - if pm_runtime_suspended(dev) returns "false", run the ->poweroff_noirq() | ||
694 | callback provided by the device's driver and return its result, or return | ||
695 | 0 if not defined | ||
696 | |||
612 | int pm_generic_restore(struct device *dev); | 697 | int pm_generic_restore(struct device *dev); |
613 | - invoke the ->restore() callback provided by the driver of this device and, | 698 | - invoke the ->restore() callback provided by the driver of this device and, |
614 | if successful, change the device's runtime PM status to 'active' | 699 | if successful, change the device's runtime PM status to 'active' |
615 | 700 | ||
701 | int pm_generic_restore_noirq(struct device *dev); | ||
702 | - invoke the ->restore_noirq() callback provided by the device's driver | ||
703 | |||
616 | These functions can be assigned to the ->runtime_idle(), ->runtime_suspend(), | 704 | These functions can be assigned to the ->runtime_idle(), ->runtime_suspend(), |
617 | ->runtime_resume(), ->suspend(), ->resume(), ->freeze(), ->thaw(), ->poweroff(), | 705 | ->runtime_resume(), ->suspend(), ->suspend_noirq(), ->resume(), |
618 | or ->restore() callback pointers in the subsystem-level dev_pm_ops structures. | 706 | ->resume_noirq(), ->freeze(), ->freeze_noirq(), ->thaw(), ->thaw_noirq(), |
707 | ->poweroff(), ->poweroff_noirq(), ->restore(), ->restore_noirq() callback | ||
708 | pointers in the subsystem-level dev_pm_ops structures. | ||
619 | 709 | ||
620 | If a subsystem wishes to use all of them at the same time, it can simply assign | 710 | If a subsystem wishes to use all of them at the same time, it can simply assign |
621 | the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its | 711 | the GENERIC_SUBSYS_PM_OPS macro, defined in include/linux/pm.h, to its |
622 | dev_pm_ops structure pointer. | 712 | dev_pm_ops structure pointer. |
623 | 713 | ||
624 | Device drivers that wish to use the same function as a system suspend, freeze, | 714 | Device drivers that wish to use the same function as a system suspend, freeze, |
625 | poweroff and run-time suspend callback, and similarly for system resume, thaw, | 715 | poweroff and runtime suspend callback, and similarly for system resume, thaw, |
626 | restore, and run-time resume, can achieve this with the help of the | 716 | restore, and runtime resume, can achieve this with the help of the |
627 | UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its | 717 | UNIVERSAL_DEV_PM_OPS macro defined in include/linux/pm.h (possibly setting its |
628 | last argument to NULL). | 718 | last argument to NULL). |
629 | 719 | ||
@@ -633,7 +723,7 @@ Some "devices" are only logical sub-devices of their parent and cannot be | |||
633 | power-managed on their own. (The prototype example is a USB interface. Entire | 723 | power-managed on their own. (The prototype example is a USB interface. Entire |
634 | USB devices can go into low-power mode or send wake-up requests, but neither is | 724 | USB devices can go into low-power mode or send wake-up requests, but neither is |
635 | possible for individual interfaces.) The drivers for these devices have no | 725 | possible for individual interfaces.) The drivers for these devices have no |
636 | need of run-time PM callbacks; if the callbacks did exist, ->runtime_suspend() | 726 | need of runtime PM callbacks; if the callbacks did exist, ->runtime_suspend() |
637 | and ->runtime_resume() would always return 0 without doing anything else and | 727 | and ->runtime_resume() would always return 0 without doing anything else and |
638 | ->runtime_idle() would always call pm_runtime_suspend(). | 728 | ->runtime_idle() would always call pm_runtime_suspend(). |
639 | 729 | ||
@@ -641,7 +731,7 @@ Subsystems can tell the PM core about these devices by calling | |||
641 | pm_runtime_no_callbacks(). This should be done after the device structure is | 731 | pm_runtime_no_callbacks(). This should be done after the device structure is |
642 | initialized and before it is registered (although after device registration is | 732 | initialized and before it is registered (although after device registration is |
643 | also okay). The routine will set the device's power.no_callbacks flag and | 733 | also okay). The routine will set the device's power.no_callbacks flag and |
644 | prevent the non-debugging run-time PM sysfs attributes from being created. | 734 | prevent the non-debugging runtime PM sysfs attributes from being created. |
645 | 735 | ||
646 | When power.no_callbacks is set, the PM core will not invoke the | 736 | When power.no_callbacks is set, the PM core will not invoke the |
647 | ->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks. | 737 | ->runtime_idle(), ->runtime_suspend(), or ->runtime_resume() callbacks. |
@@ -649,7 +739,7 @@ Instead it will assume that suspends and resumes always succeed and that idle | |||
649 | devices should be suspended. | 739 | devices should be suspended. |
650 | 740 | ||
651 | As a consequence, the PM core will never directly inform the device's subsystem | 741 | As a consequence, the PM core will never directly inform the device's subsystem |
652 | or driver about run-time power changes. Instead, the driver for the device's | 742 | or driver about runtime power changes. Instead, the driver for the device's |
653 | parent must take responsibility for telling the device's driver when the | 743 | parent must take responsibility for telling the device's driver when the |
654 | parent's power state changes. | 744 | parent's power state changes. |
655 | 745 | ||
@@ -660,13 +750,13 @@ A device should be put in a low-power state only when there's some reason to | |||
660 | think it will remain in that state for a substantial time. A common heuristic | 750 | think it will remain in that state for a substantial time. A common heuristic |
661 | says that a device which hasn't been used for a while is liable to remain | 751 | says that a device which hasn't been used for a while is liable to remain |
662 | unused; following this advice, drivers should not allow devices to be suspended | 752 | unused; following this advice, drivers should not allow devices to be suspended |
663 | at run-time until they have been inactive for some minimum period. Even when | 753 | at runtime until they have been inactive for some minimum period. Even when |
664 | the heuristic ends up being non-optimal, it will still prevent devices from | 754 | the heuristic ends up being non-optimal, it will still prevent devices from |
665 | "bouncing" too rapidly between low-power and full-power states. | 755 | "bouncing" too rapidly between low-power and full-power states. |
666 | 756 | ||
667 | The term "autosuspend" is an historical remnant. It doesn't mean that the | 757 | The term "autosuspend" is an historical remnant. It doesn't mean that the |
668 | device is automatically suspended (the subsystem or driver still has to call | 758 | device is automatically suspended (the subsystem or driver still has to call |
669 | the appropriate PM routines); rather it means that run-time suspends will | 759 | the appropriate PM routines); rather it means that runtime suspends will |
670 | automatically be delayed until the desired period of inactivity has elapsed. | 760 | automatically be delayed until the desired period of inactivity has elapsed. |
671 | 761 | ||
672 | Inactivity is determined based on the power.last_busy field. Drivers should | 762 | Inactivity is determined based on the power.last_busy field. Drivers should |