PageRenderTime 73ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/power/power.h

https://bitbucket.org/olivier_pitton/linux-3.8
C Header | 296 lines | 177 code | 50 blank | 69 comment | 2 complexity | fb74ff0e9fe9ccd9a59a102f5c7b6984 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.0, AGPL-1.0
  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 bool freezer_test_done;
  45. extern int hibernation_snapshot(int platform_mode);
  46. extern int hibernation_restore(int platform_mode);
  47. extern int hibernation_platform_enter(void);
  48. #else /* !CONFIG_HIBERNATION */
  49. static inline void hibernate_reserved_size_init(void) {}
  50. static inline void hibernate_image_size_init(void) {}
  51. #endif /* !CONFIG_HIBERNATION */
  52. extern int pfn_is_nosave(unsigned long);
  53. #define power_attr(_name) \
  54. static struct kobj_attribute _name##_attr = { \
  55. .attr = { \
  56. .name = __stringify(_name), \
  57. .mode = 0644, \
  58. }, \
  59. .show = _name##_show, \
  60. .store = _name##_store, \
  61. }
  62. /* Preferred image size in bytes (default 500 MB) */
  63. extern unsigned long image_size;
  64. /* Size of memory reserved for drivers (default SPARE_PAGES x PAGE_SIZE) */
  65. extern unsigned long reserved_size;
  66. extern int in_suspend;
  67. extern dev_t swsusp_resume_device;
  68. extern sector_t swsusp_resume_block;
  69. extern asmlinkage int swsusp_arch_suspend(void);
  70. extern asmlinkage int swsusp_arch_resume(void);
  71. extern int create_basic_memory_bitmaps(void);
  72. extern void free_basic_memory_bitmaps(void);
  73. extern int hibernate_preallocate_memory(void);
  74. /**
  75. * Auxiliary structure used for reading the snapshot image data and
  76. * metadata from and writing them to the list of page backup entries
  77. * (PBEs) which is the main data structure of swsusp.
  78. *
  79. * Using struct snapshot_handle we can transfer the image, including its
  80. * metadata, as a continuous sequence of bytes with the help of
  81. * snapshot_read_next() and snapshot_write_next().
  82. *
  83. * The code that writes the image to a storage or transfers it to
  84. * the user land is required to use snapshot_read_next() for this
  85. * purpose and it should not make any assumptions regarding the internal
  86. * structure of the image. Similarly, the code that reads the image from
  87. * a storage or transfers it from the user land is required to use
  88. * snapshot_write_next().
  89. *
  90. * This may allow us to change the internal structure of the image
  91. * in the future with considerably less effort.
  92. */
  93. struct snapshot_handle {
  94. unsigned int cur; /* number of the block of PAGE_SIZE bytes the
  95. * next operation will refer to (ie. current)
  96. */
  97. void *buffer; /* address of the block to read from
  98. * or write to
  99. */
  100. int sync_read; /* Set to one to notify the caller of
  101. * snapshot_write_next() that it may
  102. * need to call wait_on_bio_chain()
  103. */
  104. };
  105. /* This macro returns the address from/to which the caller of
  106. * snapshot_read_next()/snapshot_write_next() is allowed to
  107. * read/write data after the function returns
  108. */
  109. #define data_of(handle) ((handle).buffer)
  110. extern unsigned int snapshot_additional_pages(struct zone *zone);
  111. extern unsigned long snapshot_get_image_size(void);
  112. extern int snapshot_read_next(struct snapshot_handle *handle);
  113. extern int snapshot_write_next(struct snapshot_handle *handle);
  114. extern void snapshot_write_finalize(struct snapshot_handle *handle);
  115. extern int snapshot_image_loaded(struct snapshot_handle *handle);
  116. /* If unset, the snapshot device cannot be open. */
  117. extern atomic_t snapshot_device_available;
  118. extern sector_t alloc_swapdev_block(int swap);
  119. extern void free_all_swap_pages(int swap);
  120. extern int swsusp_swap_in_use(void);
  121. /*
  122. * Flags that can be passed from the hibernatig hernel to the "boot" kernel in
  123. * the image header.
  124. */
  125. #define SF_PLATFORM_MODE 1
  126. #define SF_NOCOMPRESS_MODE 2
  127. #define SF_CRC32_MODE 4
  128. /* kernel/power/hibernate.c */
  129. extern int swsusp_check(void);
  130. extern void swsusp_free(void);
  131. extern int swsusp_read(unsigned int *flags_p);
  132. extern int swsusp_write(unsigned int flags);
  133. extern void swsusp_close(fmode_t);
  134. #ifdef CONFIG_SUSPEND
  135. extern int swsusp_unmark(void);
  136. #endif
  137. /* kernel/power/block_io.c */
  138. extern struct block_device *hib_resume_bdev;
  139. extern int hib_bio_read_page(pgoff_t page_off, void *addr,
  140. struct bio **bio_chain);
  141. extern int hib_bio_write_page(pgoff_t page_off, void *addr,
  142. struct bio **bio_chain);
  143. extern int hib_wait_on_bio_chain(struct bio **bio_chain);
  144. struct timeval;
  145. /* kernel/power/swsusp.c */
  146. extern void swsusp_show_speed(struct timeval *, struct timeval *,
  147. unsigned int, char *);
  148. #ifdef CONFIG_SUSPEND
  149. /* kernel/power/suspend.c */
  150. extern const char *const pm_states[];
  151. extern bool valid_state(suspend_state_t state);
  152. extern int suspend_devices_and_enter(suspend_state_t state);
  153. #else /* !CONFIG_SUSPEND */
  154. static inline int suspend_devices_and_enter(suspend_state_t state)
  155. {
  156. return -ENOSYS;
  157. }
  158. static inline bool valid_state(suspend_state_t state) { return false; }
  159. #endif /* !CONFIG_SUSPEND */
  160. #ifdef CONFIG_PM_TEST_SUSPEND
  161. /* kernel/power/suspend_test.c */
  162. extern void suspend_test_start(void);
  163. extern void suspend_test_finish(const char *label);
  164. #else /* !CONFIG_PM_TEST_SUSPEND */
  165. static inline void suspend_test_start(void) {}
  166. static inline void suspend_test_finish(const char *label) {}
  167. #endif /* !CONFIG_PM_TEST_SUSPEND */
  168. #ifdef CONFIG_PM_SLEEP
  169. /* kernel/power/main.c */
  170. extern int pm_notifier_call_chain(unsigned long val);
  171. #endif
  172. #ifdef CONFIG_HIGHMEM
  173. int restore_highmem(void);
  174. #else
  175. static inline unsigned int count_highmem_pages(void) { return 0; }
  176. static inline int restore_highmem(void) { return 0; }
  177. #endif
  178. /*
  179. * Suspend test levels
  180. */
  181. enum {
  182. /* keep first */
  183. TEST_NONE,
  184. TEST_CORE,
  185. TEST_CPUS,
  186. TEST_PLATFORM,
  187. TEST_DEVICES,
  188. TEST_FREEZER,
  189. /* keep last */
  190. __TEST_AFTER_LAST
  191. };
  192. #define TEST_FIRST TEST_NONE
  193. #define TEST_MAX (__TEST_AFTER_LAST - 1)
  194. extern int pm_test_level;
  195. #ifdef CONFIG_SUSPEND_FREEZER
  196. static inline int suspend_freeze_processes(void)
  197. {
  198. int error;
  199. error = freeze_processes();
  200. /*
  201. * freeze_processes() automatically thaws every task if freezing
  202. * fails. So we need not do anything extra upon error.
  203. */
  204. if (error)
  205. return error;
  206. error = freeze_kernel_threads();
  207. /*
  208. * freeze_kernel_threads() thaws only kernel threads upon freezing
  209. * failure. So we have to thaw the userspace tasks ourselves.
  210. */
  211. if (error)
  212. thaw_processes();
  213. return error;
  214. }
  215. static inline void suspend_thaw_processes(void)
  216. {
  217. thaw_processes();
  218. }
  219. #else
  220. static inline int suspend_freeze_processes(void)
  221. {
  222. return 0;
  223. }
  224. static inline void suspend_thaw_processes(void)
  225. {
  226. }
  227. #endif
  228. #ifdef CONFIG_PM_AUTOSLEEP
  229. /* kernel/power/autosleep.c */
  230. extern int pm_autosleep_init(void);
  231. extern int pm_autosleep_lock(void);
  232. extern void pm_autosleep_unlock(void);
  233. extern suspend_state_t pm_autosleep_state(void);
  234. extern int pm_autosleep_set_state(suspend_state_t state);
  235. #else /* !CONFIG_PM_AUTOSLEEP */
  236. static inline int pm_autosleep_init(void) { return 0; }
  237. static inline int pm_autosleep_lock(void) { return 0; }
  238. static inline void pm_autosleep_unlock(void) {}
  239. static inline suspend_state_t pm_autosleep_state(void) { return PM_SUSPEND_ON; }
  240. #endif /* !CONFIG_PM_AUTOSLEEP */
  241. #ifdef CONFIG_PM_WAKELOCKS
  242. /* kernel/power/wakelock.c */
  243. extern ssize_t pm_show_wakelocks(char *buf, bool show_active);
  244. extern int pm_wake_lock(const char *buf);
  245. extern int pm_wake_unlock(const char *buf);
  246. #endif /* !CONFIG_PM_WAKELOCKS */