notifiers.rst 3.1 KB

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