brintos

brintos / linux-shallow public Read only

0
0
Text · 3.1 KiB · 186435c Raw
75 lines · plain
1.. SPDX-License-Identifier: GPL-2.02.. include:: <isonum.txt>3 4=============================5Suspend/Hibernation Notifiers6=============================7 8:Copyright: |copy| 2016 Intel Corporation9 10:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>11 12 13There are some operations that subsystems or drivers may want to carry out14before hibernation/suspend or after restore/resume, but they require the system15to be fully functional, so the drivers' and subsystems' ``->suspend()`` and16``->resume()`` or even ``->prepare()`` and ``->complete()`` callbacks are not17suitable for this purpose.18 19For example, device drivers may want to upload firmware to their devices after20resume/restore, but they cannot do it by calling :c:func:`request_firmware()`21from their ``->resume()`` or ``->complete()`` callback routines (user land22processes are frozen at these points).  The solution may be to load the firmware23into memory before processes are frozen and upload it from there in the24``->resume()`` routine.  A suspend/hibernation notifier may be used for that.25 26Subsystems or drivers having such needs can register suspend notifiers that27will be called upon the following events by the PM core:28 29``PM_HIBERNATION_PREPARE``30	The system is going to hibernate, tasks will be frozen immediately. This31	is different from ``PM_SUSPEND_PREPARE`` below,	because in this case32	additional work is done between the notifiers and the invocation of PM33	callbacks for the "freeze" transition.34 35``PM_POST_HIBERNATION``36	The system memory state has been restored from a hibernation image or an37	error occurred during hibernation.  Device restore callbacks have been38	executed and tasks have been thawed.39 40``PM_RESTORE_PREPARE``41	The system is going to restore a hibernation image.  If all goes well,42	the restored image kernel will issue a ``PM_POST_HIBERNATION``43	notification.44 45``PM_POST_RESTORE``46	An error occurred during restore from hibernation.  Device restore47	callbacks have been executed and tasks have been thawed.48 49``PM_SUSPEND_PREPARE``50	The system is preparing for suspend.51 52``PM_POST_SUSPEND``53	The system has just resumed or an error occurred during suspend.  Device54	resume callbacks have been executed and tasks have been thawed.55 56It is generally assumed that whatever the notifiers do for57``PM_HIBERNATION_PREPARE``, should be undone for ``PM_POST_HIBERNATION``.58Analogously, operations carried out for ``PM_SUSPEND_PREPARE`` should be59reversed for ``PM_POST_SUSPEND``.60 61Moreover, if one of the notifiers fails for the ``PM_HIBERNATION_PREPARE`` or62``PM_SUSPEND_PREPARE`` event, the notifiers that have already succeeded for that63event will be called for ``PM_POST_HIBERNATION`` or ``PM_POST_SUSPEND``,64respectively.65 66The hibernation and suspend notifiers are called with :c:data:`pm_mutex` held.67They are defined in the usual way, but their last argument is meaningless (it is68always NULL).69 70To register and/or unregister a suspend notifier use71:c:func:`register_pm_notifier()` and :c:func:`unregister_pm_notifier()`,72respectively (both defined in :file:`include/linux/suspend.h`).  If you don't73need to unregister the notifier, you can also use the :c:func:`pm_notifier()`74macro defined in :file:`include/linux/suspend.h`.75