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