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