Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

PM: sleep: Helpful edits for devices.rst documentation

Here are some minor edits of the devices.rst documentation file,
intended to improve the clarity and add a couple of missing details.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Alan Stern and committed by
Rafael J. Wysocki
598cc930 edb7f9d6

+52 -42
+52 -42
Documentation/driver-api/pm/devices.rst
··· 349 349 PM core will skip the ``suspend``, ``suspend_late`` and 350 350 ``suspend_noirq`` phases as well as all of the corresponding phases of 351 351 the subsequent device resume for all of these devices. In that case, 352 - the ``->complete`` callback will be invoked directly after the 352 + the ``->complete`` callback will be the next one invoked after the 353 353 ``->prepare`` callback and is entirely responsible for putting the 354 354 device into a consistent state as appropriate. 355 355 ··· 383 383 ``->suspend`` methods provided by subsystems (bus types and PM domains 384 384 in particular) must follow an additional rule regarding what can be done 385 385 to the devices before their drivers' ``->suspend`` methods are called. 386 - Namely, they can only resume the devices from runtime suspend by 387 - calling :c:func:`pm_runtime_resume` for them, if that is necessary, and 386 + Namely, they may resume the devices from runtime suspend by 387 + calling :c:func:`pm_runtime_resume` for them, if that is necessary, but 388 388 they must not update the state of the devices in any other way at that 389 389 time (in case the drivers need to resume the devices from runtime 390 - suspend in their ``->suspend`` methods). 390 + suspend in their ``->suspend`` methods). In fact, the PM core prevents 391 + subsystems or drivers from putting devices into runtime suspend at 392 + these times by calling :c:func:`pm_runtime_get_noresume` before issuing 393 + the ``->prepare`` callback (and calling :c:func:`pm_runtime_put` after 394 + issuing the ``->complete`` callback). 391 395 392 396 3. For a number of devices it is convenient to split suspend into the 393 397 "quiesce device" and "save device state" phases, in which cases ··· 463 459 464 460 Note, however, that new children may be registered below the device as 465 461 soon as the ``->resume`` callbacks occur; it's not necessary to wait 466 - until the ``complete`` phase with that. 462 + until the ``complete`` phase runs. 467 463 468 464 Moreover, if the preceding ``->prepare`` callback returned a positive 469 465 number, the device may have been left in runtime suspend throughout the 470 - whole system suspend and resume (the ``suspend``, ``suspend_late``, 471 - ``suspend_noirq`` phases of system suspend and the ``resume_noirq``, 472 - ``resume_early``, ``resume`` phases of system resume may have been 473 - skipped for it). In that case, the ``->complete`` callback is entirely 466 + whole system suspend and resume (its ``->suspend``, ``->suspend_late``, 467 + ``->suspend_noirq``, ``->resume_noirq``, 468 + ``->resume_early``, and ``->resume`` callbacks may have been 469 + skipped). In that case, the ``->complete`` callback is entirely 474 470 responsible for putting the device into a consistent state after system 475 471 suspend if necessary. [For example, it may need to queue up a runtime 476 472 resume request for the device for this purpose.] To check if that is 477 473 the case, the ``->complete`` callback can consult the device's 478 - ``power.direct_complete`` flag. Namely, if that flag is set when the 479 - ``->complete`` callback is being run, it has been called directly after 480 - the preceding ``->prepare`` and special actions may be required 481 - to make the device work correctly afterward. 474 + ``power.direct_complete`` flag. If that flag is set when the 475 + ``->complete`` callback is being run then the direct-complete mechanism 476 + was used, and special actions may be required to make the device work 477 + correctly afterward. 482 478 483 479 At the end of these phases, drivers should be as functional as they were before 484 480 suspending: I/O can be performed using DMA and IRQs, and the relevant clocks are ··· 579 575 580 576 The ``->poweroff``, ``->poweroff_late`` and ``->poweroff_noirq`` callbacks 581 577 should do essentially the same things as the ``->suspend``, ``->suspend_late`` 582 - and ``->suspend_noirq`` callbacks, respectively. The only notable difference is 578 + and ``->suspend_noirq`` callbacks, respectively. A notable difference is 583 579 that they need not store the device register values, because the registers 584 580 should already have been stored during the ``freeze``, ``freeze_late`` or 585 - ``freeze_noirq`` phases. 581 + ``freeze_noirq`` phases. Also, on many machines the firmware will power-down 582 + the entire system, so it is not necessary for the callback to put the device in 583 + a low-power state. 586 584 587 585 588 586 Leaving Hibernation ··· 770 764 771 765 If it is necessary to resume a device from runtime suspend during a system-wide 772 766 transition into a sleep state, that can be done by calling 773 - :c:func:`pm_runtime_resume` for it from the ``->suspend`` callback (or its 774 - couterpart for transitions related to hibernation) of either the device's driver 775 - or a subsystem responsible for it (for example, a bus type or a PM domain). 776 - That is guaranteed to work by the requirement that subsystems must not change 777 - the state of devices (possibly except for resuming them from runtime suspend) 767 + :c:func:`pm_runtime_resume` from the ``->suspend`` callback (or the ``->freeze`` 768 + or ``->poweroff`` callback for transitions related to hibernation) of either the 769 + device's driver or its subsystem (for example, a bus type or a PM domain). 770 + However, subsystems must not otherwise change the runtime status of devices 778 771 from their ``->prepare`` and ``->suspend`` callbacks (or equivalent) *before* 779 772 invoking device drivers' ``->suspend`` callbacks (or equivalent). 780 773 ··· 784 779 785 780 Some bus types and PM domains have a policy to resume all devices from runtime 786 781 suspend upfront in their ``->suspend`` callbacks, but that may not be really 787 - necessary if the driver of the device can cope with runtime-suspended devices. 788 - The driver can indicate that by setting ``DPM_FLAG_SMART_SUSPEND`` in 789 - :c:member:`power.driver_flags` at the probe time with the help of the 782 + necessary if the device's driver can cope with runtime-suspended devices. 783 + The driver can indicate this by setting ``DPM_FLAG_SMART_SUSPEND`` in 784 + :c:member:`power.driver_flags` at probe time, with the assistance of the 790 785 :c:func:`dev_pm_set_driver_flags` helper routine. 791 786 792 - However, setting that flag also causes the PM core and middle-layer code 787 + Setting that flag causes the PM core and middle-layer code 793 788 (bus types, PM domains etc.) to skip the ``->suspend_late`` and 794 789 ``->suspend_noirq`` callbacks provided by the driver if the device remains in 795 - runtime suspend during the ``suspend_late`` phase of system-wide suspend (or 796 - during the ``poweroff_late`` or ``freeze_late`` phase of hibernation), 797 - after runtime PM was disabled for it. [Without doing that, the same driver 790 + runtime suspend throughout those phases of the system-wide suspend (and 791 + similarly for the "freeze" and "poweroff" parts of system hibernation). 792 + [Otherwise the same driver 798 793 callback might be executed twice in a row for the same device, which would not 799 794 be valid in general.] If the middle-layer system-wide PM callbacks are present 800 - for the device, they are responsible for doing the above, and the PM core takes 801 - care of it otherwise. 795 + for the device then they are responsible for skipping these driver callbacks; 796 + if not then the PM core skips them. The subsystem callback routines can 797 + determine whether they need to skip the driver callbacks by testing the return 798 + value from the :c:func:`dev_pm_skip_suspend` helper function. 802 799 803 - In addition, with ``DPM_FLAG_SMART_SUSPEND`` set, the driver's ``->thaw_late`` 804 - and ``->thaw_noirq`` callbacks are skipped if the device remained in runtime 805 - suspend during the preceding "freeze" transition related to hibernation. 806 - Again, if the middle-layer callbacks are present for the device, they are 807 - responsible for doing that, or the PM core takes care of it otherwise. 800 + In addition, with ``DPM_FLAG_SMART_SUSPEND`` set, the driver's ``->thaw_noirq`` 801 + and ``->thaw_early`` callbacks are skipped in hibernation if the device remained 802 + in runtime suspend throughout the preceding "freeze" transition. Again, if the 803 + middle-layer callbacks are present for the device, they are responsible for 804 + doing this, otherwise the PM core takes care of it. 808 805 809 806 810 807 The ``DPM_FLAG_MAY_SKIP_RESUME`` Driver Flag ··· 827 820 after system-wide PM transitions to the working state. Whether or not that is 828 821 the case generally depends on the state of the device before the given system 829 822 suspend-resume cycle and on the type of the system transition under way. 830 - In particular, the "restore" and "thaw" transitions related to hibernation are 831 - not affected by ``DPM_FLAG_MAY_SKIP_RESUME`` at all. [All devices are always 832 - resumed during the "restore" transition and whether or not any driver callbacks 833 - are skipped during the "freeze" transition depends whether or not the 834 - ``DPM_FLAG_SMART_SUSPEND`` flag is set (see `above <smart_suspend_flag_>`_).] 823 + In particular, the "thaw" and "restore" transitions related to hibernation are 824 + not affected by ``DPM_FLAG_MAY_SKIP_RESUME`` at all. [All callbacks are 825 + issued during the "restore" transition regardless of the flag settings, 826 + and whether or not any driver callbacks 827 + are skipped during the "thaw" transition depends whether or not the 828 + ``DPM_FLAG_SMART_SUSPEND`` flag is set (see `above <smart_suspend_flag_>`_). 829 + In addition, a device is not allowed to remain in runtime suspend if any of its 830 + children will be returned to full power.] 835 831 836 832 The ``DPM_FLAG_MAY_SKIP_RESUME`` flag is taken into account in combination with 837 833 the :c:member:`power.may_skip_resume` status bit set by the PM core during the 838 834 "suspend" phase of suspend-type transitions. If the driver or the middle layer 839 835 has a reason to prevent the driver's "noirq" and "early" resume callbacks from 840 - being skipped during the subsequent resume transition of the system, it should 836 + being skipped during the subsequent system resume transition, it should 841 837 clear :c:member:`power.may_skip_resume` in its ``->suspend``, ``->suspend_late`` 842 838 or ``->suspend_noirq`` callback. [Note that the drivers setting 843 839 ``DPM_FLAG_SMART_SUSPEND`` need to clear :c:member:`power.may_skip_resume` in ··· 855 845 If that function returns ``true``, the driver's "noirq" and "early" resume 856 846 callbacks should be skipped and the device's runtime PM status will be set to 857 847 "suspended" by the PM core. Otherwise, if the device was runtime-suspended 858 - during the preceding system-wide suspend transition and 859 - ``DPM_FLAG_SMART_SUSPEND`` is set for it, its runtime PM status will be set to 848 + during the preceding system-wide suspend transition and its 849 + ``DPM_FLAG_SMART_SUSPEND`` is set, its runtime PM status will be set to 860 850 "active" by the PM core. [Hence, the drivers that do not set 861 851 ``DPM_FLAG_SMART_SUSPEND`` should not expect the runtime PM status of their 862 852 devices to be changed from "suspended" to "active" by the PM core during