Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 1 | Suspend notifiers |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 2 | (C) 2007-2011 Rafael J. Wysocki <rjw@sisk.pl>, GPL |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 3 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 4 | There are some operations that subsystems or drivers may want to carry out |
| 5 | before hibernation/suspend or after restore/resume, but they require the system |
| 6 | to be fully functional, so the drivers' and subsystems' .suspend() and .resume() |
| 7 | or even .prepare() and .complete() callbacks are not suitable for this purpose. |
| 8 | For example, device drivers may want to upload firmware to their devices after |
| 9 | resume/restore, but they cannot do it by calling request_firmware() from their |
| 10 | .resume() or .complete() routines (user land processes are frozen at these |
| 11 | points). The solution may be to load the firmware into memory before processes |
| 12 | are frozen and upload it from there in the .resume() routine. |
| 13 | A suspend/hibernation notifier may be used for this purpose. |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 14 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 15 | The subsystems or drivers having such needs can register suspend notifiers that |
| 16 | will be called upon the following events by the PM core: |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 17 | |
Borislav Petkov | 6bc08ed | 2013-05-13 12:00:03 +0000 | [diff] [blame] | 18 | PM_HIBERNATION_PREPARE The system is going to hibernate, tasks will be frozen |
| 19 | immediately. This is different from PM_SUSPEND_PREPARE |
| 20 | below because here we do additional work between notifiers |
| 21 | and drivers freezing. |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 22 | |
| 23 | PM_POST_HIBERNATION The system memory state has been restored from a |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 24 | hibernation image or an error occurred during |
| 25 | hibernation. Device drivers' restore callbacks have |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 26 | been executed and tasks have been thawed. |
| 27 | |
Alan Stern | c3e94d8 | 2007-11-19 23:38:25 +0100 | [diff] [blame] | 28 | PM_RESTORE_PREPARE The system is going to restore a hibernation image. |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 29 | If all goes well, the restored kernel will issue a |
Alan Stern | c3e94d8 | 2007-11-19 23:38:25 +0100 | [diff] [blame] | 30 | PM_POST_HIBERNATION notification. |
| 31 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 32 | PM_POST_RESTORE An error occurred during restore from hibernation. |
| 33 | Device drivers' restore callbacks have been executed |
Alan Stern | c3e94d8 | 2007-11-19 23:38:25 +0100 | [diff] [blame] | 34 | and tasks have been thawed. |
| 35 | |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 36 | PM_SUSPEND_PREPARE The system is preparing for suspend. |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 37 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 38 | PM_POST_SUSPEND The system has just resumed or an error occurred during |
Rafael J. Wysocki | 91e7c75 | 2011-05-17 23:26:00 +0200 | [diff] [blame] | 39 | suspend. Device drivers' resume callbacks have been |
| 40 | executed and tasks have been thawed. |
Rafael J. Wysocki | b10d911 | 2007-07-19 01:47:36 -0700 | [diff] [blame] | 41 | |
| 42 | It is generally assumed that whatever the notifiers do for |
| 43 | PM_HIBERNATION_PREPARE, should be undone for PM_POST_HIBERNATION. Analogously, |
| 44 | operations performed for PM_SUSPEND_PREPARE should be reversed for |
| 45 | PM_POST_SUSPEND. Additionally, all of the notifiers are called for |
| 46 | PM_POST_HIBERNATION if one of them fails for PM_HIBERNATION_PREPARE, and |
| 47 | all of the notifiers are called for PM_POST_SUSPEND if one of them fails for |
| 48 | PM_SUSPEND_PREPARE. |
| 49 | |
| 50 | The hibernation and suspend notifiers are called with pm_mutex held. They are |
| 51 | defined in the usual way, but their last argument is meaningless (it is always |
| 52 | NULL). To register and/or unregister a suspend notifier use the functions |
| 53 | register_pm_notifier() and unregister_pm_notifier(), respectively, defined in |
| 54 | include/linux/suspend.h . If you don't need to unregister the notifier, you can |
| 55 | also use the pm_notifier() macro defined in include/linux/suspend.h . |