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