diff options
author | Alan Stern <stern@rowland.harvard.edu> | 2010-03-26 18:53:55 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rjw@sisk.pl> | 2010-05-10 17:08:16 -0400 |
commit | d6f9cda1fd241bc7a1d896da94950fd972eca9b7 (patch) | |
tree | e2429cbfb7b59e52c77672a85c9e0ef1aa8c759e /Documentation/power | |
parent | 624f6ec871886525ca19cf7841f918da91d4315e (diff) |
PM: Improve device power management document
Improve the device power management document after it's been
updated by the previous patch.
Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Diffstat (limited to 'Documentation/power')
-rw-r--r-- | Documentation/power/devices.txt | 811 |
1 files changed, 383 insertions, 428 deletions
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt index 10018d19e0b..57080cd7457 100644 --- a/Documentation/power/devices.txt +++ b/Documentation/power/devices.txt | |||
@@ -1,11 +1,13 @@ | |||
1 | Device Power Management | 1 | Device Power Management |
2 | 2 | ||
3 | (C) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. | 3 | Copyright (c) 2010 Rafael J. Wysocki <rjw@sisk.pl>, Novell Inc. |
4 | Copyright (c) 2010 Alan Stern <stern@rowland.harvard.edu> | ||
5 | |||
4 | 6 | ||
5 | Most of the code in Linux is device drivers, so most of the Linux power | 7 | Most of the code in Linux is device drivers, so most of the Linux power |
6 | management code is also driver-specific. Most drivers will do very little; | 8 | management (PM) code is also driver-specific. Most drivers will do very |
7 | others, especially for platforms with small batteries (like cell phones), | 9 | little; others, especially for platforms with small batteries (like cell |
8 | will do a lot. | 10 | phones), will do a lot. |
9 | 11 | ||
10 | This writeup gives an overview of how drivers interact with system-wide | 12 | This writeup gives an overview of how drivers interact with system-wide |
11 | power management goals, emphasizing the models and interfaces that are | 13 | power management goals, emphasizing the models and interfaces that are |
@@ -19,9 +21,10 @@ Drivers will use one or both of these models to put devices into low-power | |||
19 | states: | 21 | states: |
20 | 22 | ||
21 | System Sleep model: | 23 | System Sleep model: |
22 | Drivers can enter low power states as part of entering system-wide | 24 | Drivers can enter low-power states as part of entering system-wide |
23 | low-power states like "suspend-to-ram", or (mostly for systems with | 25 | low-power states like "suspend" (also known as "suspend-to-RAM"), or |
24 | disks) "hibernate" (suspend-to-disk). | 26 | (mostly for systems with disks) "hibernation" (also known as |
27 | "suspend-to-disk"). | ||
25 | 28 | ||
26 | This is something that device, bus, and class drivers collaborate on | 29 | This is something that device, bus, and class drivers collaborate on |
27 | by implementing various role-specific suspend and resume methods to | 30 | by implementing various role-specific suspend and resume methods to |
@@ -29,41 +32,41 @@ states: | |||
29 | them without loss of data. | 32 | them without loss of data. |
30 | 33 | ||
31 | Some drivers can manage hardware wakeup events, which make the system | 34 | Some drivers can manage hardware wakeup events, which make the system |
32 | leave that low-power state. This feature may be enabled or disabled | 35 | leave the low-power state. This feature may be enabled or disabled |
33 | using the relevant /sys/devices/.../power/wakeup file (for Ethernet | 36 | using the relevant /sys/devices/.../power/wakeup file (for Ethernet |
34 | drivers the ioctl interface used by ethtool may also be used for this | 37 | drivers the ioctl interface used by ethtool may also be used for this |
35 | purpose); enabling it may cost some power usage, but let the whole | 38 | purpose); enabling it may cost some power usage, but let the whole |
36 | system enter low power states more often. | 39 | system enter low-power states more often. |
37 | 40 | ||
38 | Runtime Power Management model: | 41 | Runtime Power Management model: |
39 | Devices may also be put into low power states while the system is | 42 | Devices may also be put into low-power states while the system is |
40 | running, independently of other power management activity in principle. | 43 | running, independently of other power management activity in principle. |
41 | However, devices are not generally independent of each other (for | 44 | However, devices are not generally independent of each other (for |
42 | example, parent device cannot be suspended unless all of its child | 45 | example, a parent device cannot be suspended unless all of its child |
43 | devices have been suspended). Moreover, depending on the bus type the | 46 | devices have been suspended). Moreover, depending on the bus type the |
44 | device is on, it may be necessary to carry out some bus-specific | 47 | device is on, it may be necessary to carry out some bus-specific |
45 | operations on the device for this purpose. Also, devices put into low | 48 | operations on the device for this purpose. Devices put into low power |
46 | power states at run time may require special handling during system-wide | 49 | states at run time may require special handling during system-wide power |
47 | power transitions, like suspend to RAM. | 50 | transitions (suspend or hibernation). |
48 | 51 | ||
49 | For these reasons not only the device driver itself, but also the | 52 | For these reasons not only the device driver itself, but also the |
50 | appropriate subsystem (bus type, device type or device class) driver | 53 | appropriate subsystem (bus type, device type or device class) driver and |
51 | and the PM core are involved in the runtime power management of devices. | 54 | the PM core are involved in runtime power management. As in the system |
52 | Like in the system sleep power management case, they need to collaborate | 55 | sleep power management case, they need to collaborate by implementing |
53 | by implementing various role-specific suspend and resume methods, so | 56 | various role-specific suspend and resume methods, so that the hardware |
54 | that the hardware is cleanly powered down and reactivated without data | 57 | is cleanly powered down and reactivated without data or service loss. |
55 | or service loss. | 58 | |
56 | 59 | There's not a lot to be said about those low-power states except that they are | |
57 | There's not a lot to be said about those low power states except that they | 60 | very system-specific, and often device-specific. Also, that if enough devices |
58 | are very system-specific, and often device-specific. Also, that if enough | 61 | have been put into low-power states (at runtime), the effect may be very similar |
59 | devices have been put into low power states (at "run time"), the effect may be | 62 | to entering some system-wide low-power state (system sleep) ... and that |
60 | very similar to entering some system-wide low-power state (system sleep) ... and | 63 | synergies exist, so that several drivers using runtime PM might put the system |
61 | that synergies exist, so that several drivers using runtime PM might put the | 64 | into a state where even deeper power saving options are available. |
62 | system into a state where even deeper power saving options are available. | 65 | |
63 | 66 | Most suspended devices will have quiesced all I/O: no more DMA or IRQs (except | |
64 | Most suspended devices will have quiesced all I/O: no more DMA or IRQs, no | 67 | for wakeup events), no more data read or written, and requests from upstream |
65 | more data read or written, and requests from upstream drivers are no longer | 68 | drivers are no longer accepted. A given bus or platform may have different |
66 | accepted. A given bus or platform may have different requirements though. | 69 | requirements though. |
67 | 70 | ||
68 | Examples of hardware wakeup events include an alarm from a real time clock, | 71 | Examples of hardware wakeup events include an alarm from a real time clock, |
69 | network wake-on-LAN packets, keyboard or mouse activity, and media insertion | 72 | network wake-on-LAN packets, keyboard or mouse activity, and media insertion |
@@ -72,10 +75,10 @@ or removal (for PCMCIA, MMC/SD, USB, and so on). | |||
72 | 75 | ||
73 | Interfaces for Entering System Sleep States | 76 | Interfaces for Entering System Sleep States |
74 | =========================================== | 77 | =========================================== |
75 | There are programming interfaces provided for subsystem (bus type, device type, | 78 | There are programming interfaces provided for subsystems (bus type, device type, |
76 | device class) and device drivers in order to allow them to participate in the | 79 | device class) and device drivers to allow them to participate in the power |
77 | power management of devices they are concerned with. They cover the system | 80 | management of devices they are concerned with. These interfaces cover both |
78 | sleep power management as well as the runtime power management of devices. | 81 | system sleep and runtime power management. |
79 | 82 | ||
80 | 83 | ||
81 | Device Power Management Operations | 84 | Device Power Management Operations |
@@ -106,16 +109,15 @@ struct dev_pm_ops { | |||
106 | 109 | ||
107 | This structure is defined in include/linux/pm.h and the methods included in it | 110 | This structure is defined in include/linux/pm.h and the methods included in it |
108 | are also described in that file. Their roles will be explained in what follows. | 111 | are also described in that file. Their roles will be explained in what follows. |
109 | For now, it should be sufficient to remember that the last three of them are | 112 | For now, it should be sufficient to remember that the last three methods are |
110 | specific to runtime power management, while the remaining ones are used during | 113 | specific to runtime power management while the remaining ones are used during |
111 | system-wide power transitions. | 114 | system-wide power transitions. |
112 | 115 | ||
113 | There also is an "old" or "legacy", deprecated way of implementing power | 116 | There also is a deprecated "old" or "legacy" interface for power management |
114 | management operations available at least for some subsystems. This approach | 117 | operations available at least for some subsystems. This approach does not use |
115 | does not use struct dev_pm_ops objects and it only is suitable for implementing | 118 | struct dev_pm_ops objects and it is suitable only for implementing system sleep |
116 | system sleep power management methods. Therefore it is not described in this | 119 | power management methods. Therefore it is not described in this document, so |
117 | document, so please refer directly to the source code for more information about | 120 | please refer directly to the source code for more information about it. |
118 | it. | ||
119 | 121 | ||
120 | 122 | ||
121 | Subsystem-Level Methods | 123 | Subsystem-Level Methods |
@@ -125,10 +127,10 @@ pointed to by the pm member of struct bus_type, struct device_type and | |||
125 | struct class. They are mostly of interest to the people writing infrastructure | 127 | struct class. They are mostly of interest to the people writing infrastructure |
126 | for buses, like PCI or USB, or device type and device class drivers. | 128 | for buses, like PCI or USB, or device type and device class drivers. |
127 | 129 | ||
128 | Bus drivers implement these methods as appropriate for the hardware and | 130 | Bus drivers implement these methods as appropriate for the hardware and the |
129 | the drivers using it; PCI works differently from USB, and so on. Not many | 131 | drivers using it; PCI works differently from USB, and so on. Not many people |
130 | people write subsystem-level drivers; most driver code is a "device driver" that | 132 | write subsystem-level drivers; most driver code is a "device driver" that builds |
131 | builds on top of bus-specific framework code. | 133 | on top of bus-specific framework code. |
132 | 134 | ||
133 | For more information on these driver calls, see the description later; | 135 | For more information on these driver calls, see the description later; |
134 | they are called in phases for every device, respecting the parent-child | 136 | they are called in phases for every device, respecting the parent-child |
@@ -137,66 +139,78 @@ sequencing in the driver model tree. | |||
137 | 139 | ||
138 | /sys/devices/.../power/wakeup files | 140 | /sys/devices/.../power/wakeup files |
139 | ----------------------------------- | 141 | ----------------------------------- |
140 | All devices in the driver model have two flags to control handling of | 142 | All devices in the driver model have two flags to control handling of wakeup |
141 | wakeup events, which are hardware signals that can force the device and/or | 143 | events (hardware signals that can force the device and/or system out of a low |
142 | system out of a low power state. These are initialized by bus or device | 144 | power state). These flags are initialized by bus or device driver code using |
143 | driver code using device_init_wakeup(). | 145 | device_set_wakeup_capable() and device_set_wakeup_enable(), defined in |
146 | include/linux/pm_wakeup.h. | ||
144 | 147 | ||
145 | The "can_wakeup" flag just records whether the device (and its driver) can | 148 | The "can_wakeup" flag just records whether the device (and its driver) can |
146 | physically support wakeup events. When that flag is clear, the sysfs | 149 | physically support wakeup events. The device_set_wakeup_capable() routine |
147 | "wakeup" file is empty, and device_may_wakeup() returns false. | 150 | affects this flag. The "should_wakeup" flag controls whether the device should |
148 | 151 | try to use its wakeup mechanism. device_set_wakeup_enable() affects this flag; | |
149 | For devices that can issue wakeup events, a separate flag controls whether | 152 | for the most part drivers should not change its value. The initial value of |
150 | that device should try to use its wakeup mechanism. The initial value of | 153 | should_wakeup is supposed to be false for the majority of devices; the major |
151 | device_may_wakeup() will be false for the majority of devices, except for | 154 | exceptions are power buttons, keyboards, and Ethernet adapters whose WoL |
152 | power buttons, keyboards, and Ethernet adapters whose WoL (wake-on-LAN) feature | 155 | (wake-on-LAN) feature has been set up with ethtool. |
153 | has been set up with ethtool. Thus in the majority of cases the device's | 156 | |
154 | "wakeup" file will initially hold the value "disabled". Userspace can change | 157 | Whether or not a device is capable of issuing wakeup events is a hardware |
155 | that to "enabled", so that device_may_wakeup() returns true, or change it back | 158 | matter, and the kernel is responsible for keeping track of it. By contrast, |
156 | to "disabled", so that it returns false again. | 159 | whether or not a wakeup-capable device should issue wakeup events is a policy |
160 | decision, and it is managed by user space through a sysfs attribute: the | ||
161 | power/wakeup file. User space can write the strings "enabled" or "disabled" to | ||
162 | set or clear the should_wakeup flag, respectively. Reads from the file will | ||
163 | return the corresponding string if can_wakeup is true, but if can_wakeup is | ||
164 | false then reads will return an empty string, to indicate that the device | ||
165 | doesn't support wakeup events. (But even though the file appears empty, writes | ||
166 | will still affect the should_wakeup flag.) | ||
167 | |||
168 | The device_may_wakeup() routine returns true only if both flags are set. | ||
169 | Drivers should check this routine when putting devices in a low-power state | ||
170 | during a system sleep transition, to see whether or not to enable the devices' | ||
171 | wakeup mechanisms. However for runtime power management, wakeup events should | ||
172 | be enabled whenever the device and driver both support them, regardless of the | ||
173 | should_wakeup flag. | ||
157 | 174 | ||
158 | 175 | ||
159 | /sys/devices/.../power/control files | 176 | /sys/devices/.../power/control files |
160 | ------------------------------------ | 177 | ------------------------------------ |
161 | All devices in the driver model have a flag to control the desired behavior of | 178 | Each device in the driver model has a flag to control whether it is subject to |
162 | its driver with respect to runtime power management. This flag, called | 179 | runtime power management. This flag, called runtime_auto, is initialized by the |
163 | runtime_auto, is initialized by the bus type (or generally subsystem) code using | 180 | bus type (or generally subsystem) code using pm_runtime_allow() or |
164 | pm_runtime_allow() or pm_runtime_forbid(), depending on whether or not the | 181 | pm_runtime_forbid(); the default is to allow runtime power management. |
165 | driver is supposed to power manage the device at run time by default, | 182 | |
166 | respectively. | 183 | The setting can be adjusted by user space by writing either "on" or "auto" to |
167 | 184 | the device's power/control sysfs file. Writing "auto" calls pm_runtime_allow(), | |
168 | This setting may be adjusted by user space by writing either "on" or "auto" to | 185 | setting the flag and allowing the device to be runtime power-managed by its |
169 | the device's "control" file. If "auto" is written, the device's runtime_auto | 186 | driver. Writing "on" calls pm_runtime_forbid(), clearing the flag, returning |
170 | flag will be set and the driver will be allowed to power manage the device if | 187 | the device to full power if it was in a low-power state, and preventing the |
171 | capable of doing that. If "on" is written, the driver is not allowed to power | 188 | device from being runtime power-managed. User space can check the current value |
172 | manage the device which in turn is supposed to remain in the full power state at | 189 | of the runtime_auto flag by reading the file. |
173 | run time. User space can check the current value of the runtime_auto flag by | ||
174 | reading from the device's "control" file. | ||
175 | 190 | ||
176 | The device's runtime_auto flag has no effect on the handling of system-wide | 191 | The device's runtime_auto flag has no effect on the handling of system-wide |
177 | power transitions by its driver. In particular, the device can (and in the | 192 | power transitions. In particular, the device can (and in the majority of cases |
178 | majority of cases should and will) be put into a low power state during a | 193 | should and will) be put into a low-power state during a system-wide transition |
179 | system-wide transition to a sleep state (like "suspend-to-RAM") even though its | 194 | to a sleep state even though its runtime_auto flag is clear. |
180 | runtime_auto flag is unset (in which case its "control" file contains "on"). | ||
181 | 195 | ||
182 | For more information about the runtime power management framework for devices | 196 | For more information about the runtime power management framework, refer to |
183 | refer to Documentation/power/runtime_pm.txt. | 197 | Documentation/power/runtime_pm.txt. |
184 | 198 | ||
185 | 199 | ||
186 | Calling Drivers to Enter System Sleep States | 200 | Calling Drivers to Enter and Leave System Sleep States |
187 | ============================================ | 201 | ====================================================== |
188 | When the system goes into a sleep state, each device's driver is asked | 202 | When the system goes into a sleep state, each device's driver is asked to |
189 | to suspend the device by putting it into state compatible with the target | 203 | suspend the device by putting it into a state compatible with the target |
190 | system state. That's usually some version of "off", but the details are | 204 | system state. That's usually some version of "off", but the details are |
191 | system-specific. Also, wakeup-enabled devices will usually stay partly | 205 | system-specific. Also, wakeup-enabled devices will usually stay partly |
192 | functional in order to wake the system. | 206 | functional in order to wake the system. |
193 | 207 | ||
194 | When the system leaves that low power state, the device's driver is asked | 208 | When the system leaves that low-power state, the device's driver is asked to |
195 | to resume it. The suspend and resume operations always go together, and | 209 | resume it by returning it to full power. The suspend and resume operations |
196 | both are multi-phase operations. | 210 | always go together, and both are multi-phase operations. |
197 | 211 | ||
198 | For simple drivers, suspend might quiesce the device using the class code | 212 | For simple drivers, suspend might quiesce the device using class code |
199 | and then turn its hardware as "off" as possible with late_suspend. The | 213 | and then turn its hardware as "off" as possible during suspend_noirq. The |
200 | matching resume calls would then completely reinitialize the hardware | 214 | matching resume calls would then completely reinitialize the hardware |
201 | before reactivating its class I/O queues. | 215 | before reactivating its class I/O queues. |
202 | 216 | ||
@@ -224,269 +238,129 @@ devices have been suspended. Device drivers must be prepared to cope with such | |||
224 | situations. | 238 | situations. |
225 | 239 | ||
226 | 240 | ||
227 | Suspending Devices | 241 | System Power Management Phases |
228 | ------------------ | 242 | ------------------------------ |
229 | Suspending a given device is done in several phases. Suspending the | 243 | Suspending or resuming the system is done in several phases. Different phases |
230 | system always includes every phase, executing calls for every device | 244 | are used for standby or memory sleep states ("suspend-to-RAM") and the |
231 | before the next phase begins. Not all busses or classes support all | 245 | hibernation state ("suspend-to-disk"). Each phase involves executing callbacks |
232 | these callbacks; and not all drivers use all the callbacks. | 246 | for every device before the next phase begins. Not all busses or classes |
233 | 247 | support all these callbacks and not all drivers use all the callbacks. The | |
234 | Generally, different callbacks are used depending on whether the system is | 248 | various phases always run after tasks have been frozen and before they are |
235 | going to the standby or memory sleep state ("suspend-to-RAM") or it is going to | 249 | unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have |
236 | be hibernated ("suspend-to-disk"). | 250 | been disabled (except for those marked with the IRQ_WAKEUP flag). |
237 | 251 | ||
238 | If the system goes to the standby or memory sleep state the phases are seen by | 252 | Most phases use bus, type, and class callbacks (that is, methods defined in |
239 | driver notifications issued in this order: | 253 | dev->bus->pm, dev->type->pm, and dev->class->pm). The prepare and complete |
254 | phases are exceptions; they use only bus callbacks. When multiple callbacks | ||
255 | are used in a phase, they are invoked in the order: <class, type, bus> during | ||
256 | power-down transitions and in the opposite order during power-up transitions. | ||
257 | For example, during the suspend phase the PM core invokes | ||
240 | 258 | ||
241 | 1 bus->pm.prepare(dev) is called after tasks are frozen and it is supposed | 259 | dev->class->pm.suspend(dev); |
242 | to call the device driver's ->pm.prepare() method. | 260 | dev->type->pm.suspend(dev); |
261 | dev->bus->pm.suspend(dev); | ||
243 | 262 | ||
244 | The purpose of this method is mainly to prevent new children of the | 263 | before moving on to the next device, whereas during the resume phase the core |
245 | device from being registered after it has returned. It also may be used | 264 | invokes |
246 | to generally prepare the device for the upcoming system transition, but | ||
247 | it should not put the device into a low power state. | ||
248 | 265 | ||
249 | 2 class->pm.suspend(dev) is called if dev is associated with a class that | 266 | dev->bus->pm.resume(dev); |
250 | has such a method. It may invoke the device driver's ->pm.suspend() | 267 | dev->type->pm.resume(dev); |
251 | method, unless type->pm.suspend(dev) or bus->pm.suspend() does that. | 268 | dev->class->pm.resume(dev); |
252 | 269 | ||
253 | 3 type->pm.suspend(dev) is called if dev is associated with a device type | 270 | These callbacks may in turn invoke device- or driver-specific methods stored in |
254 | that has such a method. It may invoke the device driver's | 271 | dev->driver->pm, but they don't have to. |
255 | ->pm.suspend() method, unless class->pm.suspend(dev) or | ||
256 | bus->pm.suspend() does that. | ||
257 | 272 | ||
258 | 4 bus->pm.suspend(dev) is called, if implemented. It usually calls the | ||
259 | device driver's ->pm.suspend() method. | ||
260 | 273 | ||
261 | This call should generally quiesce the device so that it doesn't do any | 274 | Entering System Suspend |
262 | I/O after the call has returned. It also may save the device registers | 275 | ----------------------- |
263 | and put it into the appropriate low power state, depending on the bus | 276 | When the system goes into the standby or memory sleep state, the phases are: |
264 | type the device is on. | 277 | |
265 | 278 | prepare, suspend, suspend_noirq. | |
266 | 5 bus->pm.suspend_noirq(dev) is called, if implemented. It may call the | 279 | |
267 | device driver's ->pm.suspend_noirq() method, depending on the bus type | 280 | 1. The prepare phase is meant to prevent races by preventing new devices |
268 | in question. | 281 | from being registered; the PM core would never know that all the |
269 | 282 | children of a device had been suspended if new children could be | |
270 | This method is invoked after device interrupts have been suspended, | 283 | registered at will. (By contrast, devices may be unregistered at any |
271 | which means that the driver's interrupt handler will not be called | 284 | time.) Unlike the other suspend-related phases, during the prepare |
272 | while it is running. It should save the values of the device's | 285 | phase the device tree is traversed top-down. |
273 | registers that weren't saved previously and finally put the device into | 286 | |
274 | the appropriate low power state. | 287 | The prepare phase uses only a bus callback. After the callback method |
288 | returns, no new children may be registered below the device. The method | ||
289 | may also prepare the device or driver in some way for the upcoming | ||
290 | system power transition, but it should not put the device into a | ||
291 | low-power state. | ||
292 | |||
293 | 2. The suspend methods should quiesce the device to stop it from performing | ||
294 | I/O. They also may save the device registers and put it into the | ||
295 | appropriate low-power state, depending on the bus type the device is on, | ||
296 | and they may enable wakeup events. | ||
297 | |||
298 | 3. The suspend_noirq phase occurs after IRQ handlers have been disabled, | ||
299 | which means that the driver's interrupt handler will not be called while | ||
300 | the callback method is running. The methods should save the values of | ||
301 | the device's registers that weren't saved previously and finally put the | ||
302 | device into the appropriate low-power state. | ||
275 | 303 | ||
276 | The majority of subsystems and device drivers need not implement this | 304 | The majority of subsystems and device drivers need not implement this |
277 | method. However, bus types allowing devices to share interrupt vectors, | 305 | callback. However, bus types allowing devices to share interrupt |
278 | like PCI, generally need to use it to prevent interrupt handling issues | 306 | vectors, like PCI, generally need it; otherwise a driver might encounter |
279 | from happening during suspend. | 307 | an error during the suspend phase by fielding a shared interrupt |
280 | 308 | generated by some other device after its own device had been set to low | |
281 | At the end of those phases, drivers should normally have stopped all I/O | 309 | power. |
282 | transactions (DMA, IRQs), saved enough state that they can re-initialize | 310 | |
283 | or restore previous state (as needed by the hardware), and placed the | 311 | At the end of these phases, drivers should have stopped all I/O transactions |
284 | device into a low-power state. On many platforms they will also use | 312 | (DMA, IRQs), saved enough state that they can re-initialize or restore previous |
285 | gate off one or more clock sources; sometimes they will also switch off power | 313 | state (as needed by the hardware), and placed the device into a low-power state. |
286 | supplies, or reduce voltages. [Drivers supporting runtime PM may already have | 314 | On many platforms they will gate off one or more clock sources; sometimes they |
287 | performed some or all of the steps needed to prepare for the upcoming system | 315 | will also switch off power supplies or reduce voltages. (Drivers supporting |
288 | state transition.] | 316 | runtime PM may already have performed some or all of these steps.) |
289 | 317 | ||
290 | If device_may_wakeup(dev) returns true, the device should be prepared for | 318 | If device_may_wakeup(dev) returns true, the device should be prepared for |
291 | generating hardware wakeup signals when the system is in the sleep state to | 319 | generating hardware wakeup signals to trigger a system wakeup event when the |
292 | trigger a system wakeup event. For example, enable_irq_wake() might identify | 320 | system is in the sleep state. For example, enable_irq_wake() might identify |
293 | GPIO signals hooked up to a switch or other external hardware, and | 321 | GPIO signals hooked up to a switch or other external hardware, and |
294 | pci_enable_wake() does something similar for the PCI PME signal. | 322 | pci_enable_wake() does something similar for the PCI PME signal. |
295 | 323 | ||
296 | If a driver (or subsystem) fails it suspend method, the system won't enter the | 324 | If any of these callbacks returns an error, the system won't enter the desired |
297 | desired low power state; it will resume all the devices it's suspended so far. | 325 | low-power state. Instead the PM core will unwind its actions by resuming all |
298 | 326 | the devices that were suspended. | |
299 | |||
300 | Hibernation Phases | ||
301 | ------------------ | ||
302 | Hibernating the system is more complicated than putting it into the standby or | ||
303 | memory sleep state, because it involves creating a system image and saving it. | ||
304 | Therefore there are more phases of hibernation and special device PM methods are | ||
305 | used in this case. | ||
306 | |||
307 | First, it is necessary to prepare the system for creating a hibernation image. | ||
308 | This is similar to putting the system into the standby or memory sleep state, | ||
309 | although it generally doesn't require that devices be put into low power states | ||
310 | (that is even not desirable at this point). Driver notifications are then | ||
311 | issued in the following order: | ||
312 | |||
313 | 1 bus->pm.prepare(dev) is called after tasks have been frozen and enough | ||
314 | memory has been freed. | ||
315 | |||
316 | 2 class->pm.freeze(dev) is called if implemented. It may invoke the | ||
317 | device driver's ->pm.freeze() method, unless type->pm.freeze(dev) or | ||
318 | bus->pm.freeze() does that. | ||
319 | |||
320 | 3 type->pm.freeze(dev) is called if implemented. It may invoke the device | ||
321 | driver's ->pm.suspend() method, unless class->pm.freeze(dev) or | ||
322 | bus->pm.freeze() does that. | ||
323 | |||
324 | 4 bus->pm.freeze(dev) is called, if implemented. It usually calls the | ||
325 | device driver's ->pm.freeze() method. | ||
326 | |||
327 | 5 bus->pm.freeze_noirq(dev) is called, if implemented. It may call the | ||
328 | device driver's ->pm.freeze_noirq() method, depending on the bus type | ||
329 | in question. | ||
330 | |||
331 | The difference between ->pm.freeze() and the corresponding ->pm.suspend() (and | ||
332 | similarly for the "noirq" variants) is that the former should avoid preparing | ||
333 | devices to trigger system wakeup events and putting devices into low power | ||
334 | states, although they generally have to save the values of device registers | ||
335 | so that it's possible to restore them during system resume. | ||
336 | |||
337 | Second, after the system image has been created, the functionality of devices | ||
338 | has to be restored so that the image can be saved. That is similar to resuming | ||
339 | devices after the system has been woken up from the standby or memory sleep | ||
340 | state, which is described below, and causes the following device notifications | ||
341 | to be issued: | ||
342 | |||
343 | 1 bus->pm.thaw_noirq(dev), if implemented; may call the device driver's | ||
344 | ->pm.thaw_noirq() method, depending on the bus type in question. | ||
345 | |||
346 | 2 bus->pm.thaw(dev), if implemented; usually calls the device driver's | ||
347 | ->pm.thaw() method. | ||
348 | |||
349 | 3 type->pm.thaw(dev), if implemented; may call the device driver's | ||
350 | ->pm.thaw() method if not called by the bus type or class. | ||
351 | |||
352 | 4 class->pm.thaw(dev), if implemented; may call the device driver's | ||
353 | ->pm.thaw() method if not called by the bus type or device type. | ||
354 | |||
355 | 5 bus->pm.complete(dev), if implemented; may call the device driver's | ||
356 | ->pm.complete() method. | ||
357 | |||
358 | Generally, the role of the ->pm.thaw() methods (including the "noirq" variants) | ||
359 | is to bring the device back to the fully functional state, so that it may be | ||
360 | used for saving the image, if necessary. The role of bus->pm.complete() is to | ||
361 | reverse whatever bus->pm.prepare() did (likewise for the analogous device driver | ||
362 | callbacks). | ||
363 | |||
364 | After the image has been saved, the devices need to be prepared for putting the | ||
365 | system into the low power state. That is analogous to suspending them before | ||
366 | putting the system into the standby or memory sleep state and involves the | ||
367 | following device notifications: | ||
368 | |||
369 | 1 bus->pm.prepare(dev). | ||
370 | |||
371 | 2 class->pm.poweroff(dev), if implemented; may invoke the device driver's | ||
372 | ->pm.poweroff() method if not called by the bus type or device type. | ||
373 | |||
374 | 3 type->pm.poweroff(dev), if implemented; may invoke the device driver's | ||
375 | ->pm.poweroff() method if not called by the bus type or device class. | ||
376 | |||
377 | 4 bus->pm.poweroff(dev), if implemented; usually calls the device driver's | ||
378 | ->pm.poweroff() method (if not called by the device class or type). | ||
379 | |||
380 | 5 bus->pm.poweroff_noirq(dev), if implemented; may call the device | ||
381 | driver's ->pm.poweroff_noirq() method, depending on the bus type | ||
382 | in question. | ||
383 | |||
384 | The difference between ->pm.poweroff() and the corresponding ->pm.suspend() (and | ||
385 | analogously for the "noirq" variants) is that the former need not save the | ||
386 | device's registers. Still, they should prepare the device for triggering | ||
387 | system wakeup events if necessary and finally put it into the appropriate low | ||
388 | power state. | ||
389 | |||
390 | |||
391 | Device Low Power (suspend) States | ||
392 | --------------------------------- | ||
393 | Device low-power states aren't standard. One device might only handle | ||
394 | "on" and "off, while another might support a dozen different versions of | ||
395 | "on" (how many engines are active?), plus a state that gets back to "on" | ||
396 | faster than from a full "off". | ||
397 | |||
398 | Some busses define rules about what different suspend states mean. PCI | ||
399 | gives one example: after the suspend sequence completes, a non-legacy | ||
400 | PCI device may not perform DMA or issue IRQs, and any wakeup events it | ||
401 | issues would be issued through the PME# bus signal. Plus, there are | ||
402 | several PCI-standard device states, some of which are optional. | ||
403 | |||
404 | In contrast, integrated system-on-chip processors often use IRQs as the | ||
405 | wakeup event sources (so drivers would call enable_irq_wake) and might | ||
406 | be able to treat DMA completion as a wakeup event (sometimes DMA can stay | ||
407 | active too, it'd only be the CPU and some peripherals that sleep). | ||
408 | |||
409 | Some details here may be platform-specific. Systems may have devices that | ||
410 | can be fully active in certain sleep states, such as an LCD display that's | ||
411 | refreshed using DMA while most of the system is sleeping lightly ... and | ||
412 | its frame buffer might even be updated by a DSP or other non-Linux CPU while | ||
413 | the Linux control processor stays idle. | ||
414 | |||
415 | Moreover, the specific actions taken may depend on the target system state. | ||
416 | One target system state might allow a given device to be very operational; | ||
417 | another might require a hard shut down with re-initialization on resume. | ||
418 | And two different target systems might use the same device in different | ||
419 | ways; the aforementioned LCD might be active in one product's "standby", | ||
420 | but a different product using the same SOC might work differently. | ||
421 | 327 | ||
422 | 328 | ||
423 | Resuming Devices | 329 | Leaving System Suspend |
424 | ---------------- | 330 | ---------------------- |
425 | Resuming is done in multiple phases, much like suspending, with all | 331 | When resuming from standby or memory sleep, the phases are: |
426 | devices processing each phase's calls before the next phase begins. | ||
427 | 332 | ||
428 | Again, however, different callbacks are used depending on whether the system is | 333 | resume_noirq, resume, complete. |
429 | waking up from the standby or memory sleep state ("suspend-to-RAM") or from | ||
430 | hibernation ("suspend-to-disk"). | ||
431 | 334 | ||
432 | If the system is waking up from the standby or memory sleep state, the phases | 335 | 1. The resume_noirq callback methods should perform any actions needed |
433 | are seen by driver notifications issued in this order: | 336 | before the driver's interrupt handlers are invoked. This generally |
434 | 337 | means undoing the actions of the suspend_noirq phase. If the bus type | |
435 | 1 bus->pm.resume_noirq(dev) is called, if implemented. It may call the | 338 | permits devices to share interrupt vectors, like PCI, the method should |
436 | device driver's ->pm.resume_noirq() method, depending on the bus type in | 339 | bring the device and its driver into a state in which the driver can |
437 | question. | 340 | recognize if the device is the source of incoming interrupts, if any, |
438 | 341 | and handle them correctly. | |
439 | The role of this method is to perform actions that need to be performed | ||
440 | before device drivers' interrupt handlers are allowed to be invoked. If | ||
441 | the given bus type permits devices to share interrupt vectors, like PCI, | ||
442 | this method should bring the device and its driver into a state in which | ||
443 | the driver can recognize if the device is the source of incoming | ||
444 | interrupts, if any, and handle them correctly. | ||
445 | 342 | ||
446 | For example, the PCI bus type's ->pm.resume_noirq() puts the device into | 343 | For example, the PCI bus type's ->pm.resume_noirq() puts the device into |
447 | the full power state (D0 in the PCI terminology) and restores the | 344 | the full-power state (D0 in the PCI terminology) and restores the |
448 | standard configuration registers of the device. Then, it calls the | 345 | standard configuration registers of the device. Then it calls the |
449 | device driver's ->pm.resume_noirq() method to perform device-specific | 346 | device driver's ->pm.resume_noirq() method to perform device-specific |
450 | actions needed at this stage of resume. | 347 | actions. |
451 | |||
452 | 2 bus->pm.resume(dev) is called, if implemented. It usually calls the | ||
453 | device driver's ->pm.resume() method. | ||
454 | |||
455 | This call should generally bring the the device back to the working | ||
456 | state, so that it can do I/O as requested after the call has returned. | ||
457 | However, it may be more convenient to use the device class or device | ||
458 | type ->pm.resume() for this purpose, in which case the bus type's | ||
459 | ->pm.resume() method need not be implemented at all. | ||
460 | |||
461 | 3 type->pm.resume(dev) is called, if implemented. It may invoke the | ||
462 | device driver's ->pm.resume() method, unless class->pm.resume(dev) or | ||
463 | bus->pm.resume() does that. | ||
464 | |||
465 | For devices that are not associated with any bus type or device class | ||
466 | this method plays the role of bus->pm.resume(). | ||
467 | |||
468 | 4 class->pm.resume(dev) is called, if implemented. It may invoke the | ||
469 | device driver's ->pm.resume() method, unless bus->pm.resume(dev) or | ||
470 | type->pm.resume() does that. | ||
471 | |||
472 | For devices that are not associated with any bus type or device type | ||
473 | this method plays the role of bus->pm.resume(). | ||
474 | 348 | ||
475 | 5 bus->pm.complete(dev) is called, if implemented. It is supposed to | 349 | 2. The resume methods should bring the the device back to its operating |
476 | invoke the device driver's ->pm.complete() method. | 350 | state, so that it can perform normal I/O. This generally involves |
351 | undoing the actions of the suspend phase. | ||
477 | 352 | ||
478 | The role of this method is to reverse whatever bus->pm.prepare(dev) | 353 | 3. The complete phase uses only a bus callback. The method should undo the |
479 | (or the driver's ->pm.prepare()) did during suspend, if necessary. | 354 | actions of the prepare phase. Note, however, that new children may be |
355 | registered below the device as soon as the resume callbacks occur; it's | ||
356 | not necessary to wait until the complete phase. | ||
480 | 357 | ||
481 | At the end of those phases, drivers should normally be as functional as | 358 | At the end of these phases, drivers should be as functional as they were before |
482 | they were before suspending: I/O can be performed using DMA and IRQs, and | 359 | suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are |
483 | the relevant clocks are gated on. In principle the device need not be | 360 | gated on. Even if the device was in a low-power state before the system sleep |
484 | "fully on"; it might be in a runtime lowpower/suspend state during suspend and | 361 | because of runtime power management, afterwards it should be back in its |
485 | the resume callbacks may try to restore that state, but that need not be | 362 | full-power state. There are multiple reasons why it's best to do this; they are |
486 | desirable from the user's point of view. In fact, there are multiple reasons | 363 | discussed in more detail in Documentation/power/runtime_pm.txt. |
487 | why it's better to always put devices into the "fully working" state in the | ||
488 | system sleep resume callbacks and they are discussed in more detail in | ||
489 | Documentation/power/runtime_pm.txt. | ||
490 | 364 | ||
491 | However, the details here may again be platform-specific. For example, | 365 | However, the details here may again be platform-specific. For example, |
492 | some systems support multiple "run" states, and the mode in effect at | 366 | some systems support multiple "run" states, and the mode in effect at |
@@ -502,103 +376,156 @@ the suspend was carried out, but that can't be guaranteed (in fact, it ususally | |||
502 | is not the case). | 376 | is not the case). |
503 | 377 | ||
504 | Drivers must also be prepared to notice that the device has been removed | 378 | Drivers must also be prepared to notice that the device has been removed |
505 | while the system was powered off, whenever that's physically possible. | 379 | while the system was powered down, whenever that's physically possible. |
506 | PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses | 380 | PCMCIA, MMC, USB, Firewire, SCSI, and even IDE are common examples of busses |
507 | where common Linux platforms will see such removal. Details of how drivers | 381 | where common Linux platforms will see such removal. Details of how drivers |
508 | will notice and handle such removals are currently bus-specific, and often | 382 | will notice and handle such removals are currently bus-specific, and often |
509 | involve a separate thread. | 383 | involve a separate thread. |
510 | 384 | ||
385 | These callbacks may return an error value, but the PM core will ignore such | ||
386 | errors since there's nothing it can do about them other than printing them in | ||
387 | the system log. | ||
511 | 388 | ||
512 | Resume From Hibernation | 389 | |
513 | ----------------------- | 390 | Entering Hibernation |
391 | -------------------- | ||
392 | Hibernating the system is more complicated than putting it into the standby or | ||
393 | memory sleep state, because it involves creating and saving a system image. | ||
394 | Therefore there are more phases for hibernation, with a different set of | ||
395 | callbacks. These phases always run after tasks have been frozen and memory has | ||
396 | been freed. | ||
397 | |||
398 | The general procedure for hibernation is to quiesce all devices (freeze), create | ||
399 | an image of the system memory while everything is stable, reactivate all | ||
400 | devices (thaw), write the image to permanent storage, and finally shut down the | ||
401 | system (poweroff). The phases used to accomplish this are: | ||
402 | |||
403 | prepare, freeze, freeze_noirq, thaw_noirq, thaw, complete, | ||
404 | prepare, poweroff, poweroff_noirq | ||
405 | |||
406 | 1. The prepare phase is discussed in the "Entering System Suspend" section | ||
407 | above. | ||
408 | |||
409 | 2. The freeze methods should quiesce the device so that it doesn't generate | ||
410 | IRQs or DMA, and they may need to save the values of device registers. | ||
411 | However the device does not have to be put in a low-power state, and to | ||
412 | save time it's best not to do so. Also, the device should not be | ||
413 | prepared to generate wakeup events. | ||
414 | |||
415 | 3. The freeze_noirq phase is analogous to the suspend_noirq phase discussed | ||
416 | above, except again that the device should not be put in a low-power | ||
417 | state and should not be allowed to generate wakeup events. | ||
418 | |||
419 | At this point the system image is created. All devices should be inactive and | ||
420 | the contents of memory should remain undisturbed while this happens, so that the | ||
421 | image forms an atomic snapshot of the system state. | ||
422 | |||
423 | 4. The thaw_noirq phase is analogous to the resume_noirq phase discussed | ||
424 | above. The main difference is that its methods can assume the device is | ||
425 | in the same state as at the end of the freeze_noirq phase. | ||
426 | |||
427 | 5. The thaw phase is analogous to the resume phase discussed above. Its | ||
428 | methods should bring the device back to an operating state, so that it | ||
429 | can be used for saving the image if necessary. | ||
430 | |||
431 | 6. The complete phase is discussed in the "Leaving System Suspend" section | ||
432 | above. | ||
433 | |||
434 | At this point the system image is saved, and the devices then need to be | ||
435 | prepared for the upcoming system shutdown. This is much like suspending them | ||
436 | before putting the system into the standby or memory sleep state, and the phases | ||
437 | are similar. | ||
438 | |||
439 | 7. The prepare phase is discussed above. | ||
440 | |||
441 | 8. The poweroff phase is analogous to the suspend phase. | ||
442 | |||
443 | 9. The poweroff_noirq phase is analogous to the suspend_noirq phase. | ||
444 | |||
445 | The poweroff and poweroff_noirq callbacks should do essentially the same things | ||
446 | as the suspend and suspend_noirq callbacks. The only notable difference is that | ||
447 | they need not store the device register values, because the registers should | ||
448 | already have been stored during the freeze or freeze_noirq phases. | ||
449 | |||
450 | |||
451 | Leaving Hibernation | ||
452 | ------------------- | ||
514 | Resuming from hibernation is, again, more complicated than resuming from a sleep | 453 | Resuming from hibernation is, again, more complicated than resuming from a sleep |
515 | state in which the contents of main memory are preserved, because it requires | 454 | state in which the contents of main memory are preserved, because it requires |
516 | a system image to be loaded into memory and the pre-hibernation memory contents | 455 | a system image to be loaded into memory and the pre-hibernation memory contents |
517 | to be restored before control can be passed back to the image kernel. | 456 | to be restored before control can be passed back to the image kernel. |
518 | 457 | ||
519 | In principle, the image might be loaded into memory and the pre-hibernation | 458 | Although in principle, the image might be loaded into memory and the |
520 | memory contents might be restored by the boot loader. For this purpose, | 459 | pre-hibernation memory contents restored by the boot loader, in practice this |
521 | however, the boot loader would need to know the image kernel's entry point and | 460 | can't be done because boot loaders aren't smart enough and there is no |
522 | there's no protocol defined for passing that information to boot loaders. As | 461 | established protocol for passing the necessary information. So instead, the |
523 | a workaround, the boot loader loads a fresh instance of the kernel, called the | 462 | boot loader loads a fresh instance of the kernel, called the boot kernel, into |
524 | boot kernel, into memory and passes control to it in a usual way. Then, the | 463 | memory and passes control to it in the usual way. Then the boot kernel reads |
525 | boot kernel reads the hibernation image, restores the pre-hibernation memory | 464 | the system image, restores the pre-hibernation memory contents, and passes |
526 | contents and passes control to the image kernel. Thus, in fact, two different | 465 | control to the image kernel. Thus two different kernels are involved in |
527 | kernels are involved in resuming from hibernation and in general they are not | 466 | resuming from hibernation. In fact, the boot kernel may be completely different |
528 | only different because they play different roles in this operation. Actually, | 467 | from the image kernel: a different configuration and even a different version. |
529 | the boot kernel may be completely different from the image kernel. Not only | 468 | This has important consequences for device drivers and their subsystems. |
530 | the configuration of it, but also the version of it may be different. | 469 | |
531 | The consequences of this are important to device drivers and their subsystems | 470 | To be able to load the system image into memory, the boot kernel needs to |
532 | (bus types, device classes and device types) too. | 471 | include at least a subset of device drivers allowing it to access the storage |
533 | 472 | medium containing the image, although it doesn't need to include all of the | |
534 | Namely, to be able to load the hibernation image into memory, the boot kernel | 473 | drivers present in the image kernel. After the image has been loaded, the |
535 | needs to include at least the subset of device drivers allowing it to access the | 474 | devices managed by the boot kernel need to be prepared for passing control back |
536 | storage medium containing the image, although it generally doesn't need to | 475 | to the image kernel. This is very similar to the initial steps involved in |
537 | include all of the drivers included into the image kernel. After the image has | 476 | creating a system image, and it is accomplished in the same way, using prepare, |
538 | been loaded the devices handled by those drivers need to be prepared for passing | 477 | freeze, and freeze_noirq phases. However the devices affected by these phases |
539 | control back to the image kernel. This is very similar to the preparation of | 478 | are only those having drivers in the boot kernel; other devices will still be in |
540 | devices for creating a hibernation image described above. In fact, it is done | 479 | whatever state the boot loader left them. |
541 | in the same way, with the help of the ->pm.prepare(), ->pm.freeze() and | ||
542 | ->pm.freeze_noirq() callbacks, but only for device drivers included in the boot | ||
543 | kernel (whose versions may generally be different from the versions of the | ||
544 | analogous drivers from the image kernel). | ||
545 | 480 | ||
546 | Should the restoration of the pre-hibernation memory contents fail, the boot | 481 | Should the restoration of the pre-hibernation memory contents fail, the boot |
547 | kernel would carry out the procedure of "thawing" devices described above, using | 482 | kernel would go through the "thawing" procedure described above, using the |
548 | the ->pm.thaw_noirq(), ->pm.thaw(), and ->pm.complete() callbacks provided by | 483 | thaw_noirq, thaw, and complete phases, and then continue running normally. This |
549 | subsystems and device drivers. This, however, is a very rare condition. Most | 484 | happens only rarely. Most often the pre-hibernation memory contents are |
550 | often the pre-hibernation memory contents are restored successfully and control | 485 | restored successfully and control is passed to the image kernel, which then |
551 | is passed to the image kernel that is now responsible for bringing the system | 486 | becomes responsible for bringing the system back to the working state. |
552 | back to the working state. | ||
553 | 487 | ||
554 | To achieve this goal, among other things, the image kernel restores the | 488 | To achieve this, the image kernel must restore the devices' pre-hibernation |
555 | pre-hibernation functionality of devices. This operation is analogous to the | 489 | functionality. The operation is much like waking up from the memory sleep |
556 | resuming of devices after waking up from the memory sleep state, although it | 490 | state, although it involves different phases: |
557 | involves different device notifications which are the following: | ||
558 | 491 | ||
559 | 1 bus->pm.restore_noirq(dev), if implemented; may call the device driver's | 492 | restore_noirq, restore, complete |
560 | ->pm.restore_noirq() method, depending on the bus type in question. | ||
561 | 493 | ||
562 | 2 bus->pm.restore(dev), if implemented; usually calls the device driver's | 494 | 1. The restore_noirq phase is analogous to the resume_noirq phase. |
563 | ->pm.restore() method. | ||
564 | 495 | ||
565 | 3 type->pm.restore(dev), if implemented; may call the device driver's | 496 | 2. The restore phase is analogous to the resume phase. |
566 | ->pm.restore() method if not called by the bus type or class. | ||
567 | 497 | ||
568 | 4 class->pm.restore(dev), if implemented; may call the device driver's | 498 | 3. The complete phase is discussed above. |
569 | ->pm.restore() method if not called by the bus type or device type. | ||
570 | 499 | ||
571 | 5 bus->pm.complete(dev), if implemented; may call the device driver's | 500 | The main difference from resume[_noirq] is that restore[_noirq] must assume the |
572 | ->pm.complete() method. | 501 | device has been accessed and reconfigured by the boot loader or the boot kernel. |
573 | 502 | Consequently the state of the device may be different from the state remembered | |
574 | The roles of the ->pm.restore_noirq() and ->pm.restore() callbacks are analogous | 503 | from the freeze and freeze_noirq phases. The device may even need to be reset |
575 | to the roles of the corresponding resume callbacks, but they must assume that | 504 | and completely re-initialized. In many cases this difference doesn't matter, so |
576 | the device may have been accessed before by the boot kernel. Consequently, the | 505 | the resume[_noirq] and restore[_norq] method pointers can be set to the same |
577 | state of the device before they are called may be different from the state of it | 506 | routines. Nevertheless, different callback pointers are used in case there is a |
578 | right prior to calling the resume callbacks. That difference usually doesn't | 507 | situation where it actually matters. |
579 | matter, so the majority of device drivers can set their resume and restore | ||
580 | callback pointers to the same routine. Nevertheless, different callback | ||
581 | pointers are used in case there is a situation where it actually matters. | ||
582 | 508 | ||
583 | 509 | ||
584 | System Devices | 510 | System Devices |
585 | -------------- | 511 | -------------- |
586 | System devices follow a slightly different API, which can be found in | 512 | System devices (sysdevs) follow a slightly different API, which can be found in |
587 | 513 | ||
588 | include/linux/sysdev.h | 514 | include/linux/sysdev.h |
589 | drivers/base/sys.c | 515 | drivers/base/sys.c |
590 | 516 | ||
591 | System devices will only be suspended with interrupts disabled, and after | 517 | System devices will be suspended with interrupts disabled, and after all other |
592 | all other devices have been suspended. On resume, they will be resumed | 518 | devices have been suspended. On resume, they will be resumed before any other |
593 | before any other devices, and also with interrupts disabled. | 519 | devices, and also with interrupts disabled. These things occur in special |
520 | "sysdev_driver" phases, which affect only system devices. | ||
594 | 521 | ||
595 | That is, when the non-boot CPUs are all offline and IRQs are disabled on the | 522 | Thus, after the suspend_noirq (or freeze_noirq or poweroff_noirq) phase, when |
596 | remaining online CPU, then the sysdev_driver.suspend() phase is carried out, and | 523 | the non-boot CPUs are all offline and IRQs are disabled on the remaining online |
597 | the system enters a sleep state (or hibernation image is created). During | 524 | CPU, then a sysdev_driver.suspend phase is carried out, and the system enters a |
598 | resume (or after the image has been created) the sysdev_driver.resume() phase | 525 | sleep state (or a system image is created). During resume (or after the image |
599 | is carried out, IRQs are enabled on the only online CPU, the non-boot CPUs are | 526 | has been created or loaded) a sysdev_driver.resume phase is carried out, IRQs |
600 | enabled and that is followed by the "early resume" phase (in which the "noirq" | 527 | are enabled on the only online CPU, the non-boot CPUs are enabled, and the |
601 | callbacks provided by subsystems and device drivers are invoked). | 528 | resume_noirq (or thaw_noirq or restore_noirq) phase begins. |
602 | 529 | ||
603 | Code to actually enter and exit the system-wide low power state sometimes | 530 | Code to actually enter and exit the system-wide low power state sometimes |
604 | involves hardware details that are only known to the boot firmware, and | 531 | involves hardware details that are only known to the boot firmware, and |
@@ -606,18 +533,47 @@ may leave a CPU running software (from SRAM or flash memory) that monitors | |||
606 | the system and manages its wakeup sequence. | 533 | the system and manages its wakeup sequence. |
607 | 534 | ||
608 | 535 | ||
536 | Device Low Power (suspend) States | ||
537 | --------------------------------- | ||
538 | Device low-power states aren't standard. One device might only handle | ||
539 | "on" and "off, while another might support a dozen different versions of | ||
540 | "on" (how many engines are active?), plus a state that gets back to "on" | ||
541 | faster than from a full "off". | ||
542 | |||
543 | Some busses define rules about what different suspend states mean. PCI | ||
544 | gives one example: after the suspend sequence completes, a non-legacy | ||
545 | PCI device may not perform DMA or issue IRQs, and any wakeup events it | ||
546 | issues would be issued through the PME# bus signal. Plus, there are | ||
547 | several PCI-standard device states, some of which are optional. | ||
548 | |||
549 | In contrast, integrated system-on-chip processors often use IRQs as the | ||
550 | wakeup event sources (so drivers would call enable_irq_wake) and might | ||
551 | be able to treat DMA completion as a wakeup event (sometimes DMA can stay | ||
552 | active too, it'd only be the CPU and some peripherals that sleep). | ||
553 | |||
554 | Some details here may be platform-specific. Systems may have devices that | ||
555 | can be fully active in certain sleep states, such as an LCD display that's | ||
556 | refreshed using DMA while most of the system is sleeping lightly ... and | ||
557 | its frame buffer might even be updated by a DSP or other non-Linux CPU while | ||
558 | the Linux control processor stays idle. | ||
559 | |||
560 | Moreover, the specific actions taken may depend on the target system state. | ||
561 | One target system state might allow a given device to be very operational; | ||
562 | another might require a hard shut down with re-initialization on resume. | ||
563 | And two different target systems might use the same device in different | ||
564 | ways; the aforementioned LCD might be active in one product's "standby", | ||
565 | but a different product using the same SOC might work differently. | ||
566 | |||
567 | |||
609 | Power Management Notifiers | 568 | Power Management Notifiers |
610 | -------------------------- | 569 | -------------------------- |
611 | As stated in Documentation/power/notifiers.txt, there are some operations that | 570 | There are some operations that cannot be carried out by the power management |
612 | cannot be carried out by the power management callbacks discussed above, because | 571 | callbacks discussed above, because the callbacks occur too late or too early. |
613 | carrying them out at these points would be too late or too early. To handle | 572 | To handle these cases, subsystems and device drivers may register power |
614 | these cases subsystems and device drivers may register power management | 573 | management notifiers that are called before tasks are frozen and after they have |
615 | notifiers that are called before tasks are frozen and after they have been | 574 | been thawed. Generally speaking, the PM notifiers are suitable for performing |
616 | thawed. | 575 | actions that either require user space to be available, or at least won't |
617 | 576 | interfere with user space. | |
618 | Generally speaking, the PM notifiers are suitable for performing actions that | ||
619 | either require user space to be available, or at least won't interfere with user | ||
620 | space in a wrong way. | ||
621 | 577 | ||
622 | For details refer to Documentation/power/notifiers.txt. | 578 | For details refer to Documentation/power/notifiers.txt. |
623 | 579 | ||
@@ -629,24 +585,23 @@ running. This feature is useful for devices that are not being used, and | |||
629 | can offer significant power savings on a running system. These devices | 585 | can offer significant power savings on a running system. These devices |
630 | often support a range of runtime power states, which might use names such | 586 | often support a range of runtime power states, which might use names such |
631 | as "off", "sleep", "idle", "active", and so on. Those states will in some | 587 | as "off", "sleep", "idle", "active", and so on. Those states will in some |
632 | cases (like PCI) be partially constrained by a bus the device uses, and will | 588 | cases (like PCI) be partially constrained by the bus the device uses, and will |
633 | usually include hardware states that are also used in system sleep states. | 589 | usually include hardware states that are also used in system sleep states. |
634 | 590 | ||
635 | Note, however, that a system-wide power transition can be started while some | 591 | A system-wide power transition can be started while some devices are in low |
636 | devices are in low power states due to the runtime power management. The system | 592 | power states due to runtime power management. The system sleep PM callbacks |
637 | sleep PM callbacks should generally recognize such situations and react to them | 593 | should recognize such situations and react to them appropriately, but the |
638 | appropriately, but the recommended actions to be taken in that cases are | 594 | necessary actions are subsystem-specific. |
639 | subsystem-specific. | 595 | |
640 | 596 | In some cases the decision may be made at the subsystem level while in other | |
641 | In some cases the decision may be made at the subsystem level while in some | 597 | cases the device driver may be left to decide. In some cases it may be |
642 | other cases the device driver may be left to decide. In some cases it may be | 598 | desirable to leave a suspended device in that state during a system-wide power |
643 | desirable to leave a suspended device in that state during system-wide power | 599 | transition, but in other cases the device must be put back into the full-power |
644 | transition, but in some other cases the device ought to be put back into the | 600 | state temporarily, for example so that its system wakeup capability can be |
645 | full power state, for example to be configured for system wakeup or so that its | 601 | disabled. This all depends on the hardware and the design of the subsystem and |
646 | system wakeup capability can be disabled. That all depends on the hardware | 602 | device driver in question. |
647 | and the design of the subsystem and device driver in question. | 603 | |
648 | 604 | During system-wide resume from a sleep state it's best to put devices into the | |
649 | During system-wide resume from a sleep state it's better to put devices into | 605 | full-power state, as explained in Documentation/power/runtime_pm.txt. Refer to |
650 | the full power state, as explained in Documentation/power/runtime_pm.txt. Refer | 606 | that document for more information regarding this particular issue as well as |
651 | to that document for more information regarding this particular issue as well as | ||
652 | for information on the device runtime power management framework in general. | 607 | for information on the device runtime power management framework in general. |