diff options
Diffstat (limited to 'Documentation/power')
-rw-r--r-- | Documentation/power/devices.txt | 118 | ||||
-rw-r--r-- | Documentation/power/freezing-of-tasks.txt | 39 | ||||
-rw-r--r-- | Documentation/power/runtime_pm.txt | 158 |
3 files changed, 193 insertions, 122 deletions
diff --git a/Documentation/power/devices.txt b/Documentation/power/devices.txt index 646a89e0c07d..20af7def23c8 100644 --- a/Documentation/power/devices.txt +++ b/Documentation/power/devices.txt | |||
@@ -123,9 +123,12 @@ please refer directly to the source code for more information about it. | |||
123 | Subsystem-Level Methods | 123 | Subsystem-Level Methods |
124 | ----------------------- | 124 | ----------------------- |
125 | The core methods to suspend and resume devices reside in struct dev_pm_ops | 125 | The core methods to suspend and resume devices reside in struct dev_pm_ops |
126 | pointed to by the pm member of struct bus_type, struct device_type and | 126 | pointed to by the ops member of struct dev_pm_domain, or by the pm member of |
127 | struct class. They are mostly of interest to the people writing infrastructure | 127 | struct bus_type, struct device_type and struct class. They are mostly of |
128 | for buses, like PCI or USB, or device type and device class drivers. | 128 | interest to the people writing infrastructure for platforms and buses, like PCI |
129 | or USB, or device type and device class drivers. They also are relevant to the | ||
130 | writers of device drivers whose subsystems (PM domains, device types, device | ||
131 | classes and bus types) don't provide all power management methods. | ||
129 | 132 | ||
130 | Bus drivers implement these methods as appropriate for the hardware and the | 133 | Bus drivers implement these methods as appropriate for the hardware and the |
131 | drivers using it; PCI works differently from USB, and so on. Not many people | 134 | drivers using it; PCI works differently from USB, and so on. Not many people |
@@ -139,41 +142,57 @@ sequencing in the driver model tree. | |||
139 | 142 | ||
140 | /sys/devices/.../power/wakeup files | 143 | /sys/devices/.../power/wakeup files |
141 | ----------------------------------- | 144 | ----------------------------------- |
142 | All devices in the driver model have two flags to control handling of wakeup | 145 | All device objects in the driver model contain fields that control the handling |
143 | events (hardware signals that can force the device and/or system out of a low | 146 | of system wakeup events (hardware signals that can force the system out of a |
144 | power state). These flags are initialized by bus or device driver code using | 147 | sleep state). These fields are initialized by bus or device driver code using |
145 | device_set_wakeup_capable() and device_set_wakeup_enable(), defined in | 148 | device_set_wakeup_capable() and device_set_wakeup_enable(), defined in |
146 | include/linux/pm_wakeup.h. | 149 | include/linux/pm_wakeup.h. |
147 | 150 | ||
148 | The "can_wakeup" flag just records whether the device (and its driver) can | 151 | The "power.can_wakeup" flag just records whether the device (and its driver) can |
149 | physically support wakeup events. The device_set_wakeup_capable() routine | 152 | physically support wakeup events. The device_set_wakeup_capable() routine |
150 | affects this flag. The "should_wakeup" flag controls whether the device should | 153 | affects this flag. The "power.wakeup" field is a pointer to an object of type |
151 | try to use its wakeup mechanism. device_set_wakeup_enable() affects this flag; | 154 | struct wakeup_source used for controlling whether or not the device should use |
152 | for the most part drivers should not change its value. The initial value of | 155 | its system wakeup mechanism and for notifying the PM core of system wakeup |
153 | should_wakeup is supposed to be false for the majority of devices; the major | 156 | events signaled by the device. This object is only present for wakeup-capable |
154 | exceptions are power buttons, keyboards, and Ethernet adapters whose WoL | 157 | devices (i.e. devices whose "can_wakeup" flags are set) and is created (or |
155 | (wake-on-LAN) feature has been set up with ethtool. It should also default | 158 | removed) by device_set_wakeup_capable(). |
156 | to true for devices that don't generate wakeup requests on their own but merely | ||
157 | forward wakeup requests from one bus to another (like PCI bridges). | ||
158 | 159 | ||
159 | Whether or not a device is capable of issuing wakeup events is a hardware | 160 | Whether or not a device is capable of issuing wakeup events is a hardware |
160 | matter, and the kernel is responsible for keeping track of it. By contrast, | 161 | matter, and the kernel is responsible for keeping track of it. By contrast, |
161 | whether or not a wakeup-capable device should issue wakeup events is a policy | 162 | whether or not a wakeup-capable device should issue wakeup events is a policy |
162 | decision, and it is managed by user space through a sysfs attribute: the | 163 | decision, and it is managed by user space through a sysfs attribute: the |
163 | power/wakeup file. User space can write the strings "enabled" or "disabled" to | 164 | "power/wakeup" file. User space can write the strings "enabled" or "disabled" |
164 | set or clear the "should_wakeup" flag, respectively. This file is only present | 165 | to it to indicate whether or not, respectively, the device is supposed to signal |
165 | for wakeup-capable devices (i.e. devices whose "can_wakeup" flags are set) | 166 | system wakeup. This file is only present if the "power.wakeup" object exists |
166 | and is created (or removed) by device_set_wakeup_capable(). Reads from the | 167 | for the given device and is created (or removed) along with that object, by |
167 | file will return the corresponding string. | 168 | device_set_wakeup_capable(). Reads from the file will return the corresponding |
168 | 169 | string. | |
169 | The device_may_wakeup() routine returns true only if both flags are set. | 170 | |
171 | The "power/wakeup" file is supposed to contain the "disabled" string initially | ||
172 | for the majority of devices; the major exceptions are power buttons, keyboards, | ||
173 | and Ethernet adapters whose WoL (wake-on-LAN) feature has been set up with | ||
174 | ethtool. It should also default to "enabled" for devices that don't generate | ||
175 | wakeup requests on their own but merely forward wakeup requests from one bus to | ||
176 | another (like PCI Express ports). | ||
177 | |||
178 | The device_may_wakeup() routine returns true only if the "power.wakeup" object | ||
179 | exists and the corresponding "power/wakeup" file contains the string "enabled". | ||
170 | This information is used by subsystems, like the PCI bus type code, to see | 180 | This information is used by subsystems, like the PCI bus type code, to see |
171 | whether or not to enable the devices' wakeup mechanisms. If device wakeup | 181 | whether or not to enable the devices' wakeup mechanisms. If device wakeup |
172 | mechanisms are enabled or disabled directly by drivers, they also should use | 182 | mechanisms are enabled or disabled directly by drivers, they also should use |
173 | device_may_wakeup() to decide what to do during a system sleep transition. | 183 | device_may_wakeup() to decide what to do during a system sleep transition. |
174 | However for runtime power management, wakeup events should be enabled whenever | 184 | Device drivers, however, are not supposed to call device_set_wakeup_enable() |
175 | the device and driver both support them, regardless of the should_wakeup flag. | 185 | directly in any case. |
176 | 186 | ||
187 | It ought to be noted that system wakeup is conceptually different from "remote | ||
188 | wakeup" used by runtime power management, although it may be supported by the | ||
189 | same physical mechanism. Remote wakeup is a feature allowing devices in | ||
190 | low-power states to trigger specific interrupts to signal conditions in which | ||
191 | they should be put into the full-power state. Those interrupts may or may not | ||
192 | be used to signal system wakeup events, depending on the hardware design. On | ||
193 | some systems it is impossible to trigger them from system sleep states. In any | ||
194 | case, remote wakeup should always be enabled for runtime power management for | ||
195 | all devices and drivers that support it. | ||
177 | 196 | ||
178 | /sys/devices/.../power/control files | 197 | /sys/devices/.../power/control files |
179 | ------------------------------------ | 198 | ------------------------------------ |
@@ -249,23 +268,37 @@ for every device before the next phase begins. Not all busses or classes | |||
249 | support all these callbacks and not all drivers use all the callbacks. The | 268 | support all these callbacks and not all drivers use all the callbacks. The |
250 | various phases always run after tasks have been frozen and before they are | 269 | various phases always run after tasks have been frozen and before they are |
251 | unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have | 270 | unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have |
252 | been disabled (except for those marked with the IRQ_WAKEUP flag). | 271 | been disabled (except for those marked with the IRQF_NO_SUSPEND flag). |
272 | |||
273 | All phases use PM domain, bus, type, class or driver callbacks (that is, methods | ||
274 | defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, dev->class->pm or | ||
275 | dev->driver->pm). These callbacks are regarded by the PM core as mutually | ||
276 | exclusive. Moreover, PM domain callbacks always take precedence over all of the | ||
277 | other callbacks and, for example, type callbacks take precedence over bus, class | ||
278 | and driver callbacks. To be precise, the following rules are used to determine | ||
279 | which callback to execute in the given phase: | ||
280 | |||
281 | 1. If dev->pm_domain is present, the PM core will choose the callback | ||
282 | included in dev->pm_domain->ops for execution | ||
283 | |||
284 | 2. Otherwise, if both dev->type and dev->type->pm are present, the callback | ||
285 | included in dev->type->pm will be chosen for execution. | ||
286 | |||
287 | 3. Otherwise, if both dev->class and dev->class->pm are present, the | ||
288 | callback included in dev->class->pm will be chosen for execution. | ||
289 | |||
290 | 4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback | ||
291 | included in dev->bus->pm will be chosen for execution. | ||
292 | |||
293 | This allows PM domains and device types to override callbacks provided by bus | ||
294 | types or device classes if necessary. | ||
253 | 295 | ||
254 | All phases use bus, type, or class callbacks (that is, methods defined in | 296 | The PM domain, type, class and bus callbacks may in turn invoke device- or |
255 | dev->bus->pm, dev->type->pm, or dev->class->pm). These callbacks are mutually | 297 | driver-specific methods stored in dev->driver->pm, but they don't have to do |
256 | exclusive, so if the device type provides a struct dev_pm_ops object pointed to | 298 | that. |
257 | by its pm field (i.e. both dev->type and dev->type->pm are defined), the | ||
258 | callbacks included in that object (i.e. dev->type->pm) will be used. Otherwise, | ||
259 | if the class provides a struct dev_pm_ops object pointed to by its pm field | ||
260 | (i.e. both dev->class and dev->class->pm are defined), the PM core will use the | ||
261 | callbacks from that object (i.e. dev->class->pm). Finally, if the pm fields of | ||
262 | both the device type and class objects are NULL (or those objects do not exist), | ||
263 | the callbacks provided by the bus (that is, the callbacks from dev->bus->pm) | ||
264 | will be used (this allows device types to override callbacks provided by bus | ||
265 | types or classes if necessary). | ||
266 | 299 | ||
267 | These callbacks may in turn invoke device- or driver-specific methods stored in | 300 | If the subsystem callback chosen for execution is not present, the PM core will |
268 | dev->driver->pm, but they don't have to. | 301 | execute the corresponding method from dev->driver->pm instead if there is one. |
269 | 302 | ||
270 | 303 | ||
271 | Entering System Suspend | 304 | Entering System Suspend |
@@ -283,9 +316,8 @@ When the system goes into the standby or memory sleep state, the phases are: | |||
283 | 316 | ||
284 | After the prepare callback method returns, no new children may be | 317 | After the prepare callback method returns, no new children may be |
285 | registered below the device. The method may also prepare the device or | 318 | registered below the device. The method may also prepare the device or |
286 | driver in some way for the upcoming system power transition (for | 319 | driver in some way for the upcoming system power transition, but it |
287 | example, by allocating additional memory required for this purpose), but | 320 | should not put the device into a low-power state. |
288 | it should not put the device into a low-power state. | ||
289 | 321 | ||
290 | 2. The suspend methods should quiesce the device to stop it from performing | 322 | 2. The suspend methods should quiesce the device to stop it from performing |
291 | I/O. They also may save the device registers and put it into the | 323 | I/O. They also may save the device registers and put it into the |
diff --git a/Documentation/power/freezing-of-tasks.txt b/Documentation/power/freezing-of-tasks.txt index 316c2ba187f4..6ccb68f68da6 100644 --- a/Documentation/power/freezing-of-tasks.txt +++ b/Documentation/power/freezing-of-tasks.txt | |||
@@ -21,7 +21,7 @@ freeze_processes() (defined in kernel/power/process.c) is called. It executes | |||
21 | try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and | 21 | try_to_freeze_tasks() that sets TIF_FREEZE for all of the freezable tasks and |
22 | either wakes them up, if they are kernel threads, or sends fake signals to them, | 22 | either wakes them up, if they are kernel threads, or sends fake signals to them, |
23 | if they are user space processes. A task that has TIF_FREEZE set, should react | 23 | if they are user space processes. A task that has TIF_FREEZE set, should react |
24 | to it by calling the function called refrigerator() (defined in | 24 | to it by calling the function called __refrigerator() (defined in |
25 | kernel/freezer.c), which sets the task's PF_FROZEN flag, changes its state | 25 | kernel/freezer.c), which sets the task's PF_FROZEN flag, changes its state |
26 | to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is cleared for it. | 26 | to TASK_UNINTERRUPTIBLE and makes it loop until PF_FROZEN is cleared for it. |
27 | Then, we say that the task is 'frozen' and therefore the set of functions | 27 | Then, we say that the task is 'frozen' and therefore the set of functions |
@@ -29,10 +29,10 @@ handling this mechanism is referred to as 'the freezer' (these functions are | |||
29 | defined in kernel/power/process.c, kernel/freezer.c & include/linux/freezer.h). | 29 | defined in kernel/power/process.c, kernel/freezer.c & include/linux/freezer.h). |
30 | User space processes are generally frozen before kernel threads. | 30 | User space processes are generally frozen before kernel threads. |
31 | 31 | ||
32 | It is not recommended to call refrigerator() directly. Instead, it is | 32 | __refrigerator() must not be called directly. Instead, use the |
33 | recommended to use the try_to_freeze() function (defined in | 33 | try_to_freeze() function (defined in include/linux/freezer.h), that checks |
34 | include/linux/freezer.h), that checks the task's TIF_FREEZE flag and makes the | 34 | the task's TIF_FREEZE flag and makes the task enter __refrigerator() if the |
35 | task enter refrigerator() if the flag is set. | 35 | flag is set. |
36 | 36 | ||
37 | For user space processes try_to_freeze() is called automatically from the | 37 | For user space processes try_to_freeze() is called automatically from the |
38 | signal-handling code, but the freezable kernel threads need to call it | 38 | signal-handling code, but the freezable kernel threads need to call it |
@@ -61,13 +61,13 @@ wait_event_freezable() and wait_event_freezable_timeout() macros. | |||
61 | After the system memory state has been restored from a hibernation image and | 61 | After the system memory state has been restored from a hibernation image and |
62 | devices have been reinitialized, the function thaw_processes() is called in | 62 | devices have been reinitialized, the function thaw_processes() is called in |
63 | order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that | 63 | order to clear the PF_FROZEN flag for each frozen task. Then, the tasks that |
64 | have been frozen leave refrigerator() and continue running. | 64 | have been frozen leave __refrigerator() and continue running. |
65 | 65 | ||
66 | III. Which kernel threads are freezable? | 66 | III. Which kernel threads are freezable? |
67 | 67 | ||
68 | Kernel threads are not freezable by default. However, a kernel thread may clear | 68 | Kernel threads are not freezable by default. However, a kernel thread may clear |
69 | PF_NOFREEZE for itself by calling set_freezable() (the resetting of PF_NOFREEZE | 69 | PF_NOFREEZE for itself by calling set_freezable() (the resetting of PF_NOFREEZE |
70 | directly is strongly discouraged). From this point it is regarded as freezable | 70 | directly is not allowed). From this point it is regarded as freezable |
71 | and must call try_to_freeze() in a suitable place. | 71 | and must call try_to_freeze() in a suitable place. |
72 | 72 | ||
73 | IV. Why do we do that? | 73 | IV. Why do we do that? |
@@ -176,3 +176,28 @@ tasks, since it generally exists anyway. | |||
176 | A driver must have all firmwares it may need in RAM before suspend() is called. | 176 | A driver must have all firmwares it may need in RAM before suspend() is called. |
177 | If keeping them is not practical, for example due to their size, they must be | 177 | If keeping them is not practical, for example due to their size, they must be |
178 | requested early enough using the suspend notifier API described in notifiers.txt. | 178 | requested early enough using the suspend notifier API described in notifiers.txt. |
179 | |||
180 | VI. Are there any precautions to be taken to prevent freezing failures? | ||
181 | |||
182 | Yes, there are. | ||
183 | |||
184 | First of all, grabbing the 'pm_mutex' lock to mutually exclude a piece of code | ||
185 | from system-wide sleep such as suspend/hibernation is not encouraged. | ||
186 | If possible, that piece of code must instead hook onto the suspend/hibernation | ||
187 | notifiers to achieve mutual exclusion. Look at the CPU-Hotplug code | ||
188 | (kernel/cpu.c) for an example. | ||
189 | |||
190 | However, if that is not feasible, and grabbing 'pm_mutex' is deemed necessary, | ||
191 | it is strongly discouraged to directly call mutex_[un]lock(&pm_mutex) since | ||
192 | that could lead to freezing failures, because if the suspend/hibernate code | ||
193 | successfully acquired the 'pm_mutex' lock, and hence that other entity failed | ||
194 | to acquire the lock, then that task would get blocked in TASK_UNINTERRUPTIBLE | ||
195 | state. As a consequence, the freezer would not be able to freeze that task, | ||
196 | leading to freezing failure. | ||
197 | |||
198 | However, the [un]lock_system_sleep() APIs are safe to use in this scenario, | ||
199 | since they ask the freezer to skip freezing this task, since it is anyway | ||
200 | "frozen enough" as it is blocked on 'pm_mutex', which will be released | ||
201 | only after the entire suspend/hibernation sequence is complete. | ||
202 | So, to summarize, use [un]lock_system_sleep() instead of directly using | ||
203 | mutex_[un]lock(&pm_mutex). That would prevent freezing failures. | ||
diff --git a/Documentation/power/runtime_pm.txt b/Documentation/power/runtime_pm.txt index 5336149f831b..4abe83e1045a 100644 --- a/Documentation/power/runtime_pm.txt +++ b/Documentation/power/runtime_pm.txt | |||
@@ -44,98 +44,112 @@ struct dev_pm_ops { | |||
44 | }; | 44 | }; |
45 | 45 | ||
46 | The ->runtime_suspend(), ->runtime_resume() and ->runtime_idle() callbacks | 46 | The ->runtime_suspend(), ->runtime_resume() and ->runtime_idle() callbacks |
47 | are executed by the PM core for either the power domain, or the device type | 47 | are executed by the PM core for the device's subsystem that may be either of |
48 | (if the device power domain's struct dev_pm_ops does not exist), or the class | 48 | the following: |
49 | (if the device power domain's and type's struct dev_pm_ops object does not | 49 | |
50 | exist), or the bus type (if the device power domain's, type's and class' | 50 | 1. PM domain of the device, if the device's PM domain object, dev->pm_domain, |
51 | struct dev_pm_ops objects do not exist) of the given device, so the priority | 51 | is present. |
52 | order of callbacks from high to low is that power domain callbacks, device | 52 | |
53 | type callbacks, class callbacks and bus type callbacks, and the high priority | 53 | 2. Device type of the device, if both dev->type and dev->type->pm are present. |
54 | one will take precedence over low priority one. The bus type, device type and | 54 | |
55 | class callbacks are referred to as subsystem-level callbacks in what follows, | 55 | 3. Device class of the device, if both dev->class and dev->class->pm are |
56 | and generally speaking, the power domain callbacks are used for representing | 56 | present. |
57 | power domains within a SoC. | 57 | |
58 | 4. Bus type of the device, if both dev->bus and dev->bus->pm are present. | ||
59 | |||
60 | If the subsystem chosen by applying the above rules doesn't provide the relevant | ||
61 | callback, the PM core will invoke the corresponding driver callback stored in | ||
62 | dev->driver->pm directly (if present). | ||
63 | |||
64 | The PM core always checks which callback to use in the order given above, so the | ||
65 | priority order of callbacks from high to low is: PM domain, device type, class | ||
66 | and bus type. Moreover, the high-priority one will always take precedence over | ||
67 | a low-priority one. The PM domain, bus type, device type and class callbacks | ||
68 | are referred to as subsystem-level callbacks in what follows. | ||
58 | 69 | ||
59 | By default, the callbacks are always invoked in process context with interrupts | 70 | By default, the callbacks are always invoked in process context with interrupts |
60 | enabled. However, subsystems can use the pm_runtime_irq_safe() helper function | 71 | enabled. However, the pm_runtime_irq_safe() helper function can be used to tell |
61 | to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume() | 72 | the PM core that it is safe to run the ->runtime_suspend(), ->runtime_resume() |
62 | callbacks should be invoked in atomic context with interrupts disabled. | 73 | and ->runtime_idle() callbacks for the given device in atomic context with |
63 | This implies that these callback routines must not block or sleep, but it also | 74 | interrupts disabled. This implies that the callback routines in question must |
64 | means that the synchronous helper functions listed at the end of Section 4 can | 75 | not block or sleep, but it also means that the synchronous helper functions |
65 | be used within an interrupt handler or in an atomic context. | 76 | listed at the end of Section 4 may be used for that device within an interrupt |
66 | 77 | handler or generally in an atomic context. | |
67 | The subsystem-level suspend callback is _entirely_ _responsible_ for handling | 78 | |
68 | the suspend of the device as appropriate, which may, but need not include | 79 | The subsystem-level suspend callback, if present, is _entirely_ _responsible_ |
69 | executing the device driver's own ->runtime_suspend() callback (from the | 80 | for handling the suspend of the device as appropriate, which may, but need not |
81 | include executing the device driver's own ->runtime_suspend() callback (from the | ||
70 | PM core's point of view it is not necessary to implement a ->runtime_suspend() | 82 | PM core's point of view it is not necessary to implement a ->runtime_suspend() |
71 | callback in a device driver as long as the subsystem-level suspend callback | 83 | callback in a device driver as long as the subsystem-level suspend callback |
72 | knows what to do to handle the device). | 84 | knows what to do to handle the device). |
73 | 85 | ||
74 | * Once the subsystem-level suspend callback has completed successfully | 86 | * Once the subsystem-level suspend callback (or the driver suspend callback, |
75 | for given device, the PM core regards the device as suspended, which need | 87 | if invoked directly) has completed successfully for the given device, the PM |
76 | not mean that the device has been put into a low power state. It is | 88 | core regards the device as suspended, which need not mean that it has been |
77 | supposed to mean, however, that the device will not process data and will | 89 | put into a low power state. It is supposed to mean, however, that the |
78 | not communicate with the CPU(s) and RAM until the subsystem-level resume | 90 | device will not process data and will not communicate with the CPU(s) and |
79 | callback is executed for it. The runtime PM status of a device after | 91 | RAM until the appropriate resume callback is executed for it. The runtime |
80 | successful execution of the subsystem-level suspend callback is 'suspended'. | 92 | PM status of a device after successful execution of the suspend callback is |
81 | 93 | 'suspended'. | |
82 | * If the subsystem-level suspend callback returns -EBUSY or -EAGAIN, | 94 | |
83 | the device's runtime PM status is 'active', which means that the device | 95 | * If the suspend callback returns -EBUSY or -EAGAIN, the device's runtime PM |
84 | _must_ be fully operational afterwards. | 96 | status remains 'active', which means that the device _must_ be fully |
85 | 97 | operational afterwards. | |
86 | * If the subsystem-level suspend callback returns an error code different | 98 | |
87 | from -EBUSY or -EAGAIN, the PM core regards this as a fatal error and will | 99 | * If the suspend callback returns an error code different from -EBUSY and |
88 | refuse to run the helper functions described in Section 4 for the device, | 100 | -EAGAIN, the PM core regards this as a fatal error and will refuse to run |
89 | until the status of it is directly set either to 'active', or to 'suspended' | 101 | the helper functions described in Section 4 for the device until its status |
90 | (the PM core provides special helper functions for this purpose). | 102 | is directly set to either'active', or 'suspended' (the PM core provides |
91 | 103 | special helper functions for this purpose). | |
92 | In particular, if the driver requires remote wake-up capability (i.e. hardware | 104 | |
105 | In particular, if the driver requires remote wakeup capability (i.e. hardware | ||
93 | mechanism allowing the device to request a change of its power state, such as | 106 | mechanism allowing the device to request a change of its power state, such as |
94 | PCI PME) for proper functioning and device_run_wake() returns 'false' for the | 107 | PCI PME) for proper functioning and device_run_wake() returns 'false' for the |
95 | device, then ->runtime_suspend() should return -EBUSY. On the other hand, if | 108 | device, then ->runtime_suspend() should return -EBUSY. On the other hand, if |
96 | device_run_wake() returns 'true' for the device and the device is put into a low | 109 | device_run_wake() returns 'true' for the device and the device is put into a |
97 | power state during the execution of the subsystem-level suspend callback, it is | 110 | low-power state during the execution of the suspend callback, it is expected |
98 | expected that remote wake-up will be enabled for the device. Generally, remote | 111 | that remote wakeup will be enabled for the device. Generally, remote wakeup |
99 | wake-up should be enabled for all input devices put into a low power state at | 112 | should be enabled for all input devices put into low-power states at run time. |
100 | run time. | 113 | |
101 | 114 | The subsystem-level resume callback, if present, is _entirely_ _responsible_ for | |
102 | The subsystem-level resume callback is _entirely_ _responsible_ for handling the | 115 | handling the resume of the device as appropriate, which may, but need not |
103 | resume of the device as appropriate, which may, but need not include executing | 116 | include executing the device driver's own ->runtime_resume() callback (from the |
104 | the device driver's own ->runtime_resume() callback (from the PM core's point of | 117 | PM core's point of view it is not necessary to implement a ->runtime_resume() |
105 | view it is not necessary to implement a ->runtime_resume() callback in a device | 118 | callback in a device driver as long as the subsystem-level resume callback knows |
106 | driver as long as the subsystem-level resume callback knows what to do to handle | 119 | what to do to handle the device). |
107 | the device). | 120 | |
108 | 121 | * Once the subsystem-level resume callback (or the driver resume callback, if | |
109 | * Once the subsystem-level resume callback has completed successfully, the PM | 122 | invoked directly) has completed successfully, the PM core regards the device |
110 | core regards the device as fully operational, which means that the device | 123 | as fully operational, which means that the device _must_ be able to complete |
111 | _must_ be able to complete I/O operations as needed. The runtime PM status | 124 | I/O operations as needed. The runtime PM status of the device is then |
112 | of the device is then 'active'. | 125 | 'active'. |
113 | 126 | ||
114 | * If the subsystem-level resume callback returns an error code, the PM core | 127 | * If the resume callback returns an error code, the PM core regards this as a |
115 | regards this as a fatal error and will refuse to run the helper functions | 128 | fatal error and will refuse to run the helper functions described in Section |
116 | described in Section 4 for the device, until its status is directly set | 129 | 4 for the device, until its status is directly set to either 'active', or |
117 | either to 'active' or to 'suspended' (the PM core provides special helper | 130 | 'suspended' (by means of special helper functions provided by the PM core |
118 | functions for this purpose). | 131 | for this purpose). |
119 | 132 | ||
120 | The subsystem-level idle callback is executed by the PM core whenever the device | 133 | The idle callback (a subsystem-level one, if present, or the driver one) is |
121 | appears to be idle, which is indicated to the PM core by two counters, the | 134 | executed by the PM core whenever the device appears to be idle, which is |
122 | device's usage counter and the counter of 'active' children of the device. | 135 | indicated to the PM core by two counters, the device's usage counter and the |
136 | counter of 'active' children of the device. | ||
123 | 137 | ||
124 | * If any of these counters is decreased using a helper function provided by | 138 | * If any of these counters is decreased using a helper function provided by |
125 | the PM core and it turns out to be equal to zero, the other counter is | 139 | the PM core and it turns out to be equal to zero, the other counter is |
126 | checked. If that counter also is equal to zero, the PM core executes the | 140 | checked. If that counter also is equal to zero, the PM core executes the |
127 | subsystem-level idle callback with the device as an argument. | 141 | idle callback with the device as its argument. |
128 | 142 | ||
129 | The action performed by a subsystem-level idle callback is totally dependent on | 143 | The action performed by the idle callback is totally dependent on the subsystem |
130 | the subsystem in question, but the expected and recommended action is to check | 144 | (or driver) in question, but the expected and recommended action is to check |
131 | if the device can be suspended (i.e. if all of the conditions necessary for | 145 | if the device can be suspended (i.e. if all of the conditions necessary for |
132 | suspending the device are satisfied) and to queue up a suspend request for the | 146 | suspending the device are satisfied) and to queue up a suspend request for the |
133 | device in that case. The value returned by this callback is ignored by the PM | 147 | device in that case. The value returned by this callback is ignored by the PM |
134 | core. | 148 | core. |
135 | 149 | ||
136 | The helper functions provided by the PM core, described in Section 4, guarantee | 150 | The helper functions provided by the PM core, described in Section 4, guarantee |
137 | that the following constraints are met with respect to the bus type's runtime | 151 | that the following constraints are met with respect to runtime PM callbacks for |
138 | PM callbacks: | 152 | one device: |
139 | 153 | ||
140 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute | 154 | (1) The callbacks are mutually exclusive (e.g. it is forbidden to execute |
141 | ->runtime_suspend() in parallel with ->runtime_resume() or with another | 155 | ->runtime_suspend() in parallel with ->runtime_resume() or with another |