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