power.h 7.9 KB

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