xref: /linux-6.15/include/linux/suspend.h (revision aeb3f462)
1 #ifndef _LINUX_SWSUSP_H
2 #define _LINUX_SWSUSP_H
3 
4 #if defined(CONFIG_X86) || defined(CONFIG_FRV) || defined(CONFIG_PPC32) || defined(CONFIG_PPC64)
5 #include <asm/suspend.h>
6 #endif
7 #include <linux/swap.h>
8 #include <linux/notifier.h>
9 #include <linux/init.h>
10 #include <linux/pm.h>
11 #include <linux/mm.h>
12 
13 /* struct pbe is used for creating lists of pages that should be restored
14  * atomically during the resume from disk, because the page frames they have
15  * occupied before the suspend are in use.
16  */
17 struct pbe {
18 	void *address;		/* address of the copy */
19 	void *orig_address;	/* original address of a page */
20 	struct pbe *next;
21 };
22 
23 /* mm/page_alloc.c */
24 extern void drain_local_pages(void);
25 extern void mark_free_pages(struct zone *zone);
26 
27 #if defined(CONFIG_PM_SLEEP) && defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
28 extern int pm_prepare_console(void);
29 extern void pm_restore_console(void);
30 #else
31 static inline int pm_prepare_console(void) { return 0; }
32 static inline void pm_restore_console(void) {}
33 #endif
34 
35 /**
36  * struct hibernation_ops - hibernation platform support
37  *
38  * The methods in this structure allow a platform to override the default
39  * mechanism of shutting down the machine during a hibernation transition.
40  *
41  * All three methods must be assigned.
42  *
43  * @prepare: prepare system for hibernation
44  * @enter: shut down system after state has been saved to disk
45  * @finish: finish/clean up after state has been reloaded
46  * @pre_restore: prepare system for the restoration from a hibernation image
47  * @restore_cleanup: clean up after a failing image restoration
48  */
49 struct hibernation_ops {
50 	int (*prepare)(void);
51 	int (*enter)(void);
52 	void (*finish)(void);
53 	int (*pre_restore)(void);
54 	void (*restore_cleanup)(void);
55 };
56 
57 #ifdef CONFIG_HIBERNATION
58 /* kernel/power/snapshot.c */
59 extern void __register_nosave_region(unsigned long b, unsigned long e, int km);
60 static inline void register_nosave_region(unsigned long b, unsigned long e)
61 {
62 	__register_nosave_region(b, e, 0);
63 }
64 static inline void register_nosave_region_late(unsigned long b, unsigned long e)
65 {
66 	__register_nosave_region(b, e, 1);
67 }
68 extern int swsusp_page_is_forbidden(struct page *);
69 extern void swsusp_set_page_free(struct page *);
70 extern void swsusp_unset_page_free(struct page *);
71 extern unsigned long get_safe_page(gfp_t gfp_mask);
72 
73 extern void hibernation_set_ops(struct hibernation_ops *ops);
74 extern int hibernate(void);
75 #else /* CONFIG_HIBERNATION */
76 static inline int swsusp_page_is_forbidden(struct page *p) { return 0; }
77 static inline void swsusp_set_page_free(struct page *p) {}
78 static inline void swsusp_unset_page_free(struct page *p) {}
79 
80 static inline void hibernation_set_ops(struct hibernation_ops *ops) {}
81 static inline int hibernate(void) { return -ENOSYS; }
82 #endif /* CONFIG_HIBERNATION */
83 
84 #ifdef CONFIG_PM_SLEEP
85 void save_processor_state(void);
86 void restore_processor_state(void);
87 struct saved_context;
88 void __save_processor_state(struct saved_context *ctxt);
89 void __restore_processor_state(struct saved_context *ctxt);
90 
91 /* kernel/power/main.c */
92 extern struct blocking_notifier_head pm_chain_head;
93 
94 static inline int register_pm_notifier(struct notifier_block *nb)
95 {
96 	return blocking_notifier_chain_register(&pm_chain_head, nb);
97 }
98 
99 static inline int unregister_pm_notifier(struct notifier_block *nb)
100 {
101 	return blocking_notifier_chain_unregister(&pm_chain_head, nb);
102 }
103 
104 #define pm_notifier(fn, pri) {				\
105 	static struct notifier_block fn##_nb =			\
106 		{ .notifier_call = fn, .priority = pri };	\
107 	register_pm_notifier(&fn##_nb);			\
108 }
109 #else /* !CONFIG_PM_SLEEP */
110 
111 static inline int register_pm_notifier(struct notifier_block *nb)
112 {
113 	return 0;
114 }
115 
116 static inline int unregister_pm_notifier(struct notifier_block *nb)
117 {
118 	return 0;
119 }
120 
121 #define pm_notifier(fn, pri)	do { (void)(fn); } while (0)
122 #endif /* !CONFIG_PM_SLEEP */
123 
124 #ifndef CONFIG_HIBERNATION
125 static inline void register_nosave_region(unsigned long b, unsigned long e)
126 {
127 }
128 static inline void register_nosave_region_late(unsigned long b, unsigned long e)
129 {
130 }
131 #endif
132 
133 #endif /* _LINUX_SWSUSP_H */
134