PM: Update comments describing device power management callbacks

The comments describing device power management callbacks in
include/pm.h are outdated and somewhat confusing, so make them
reflect the reality more accurately.

Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
This commit is contained in:
Rafael J. Wysocki 2011-11-23 21:20:32 +01:00
parent fafba48d4d
commit f7bc83d87d
1 changed files with 127 additions and 88 deletions

View File

@ -54,118 +54,145 @@ typedef struct pm_message {
/** /**
* struct dev_pm_ops - device PM callbacks * struct dev_pm_ops - device PM callbacks
* *
* Several driver power state transitions are externally visible, affecting * Several device power state transitions are externally visible, affecting
* the state of pending I/O queues and (for drivers that touch hardware) * the state of pending I/O queues and (for drivers that touch hardware)
* interrupts, wakeups, DMA, and other hardware state. There may also be * interrupts, wakeups, DMA, and other hardware state. There may also be
* internal transitions to various low power modes, which are transparent * internal transitions to various low-power modes which are transparent
* to the rest of the driver stack (such as a driver that's ON gating off * to the rest of the driver stack (such as a driver that's ON gating off
* clocks which are not in active use). * clocks which are not in active use).
* *
* The externally visible transitions are handled with the help of the following * The externally visible transitions are handled with the help of callbacks
* callbacks included in this structure: * included in this structure in such a way that two levels of callbacks are
* involved. First, the PM core executes callbacks provided by PM domains,
* device types, classes and bus types. They are the subsystem-level callbacks
* supposed to execute callbacks provided by device drivers, although they may
* choose not to do that. If the driver callbacks are executed, they have to
* collaborate with the subsystem-level callbacks to achieve the goals
* appropriate for the given system transition, given transition phase and the
* subsystem the device belongs to.
* *
* @prepare: Prepare the device for the upcoming transition, but do NOT change * @prepare: The principal role of this callback is to prevent new children of
* its hardware state. Prevent new children of the device from being * the device from being registered after it has returned (the driver's
* registered after @prepare() returns (the driver's subsystem and * subsystem and generally the rest of the kernel is supposed to prevent
* generally the rest of the kernel is supposed to prevent new calls to the * new calls to the probe method from being made too once @prepare() has
* probe method from being made too once @prepare() has succeeded). If * succeeded). If @prepare() detects a situation it cannot handle (e.g.
* @prepare() detects a situation it cannot handle (e.g. registration of a * registration of a child already in progress), it may return -EAGAIN, so
* child already in progress), it may return -EAGAIN, so that the PM core * that the PM core can execute it once again (e.g. after a new child has
* can execute it once again (e.g. after the new child has been registered) * been registered) to recover from the race condition.
* to recover from the race condition. This method is executed for all * This method is executed for all kinds of suspend transitions and is
* kinds of suspend transitions and is followed by one of the suspend * followed by one of the suspend callbacks: @suspend(), @freeze(), or
* callbacks: @suspend(), @freeze(), or @poweroff(). * @poweroff(). The PM core executes subsystem-level @prepare() for all
* The PM core executes @prepare() for all devices before starting to * devices before starting to invoke suspend callbacks for any of them, so
* execute suspend callbacks for any of them, so drivers may assume all of * generally devices may be assumed to be functional or to respond to
* the other devices to be present and functional while @prepare() is being * runtime resume requests while @prepare() is being executed. However,
* executed. In particular, it is safe to make GFP_KERNEL memory * device drivers may NOT assume anything about the availability of user
* allocations from within @prepare(). However, drivers may NOT assume * space at that time and it is NOT valid to request firmware from within
* anything about the availability of the user space at that time and it * @prepare() (it's too late to do that). It also is NOT valid to allocate
* is not correct to request firmware from within @prepare() (it's too * substantial amounts of memory from @prepare() in the GFP_KERNEL mode.
* late to do that). [To work around this limitation, drivers may * [To work around these limitations, drivers may register suspend and
* register suspend and hibernation notifiers that are executed before the * hibernation notifiers to be executed before the freezing of tasks.]
* freezing of tasks.]
* *
* @complete: Undo the changes made by @prepare(). This method is executed for * @complete: Undo the changes made by @prepare(). This method is executed for
* all kinds of resume transitions, following one of the resume callbacks: * all kinds of resume transitions, following one of the resume callbacks:
* @resume(), @thaw(), @restore(). Also called if the state transition * @resume(), @thaw(), @restore(). Also called if the state transition
* fails before the driver's suspend callback (@suspend(), @freeze(), * fails before the driver's suspend callback: @suspend(), @freeze() or
* @poweroff()) can be executed (e.g. if the suspend callback fails for one * @poweroff(), can be executed (e.g. if the suspend callback fails for one
* of the other devices that the PM core has unsuccessfully attempted to * of the other devices that the PM core has unsuccessfully attempted to
* suspend earlier). * suspend earlier).
* The PM core executes @complete() after it has executed the appropriate * The PM core executes subsystem-level @complete() after it has executed
* resume callback for all devices. * the appropriate resume callbacks for all devices.
* *
* @suspend: Executed before putting the system into a sleep state in which the * @suspend: Executed before putting the system into a sleep state in which the
* contents of main memory are preserved. Quiesce the device, put it into * contents of main memory are preserved. The exact action to perform
* a low power state appropriate for the upcoming system state (such as * depends on the device's subsystem (PM domain, device type, class or bus
* PCI_D3hot), and enable wakeup events as appropriate. * type), but generally the device must be quiescent after subsystem-level
* @suspend() has returned, so that it doesn't do any I/O or DMA.
* Subsystem-level @suspend() is executed for all devices after invoking
* subsystem-level @prepare() for all of them.
* *
* @resume: Executed after waking the system up from a sleep state in which the * @resume: Executed after waking the system up from a sleep state in which the
* contents of main memory were preserved. Put the device into the * contents of main memory were preserved. The exact action to perform
* appropriate state, according to the information saved in memory by the * depends on the device's subsystem, but generally the driver is expected
* preceding @suspend(). The driver starts working again, responding to * to start working again, responding to hardware events and software
* hardware events and software requests. The hardware may have gone * requests (the device itself may be left in a low-power state, waiting
* through a power-off reset, or it may have maintained state from the * for a runtime resume to occur). The state of the device at the time its
* previous suspend() which the driver may rely on while resuming. On most * driver's @resume() callback is run depends on the platform and subsystem
* platforms, there are no restrictions on availability of resources like * the device belongs to. On most platforms, there are no restrictions on
* clocks during @resume(). * availability of resources like clocks during @resume().
* Subsystem-level @resume() is executed for all devices after invoking
* subsystem-level @resume_noirq() for all of them.
* *
* @freeze: Hibernation-specific, executed before creating a hibernation image. * @freeze: Hibernation-specific, executed before creating a hibernation image.
* Quiesce operations so that a consistent image can be created, but do NOT * Analogous to @suspend(), but it should not enable the device to signal
* otherwise put the device into a low power device state and do NOT emit * wakeup events or change its power state. The majority of subsystems
* system wakeup events. Save in main memory the device settings to be * (with the notable exception of the PCI bus type) expect the driver-level
* used by @restore() during the subsequent resume from hibernation or by * @freeze() to save the device settings in memory to be used by @restore()
* the subsequent @thaw(), if the creation of the image or the restoration * during the subsequent resume from hibernation.
* of main memory contents from it fails. * Subsystem-level @freeze() is executed for all devices after invoking
* subsystem-level @prepare() for all of them.
* *
* @thaw: Hibernation-specific, executed after creating a hibernation image OR * @thaw: Hibernation-specific, executed after creating a hibernation image OR
* if the creation of the image fails. Also executed after a failing * if the creation of an image has failed. Also executed after a failing
* attempt to restore the contents of main memory from such an image. * attempt to restore the contents of main memory from such an image.
* Undo the changes made by the preceding @freeze(), so the device can be * Undo the changes made by the preceding @freeze(), so the device can be
* operated in the same way as immediately before the call to @freeze(). * operated in the same way as immediately before the call to @freeze().
* Subsystem-level @thaw() is executed for all devices after invoking
* subsystem-level @thaw_noirq() for all of them. It also may be executed
* directly after @freeze() in case of a transition error.
* *
* @poweroff: Hibernation-specific, executed after saving a hibernation image. * @poweroff: Hibernation-specific, executed after saving a hibernation image.
* Quiesce the device, put it into a low power state appropriate for the * Analogous to @suspend(), but it need not save the device's settings in
* upcoming system state (such as PCI_D3hot), and enable wakeup events as * memory.
* appropriate. * Subsystem-level @poweroff() is executed for all devices after invoking
* subsystem-level @prepare() for all of them.
* *
* @restore: Hibernation-specific, executed after restoring the contents of main * @restore: Hibernation-specific, executed after restoring the contents of main
* memory from a hibernation image. Driver starts working again, * memory from a hibernation image, analogous to @resume().
* responding to hardware events and software requests. Drivers may NOT
* make ANY assumptions about the hardware state right prior to @restore().
* On most platforms, there are no restrictions on availability of
* resources like clocks during @restore().
* *
* @suspend_noirq: Complete the operations of ->suspend() by carrying out any * @suspend_noirq: Complete the actions started by @suspend(). Carry out any
* actions required for suspending the device that need interrupts to be * additional operations required for suspending the device that might be
* disabled * racing with its driver's interrupt handler, which is guaranteed not to
* run while @suspend_noirq() is being executed.
* It generally is expected that the device will be in a low-power state
* (appropriate for the target system sleep state) after subsystem-level
* @suspend_noirq() has returned successfully. If the device can generate
* system wakeup signals and is enabled to wake up the system, it should be
* configured to do so at that time. However, depending on the platform
* and device's subsystem, @suspend() may be allowed to put the device into
* the low-power state and configure it to generate wakeup signals, in
* which case it generally is not necessary to define @suspend_noirq().
* *
* @resume_noirq: Prepare for the execution of ->resume() by carrying out any * @resume_noirq: Prepare for the execution of @resume() by carrying out any
* actions required for resuming the device that need interrupts to be * operations required for resuming the device that might be racing with
* disabled * its driver's interrupt handler, which is guaranteed not to run while
* @resume_noirq() is being executed.
* *
* @freeze_noirq: Complete the operations of ->freeze() by carrying out any * @freeze_noirq: Complete the actions started by @freeze(). Carry out any
* actions required for freezing the device that need interrupts to be * additional operations required for freezing the device that might be
* disabled * racing with its driver's interrupt handler, which is guaranteed not to
* run while @freeze_noirq() is being executed.
* The power state of the device should not be changed by either @freeze()
* or @freeze_noirq() and it should not be configured to signal system
* wakeup by any of these callbacks.
* *
* @thaw_noirq: Prepare for the execution of ->thaw() by carrying out any * @thaw_noirq: Prepare for the execution of @thaw() by carrying out any
* actions required for thawing the device that need interrupts to be * operations required for thawing the device that might be racing with its
* disabled * driver's interrupt handler, which is guaranteed not to run while
* @thaw_noirq() is being executed.
* *
* @poweroff_noirq: Complete the operations of ->poweroff() by carrying out any * @poweroff_noirq: Complete the actions started by @poweroff(). Analogous to
* actions required for handling the device that need interrupts to be * @suspend_noirq(), but it need not save the device's settings in memory.
* disabled
* *
* @restore_noirq: Prepare for the execution of ->restore() by carrying out any * @restore_noirq: Prepare for the execution of @restore() by carrying out any
* actions required for restoring the operations of the device that need * operations required for thawing the device that might be racing with its
* interrupts to be disabled * driver's interrupt handler, which is guaranteed not to run while
* @restore_noirq() is being executed. Analogous to @resume_noirq().
* *
* All of the above callbacks, except for @complete(), return error codes. * All of the above callbacks, except for @complete(), return error codes.
* However, the error codes returned by the resume operations, @resume(), * However, the error codes returned by the resume operations, @resume(),
* @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq() do * @thaw(), @restore(), @resume_noirq(), @thaw_noirq(), and @restore_noirq(), do
* not cause the PM core to abort the resume transition during which they are * not cause the PM core to abort the resume transition during which they are
* returned. The error codes returned in that cases are only printed by the PM * returned. The error codes returned in those cases are only printed by the PM
* core to the system logs for debugging purposes. Still, it is recommended * core to the system logs for debugging purposes. Still, it is recommended
* that drivers only return error codes from their resume methods in case of an * that drivers only return error codes from their resume methods in case of an
* unrecoverable failure (i.e. when the device being handled refuses to resume * unrecoverable failure (i.e. when the device being handled refuses to resume
@ -174,31 +201,43 @@ typedef struct pm_message {
* their children. * their children.
* *
* It is allowed to unregister devices while the above callbacks are being * It is allowed to unregister devices while the above callbacks are being
* executed. However, it is not allowed to unregister a device from within any * executed. However, a callback routine must NOT try to unregister the device
* of its own callbacks. * it was called for, although it may unregister children of that device (for
* example, if it detects that a child was unplugged while the system was
* asleep).
* *
* There also are the following callbacks related to run-time power management * Refer to Documentation/power/devices.txt for more information about the role
* of devices: * of the above callbacks in the system suspend process.
*
* There also are callbacks related to runtime power management of devices.
* Again, these callbacks are executed by the PM core only for subsystems
* (PM domains, device types, classes and bus types) and the subsystem-level
* callbacks are supposed to invoke the driver callbacks. Moreover, the exact
* actions to be performed by a device driver's callbacks generally depend on
* the platform and subsystem the device belongs to.
* *
* @runtime_suspend: Prepare the device for a condition in which it won't be * @runtime_suspend: Prepare the device for a condition in which it won't be
* able to communicate with the CPU(s) and RAM due to power management. * able to communicate with the CPU(s) and RAM due to power management.
* This need not mean that the device should be put into a low power state. * This need not mean that the device should be put into a low-power state.
* For example, if the device is behind a link which is about to be turned * For example, if the device is behind a link which is about to be turned
* off, the device may remain at full power. If the device does go to low * off, the device may remain at full power. If the device does go to low
* power and is capable of generating run-time wake-up events, remote * power and is capable of generating runtime wakeup events, remote wakeup
* wake-up (i.e., a hardware mechanism allowing the device to request a * (i.e., a hardware mechanism allowing the device to request a change of
* change of its power state via a wake-up event, such as PCI PME) should * its power state via an interrupt) should be enabled for it.
* be enabled for it.
* *
* @runtime_resume: Put the device into the fully active state in response to a * @runtime_resume: Put the device into the fully active state in response to a
* wake-up event generated by hardware or at the request of software. If * wakeup event generated by hardware or at the request of software. If
* necessary, put the device into the full power state and restore its * necessary, put the device into the full-power state and restore its
* registers, so that it is fully operational. * registers, so that it is fully operational.
* *
* @runtime_idle: Device appears to be inactive and it might be put into a low * @runtime_idle: Device appears to be inactive and it might be put into a
* power state if all of the necessary conditions are satisfied. Check * low-power state if all of the necessary conditions are satisfied. Check
* these conditions and handle the device as appropriate, possibly queueing * these conditions and handle the device as appropriate, possibly queueing
* a suspend request for it. The return value is ignored by the PM core. * a suspend request for it. The return value is ignored by the PM core.
*
* Refer to Documentation/power/runtime_pm.txt for more information about the
* role of the above callbacks in device runtime power management.
*
*/ */
struct dev_pm_ops { struct dev_pm_ops {