suspend.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_SUSPEND_H
  3. #define _LINUX_SUSPEND_H
  4. #include <linux/swap.h>
  5. #include <linux/notifier.h>
  6. #include <linux/init.h>
  7. #include <linux/pm.h>
  8. #include <linux/mm.h>
  9. #include <linux/freezer.h>
  10. #include <linux/android_kabi.h>
  11. #include <asm/errno.h>
  12. #ifdef CONFIG_VT
  13. extern void pm_set_vt_switch(int);
  14. #else
  15. static inline void pm_set_vt_switch(int do_switch)
  16. {
  17. }
  18. #endif
  19. #ifdef CONFIG_VT_CONSOLE_SLEEP
  20. extern void pm_prepare_console(void);
  21. extern void pm_restore_console(void);
  22. #else
  23. static inline void pm_prepare_console(void)
  24. {
  25. }
  26. static inline void pm_restore_console(void)
  27. {
  28. }
  29. #endif
  30. typedef int __bitwise suspend_state_t;
  31. #define PM_SUSPEND_ON ((__force suspend_state_t) 0)
  32. #define PM_SUSPEND_TO_IDLE ((__force suspend_state_t) 1)
  33. #define PM_SUSPEND_STANDBY ((__force suspend_state_t) 2)
  34. #define PM_SUSPEND_MEM ((__force suspend_state_t) 3)
  35. #define PM_SUSPEND_MIN PM_SUSPEND_TO_IDLE
  36. #define PM_SUSPEND_MAX ((__force suspend_state_t) 4)
  37. enum suspend_stat_step {
  38. SUSPEND_FREEZE = 1,
  39. SUSPEND_PREPARE,
  40. SUSPEND_SUSPEND,
  41. SUSPEND_SUSPEND_LATE,
  42. SUSPEND_SUSPEND_NOIRQ,
  43. SUSPEND_RESUME_NOIRQ,
  44. SUSPEND_RESUME_EARLY,
  45. SUSPEND_RESUME
  46. };
  47. struct suspend_stats {
  48. int success;
  49. int fail;
  50. int failed_freeze;
  51. int failed_prepare;
  52. int failed_suspend;
  53. int failed_suspend_late;
  54. int failed_suspend_noirq;
  55. int failed_resume;
  56. int failed_resume_early;
  57. int failed_resume_noirq;
  58. #define REC_FAILED_NUM 2
  59. int last_failed_dev;
  60. char failed_devs[REC_FAILED_NUM][40];
  61. int last_failed_errno;
  62. int errno[REC_FAILED_NUM];
  63. int last_failed_step;
  64. enum suspend_stat_step failed_steps[REC_FAILED_NUM];
  65. };
  66. extern struct suspend_stats suspend_stats;
  67. static inline void dpm_save_failed_dev(const char *name)
  68. {
  69. strscpy(suspend_stats.failed_devs[suspend_stats.last_failed_dev],
  70. name,
  71. sizeof(suspend_stats.failed_devs[0]));
  72. suspend_stats.last_failed_dev++;
  73. suspend_stats.last_failed_dev %= REC_FAILED_NUM;
  74. }
  75. static inline void dpm_save_failed_errno(int err)
  76. {
  77. suspend_stats.errno[suspend_stats.last_failed_errno] = err;
  78. suspend_stats.last_failed_errno++;
  79. suspend_stats.last_failed_errno %= REC_FAILED_NUM;
  80. }
  81. static inline void dpm_save_failed_step(enum suspend_stat_step step)
  82. {
  83. suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
  84. suspend_stats.last_failed_step++;
  85. suspend_stats.last_failed_step %= REC_FAILED_NUM;
  86. }
  87. /**
  88. * struct platform_suspend_ops - Callbacks for managing platform dependent
  89. * system sleep states.
  90. *
  91. * @valid: Callback to determine if given system sleep state is supported by
  92. * the platform.
  93. * Valid (ie. supported) states are advertised in /sys/power/state. Note
  94. * that it still may be impossible to enter given system sleep state if the
  95. * conditions aren't right.
  96. * There is the %suspend_valid_only_mem function available that can be
  97. * assigned to this if the platform only supports mem sleep.
  98. *
  99. * @begin: Initialise a transition to given system sleep state.
  100. * @begin() is executed right prior to suspending devices. The information
  101. * conveyed to the platform code by @begin() should be disregarded by it as
  102. * soon as @end() is executed. If @begin() fails (ie. returns nonzero),
  103. * @prepare(), @enter() and @finish() will not be called by the PM core.
  104. * This callback is optional. However, if it is implemented, the argument
  105. * passed to @enter() is redundant and should be ignored.
  106. *
  107. * @prepare: Prepare the platform for entering the system sleep state indicated
  108. * by @begin().
  109. * @prepare() is called right after devices have been suspended (ie. the
  110. * appropriate .suspend() method has been executed for each device) and
  111. * before device drivers' late suspend callbacks are executed. It returns
  112. * 0 on success or a negative error code otherwise, in which case the
  113. * system cannot enter the desired sleep state (@prepare_late(), @enter(),
  114. * and @wake() will not be called in that case).
  115. *
  116. * @prepare_late: Finish preparing the platform for entering the system sleep
  117. * state indicated by @begin().
  118. * @prepare_late is called before disabling nonboot CPUs and after
  119. * device drivers' late suspend callbacks have been executed. It returns
  120. * 0 on success or a negative error code otherwise, in which case the
  121. * system cannot enter the desired sleep state (@enter() will not be
  122. * executed).
  123. *
  124. * @enter: Enter the system sleep state indicated by @begin() or represented by
  125. * the argument if @begin() is not implemented.
  126. * This callback is mandatory. It returns 0 on success or a negative
  127. * error code otherwise, in which case the system cannot enter the desired
  128. * sleep state.
  129. *
  130. * @wake: Called when the system has just left a sleep state, right after
  131. * the nonboot CPUs have been enabled and before device drivers' early
  132. * resume callbacks are executed.
  133. * This callback is optional, but should be implemented by the platforms
  134. * that implement @prepare_late(). If implemented, it is always called
  135. * after @prepare_late and @enter(), even if one of them fails.
  136. *
  137. * @finish: Finish wake-up of the platform.
  138. * @finish is called right prior to calling device drivers' regular suspend
  139. * callbacks.
  140. * This callback is optional, but should be implemented by the platforms
  141. * that implement @prepare(). If implemented, it is always called after
  142. * @enter() and @wake(), even if any of them fails. It is executed after
  143. * a failing @prepare.
  144. *
  145. * @suspend_again: Returns whether the system should suspend again (true) or
  146. * not (false). If the platform wants to poll sensors or execute some
  147. * code during suspended without invoking userspace and most of devices,
  148. * suspend_again callback is the place assuming that periodic-wakeup or
  149. * alarm-wakeup is already setup. This allows to execute some codes while
  150. * being kept suspended in the view of userland and devices.
  151. *
  152. * @end: Called by the PM core right after resuming devices, to indicate to
  153. * the platform that the system has returned to the working state or
  154. * the transition to the sleep state has been aborted.
  155. * This callback is optional, but should be implemented by the platforms
  156. * that implement @begin(). Accordingly, platforms implementing @begin()
  157. * should also provide a @end() which cleans up transitions aborted before
  158. * @enter().
  159. *
  160. * @recover: Recover the platform from a suspend failure.
  161. * Called by the PM core if the suspending of devices fails.
  162. * This callback is optional and should only be implemented by platforms
  163. * which require special recovery actions in that situation.
  164. */
  165. struct platform_suspend_ops {
  166. int (*valid)(suspend_state_t state);
  167. int (*begin)(suspend_state_t state);
  168. int (*prepare)(void);
  169. int (*prepare_late)(void);
  170. int (*enter)(suspend_state_t state);
  171. void (*wake)(void);
  172. void (*finish)(void);
  173. bool (*suspend_again)(void);
  174. void (*end)(void);
  175. void (*recover)(void);
  176. ANDROID_KABI_RESERVE(1);
  177. };
  178. struct platform_s2idle_ops {
  179. int (*begin)(void);
  180. int (*prepare)(void);
  181. int (*prepare_late)(void);
  182. void (*check)(void);
  183. bool (*wake)(void);
  184. void (*restore_early)(void);
  185. void (*restore)(void);
  186. void (*end)(void);
  187. ANDROID_KABI_RESERVE(1);
  188. };
  189. #ifdef CONFIG_SUSPEND
  190. extern suspend_state_t mem_sleep_current;
  191. extern suspend_state_t mem_sleep_default;
  192. /**
  193. * suspend_set_ops - set platform dependent suspend operations
  194. * @ops: The new suspend operations to set.
  195. */
  196. extern void suspend_set_ops(const struct platform_suspend_ops *ops);
  197. extern int suspend_valid_only_mem(suspend_state_t state);
  198. extern unsigned int pm_suspend_global_flags;
  199. #define PM_SUSPEND_FLAG_FW_SUSPEND BIT(0)
  200. #define PM_SUSPEND_FLAG_FW_RESUME BIT(1)
  201. #define PM_SUSPEND_FLAG_NO_PLATFORM BIT(2)
  202. static inline void pm_suspend_clear_flags(void)
  203. {
  204. pm_suspend_global_flags = 0;
  205. }
  206. static inline void pm_set_suspend_via_firmware(void)
  207. {
  208. pm_suspend_global_flags |= PM_SUSPEND_FLAG_FW_SUSPEND;
  209. }
  210. static inline void pm_set_resume_via_firmware(void)
  211. {
  212. pm_suspend_global_flags |= PM_SUSPEND_FLAG_FW_RESUME;
  213. }
  214. static inline void pm_set_suspend_no_platform(void)
  215. {
  216. pm_suspend_global_flags |= PM_SUSPEND_FLAG_NO_PLATFORM;
  217. }
  218. /**
  219. * pm_suspend_via_firmware - Check if platform firmware will suspend the system.
  220. *
  221. * To be called during system-wide power management transitions to sleep states
  222. * or during the subsequent system-wide transitions back to the working state.
  223. *
  224. * Return 'true' if the platform firmware is going to be invoked at the end of
  225. * the system-wide power management transition (to a sleep state) in progress in
  226. * order to complete it, or if the platform firmware has been invoked in order
  227. * to complete the last (or preceding) transition of the system to a sleep
  228. * state.
  229. *
  230. * This matters if the caller needs or wants to carry out some special actions
  231. * depending on whether or not control will be passed to the platform firmware
  232. * subsequently (for example, the device may need to be reset before letting the
  233. * platform firmware manipulate it, which is not necessary when the platform
  234. * firmware is not going to be invoked) or when such special actions may have
  235. * been carried out during the preceding transition of the system to a sleep
  236. * state (as they may need to be taken into account).
  237. */
  238. static inline bool pm_suspend_via_firmware(void)
  239. {
  240. return !!(pm_suspend_global_flags & PM_SUSPEND_FLAG_FW_SUSPEND);
  241. }
  242. /**
  243. * pm_resume_via_firmware - Check if platform firmware has woken up the system.
  244. *
  245. * To be called during system-wide power management transitions from sleep
  246. * states.
  247. *
  248. * Return 'true' if the platform firmware has passed control to the kernel at
  249. * the beginning of the system-wide power management transition in progress, so
  250. * the event that woke up the system from sleep has been handled by the platform
  251. * firmware.
  252. */
  253. static inline bool pm_resume_via_firmware(void)
  254. {
  255. return !!(pm_suspend_global_flags & PM_SUSPEND_FLAG_FW_RESUME);
  256. }
  257. /**
  258. * pm_suspend_no_platform - Check if platform may change device power states.
  259. *
  260. * To be called during system-wide power management transitions to sleep states
  261. * or during the subsequent system-wide transitions back to the working state.
  262. *
  263. * Return 'true' if the power states of devices remain under full control of the
  264. * kernel throughout the system-wide suspend and resume cycle in progress (that
  265. * is, if a device is put into a certain power state during suspend, it can be
  266. * expected to remain in that state during resume).
  267. */
  268. static inline bool pm_suspend_no_platform(void)
  269. {
  270. return !!(pm_suspend_global_flags & PM_SUSPEND_FLAG_NO_PLATFORM);
  271. }
  272. /* Suspend-to-idle state machnine. */
  273. enum s2idle_states {
  274. S2IDLE_STATE_NONE, /* Not suspended/suspending. */
  275. S2IDLE_STATE_ENTER, /* Enter suspend-to-idle. */
  276. S2IDLE_STATE_WAKE, /* Wake up from suspend-to-idle. */
  277. };
  278. extern enum s2idle_states __read_mostly s2idle_state;
  279. static inline bool idle_should_enter_s2idle(void)
  280. {
  281. return unlikely(s2idle_state == S2IDLE_STATE_ENTER);
  282. }
  283. extern bool pm_suspend_default_s2idle(void);
  284. extern void __init pm_states_init(void);
  285. extern void s2idle_set_ops(const struct platform_s2idle_ops *ops);
  286. extern void s2idle_wake(void);
  287. /**
  288. * arch_suspend_disable_irqs - disable IRQs for suspend
  289. *
  290. * Disables IRQs (in the default case). This is a weak symbol in the common
  291. * code and thus allows architectures to override it if more needs to be
  292. * done. Not called for suspend to disk.
  293. */
  294. extern void arch_suspend_disable_irqs(void);
  295. /**
  296. * arch_suspend_enable_irqs - enable IRQs after suspend
  297. *
  298. * Enables IRQs (in the default case). This is a weak symbol in the common
  299. * code and thus allows architectures to override it if more needs to be
  300. * done. Not called for suspend to disk.
  301. */
  302. extern void arch_suspend_enable_irqs(void);
  303. extern int pm_suspend(suspend_state_t state);
  304. extern bool sync_on_suspend_enabled;
  305. #else /* !CONFIG_SUSPEND */
  306. #define suspend_valid_only_mem NULL
  307. static inline void pm_suspend_clear_flags(void) {}
  308. static inline void pm_set_suspend_via_firmware(void) {}
  309. static inline void pm_set_resume_via_firmware(void) {}
  310. static inline bool pm_suspend_via_firmware(void) { return false; }
  311. static inline bool pm_resume_via_firmware(void) { return false; }
  312. static inline bool pm_suspend_no_platform(void) { return false; }
  313. static inline bool pm_suspend_default_s2idle(void) { return false; }
  314. static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
  315. static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
  316. static inline bool sync_on_suspend_enabled(void) { return true; }
  317. static inline bool idle_should_enter_s2idle(void) { return false; }
  318. static inline void __init pm_states_init(void) {}
  319. static inline void s2idle_set_ops(const struct platform_s2idle_ops *ops) {}
  320. static inline void s2idle_wake(void) {}
  321. #endif /* !CONFIG_SUSPEND */
  322. /* struct pbe is used for creating lists of pages that should be restored
  323. * atomically during the resume from disk, because the page frames they have
  324. * occupied before the suspend are in use.
  325. */
  326. struct pbe {
  327. void *address; /* address of the copy */
  328. void *orig_address; /* original address of a page */
  329. struct pbe *next;
  330. };
  331. /* mm/page_alloc.c */
  332. extern void mark_free_pages(struct zone *zone);
  333. /**
  334. * struct platform_hibernation_ops - hibernation platform support
  335. *
  336. * The methods in this structure allow a platform to carry out special
  337. * operations required by it during a hibernation transition.
  338. *
  339. * All the methods below, except for @recover(), must be implemented.
  340. *
  341. * @begin: Tell the platform driver that we're starting hibernation.
  342. * Called right after shrinking memory and before freezing devices.
  343. *
  344. * @end: Called by the PM core right after resuming devices, to indicate to
  345. * the platform that the system has returned to the working state.
  346. *
  347. * @pre_snapshot: Prepare the platform for creating the hibernation image.
  348. * Called right after devices have been frozen and before the nonboot
  349. * CPUs are disabled (runs with IRQs on).
  350. *
  351. * @finish: Restore the previous state of the platform after the hibernation
  352. * image has been created *or* put the platform into the normal operation
  353. * mode after the hibernation (the same method is executed in both cases).
  354. * Called right after the nonboot CPUs have been enabled and before
  355. * thawing devices (runs with IRQs on).
  356. *
  357. * @prepare: Prepare the platform for entering the low power state.
  358. * Called right after the hibernation image has been saved and before
  359. * devices are prepared for entering the low power state.
  360. *
  361. * @enter: Put the system into the low power state after the hibernation image
  362. * has been saved to disk.
  363. * Called after the nonboot CPUs have been disabled and all of the low
  364. * level devices have been shut down (runs with IRQs off).
  365. *
  366. * @leave: Perform the first stage of the cleanup after the system sleep state
  367. * indicated by @set_target() has been left.
  368. * Called right after the control has been passed from the boot kernel to
  369. * the image kernel, before the nonboot CPUs are enabled and before devices
  370. * are resumed. Executed with interrupts disabled.
  371. *
  372. * @pre_restore: Prepare system for the restoration from a hibernation image.
  373. * Called right after devices have been frozen and before the nonboot
  374. * CPUs are disabled (runs with IRQs on).
  375. *
  376. * @restore_cleanup: Clean up after a failing image restoration.
  377. * Called right after the nonboot CPUs have been enabled and before
  378. * thawing devices (runs with IRQs on).
  379. *
  380. * @recover: Recover the platform from a failure to suspend devices.
  381. * Called by the PM core if the suspending of devices during hibernation
  382. * fails. This callback is optional and should only be implemented by
  383. * platforms which require special recovery actions in that situation.
  384. */
  385. struct platform_hibernation_ops {
  386. int (*begin)(pm_message_t stage);
  387. void (*end)(void);
  388. int (*pre_snapshot)(void);
  389. void (*finish)(void);
  390. int (*prepare)(void);
  391. int (*enter)(void);
  392. void (*leave)(void);
  393. int (*pre_restore)(void);
  394. void (*restore_cleanup)(void);
  395. void (*recover)(void);
  396. ANDROID_KABI_RESERVE(1);
  397. };
  398. #ifdef CONFIG_HIBERNATION
  399. /* kernel/power/snapshot.c */
  400. extern void register_nosave_region(unsigned long b, unsigned long e);
  401. extern int swsusp_page_is_forbidden(struct page *);
  402. extern void swsusp_set_page_free(struct page *);
  403. extern void swsusp_unset_page_free(struct page *);
  404. extern unsigned long get_safe_page(gfp_t gfp_mask);
  405. extern asmlinkage int swsusp_arch_suspend(void);
  406. extern asmlinkage int swsusp_arch_resume(void);
  407. extern u32 swsusp_hardware_signature;
  408. extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
  409. extern int hibernate(void);
  410. extern bool system_entering_hibernation(void);
  411. extern bool hibernation_available(void);
  412. asmlinkage int swsusp_save(void);
  413. extern struct pbe *restore_pblist;
  414. int pfn_is_nosave(unsigned long pfn);
  415. int hibernate_quiet_exec(int (*func)(void *data), void *data);
  416. #else /* CONFIG_HIBERNATION */
  417. static inline void register_nosave_region(unsigned long b, unsigned long e) {}
  418. static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
  419. static inline void swsusp_set_page_free(struct page *p) {}
  420. static inline void swsusp_unset_page_free(struct page *p) {}
  421. static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
  422. static inline int hibernate(void) { return -ENOSYS; }
  423. static inline bool system_entering_hibernation(void) { return false; }
  424. static inline bool hibernation_available(void) { return false; }
  425. static inline int hibernate_quiet_exec(int (*func)(void *data), void *data) {
  426. return -ENOTSUPP;
  427. }
  428. #endif /* CONFIG_HIBERNATION */
  429. #ifdef CONFIG_HIBERNATION_SNAPSHOT_DEV
  430. int is_hibernate_resume_dev(dev_t dev);
  431. #else
  432. static inline int is_hibernate_resume_dev(dev_t dev) { return 0; }
  433. #endif
  434. /* Hibernation and suspend events */
  435. #define PM_HIBERNATION_PREPARE 0x0001 /* Going to hibernate */
  436. #define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */
  437. #define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */
  438. #define PM_POST_SUSPEND 0x0004 /* Suspend finished */
  439. #define PM_RESTORE_PREPARE 0x0005 /* Going to restore a saved image */
  440. #define PM_POST_RESTORE 0x0006 /* Restore failed */
  441. extern struct mutex system_transition_mutex;
  442. #ifdef CONFIG_PM_SLEEP
  443. void save_processor_state(void);
  444. void restore_processor_state(void);
  445. /* kernel/power/main.c */
  446. extern int register_pm_notifier(struct notifier_block *nb);
  447. extern int unregister_pm_notifier(struct notifier_block *nb);
  448. extern void ksys_sync_helper(void);
  449. #define pm_notifier(fn, pri) { \
  450. static struct notifier_block fn##_nb = \
  451. { .notifier_call = fn, .priority = pri }; \
  452. register_pm_notifier(&fn##_nb); \
  453. }
  454. /* drivers/base/power/wakeup.c */
  455. extern bool events_check_enabled;
  456. extern suspend_state_t pm_suspend_target_state;
  457. extern bool pm_wakeup_pending(void);
  458. extern void pm_system_wakeup(void);
  459. extern void pm_system_cancel_wakeup(void);
  460. extern void pm_wakeup_clear(unsigned int irq_number);
  461. extern void pm_system_irq_wakeup(unsigned int irq_number);
  462. extern unsigned int pm_wakeup_irq(void);
  463. extern bool pm_get_wakeup_count(unsigned int *count, bool block);
  464. extern bool pm_save_wakeup_count(unsigned int count);
  465. extern void pm_wakep_autosleep_enabled(bool set);
  466. extern void pm_print_active_wakeup_sources(void);
  467. extern void pm_get_active_wakeup_sources(char *pending_sources, size_t max);
  468. extern unsigned int lock_system_sleep(void);
  469. extern void unlock_system_sleep(unsigned int);
  470. #else /* !CONFIG_PM_SLEEP */
  471. static inline int register_pm_notifier(struct notifier_block *nb)
  472. {
  473. return 0;
  474. }
  475. static inline int unregister_pm_notifier(struct notifier_block *nb)
  476. {
  477. return 0;
  478. }
  479. static inline void ksys_sync_helper(void) {}
  480. #define pm_notifier(fn, pri) do { (void)(fn); } while (0)
  481. static inline bool pm_wakeup_pending(void) { return false; }
  482. static inline void pm_system_wakeup(void) {}
  483. static inline void pm_wakeup_clear(bool reset) {}
  484. static inline void pm_system_irq_wakeup(unsigned int irq_number) {}
  485. static inline unsigned int lock_system_sleep(void) { return 0; }
  486. static inline void unlock_system_sleep(unsigned int flags) {}
  487. #endif /* !CONFIG_PM_SLEEP */
  488. #ifdef CONFIG_PM_SLEEP_DEBUG
  489. extern bool pm_print_times_enabled;
  490. extern bool pm_debug_messages_on;
  491. static inline int pm_dyn_debug_messages_on(void)
  492. {
  493. #ifdef CONFIG_DYNAMIC_DEBUG
  494. return 1;
  495. #else
  496. return 0;
  497. #endif
  498. }
  499. #ifndef pr_fmt
  500. #define pr_fmt(fmt) "PM: " fmt
  501. #endif
  502. #define __pm_pr_dbg(fmt, ...) \
  503. do { \
  504. if (pm_debug_messages_on) \
  505. printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
  506. else if (pm_dyn_debug_messages_on()) \
  507. pr_debug(fmt, ##__VA_ARGS__); \
  508. } while (0)
  509. #define __pm_deferred_pr_dbg(fmt, ...) \
  510. do { \
  511. if (pm_debug_messages_on) \
  512. printk_deferred(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__); \
  513. } while (0)
  514. #else
  515. #define pm_print_times_enabled (false)
  516. #define pm_debug_messages_on (false)
  517. #include <linux/printk.h>
  518. #define __pm_pr_dbg(fmt, ...) \
  519. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  520. #define __pm_deferred_pr_dbg(fmt, ...) \
  521. no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
  522. #endif
  523. /**
  524. * pm_pr_dbg - print pm sleep debug messages
  525. *
  526. * If pm_debug_messages_on is enabled, print message.
  527. * If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is enabled,
  528. * print message only from instances explicitly enabled on dynamic debug's
  529. * control.
  530. * If pm_debug_messages_on is disabled and CONFIG_DYNAMIC_DEBUG is disabled,
  531. * don't print message.
  532. */
  533. #define pm_pr_dbg(fmt, ...) \
  534. __pm_pr_dbg(fmt, ##__VA_ARGS__)
  535. #define pm_deferred_pr_dbg(fmt, ...) \
  536. __pm_deferred_pr_dbg(fmt, ##__VA_ARGS__)
  537. #ifdef CONFIG_PM_AUTOSLEEP
  538. /* kernel/power/autosleep.c */
  539. void queue_up_suspend_work(void);
  540. #else /* !CONFIG_PM_AUTOSLEEP */
  541. static inline void queue_up_suspend_work(void) {}
  542. #endif /* !CONFIG_PM_AUTOSLEEP */
  543. #endif /* _LINUX_SUSPEND_H */