Commit 8cd79203 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'pm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm

* 'pm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm:
  PM: Update comments describing device power management callbacks
  PM / Sleep: Update documentation related to system wakeup
  PM / Runtime: Make documentation follow the new behavior of irq_safe
  PM / Sleep: Correct inaccurate information in devices.txt
  PM / Domains: Document how PM domains are used by the PM core
  PM / Hibernate: Do not leak memory in error/test code paths
parents 57db53b0 f7bc83d8
...@@ -123,9 +123,10 @@ please refer directly to the source code for more information about it. ...@@ -123,9 +123,10 @@ please refer directly to the source code for more information about it.
Subsystem-Level Methods Subsystem-Level Methods
----------------------- -----------------------
The core methods to suspend and resume devices reside in struct dev_pm_ops The core methods to suspend and resume devices reside in struct dev_pm_ops
pointed to by the pm member of struct bus_type, struct device_type and pointed to by the ops member of struct dev_pm_domain, or by the pm member of
struct class. They are mostly of interest to the people writing infrastructure struct bus_type, struct device_type and struct class. They are mostly of
for buses, like PCI or USB, or device type and device class drivers. interest to the people writing infrastructure for platforms and buses, like PCI
or USB, or device type and device class drivers.
Bus drivers implement these methods as appropriate for the hardware and the Bus drivers implement these methods as appropriate for the hardware and the
drivers using it; PCI works differently from USB, and so on. Not many people drivers using it; PCI works differently from USB, and so on. Not many people
...@@ -139,41 +140,57 @@ sequencing in the driver model tree. ...@@ -139,41 +140,57 @@ sequencing in the driver model tree.
/sys/devices/.../power/wakeup files /sys/devices/.../power/wakeup files
----------------------------------- -----------------------------------
All devices in the driver model have two flags to control handling of wakeup All device objects in the driver model contain fields that control the handling
events (hardware signals that can force the device and/or system out of a low of system wakeup events (hardware signals that can force the system out of a
power state). These flags are initialized by bus or device driver code using sleep state). These fields are initialized by bus or device driver code using
device_set_wakeup_capable() and device_set_wakeup_enable(), defined in device_set_wakeup_capable() and device_set_wakeup_enable(), defined in
include/linux/pm_wakeup.h. include/linux/pm_wakeup.h.
The "can_wakeup" flag just records whether the device (and its driver) can The "power.can_wakeup" flag just records whether the device (and its driver) can
physically support wakeup events. The device_set_wakeup_capable() routine physically support wakeup events. The device_set_wakeup_capable() routine
affects this flag. The "should_wakeup" flag controls whether the device should affects this flag. The "power.wakeup" field is a pointer to an object of type
try to use its wakeup mechanism. device_set_wakeup_enable() affects this flag; struct wakeup_source used for controlling whether or not the device should use
for the most part drivers should not change its value. The initial value of its system wakeup mechanism and for notifying the PM core of system wakeup
should_wakeup is supposed to be false for the majority of devices; the major events signaled by the device. This object is only present for wakeup-capable
exceptions are power buttons, keyboards, and Ethernet adapters whose WoL devices (i.e. devices whose "can_wakeup" flags are set) and is created (or
(wake-on-LAN) feature has been set up with ethtool. It should also default removed) by device_set_wakeup_capable().
to true for devices that don't generate wakeup requests on their own but merely
forward wakeup requests from one bus to another (like PCI bridges).
Whether or not a device is capable of issuing wakeup events is a hardware Whether or not a device is capable of issuing wakeup events is a hardware
matter, and the kernel is responsible for keeping track of it. By contrast, matter, and the kernel is responsible for keeping track of it. By contrast,
whether or not a wakeup-capable device should issue wakeup events is a policy whether or not a wakeup-capable device should issue wakeup events is a policy
decision, and it is managed by user space through a sysfs attribute: the decision, and it is managed by user space through a sysfs attribute: the
power/wakeup file. User space can write the strings "enabled" or "disabled" to "power/wakeup" file. User space can write the strings "enabled" or "disabled"
set or clear the "should_wakeup" flag, respectively. This file is only present to it to indicate whether or not, respectively, the device is supposed to signal
for wakeup-capable devices (i.e. devices whose "can_wakeup" flags are set) system wakeup. This file is only present if the "power.wakeup" object exists
and is created (or removed) by device_set_wakeup_capable(). Reads from the for the given device and is created (or removed) along with that object, by
file will return the corresponding string. device_set_wakeup_capable(). Reads from the file will return the corresponding
string.
The device_may_wakeup() routine returns true only if both flags are set.
The "power/wakeup" file is supposed to contain the "disabled" string initially
for the majority of devices; the major exceptions are power buttons, keyboards,
and Ethernet adapters whose WoL (wake-on-LAN) feature has been set up with
ethtool. It should also default to "enabled" for devices that don't generate
wakeup requests on their own but merely forward wakeup requests from one bus to
another (like PCI Express ports).
The device_may_wakeup() routine returns true only if the "power.wakeup" object
exists and the corresponding "power/wakeup" file contains the string "enabled".
This information is used by subsystems, like the PCI bus type code, to see This information is used by subsystems, like the PCI bus type code, to see
whether or not to enable the devices' wakeup mechanisms. If device wakeup whether or not to enable the devices' wakeup mechanisms. If device wakeup
mechanisms are enabled or disabled directly by drivers, they also should use mechanisms are enabled or disabled directly by drivers, they also should use
device_may_wakeup() to decide what to do during a system sleep transition. device_may_wakeup() to decide what to do during a system sleep transition.
However for runtime power management, wakeup events should be enabled whenever Device drivers, however, are not supposed to call device_set_wakeup_enable()
the device and driver both support them, regardless of the should_wakeup flag. directly in any case.
It ought to be noted that system wakeup is conceptually different from "remote
wakeup" used by runtime power management, although it may be supported by the
same physical mechanism. Remote wakeup is a feature allowing devices in
low-power states to trigger specific interrupts to signal conditions in which
they should be put into the full-power state. Those interrupts may or may not
be used to signal system wakeup events, depending on the hardware design. On
some systems it is impossible to trigger them from system sleep states. In any
case, remote wakeup should always be enabled for runtime power management for
all devices and drivers that support it.
/sys/devices/.../power/control files /sys/devices/.../power/control files
------------------------------------ ------------------------------------
...@@ -249,20 +266,31 @@ for every device before the next phase begins. Not all busses or classes ...@@ -249,20 +266,31 @@ for every device before the next phase begins. Not all busses or classes
support all these callbacks and not all drivers use all the callbacks. The support all these callbacks and not all drivers use all the callbacks. The
various phases always run after tasks have been frozen and before they are various phases always run after tasks have been frozen and before they are
unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have unfrozen. Furthermore, the *_noirq phases run at a time when IRQ handlers have
been disabled (except for those marked with the IRQ_WAKEUP flag). been disabled (except for those marked with the IRQF_NO_SUSPEND flag).
All phases use bus, type, or class callbacks (that is, methods defined in All phases use PM domain, bus, type, or class callbacks (that is, methods
dev->bus->pm, dev->type->pm, or dev->class->pm). These callbacks are mutually defined in dev->pm_domain->ops, dev->bus->pm, dev->type->pm, or dev->class->pm).
exclusive, so if the device type provides a struct dev_pm_ops object pointed to These callbacks are regarded by the PM core as mutually exclusive. Moreover,
by its pm field (i.e. both dev->type and dev->type->pm are defined), the PM domain callbacks always take precedence over bus, type and class callbacks,
callbacks included in that object (i.e. dev->type->pm) will be used. Otherwise, while type callbacks take precedence over bus and class callbacks, and class
if the class provides a struct dev_pm_ops object pointed to by its pm field callbacks take precedence over bus callbacks. To be precise, the following
(i.e. both dev->class and dev->class->pm are defined), the PM core will use the rules are used to determine which callback to execute in the given phase:
callbacks from that object (i.e. dev->class->pm). Finally, if the pm fields of
both the device type and class objects are NULL (or those objects do not exist), 1. If dev->pm_domain is present, the PM core will attempt to execute the
the callbacks provided by the bus (that is, the callbacks from dev->bus->pm) callback included in dev->pm_domain->ops. If that callback is not
will be used (this allows device types to override callbacks provided by bus present, no action will be carried out for the given device.
types or classes if necessary).
2. Otherwise, if both dev->type and dev->type->pm are present, the callback
included in dev->type->pm will be executed.
3. Otherwise, if both dev->class and dev->class->pm are present, the
callback included in dev->class->pm will be executed.
4. Otherwise, if both dev->bus and dev->bus->pm are present, the callback
included in dev->bus->pm will be executed.
This allows PM domains and device types to override callbacks provided by bus
types or device classes if necessary.
These callbacks may in turn invoke device- or driver-specific methods stored in These callbacks may in turn invoke device- or driver-specific methods stored in
dev->driver->pm, but they don't have to. dev->driver->pm, but they don't have to.
...@@ -283,9 +311,8 @@ When the system goes into the standby or memory sleep state, the phases are: ...@@ -283,9 +311,8 @@ When the system goes into the standby or memory sleep state, the phases are:
After the prepare callback method returns, no new children may be After the prepare callback method returns, no new children may be
registered below the device. The method may also prepare the device or registered below the device. The method may also prepare the device or
driver in some way for the upcoming system power transition (for driver in some way for the upcoming system power transition, but it
example, by allocating additional memory required for this purpose), but should not put the device into a low-power state.
it should not put the device into a low-power state.
2. The suspend methods should quiesce the device to stop it from performing 2. The suspend methods should quiesce the device to stop it from performing
I/O. They also may save the device registers and put it into the I/O. They also may save the device registers and put it into the
......
...@@ -44,25 +44,33 @@ struct dev_pm_ops { ...@@ -44,25 +44,33 @@ struct dev_pm_ops {
}; };
The ->runtime_suspend(), ->runtime_resume() and ->runtime_idle() callbacks The ->runtime_suspend(), ->runtime_resume() and ->runtime_idle() callbacks
are executed by the PM core for either the power domain, or the device type are executed by the PM core for the device's subsystem that may be either of
(if the device power domain's struct dev_pm_ops does not exist), or the class the following:
(if the device power domain's and type's struct dev_pm_ops object does not
exist), or the bus type (if the device power domain's, type's and class' 1. PM domain of the device, if the device's PM domain object, dev->pm_domain,
struct dev_pm_ops objects do not exist) of the given device, so the priority is present.
order of callbacks from high to low is that power domain callbacks, device
type callbacks, class callbacks and bus type callbacks, and the high priority 2. Device type of the device, if both dev->type and dev->type->pm are present.
one will take precedence over low priority one. The bus type, device type and
class callbacks are referred to as subsystem-level callbacks in what follows, 3. Device class of the device, if both dev->class and dev->class->pm are
and generally speaking, the power domain callbacks are used for representing present.
power domains within a SoC.
4. Bus type of the device, if both dev->bus and dev->bus->pm are present.
The PM core always checks which callback to use in the order given above, so the
priority order of callbacks from high to low is: PM domain, device type, class
and bus type. Moreover, the high-priority one will always take precedence over
a low-priority one. The PM domain, bus type, device type and class callbacks
are referred to as subsystem-level callbacks in what follows.
By default, the callbacks are always invoked in process context with interrupts By default, the callbacks are always invoked in process context with interrupts
enabled. However, subsystems can use the pm_runtime_irq_safe() helper function enabled. However, subsystems can use the pm_runtime_irq_safe() helper function
to tell the PM core that a device's ->runtime_suspend() and ->runtime_resume() to tell the PM core that their ->runtime_suspend(), ->runtime_resume() and
callbacks should be invoked in atomic context with interrupts disabled. ->runtime_idle() callbacks may be invoked in atomic context with interrupts
This implies that these callback routines must not block or sleep, but it also disabled for a given device. This implies that the callback routines in
means that the synchronous helper functions listed at the end of Section 4 can question must not block or sleep, but it also means that the synchronous helper
be used within an interrupt handler or in an atomic context. functions listed at the end of Section 4 may be used for that device within an
interrupt handler or generally in an atomic context.
The subsystem-level suspend callback is _entirely_ _responsible_ for handling The subsystem-level suspend callback is _entirely_ _responsible_ for handling
the suspend of the device as appropriate, which may, but need not include the suspend of the device as appropriate, which may, but need not include
......
This diff is collapsed.
...@@ -347,7 +347,7 @@ int hibernation_snapshot(int platform_mode) ...@@ -347,7 +347,7 @@ int hibernation_snapshot(int platform_mode)
error = freeze_kernel_threads(); error = freeze_kernel_threads();
if (error) if (error)
goto Close; goto Cleanup;
if (hibernation_test(TEST_FREEZER) || if (hibernation_test(TEST_FREEZER) ||
hibernation_testmode(HIBERNATION_TESTPROC)) { hibernation_testmode(HIBERNATION_TESTPROC)) {
...@@ -357,12 +357,14 @@ int hibernation_snapshot(int platform_mode) ...@@ -357,12 +357,14 @@ int hibernation_snapshot(int platform_mode)
* successful freezer test. * successful freezer test.
*/ */
freezer_test_done = true; freezer_test_done = true;
goto Close; goto Cleanup;
} }
error = dpm_prepare(PMSG_FREEZE); error = dpm_prepare(PMSG_FREEZE);
if (error) if (error) {
goto Complete_devices; dpm_complete(msg);
goto Cleanup;
}
suspend_console(); suspend_console();
pm_restrict_gfp_mask(); pm_restrict_gfp_mask();
...@@ -391,8 +393,6 @@ int hibernation_snapshot(int platform_mode) ...@@ -391,8 +393,6 @@ int hibernation_snapshot(int platform_mode)
pm_restore_gfp_mask(); pm_restore_gfp_mask();
resume_console(); resume_console();
Complete_devices:
dpm_complete(msg); dpm_complete(msg);
Close: Close:
...@@ -402,6 +402,10 @@ int hibernation_snapshot(int platform_mode) ...@@ -402,6 +402,10 @@ int hibernation_snapshot(int platform_mode)
Recover_platform: Recover_platform:
platform_recover(platform_mode); platform_recover(platform_mode);
goto Resume_devices; goto Resume_devices;
Cleanup:
swsusp_free();
goto Close;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment