blob: c2a4a346c0d98597d3375c5a9f160c012fded709 [file] [log] [blame]
Rafael J. Wysockib10d9112007-07-19 01:47:36 -07001Suspend notifiers
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +02002 (C) 2007-2011 Rafael J. Wysocki <rjw@sisk.pl>, GPL
Rafael J. Wysockib10d9112007-07-19 01:47:36 -07003
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +02004There are some operations that subsystems or drivers may want to carry out
5before hibernation/suspend or after restore/resume, but they require the system
6to be fully functional, so the drivers' and subsystems' .suspend() and .resume()
7or even .prepare() and .complete() callbacks are not suitable for this purpose.
8For example, device drivers may want to upload firmware to their devices after
9resume/restore, but they cannot do it by calling request_firmware() from their
10.resume() or .complete() routines (user land processes are frozen at these
11points). The solution may be to load the firmware into memory before processes
12are frozen and upload it from there in the .resume() routine.
13A suspend/hibernation notifier may be used for this purpose.
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070014
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020015The subsystems or drivers having such needs can register suspend notifiers that
16will be called upon the following events by the PM core:
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070017
18PM_HIBERNATION_PREPARE The system is going to hibernate or suspend, tasks will
19 be frozen immediately.
20
21PM_POST_HIBERNATION The system memory state has been restored from a
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020022 hibernation image or an error occurred during
23 hibernation. Device drivers' restore callbacks have
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070024 been executed and tasks have been thawed.
25
Alan Sternc3e94d82007-11-19 23:38:25 +010026PM_RESTORE_PREPARE The system is going to restore a hibernation image.
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020027 If all goes well, the restored kernel will issue a
Alan Sternc3e94d82007-11-19 23:38:25 +010028 PM_POST_HIBERNATION notification.
29
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020030PM_POST_RESTORE An error occurred during restore from hibernation.
31 Device drivers' restore callbacks have been executed
Alan Sternc3e94d82007-11-19 23:38:25 +010032 and tasks have been thawed.
33
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020034PM_SUSPEND_PREPARE The system is preparing for suspend.
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070035
Lucas De Marchi25985ed2011-03-30 22:57:33 -030036PM_POST_SUSPEND The system has just resumed or an error occurred during
Rafael J. Wysocki91e7c752011-05-17 23:26:00 +020037 suspend. Device drivers' resume callbacks have been
38 executed and tasks have been thawed.
Rafael J. Wysockib10d9112007-07-19 01:47:36 -070039
40It is generally assumed that whatever the notifiers do for
41PM_HIBERNATION_PREPARE, should be undone for PM_POST_HIBERNATION. Analogously,
42operations performed for PM_SUSPEND_PREPARE should be reversed for
43PM_POST_SUSPEND. Additionally, all of the notifiers are called for
44PM_POST_HIBERNATION if one of them fails for PM_HIBERNATION_PREPARE, and
45all of the notifiers are called for PM_POST_SUSPEND if one of them fails for
46PM_SUSPEND_PREPARE.
47
48The hibernation and suspend notifiers are called with pm_mutex held. They are
49defined in the usual way, but their last argument is meaningless (it is always
50NULL). To register and/or unregister a suspend notifier use the functions
51register_pm_notifier() and unregister_pm_notifier(), respectively, defined in
52include/linux/suspend.h . If you don't need to unregister the notifier, you can
53also use the pm_notifier() macro defined in include/linux/suspend.h .