notifiers.rst 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. =============================
  2. Suspend/Hibernation Notifiers
  3. =============================
  4. ::
  5. Copyright (c) 2016 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  6. There are some operations that subsystems or drivers may want to carry out
  7. before hibernation/suspend or after restore/resume, but they require the system
  8. to be fully functional, so the drivers' and subsystems' ``->suspend()`` and
  9. ``->resume()`` or even ``->prepare()`` and ``->complete()`` callbacks are not
  10. suitable for this purpose.
  11. For example, device drivers may want to upload firmware to their devices after
  12. resume/restore, but they cannot do it by calling :c:func:`request_firmware()`
  13. from their ``->resume()`` or ``->complete()`` callback routines (user land
  14. processes are frozen at these points). The solution may be to load the firmware
  15. into memory before processes are frozen and upload it from there in the
  16. ``->resume()`` routine. A suspend/hibernation notifier may be used for that.
  17. Subsystems or drivers having such needs can register suspend notifiers that
  18. will be called upon the following events by the PM core:
  19. ``PM_HIBERNATION_PREPARE``
  20. The system is going to hibernate, tasks will be frozen immediately. This
  21. is different from ``PM_SUSPEND_PREPARE`` below, because in this case
  22. additional work is done between the notifiers and the invocation of PM
  23. callbacks for the "freeze" transition.
  24. ``PM_POST_HIBERNATION``
  25. The system memory state has been restored from a hibernation image or an
  26. error occurred during hibernation. Device restore callbacks have been
  27. executed and tasks have been thawed.
  28. ``PM_RESTORE_PREPARE``
  29. The system is going to restore a hibernation image. If all goes well,
  30. the restored image kernel will issue a ``PM_POST_HIBERNATION``
  31. notification.
  32. ``PM_POST_RESTORE``
  33. An error occurred during restore from hibernation. Device restore
  34. callbacks have been executed and tasks have been thawed.
  35. ``PM_SUSPEND_PREPARE``
  36. The system is preparing for suspend.
  37. ``PM_POST_SUSPEND``
  38. The system has just resumed or an error occurred during suspend. Device
  39. resume callbacks have been executed and tasks have been thawed.
  40. It is generally assumed that whatever the notifiers do for
  41. ``PM_HIBERNATION_PREPARE``, should be undone for ``PM_POST_HIBERNATION``.
  42. Analogously, operations carried out for ``PM_SUSPEND_PREPARE`` should be
  43. reversed for ``PM_POST_SUSPEND``.
  44. Moreover, if one of the notifiers fails for the ``PM_HIBERNATION_PREPARE`` or
  45. ``PM_SUSPEND_PREPARE`` event, the notifiers that have already succeeded for that
  46. event will be called for ``PM_POST_HIBERNATION`` or ``PM_POST_SUSPEND``,
  47. respectively.
  48. The hibernation and suspend notifiers are called with :c:data:`pm_mutex` held.
  49. They are defined in the usual way, but their last argument is meaningless (it is
  50. always NULL).
  51. To register and/or unregister a suspend notifier use
  52. :c:func:`register_pm_notifier()` and :c:func:`unregister_pm_notifier()`,
  53. respectively (both defined in :file:`include/linux/suspend.h`). If you don't
  54. need to unregister the notifier, you can also use the :c:func:`pm_notifier()`
  55. macro defined in :file:`include/linux/suspend.h`.