aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-09-19 20:26:00 -0400
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-09-23 09:00:57 -0400
commit104dc5e20ff52748a16f756ae946391bdc6a4d0a (patch)
treed03a2b3200e0138f362c27b637f6cf3de5bdf932
parent2bd6bf03f4c1c59381d62c61d03f6cc3fe71f66e (diff)
PM: Document rules on using pm_runtime_resume() in system suspend callbacks
It quite often is necessary to resume devices from runtime suspend during system suspend for various reasons (for example, if their wakeup settings need to be changed), but that requires middle-layer or subsystem code to follow additional rules which currently are not clearly documented. Namely, if a driver calls pm_runtime_resume() for the device from its ->suspend (or equivalent) system sleep callback, that may not work if the middle layer above it has updated the state of the device from its ->prepare or ->suspend callbacks already in an incompatible way. For this reason, all middle layers must follow the rule that, until the ->suspend callback provided by the device's driver is invoked, the only way in which the device's state can be updated is by calling pm_runtime_resume() for it, if necessary. Fortunately enough, all middle layers in the code base today follow this rule, but it is not explicitly stated anywhere, so do that. Note that calling pm_runtime_resume() from the ->suspend callback of a driver will cause the ->runtime_resume callback provided by the middle layer to be invoked, but the rule above guarantees that this callback will nest properly with the middle layer's ->suspend callback and it will play well with the ->prepare one invoked before. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
-rw-r--r--Documentation/driver-api/pm/devices.rst25
1 files changed, 24 insertions, 1 deletions
diff --git a/Documentation/driver-api/pm/devices.rst b/Documentation/driver-api/pm/devices.rst
index bedd32388dac..a8b07ec732bd 100644
--- a/Documentation/driver-api/pm/devices.rst
+++ b/Documentation/driver-api/pm/devices.rst
@@ -328,7 +328,10 @@ the phases are: ``prepare``, ``suspend``, ``suspend_late``, ``suspend_noirq``.
328 After the ``->prepare`` callback method returns, no new children may be 328 After the ``->prepare`` callback method returns, no new children may be
329 registered below the device. The method may also prepare the device or 329 registered below the device. The method may also prepare the device or
330 driver in some way for the upcoming system power transition, but it 330 driver in some way for the upcoming system power transition, but it
331 should not put the device into a low-power state. 331 should not put the device into a low-power state. Moreover, if the
332 device supports runtime power management, the ``->prepare`` callback
333 method must not update its state in case it is necessary to resume it
334 from runtime suspend later on.
332 335
333 For devices supporting runtime power management, the return value of the 336 For devices supporting runtime power management, the return value of the
334 prepare callback can be used to indicate to the PM core that it may 337 prepare callback can be used to indicate to the PM core that it may
@@ -356,6 +359,16 @@ the phases are: ``prepare``, ``suspend``, ``suspend_late``, ``suspend_noirq``.
356 the appropriate low-power state, depending on the bus type the device is 359 the appropriate low-power state, depending on the bus type the device is
357 on, and they may enable wakeup events. 360 on, and they may enable wakeup events.
358 361
362 However, for devices supporting runtime power management, the
363 ``->suspend`` methods provided by subsystems (bus types and PM domains
364 in particular) must follow an additional rule regarding what can be done
365 to the devices before their drivers' ``->suspend`` methods are called.
366 Namely, they can only resume the devices from runtime suspend by
367 calling :c:func:`pm_runtime_resume` for them, if that is necessary, and
368 they must not update the state of the devices in any other way at that
369 time (in case the drivers need to resume the devices from runtime
370 suspend in their ``->suspend`` methods).
371
359 3. For a number of devices it is convenient to split suspend into the 372 3. For a number of devices it is convenient to split suspend into the
360 "quiesce device" and "save device state" phases, in which cases 373 "quiesce device" and "save device state" phases, in which cases
361 ``suspend_late`` is meant to do the latter. It is always executed after 374 ``suspend_late`` is meant to do the latter. It is always executed after
@@ -729,6 +742,16 @@ state temporarily, for example so that its system wakeup capability can be
729disabled. This all depends on the hardware and the design of the subsystem and 742disabled. This all depends on the hardware and the design of the subsystem and
730device driver in question. 743device driver in question.
731 744
745If it is necessary to resume a device from runtime suspend during a system-wide
746transition into a sleep state, that can be done by calling
747:c:func:`pm_runtime_resume` for it from the ``->suspend`` callback (or its
748couterpart for transitions related to hibernation) of either the device's driver
749or a subsystem responsible for it (for example, a bus type or a PM domain).
750That is guaranteed to work by the requirement that subsystems must not change
751the state of devices (possibly except for resuming them from runtime suspend)
752from their ``->prepare`` and ``->suspend`` callbacks (or equivalent) *before*
753invoking device drivers' ``->suspend`` callbacks (or equivalent).
754
732During system-wide resume from a sleep state it's easiest to put devices into 755During system-wide resume from a sleep state it's easiest to put devices into
733the full-power state, as explained in :file:`Documentation/power/runtime_pm.txt`. 756the full-power state, as explained in :file:`Documentation/power/runtime_pm.txt`.
734Refer to that document for more information regarding this particular issue as 757Refer to that document for more information regarding this particular issue as