power.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. #include <linux/suspend.h>
  2. #include <linux/suspend_ioctls.h>
  3. #include <linux/utsname.h>
  4. #include <linux/freezer.h>
  5. struct swsusp_info {
  6. struct new_utsname uts;
  7. u32 version_code;
  8. unsigned long num_physpages;
  9. int cpus;
  10. unsigned long image_pages;
  11. unsigned long pages;
  12. unsigned long size;
  13. } __attribute__((aligned(PAGE_SIZE)));
  14. #ifdef CONFIG_HIBERNATION
  15. /* kernel/power/snapshot.c */
  16. extern void __init hibernate_image_size_init(void);
  17. #ifdef CONFIG_ARCH_HIBERNATION_HEADER
  18. /* Maximum size of architecture specific data in a hibernation header */
  19. #define MAX_ARCH_HEADER_SIZE (sizeof(struct new_utsname) + 4)
  20. extern int arch_hibernation_header_save(void *addr, unsigned int max_size);
  21. extern int arch_hibernation_header_restore(void *addr);
  22. static inline int init_header_complete(struct swsusp_info *info)
  23. {
  24. return arch_hibernation_header_save(info, MAX_ARCH_HEADER_SIZE);
  25. }
  26. static inline char *check_image_kernel(struct swsusp_info *info)
  27. {
  28. return arch_hibernation_header_restore(info) ?
  29. "architecture specific data" : NULL;
  30. }
  31. #endif /* CONFIG_ARCH_HIBERNATION_HEADER */
  32. /*
  33. * Keep some memory free so that I/O operations can succeed without paging
  34. * [Might this be more than 4 MB?]
  35. */
  36. #define PAGES_FOR_IO ((4096 * 1024) >> PAGE_SHIFT)
  37. /*
  38. * Keep 1 MB of memory free so that device drivers can allocate some pages in
  39. * their .suspend() routines without breaking the suspend to disk.
  40. */
  41. #define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT)
  42. /* kernel/power/hibernate.c */
  43. extern int hibernation_snapshot(int platform_mode);
  44. extern int hibernation_restore(int platform_mode);
  45. extern int hibernation_platform_enter(void);
  46. #else /* !CONFIG_HIBERNATION */
  47. static inline void hibernate_image_size_init(void) {}
  48. #endif /* !CONFIG_HIBERNATION */
  49. extern int pfn_is_nosave(unsigned long);
  50. #define power_attr(_name) \
  51. static struct kobj_attribute _name##_attr = { \
  52. .attr = { \
  53. .name = __stringify(_name), \
  54. .mode = 0644, \
  55. }, \
  56. .show = _name##_show, \
  57. .store = _name##_store, \
  58. }
  59. /* Preferred image size in bytes (default 500 MB) */
  60. extern unsigned long image_size;
  61. extern int in_suspend;
  62. extern dev_t swsusp_resume_device;
  63. extern sector_t swsusp_resume_block;
  64. extern asmlinkage int swsusp_arch_suspend(void);
  65. extern asmlinkage int swsusp_arch_resume(void);
  66. extern int create_basic_memory_bitmaps(void);
  67. extern void free_basic_memory_bitmaps(void);
  68. extern int hibernate_preallocate_memory(void);
  69. /**
  70. * Auxiliary structure used for reading the snapshot image data and
  71. * metadata from and writing them to the list of page backup entries
  72. * (PBEs) which is the main data structure of swsusp.
  73. *
  74. * Using struct snapshot_handle we can transfer the image, including its
  75. * metadata, as a continuous sequence of bytes with the help of
  76. * snapshot_read_next() and snapshot_write_next().
  77. *
  78. * The code that writes the image to a storage or transfers it to
  79. * the user land is required to use snapshot_read_next() for this
  80. * purpose and it should not make any assumptions regarding the internal
  81. * structure of the image. Similarly, the code that reads the image from
  82. * a storage or transfers it from the user land is required to use
  83. * snapshot_write_next().
  84. *
  85. * This may allow us to change the internal structure of the image
  86. * in the future with considerably less effort.
  87. */
  88. struct snapshot_handle {
  89. unsigned int cur; /* number of the block of PAGE_SIZE bytes the
  90. * next operation will refer to (ie. current)
  91. */
  92. void *buffer; /* address of the block to read from
  93. * or write to
  94. */
  95. int sync_read; /* Set to one to notify the caller of
  96. * snapshot_write_next() that it may
  97. * need to call wait_on_bio_chain()
  98. */
  99. };
  100. /* This macro returns the address from/to which the caller of
  101. * snapshot_read_next()/snapshot_write_next() is allowed to
  102. * read/write data after the function returns
  103. */
  104. #define data_of(handle) ((handle).buffer)
  105. extern unsigned int snapshot_additional_pages(struct zone *zone);
  106. extern unsigned long snapshot_get_image_size(void);
  107. extern int snapshot_read_next(struct snapshot_handle *handle);
  108. extern int snapshot_write_next(struct snapshot_handle *handle);
  109. extern void snapshot_write_finalize(struct snapshot_handle *handle);
  110. extern int snapshot_image_loaded(struct snapshot_handle *handle);
  111. /* If unset, the snapshot device cannot be open. */
  112. extern atomic_t snapshot_device_available;
  113. extern sector_t alloc_swapdev_block(int swap);
  114. extern void free_all_swap_pages(int swap);
  115. extern int swsusp_swap_in_use(void);
  116. /*
  117. * Flags that can be passed from the hibernatig hernel to the "boot" kernel in
  118. * the image header.
  119. */
  120. #define SF_PLATFORM_MODE 1
  121. #define SF_NOCOMPRESS_MODE 2
  122. /* kernel/power/hibernate.c */
  123. extern int swsusp_check(void);
  124. extern void swsusp_free(void);
  125. extern int swsusp_read(unsigned int *flags_p);
  126. extern int swsusp_write(unsigned int flags);
  127. extern void swsusp_close(fmode_t);
  128. /* kernel/power/block_io.c */
  129. extern struct block_device *hib_resume_bdev;
  130. extern int hib_bio_read_page(pgoff_t page_off, void *addr,
  131. struct bio **bio_chain);
  132. extern int hib_bio_write_page(pgoff_t page_off, void *addr,
  133. struct bio **bio_chain);
  134. extern int hib_wait_on_bio_chain(struct bio **bio_chain);
  135. struct timeval;
  136. /* kernel/power/swsusp.c */
  137. extern void swsusp_show_speed(struct timeval *, struct timeval *,
  138. unsigned int, char *);
  139. #ifdef CONFIG_SUSPEND
  140. /* kernel/power/suspend.c */
  141. extern const char *const pm_states[];
  142. extern bool valid_state(suspend_state_t state);
  143. extern int suspend_devices_and_enter(suspend_state_t state);
  144. extern int enter_state(suspend_state_t state);
  145. #else /* !CONFIG_SUSPEND */
  146. static inline int suspend_devices_and_enter(suspend_state_t state)
  147. {
  148. return -ENOSYS;
  149. }
  150. static inline int enter_state(suspend_state_t state) { return -ENOSYS; }
  151. static inline bool valid_state(suspend_state_t state) { return false; }
  152. #endif /* !CONFIG_SUSPEND */
  153. #ifdef CONFIG_PM_TEST_SUSPEND
  154. /* kernel/power/suspend_test.c */
  155. extern void suspend_test_start(void);
  156. extern void suspend_test_finish(const char *label);
  157. #else /* !CONFIG_PM_TEST_SUSPEND */
  158. static inline void suspend_test_start(void) {}
  159. static inline void suspend_test_finish(const char *label) {}
  160. #endif /* !CONFIG_PM_TEST_SUSPEND */
  161. #ifdef CONFIG_PM_SLEEP
  162. /* kernel/power/main.c */
  163. extern int pm_notifier_call_chain(unsigned long val);
  164. #endif
  165. #ifdef CONFIG_HIGHMEM
  166. int restore_highmem(void);
  167. #else
  168. static inline unsigned int count_highmem_pages(void) { return 0; }
  169. static inline int restore_highmem(void) { return 0; }
  170. #endif
  171. /*
  172. * Suspend test levels
  173. */
  174. enum {
  175. /* keep first */
  176. TEST_NONE,
  177. TEST_CORE,
  178. TEST_CPUS,
  179. TEST_PLATFORM,
  180. TEST_DEVICES,
  181. TEST_FREEZER,
  182. /* keep last */
  183. __TEST_AFTER_LAST
  184. };
  185. #define TEST_FIRST TEST_NONE
  186. #define TEST_MAX (__TEST_AFTER_LAST - 1)
  187. extern int pm_test_level;
  188. #ifdef CONFIG_SUSPEND_FREEZER
  189. static inline int suspend_freeze_processes(void)
  190. {
  191. return freeze_processes();
  192. }
  193. static inline void suspend_thaw_processes(void)
  194. {
  195. thaw_processes();
  196. }
  197. #else
  198. static inline int suspend_freeze_processes(void)
  199. {
  200. return 0;
  201. }
  202. static inline void suspend_thaw_processes(void)
  203. {
  204. }
  205. #endif