suspend.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #ifndef _LINUX_SWSUSP_H
  2. #define _LINUX_SWSUSP_H
  3. #if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32) || defined(CONFIG_PPC64)
  4. #include <asm/suspend.h>
  5. #endif
  6. #include <linux/swap.h>
  7. #include <linux/notifier.h>
  8. #include <linux/init.h>
  9. #include <linux/pm.h>
  10. #include <linux/mm.h>
  11. /* struct pbe is used for creating lists of pages that should be restored
  12. * atomically during the resume from disk, because the page frames they have
  13. * occupied before the suspend are in use.
  14. */
  15. struct pbe {
  16. void *address; /* address of the copy */
  17. void *orig_address; /* original address of a page */
  18. struct pbe *next;
  19. };
  20. /* mm/page_alloc.c */
  21. extern void drain_local_pages(void);
  22. extern void mark_free_pages(struct zone *zone);
  23. #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
  24. extern int pm_prepare_console(void);
  25. extern void pm_restore_console(void);
  26. #else
  27. static inline int pm_prepare_console(void) { return 0; }
  28. static inline void pm_restore_console(void) {}
  29. #endif
  30. /**
  31. * struct hibernation_ops - hibernation platform support
  32. *
  33. * The methods in this structure allow a platform to override the default
  34. * mechanism of shutting down the machine during a hibernation transition.
  35. *
  36. * All three methods must be assigned.
  37. *
  38. * @prepare: prepare system for hibernation
  39. * @enter: shut down system after state has been saved to disk
  40. * @finish: finish/clean up after state has been reloaded
  41. * @pre_restore: prepare system for the restoration from a hibernation image
  42. * @restore_cleanup: clean up after a failing image restoration
  43. */
  44. struct hibernation_ops {
  45. int (*prepare)(void);
  46. int (*enter)(void);
  47. void (*finish)(void);
  48. int (*pre_restore)(void);
  49. void (*restore_cleanup)(void);
  50. };
  51. #ifdef CONFIG_HIBERNATION
  52. /* kernel/power/snapshot.c */
  53. extern void __register_nosave_region(unsigned long b, unsigned long e, int km);
  54. static inline void register_nosave_region(unsigned long b, unsigned long e)
  55. {
  56. __register_nosave_region(b, e, 0);
  57. }
  58. static inline void register_nosave_region_late(unsigned long b, unsigned long e)
  59. {
  60. __register_nosave_region(b, e, 1);
  61. }
  62. extern int swsusp_page_is_forbidden(struct page *);
  63. extern void swsusp_set_page_free(struct page *);
  64. extern void swsusp_unset_page_free(struct page *);
  65. extern unsigned long get_safe_page(gfp_t gfp_mask);
  66. extern void hibernation_set_ops(struct hibernation_ops *ops);
  67. extern int hibernate(void);
  68. #else /* CONFIG_HIBERNATION */
  69. static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
  70. static inline void swsusp_set_page_free(struct page *p) {}
  71. static inline void swsusp_unset_page_free(struct page *p) {}
  72. static inline void hibernation_set_ops(struct hibernation_ops *ops) {}
  73. static inline int hibernate(void) { return -ENOSYS; }
  74. #endif /* CONFIG_HIBERNATION */
  75. #ifdef CONFIG_PM_SLEEP
  76. void save_processor_state(void);
  77. void restore_processor_state(void);
  78. struct saved_context;
  79. void __save_processor_state(struct saved_context *ctxt);
  80. void __restore_processor_state(struct saved_context *ctxt);
  81. /* kernel/power/main.c */
  82. extern struct blocking_notifier_head pm_chain_head;
  83. static inline int register_pm_notifier(struct notifier_block *nb)
  84. {
  85. return blocking_notifier_chain_register(&pm_chain_head, nb);
  86. }
  87. static inline int unregister_pm_notifier(struct notifier_block *nb)
  88. {
  89. return blocking_notifier_chain_unregister(&pm_chain_head, nb);
  90. }
  91. #define pm_notifier(fn, pri) { \
  92. static struct notifier_block fn##_nb = \
  93. { .notifier_call = fn, .priority = pri }; \
  94. register_pm_notifier(&fn##_nb); \
  95. }
  96. #else /* !CONFIG_PM_SLEEP */
  97. static inline int register_pm_notifier(struct notifier_block *nb)
  98. {
  99. return 0;
  100. }
  101. static inline int unregister_pm_notifier(struct notifier_block *nb)
  102. {
  103. return 0;
  104. }
  105. #define pm_notifier(fn, pri) do { (void)(fn); } while (0)
  106. #endif /* !CONFIG_PM_SLEEP */
  107. #ifndef CONFIG_HIBERNATION
  108. static inline void register_nosave_region(unsigned long b, unsigned long e)
  109. {
  110. }
  111. static inline void register_nosave_region_late(unsigned long b, unsigned long e)
  112. {
  113. }
  114. #endif
  115. #endif /* _LINUX_SWSUSP_H */