xref: /linux/Documentation/driver-api/pm/notifiers.rst (revision fc1860d6b17fa00d16df5e608eed0526e11ccad1)
1.. SPDX-License-Identifier: GPL-2.0
2.. include:: <isonum.txt>
3
4=============================
5Suspend/Hibernation Notifiers
6=============================
7
8:Copyright: |copy| 2016 Intel Corporation
9
10:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11
12
13There are some operations that subsystems or drivers may want to carry out
14before hibernation/suspend or after restore/resume, but they require the system
15to be fully functional, so the drivers' and subsystems' ``->suspend()`` and
16``->resume()`` or even ``->prepare()`` and ``->complete()`` callbacks are not
17suitable for this purpose.
18
19For example, device drivers may want to upload firmware to their devices after
20resume/restore, but they cannot do it by calling :c:func:`request_firmware()`
21from their ``->resume()`` or ``->complete()`` callback routines (user land
22processes are frozen at these points).  The solution may be to load the firmware
23into memory before processes are frozen and upload it from there in the
24``->resume()`` routine.  A suspend/hibernation notifier may be used for that.
25
26Subsystems or drivers having such needs can register suspend notifiers that
27will 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. This
31	is different from ``PM_SUSPEND_PREPARE`` below,	because in this case
32	additional work is done between the notifiers and the invocation of PM
33	callbacks for the "freeze" transition.
34
35``PM_POST_HIBERNATION``
36	The system memory state has been restored from a hibernation image or an
37	error occurred during hibernation.  Device restore callbacks have been
38	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 restore
47	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.  Device
54	resume callbacks have been executed and tasks have been thawed.
55
56It is generally assumed that whatever the notifiers do for
57``PM_HIBERNATION_PREPARE``, should be undone for ``PM_POST_HIBERNATION``.
58Analogously, operations carried out for ``PM_SUSPEND_PREPARE`` should be
59reversed for ``PM_POST_SUSPEND``.
60
61Moreover, if one of the notifiers fails for the ``PM_HIBERNATION_PREPARE`` or
62``PM_SUSPEND_PREPARE`` event, the notifiers that have already succeeded for that
63event 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 is
68always NULL).
69
70To register and/or unregister a suspend notifier use
71:c:func:`register_pm_notifier()` and :c:func:`unregister_pm_notifier()`,
72respectively (both defined in :file:`include/linux/suspend.h`).  If you don't
73need to unregister the notifier, you can also use the :c:func:`pm_notifier()`
74macro defined in :file:`include/linux/suspend.h`.
75