1#ifndef _LINUX_SUSPEND_H
2#define _LINUX_SUSPEND_H
3
4#include <linux/swap.h>
5#include <linux/notifier.h>
6#include <linux/init.h>
7#include <linux/pm.h>
8#include <linux/mm.h>
9#include <linux/freezer.h>
10#include <asm/errno.h>
11
12#ifdef CONFIG_VT
13extern void pm_set_vt_switch(int);
14#else
15static inline void pm_set_vt_switch(int do_switch)
16{
17}
18#endif
19
20#ifdef CONFIG_VT_CONSOLE_SLEEP
21extern int pm_prepare_console(void);
22extern void pm_restore_console(void);
23#else
24static inline int pm_prepare_console(void)
25{
26 return 0;
27}
28
29static inline void pm_restore_console(void)
30{
31}
32#endif
33
34typedef int __bitwise suspend_state_t;
35
36#define PM_SUSPEND_ON ((__force suspend_state_t) 0)
37#define PM_SUSPEND_FREEZE ((__force suspend_state_t) 1)
38#define PM_SUSPEND_STANDBY ((__force suspend_state_t) 2)
39#define PM_SUSPEND_MEM ((__force suspend_state_t) 3)
40#define PM_SUSPEND_MIN PM_SUSPEND_FREEZE
41#define PM_SUSPEND_MAX ((__force suspend_state_t) 4)
42
43enum suspend_stat_step {
44 SUSPEND_FREEZE = 1,
45 SUSPEND_PREPARE,
46 SUSPEND_SUSPEND,
47 SUSPEND_SUSPEND_LATE,
48 SUSPEND_SUSPEND_NOIRQ,
49 SUSPEND_RESUME_NOIRQ,
50 SUSPEND_RESUME_EARLY,
51 SUSPEND_RESUME
52};
53
54struct suspend_stats {
55 int success;
56 int fail;
57 int failed_freeze;
58 int failed_prepare;
59 int failed_suspend;
60 int failed_suspend_late;
61 int failed_suspend_noirq;
62 int failed_resume;
63 int failed_resume_early;
64 int failed_resume_noirq;
65#define REC_FAILED_NUM 2
66 int last_failed_dev;
67 char failed_devs[REC_FAILED_NUM][40];
68 int last_failed_errno;
69 int errno[REC_FAILED_NUM];
70 int last_failed_step;
71 enum suspend_stat_step failed_steps[REC_FAILED_NUM];
72};
73
74extern struct suspend_stats suspend_stats;
75
76static inline void dpm_save_failed_dev(const char *name)
77{
78 strlcpy(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
85static 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
92static inline void dpm_save_failed_step(enum suspend_stat_step step)
93{
94 suspend_stats.failed_steps[suspend_stats.last_failed_step] = step;
95 suspend_stats.last_failed_step++;
96 suspend_stats.last_failed_step %= REC_FAILED_NUM;
97}
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177struct platform_suspend_ops {
178 int (*valid)(suspend_state_t state);
179 int (*begin)(suspend_state_t state);
180 int (*prepare)(void);
181 int (*prepare_late)(void);
182 int (*enter)(suspend_state_t state);
183 void (*wake)(void);
184 void (*finish)(void);
185 bool (*suspend_again)(void);
186 void (*end)(void);
187 void (*recover)(void);
188};
189
190struct platform_freeze_ops {
191 int (*begin)(void);
192 void (*end)(void);
193};
194
195#ifdef CONFIG_SUSPEND
196
197
198
199
200extern void suspend_set_ops(const struct platform_suspend_ops *ops);
201extern int suspend_valid_only_mem(suspend_state_t state);
202extern void freeze_set_ops(const struct platform_freeze_ops *ops);
203extern void freeze_wake(void);
204
205
206
207
208
209
210
211
212extern void arch_suspend_disable_irqs(void);
213
214
215
216
217
218
219
220
221extern void arch_suspend_enable_irqs(void);
222
223extern int pm_suspend(suspend_state_t state);
224#else
225#define suspend_valid_only_mem NULL
226
227static inline void suspend_set_ops(const struct platform_suspend_ops *ops) {}
228static inline int pm_suspend(suspend_state_t state) { return -ENOSYS; }
229static inline void freeze_set_ops(const struct platform_freeze_ops *ops) {}
230static inline void freeze_wake(void) {}
231#endif
232
233
234
235
236
237struct pbe {
238 void *address;
239 void *orig_address;
240 struct pbe *next;
241};
242
243
244extern void mark_free_pages(struct zone *zone);
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298struct platform_hibernation_ops {
299 int (*begin)(void);
300 void (*end)(void);
301 int (*pre_snapshot)(void);
302 void (*finish)(void);
303 int (*prepare)(void);
304 int (*enter)(void);
305 void (*leave)(void);
306 int (*pre_restore)(void);
307 void (*restore_cleanup)(void);
308 void (*recover)(void);
309};
310
311#ifdef CONFIG_HIBERNATION
312
313extern void __register_nosave_region(unsigned long b, unsigned long e, int km);
314static inline void __init register_nosave_region(unsigned long b, unsigned long e)
315{
316 __register_nosave_region(b, e, 0);
317}
318static inline void __init register_nosave_region_late(unsigned long b, unsigned long e)
319{
320 __register_nosave_region(b, e, 1);
321}
322extern int swsusp_page_is_forbidden(struct page *);
323extern void swsusp_set_page_free(struct page *);
324extern void swsusp_unset_page_free(struct page *);
325extern unsigned long get_safe_page(gfp_t gfp_mask);
326
327extern void hibernation_set_ops(const struct platform_hibernation_ops *ops);
328extern int hibernate(void);
329extern bool system_entering_hibernation(void);
330extern bool hibernation_available(void);
331asmlinkage int swsusp_save(void);
332extern struct pbe *restore_pblist;
333#else
334static inline void register_nosave_region(unsigned long b, unsigned long e) {}
335static inline void register_nosave_region_late(unsigned long b, unsigned long e) {}
336static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
337static inline void swsusp_set_page_free(struct page *p) {}
338static inline void swsusp_unset_page_free(struct page *p) {}
339
340static inline void hibernation_set_ops(const struct platform_hibernation_ops *ops) {}
341static inline int hibernate(void) { return -ENOSYS; }
342static inline bool system_entering_hibernation(void) { return false; }
343static inline bool hibernation_available(void) { return false; }
344#endif
345
346
347#define PM_HIBERNATION_PREPARE 0x0001
348#define PM_POST_HIBERNATION 0x0002
349#define PM_SUSPEND_PREPARE 0x0003
350#define PM_POST_SUSPEND 0x0004
351#define PM_RESTORE_PREPARE 0x0005
352#define PM_POST_RESTORE 0x0006
353
354extern struct mutex pm_mutex;
355
356#ifdef CONFIG_PM_SLEEP
357void save_processor_state(void);
358void restore_processor_state(void);
359
360
361extern int register_pm_notifier(struct notifier_block *nb);
362extern int unregister_pm_notifier(struct notifier_block *nb);
363
364#define pm_notifier(fn, pri) { \
365 static struct notifier_block fn##_nb = \
366 { .notifier_call = fn, .priority = pri }; \
367 register_pm_notifier(&fn##_nb); \
368}
369
370
371extern bool events_check_enabled;
372
373extern bool pm_wakeup_pending(void);
374extern bool pm_get_wakeup_count(unsigned int *count, bool block);
375extern bool pm_save_wakeup_count(unsigned int count);
376extern void pm_wakep_autosleep_enabled(bool set);
377extern void pm_print_active_wakeup_sources(void);
378
379static inline void lock_system_sleep(void)
380{
381 current->flags |= PF_FREEZER_SKIP;
382 mutex_lock(&pm_mutex);
383}
384
385static inline void unlock_system_sleep(void)
386{
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402 current->flags &= ~PF_FREEZER_SKIP;
403 mutex_unlock(&pm_mutex);
404}
405
406#else
407
408static inline int register_pm_notifier(struct notifier_block *nb)
409{
410 return 0;
411}
412
413static inline int unregister_pm_notifier(struct notifier_block *nb)
414{
415 return 0;
416}
417
418#define pm_notifier(fn, pri) do { (void)(fn); } while (0)
419
420static inline bool pm_wakeup_pending(void) { return false; }
421
422static inline void lock_system_sleep(void) {}
423static inline void unlock_system_sleep(void) {}
424
425#endif
426
427#ifdef CONFIG_PM_SLEEP_DEBUG
428extern bool pm_print_times_enabled;
429#else
430#define pm_print_times_enabled (false)
431#endif
432
433#ifdef CONFIG_PM_AUTOSLEEP
434
435
436void queue_up_suspend_work(void);
437
438#else
439
440static inline void queue_up_suspend_work(void) {}
441
442#endif
443
444#ifdef CONFIG_ARCH_SAVE_PAGE_KEYS
445
446
447
448
449
450
451
452unsigned long page_key_additional_pages(unsigned long pages);
453int page_key_alloc(unsigned long pages);
454void page_key_free(void);
455void page_key_read(unsigned long *pfn);
456void page_key_memorize(unsigned long *pfn);
457void page_key_write(void *address);
458
459#else
460
461static inline unsigned long page_key_additional_pages(unsigned long pages)
462{
463 return 0;
464}
465
466static inline int page_key_alloc(unsigned long pages)
467{
468 return 0;
469}
470
471static inline void page_key_free(void) {}
472static inline void page_key_read(unsigned long *pfn) {}
473static inline void page_key_memorize(unsigned long *pfn) {}
474static inline void page_key_write(void *address) {}
475
476#endif
477
478#endif
479