notifiers.txt 2.8 KB

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