xref: /linux/Documentation/driver-api/pm/notifiers.rst (revision c39f2d9db0fd81ea20bb5cce9b3f082ca63753e2)
1fc7db767SRafael J. Wysocki.. SPDX-License-Identifier: GPL-2.0
2*fc1860d6SRafael J. Wysocki.. include:: <isonum.txt>
3fc7db767SRafael J. Wysocki
4730c4c05SRafael J. Wysocki=============================
5730c4c05SRafael J. WysockiSuspend/Hibernation Notifiers
6730c4c05SRafael J. Wysocki=============================
7730c4c05SRafael J. Wysocki
8*fc1860d6SRafael J. Wysocki:Copyright: |copy| 2016 Intel Corporation
9730c4c05SRafael J. Wysocki
10*fc1860d6SRafael J. Wysocki:Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
11*fc1860d6SRafael J. Wysocki
12730c4c05SRafael J. Wysocki
13730c4c05SRafael J. WysockiThere are some operations that subsystems or drivers may want to carry out
14730c4c05SRafael J. Wysockibefore hibernation/suspend or after restore/resume, but they require the system
15730c4c05SRafael J. Wysockito be fully functional, so the drivers' and subsystems' ``->suspend()`` and
16730c4c05SRafael J. Wysocki``->resume()`` or even ``->prepare()`` and ``->complete()`` callbacks are not
17730c4c05SRafael J. Wysockisuitable for this purpose.
18730c4c05SRafael J. Wysocki
19730c4c05SRafael J. WysockiFor example, device drivers may want to upload firmware to their devices after
20730c4c05SRafael J. Wysockiresume/restore, but they cannot do it by calling :c:func:`request_firmware()`
21730c4c05SRafael J. Wysockifrom their ``->resume()`` or ``->complete()`` callback routines (user land
22730c4c05SRafael J. Wysockiprocesses are frozen at these points).  The solution may be to load the firmware
23730c4c05SRafael J. Wysockiinto memory before processes are frozen and upload it from there in the
24730c4c05SRafael J. Wysocki``->resume()`` routine.  A suspend/hibernation notifier may be used for that.
25730c4c05SRafael J. Wysocki
26730c4c05SRafael J. WysockiSubsystems or drivers having such needs can register suspend notifiers that
27730c4c05SRafael J. Wysockiwill be called upon the following events by the PM core:
28730c4c05SRafael J. Wysocki
29730c4c05SRafael J. Wysocki``PM_HIBERNATION_PREPARE``
30730c4c05SRafael J. Wysocki	The system is going to hibernate, tasks will be frozen immediately. This
31730c4c05SRafael J. Wysocki	is different from ``PM_SUSPEND_PREPARE`` below,	because in this case
32730c4c05SRafael J. Wysocki	additional work is done between the notifiers and the invocation of PM
33730c4c05SRafael J. Wysocki	callbacks for the "freeze" transition.
34730c4c05SRafael J. Wysocki
35730c4c05SRafael J. Wysocki``PM_POST_HIBERNATION``
36730c4c05SRafael J. Wysocki	The system memory state has been restored from a hibernation image or an
37730c4c05SRafael J. Wysocki	error occurred during hibernation.  Device restore callbacks have been
38730c4c05SRafael J. Wysocki	executed and tasks have been thawed.
39730c4c05SRafael J. Wysocki
40730c4c05SRafael J. Wysocki``PM_RESTORE_PREPARE``
41730c4c05SRafael J. Wysocki	The system is going to restore a hibernation image.  If all goes well,
42730c4c05SRafael J. Wysocki	the restored image kernel will issue a ``PM_POST_HIBERNATION``
43730c4c05SRafael J. Wysocki	notification.
44730c4c05SRafael J. Wysocki
45730c4c05SRafael J. Wysocki``PM_POST_RESTORE``
46730c4c05SRafael J. Wysocki	An error occurred during restore from hibernation.  Device restore
47730c4c05SRafael J. Wysocki	callbacks have been executed and tasks have been thawed.
48730c4c05SRafael J. Wysocki
49730c4c05SRafael J. Wysocki``PM_SUSPEND_PREPARE``
50730c4c05SRafael J. Wysocki	The system is preparing for suspend.
51730c4c05SRafael J. Wysocki
52730c4c05SRafael J. Wysocki``PM_POST_SUSPEND``
53730c4c05SRafael J. Wysocki	The system has just resumed or an error occurred during suspend.  Device
54730c4c05SRafael J. Wysocki	resume callbacks have been executed and tasks have been thawed.
55730c4c05SRafael J. Wysocki
56730c4c05SRafael J. WysockiIt is generally assumed that whatever the notifiers do for
57730c4c05SRafael J. Wysocki``PM_HIBERNATION_PREPARE``, should be undone for ``PM_POST_HIBERNATION``.
58730c4c05SRafael J. WysockiAnalogously, operations carried out for ``PM_SUSPEND_PREPARE`` should be
59730c4c05SRafael J. Wysockireversed for ``PM_POST_SUSPEND``.
60730c4c05SRafael J. Wysocki
61730c4c05SRafael J. WysockiMoreover, if one of the notifiers fails for the ``PM_HIBERNATION_PREPARE`` or
62730c4c05SRafael J. Wysocki``PM_SUSPEND_PREPARE`` event, the notifiers that have already succeeded for that
63730c4c05SRafael J. Wysockievent will be called for ``PM_POST_HIBERNATION`` or ``PM_POST_SUSPEND``,
64730c4c05SRafael J. Wysockirespectively.
65730c4c05SRafael J. Wysocki
66730c4c05SRafael J. WysockiThe hibernation and suspend notifiers are called with :c:data:`pm_mutex` held.
67730c4c05SRafael J. WysockiThey are defined in the usual way, but their last argument is meaningless (it is
68730c4c05SRafael J. Wysockialways NULL).
69730c4c05SRafael J. Wysocki
70730c4c05SRafael J. WysockiTo register and/or unregister a suspend notifier use
71730c4c05SRafael J. Wysocki:c:func:`register_pm_notifier()` and :c:func:`unregister_pm_notifier()`,
72730c4c05SRafael J. Wysockirespectively (both defined in :file:`include/linux/suspend.h`).  If you don't
73730c4c05SRafael J. Wysockineed to unregister the notifier, you can also use the :c:func:`pm_notifier()`
74730c4c05SRafael J. Wysockimacro defined in :file:`include/linux/suspend.h`.
75