@@ -772,62 +772,107 @@ the state of devices (possibly except for resuming them from runtime suspend)
772
772
from their ``->prepare `` and ``->suspend `` callbacks (or equivalent) *before *
773
773
invoking device drivers' ``->suspend `` callbacks (or equivalent).
774
774
775
+ .. _smart_suspend_flag :
776
+
777
+ The ``DPM_FLAG_SMART_SUSPEND `` Driver Flag
778
+ ------------------------------------------
779
+
775
780
Some bus types and PM domains have a policy to resume all devices from runtime
776
781
suspend upfront in their ``->suspend `` callbacks, but that may not be really
777
782
necessary if the driver of the device can cope with runtime-suspended devices.
778
783
The driver can indicate that by setting ``DPM_FLAG_SMART_SUSPEND `` in
779
- :c:member: `power.driver_flags ` at the probe time, by passing it to the
780
- :c:func: `dev_pm_set_driver_flags ` helper. That also may cause middle-layer code
784
+ :c:member: `power.driver_flags ` at the probe time with the help of the
785
+ :c:func: `dev_pm_set_driver_flags ` helper routine.
786
+
787
+ However, setting that flag also causes the PM core and middle-layer code
781
788
(bus types, PM domains etc.) to skip the ``->suspend_late `` and
782
789
``->suspend_noirq `` callbacks provided by the driver if the device remains in
783
- runtime suspend at the beginning of the ``suspend_late `` phase of system-wide
784
- suspend (or in the ``poweroff_late `` phase of hibernation), when runtime PM
785
- has been disabled for it, under the assumption that its state should not change
786
- after that point until the system-wide transition is over (the PM core itself
787
- does that for devices whose "noirq", "late" and "early" system-wide PM callbacks
788
- are executed directly by it). If that happens, the driver's system-wide resume
789
- callbacks, if present, may still be invoked during the subsequent system-wide
790
- resume transition and the device's runtime power management status may be set
791
- to "active" before enabling runtime PM for it, so the driver must be prepared to
792
- cope with the invocation of its system-wide resume callbacks back-to-back with
793
- its ``->runtime_suspend `` one (without the intervening ``->runtime_resume `` and
794
- so on) and the final state of the device must reflect the "active" runtime PM
795
- status in that case.
790
+ runtime suspend during the ``suspend_late `` phase of system-wide suspend (or
791
+ during the ``poweroff_late `` or ``freeze_late `` phase of hibernation),
792
+ after runtime PM was disabled for it. [Without doing that, the same driver
793
+ callback might be executed twice in a row for the same device, which would not
794
+ be valid in general.] If the middle-layer system-wide PM callbacks are present
795
+ for the device, they are responsible for doing the above, and the PM core takes
796
+ care of it otherwise.
797
+
798
+ In addition, with ``DPM_FLAG_SMART_SUSPEND `` set, the driver's ``->thaw_late ``
799
+ and ``->thaw_noirq `` callbacks are skipped if the device remained in runtime
800
+ suspend during the preceding "freeze" transition related to hibernation.
801
+ Again, if the middle-layer callbacks are present for the device, they are
802
+ responsible for doing that, or the PM core takes care of it otherwise.
803
+
804
+
805
+ The ``DPM_FLAG_MAY_SKIP_RESUME `` Driver Flag
806
+ --------------------------------------------
796
807
797
808
During system-wide resume from a sleep state it's easiest to put devices into
798
809
the full-power state, as explained in :file: `Documentation/power/runtime_pm.rst `.
799
810
[Refer to that document for more information regarding this particular issue as
800
811
well as for information on the device runtime power management framework in
801
- general.]
802
-
803
- However, it often is desirable to leave devices in suspend after system
804
- transitions to the working state, especially if those devices had been in
812
+ general.] However, it often is desirable to leave devices in suspend after
813
+ system transitions to the working state, especially if those devices had been in
805
814
runtime suspend before the preceding system-wide suspend (or analogous)
806
- transition. Device drivers can use the ``DPM_FLAG_MAY_SKIP_RESUME `` flag to
807
- indicate to the PM core (and middle-layer code) that they prefer the specific
808
- devices handled by them to be left suspended and they have no problems with
809
- skipping their system-wide resume callbacks for this reason. Whether or not the
810
- devices will actually be left in suspend may depend on their state before the
811
- given system suspend-resume cycle and on the type of the system transition under
812
- way. In particular, devices are not left suspended if that transition is a
813
- restore from hibernation, as device states are not guaranteed to be reflected
814
- by the information stored in the hibernation image in that case.
815
-
816
- The middle-layer code involved in the handling of the device is expected to
817
- indicate to the PM core if the device may be left in suspend by setting its
818
- :c:member: `power.may_skip_resume ` status bit which is checked by the PM core
819
- during the "noirq" phase of the preceding system-wide suspend (or analogous)
820
- transition. The middle layer is then responsible for handling the device as
821
- appropriate in its "noirq" resume callback, which is executed regardless of
822
- whether or not the device is left suspended, but the other resume callbacks
823
- (except for ``->complete ``) will be skipped automatically by the PM core if the
824
- device really can be left in suspend.
825
-
826
- For devices whose "noirq", "late" and "early" driver callbacks are invoked
827
- directly by the PM core, all of the system-wide resume callbacks are skipped if
828
- ``DPM_FLAG_MAY_SKIP_RESUME `` is set and the device is in runtime suspend during
829
- the ``suspend_noirq `` (or analogous) phase or the transition under way is a
830
- proper system suspend (rather than anything related to hibernation) and the
831
- device's wakeup settings are suitable for runtime PM (that is, it cannot
832
- generate wakeup signals at all or it is allowed to wake up the system from
833
- sleep).
815
+ transition.
816
+
817
+ To that end, device drivers can use the ``DPM_FLAG_MAY_SKIP_RESUME `` flag to
818
+ indicate to the PM core and middle-layer code that they allow their "noirq" and
819
+ "early" resume callbacks to be skipped if the device can be left in suspend
820
+ after system-wide PM transitions to the working state. Whether or not that is
821
+ the case generally depends on the state of the device before the given system
822
+ suspend-resume cycle and on the type of the system transition under way.
823
+ In particular, the "restore" and "thaw" transitions related to hibernation are
824
+ not affected by ``DPM_FLAG_MAY_SKIP_RESUME `` at all. [All devices are always
825
+ resumed during the "restore" transition and whether or not any driver callbacks
826
+ are skipped during the "freeze" transition depends whether or not the
827
+ ``DPM_FLAG_SMART_SUSPEND `` flag is set (see `above <smart_suspend_flag _>`_).]
828
+
829
+ The ``DPM_FLAG_MAY_SKIP_RESUME `` flag is taken into account in combination with
830
+ the :c:member: `power.may_skip_resume ` status bit set by the PM core during the
831
+ "suspend" phase of suspend-type transitions. If the driver or the middle layer
832
+ has a reason to prevent the driver's "noirq" and "early" resume callbacks from
833
+ being skipped during the subsequent resume transition of the system, it should
834
+ clear :c:member: `power.may_skip_resume ` in its ``->suspend ``, ``->suspend_late ``
835
+ or ``->suspend_noirq `` callback. [Note that the drivers setting
836
+ ``DPM_FLAG_SMART_SUSPEND `` need to clear :c:member: `power.may_skip_resume ` in
837
+ their ``->suspend `` callback in case the other two are skipped.]
838
+
839
+ Setting the :c:member: `power.may_skip_resume ` status bit along with the
840
+ ``DPM_FLAG_MAY_SKIP_RESUME `` flag is necessary, but generally not sufficient,
841
+ for the driver's "noirq" and "early" resume callbacks to be skipped. Whether or
842
+ not they should be skipped can be determined by evaluating the
843
+ :c:func: `dev_pm_skip_resume ` helper function.
844
+
845
+ If that function returns ``true ``, the driver's "noirq" and "early" resume
846
+ callbacks should be skipped and the device's runtime PM status will be set to
847
+ "suspended" by the PM core. Otherwise, if the device was runtime-suspended
848
+ during the preceding system-wide suspend transition and
849
+ ``DPM_FLAG_SMART_SUSPEND `` is set for it, its runtime PM status will be set to
850
+ "active" by the PM core. [Hence, the drivers that do not set
851
+ ``DPM_FLAG_SMART_SUSPEND `` should not expect the runtime PM status of their
852
+ devices to be changed from "suspended" to "active" by the PM core during
853
+ system-wide resume-type transitions.]
854
+
855
+ If the ``DPM_FLAG_MAY_SKIP_RESUME `` flag is not set for a device, but
856
+ ``DPM_FLAG_SMART_SUSPEND `` is set and the driver's "late" and "noirq" suspend
857
+ callbacks are skipped, its system-wide "noirq" and "early" resume callbacks, if
858
+ present, are invoked as usual and the device's runtime PM status is set to
859
+ "active" by the PM core before enabling runtime PM for it. In that case, the
860
+ driver must be prepared to cope with the invocation of its system-wide resume
861
+ callbacks back-to-back with its ``->runtime_suspend `` one (without the
862
+ intervening ``->runtime_resume `` and system-wide suspend callbacks) and the
863
+ final state of the device must reflect the "active" runtime PM status in that
864
+ case. [Note that this is not a problem at all if the driver's
865
+ ``->suspend_late `` callback pointer points to the same function as its
866
+ ``->runtime_suspend `` one and its ``->resume_early `` callback pointer points to
867
+ the same function as the ``->runtime_resume `` one, while none of the other
868
+ system-wide suspend-resume callbacks of the driver are present, for example.]
869
+
870
+ Likewise, if ``DPM_FLAG_MAY_SKIP_RESUME `` is set for a device, its driver's
871
+ system-wide "noirq" and "early" resume callbacks may be skipped while its "late"
872
+ and "noirq" suspend callbacks may have been executed (in principle, regardless
873
+ of whether or not ``DPM_FLAG_SMART_SUSPEND `` is set). In that case, the driver
874
+ needs to be able to cope with the invocation of its ``->runtime_resume ``
875
+ callback back-to-back with its "late" and "noirq" suspend ones. [For instance,
876
+ that is not a concern if the driver sets both ``DPM_FLAG_SMART_SUSPEND `` and
877
+ ``DPM_FLAG_MAY_SKIP_RESUME `` and uses the same pair of suspend/resume callback
878
+ functions for runtime PM and system-wide suspend/resume.]
0 commit comments