xref: /linux/kernel/power/power.h (revision 74c7e2efbe37378026f00ad9e7253796d7b2fc99)
11da177e4SLinus Torvalds #include <linux/suspend.h>
21da177e4SLinus Torvalds #include <linux/utsname.h>
31da177e4SLinus Torvalds 
41da177e4SLinus Torvalds struct swsusp_info {
51da177e4SLinus Torvalds 	struct new_utsname	uts;
61da177e4SLinus Torvalds 	u32			version_code;
71da177e4SLinus Torvalds 	unsigned long		num_physpages;
81da177e4SLinus Torvalds 	int			cpus;
91da177e4SLinus Torvalds 	unsigned long		image_pages;
107088a5c0SRafael J. Wysocki 	unsigned long		pages;
111da177e4SLinus Torvalds } __attribute__((aligned(PAGE_SIZE)));
121da177e4SLinus Torvalds 
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds #ifdef CONFIG_SOFTWARE_SUSPEND
161da177e4SLinus Torvalds extern int pm_suspend_disk(void);
171da177e4SLinus Torvalds 
181da177e4SLinus Torvalds #else
191da177e4SLinus Torvalds static inline int pm_suspend_disk(void)
201da177e4SLinus Torvalds {
211da177e4SLinus Torvalds 	return -EPERM;
221da177e4SLinus Torvalds }
231da177e4SLinus Torvalds #endif
241da177e4SLinus Torvalds extern struct semaphore pm_sem;
251da177e4SLinus Torvalds #define power_attr(_name) \
261da177e4SLinus Torvalds static struct subsys_attribute _name##_attr = {	\
271da177e4SLinus Torvalds 	.attr	= {				\
281da177e4SLinus Torvalds 		.name = __stringify(_name),	\
291da177e4SLinus Torvalds 		.mode = 0644,			\
301da177e4SLinus Torvalds 	},					\
311da177e4SLinus Torvalds 	.show	= _name##_show,			\
321da177e4SLinus Torvalds 	.store	= _name##_store,		\
331da177e4SLinus Torvalds }
341da177e4SLinus Torvalds 
351da177e4SLinus Torvalds extern struct subsystem power_subsys;
361da177e4SLinus Torvalds 
3725761b6eSRafael J. Wysocki /* References to section boundaries */
3825761b6eSRafael J. Wysocki extern const void __nosave_begin, __nosave_end;
3925761b6eSRafael J. Wysocki 
4072a97e08SRafael J. Wysocki extern struct pbe *pagedir_nosave;
4172a97e08SRafael J. Wysocki 
42853609b6SRafael J. Wysocki /* Preferred image size in bytes (default 500 MB) */
43853609b6SRafael J. Wysocki extern unsigned long image_size;
44f577eb30SRafael J. Wysocki extern int in_suspend;
4561159a31SRafael J. Wysocki extern dev_t swsusp_resume_device;
46f577eb30SRafael J. Wysocki 
4725761b6eSRafael J. Wysocki extern asmlinkage int swsusp_arch_suspend(void);
4825761b6eSRafael J. Wysocki extern asmlinkage int swsusp_arch_resume(void);
4925761b6eSRafael J. Wysocki 
5072a97e08SRafael J. Wysocki extern unsigned int count_data_pages(void);
51f577eb30SRafael J. Wysocki 
52f577eb30SRafael J. Wysocki struct snapshot_handle {
53f577eb30SRafael J. Wysocki 	loff_t		offset;
54f577eb30SRafael J. Wysocki 	unsigned int	page;
55f577eb30SRafael J. Wysocki 	unsigned int	page_offset;
56f577eb30SRafael J. Wysocki 	unsigned int	prev;
57f577eb30SRafael J. Wysocki 	struct pbe	*pbe;
58f577eb30SRafael J. Wysocki 	void		*buffer;
59f577eb30SRafael J. Wysocki 	unsigned int	buf_offset;
60f577eb30SRafael J. Wysocki };
61f577eb30SRafael J. Wysocki 
62f577eb30SRafael J. Wysocki #define data_of(handle)	((handle).buffer + (handle).buf_offset)
63f577eb30SRafael J. Wysocki 
64f577eb30SRafael J. Wysocki extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
65f577eb30SRafael J. Wysocki extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
66f577eb30SRafael J. Wysocki int snapshot_image_loaded(struct snapshot_handle *handle);
6761159a31SRafael J. Wysocki 
6861159a31SRafael J. Wysocki /**
6961159a31SRafael J. Wysocki  *	The bitmap is used for tracing allocated swap pages
7061159a31SRafael J. Wysocki  *
7161159a31SRafael J. Wysocki  *	The entire bitmap consists of a number of bitmap_page
7261159a31SRafael J. Wysocki  *	structures linked with the help of the .next member.
7361159a31SRafael J. Wysocki  *	Thus each page can be allocated individually, so we only
7461159a31SRafael J. Wysocki  *	need to make 0-order memory allocations to create
7561159a31SRafael J. Wysocki  *	the bitmap.
7661159a31SRafael J. Wysocki  */
7761159a31SRafael J. Wysocki 
7861159a31SRafael J. Wysocki #define BITMAP_PAGE_SIZE	(PAGE_SIZE - sizeof(void *))
7961159a31SRafael J. Wysocki #define BITMAP_PAGE_CHUNKS	(BITMAP_PAGE_SIZE / sizeof(long))
8061159a31SRafael J. Wysocki #define BITS_PER_CHUNK		(sizeof(long) * 8)
8161159a31SRafael J. Wysocki #define BITMAP_PAGE_BITS	(BITMAP_PAGE_CHUNKS * BITS_PER_CHUNK)
8261159a31SRafael J. Wysocki 
8361159a31SRafael J. Wysocki struct bitmap_page {
8461159a31SRafael J. Wysocki 	unsigned long		chunks[BITMAP_PAGE_CHUNKS];
8561159a31SRafael J. Wysocki 	struct bitmap_page	*next;
8661159a31SRafael J. Wysocki };
8761159a31SRafael J. Wysocki 
8861159a31SRafael J. Wysocki extern void free_bitmap(struct bitmap_page *bitmap);
8961159a31SRafael J. Wysocki extern struct bitmap_page *alloc_bitmap(unsigned int nr_bits);
9061159a31SRafael J. Wysocki extern unsigned long alloc_swap_page(int swap, struct bitmap_page *bitmap);
9161159a31SRafael J. Wysocki extern void free_all_swap_pages(int swap, struct bitmap_page *bitmap);
9261159a31SRafael J. Wysocki 
93*74c7e2efSRandy Dunlap extern int swsusp_check(void);
9461159a31SRafael J. Wysocki extern int swsusp_shrink_memory(void);
95*74c7e2efSRandy Dunlap extern void swsusp_free(void);
9661159a31SRafael J. Wysocki extern int swsusp_suspend(void);
9761159a31SRafael J. Wysocki extern int swsusp_resume(void);
98*74c7e2efSRandy Dunlap extern int swsusp_read(void);
99*74c7e2efSRandy Dunlap extern int swsusp_write(void);
100*74c7e2efSRandy Dunlap extern void swsusp_close(void);
101