xref: /linux/kernel/power/power.h (revision d1d241cc2c5feec057c370aa71637380b1b945d5)
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;
116e1819d6SRafael J. Wysocki 	unsigned long		size;
121da177e4SLinus Torvalds } __attribute__((aligned(PAGE_SIZE)));
131da177e4SLinus Torvalds 
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #ifdef CONFIG_SOFTWARE_SUSPEND
171da177e4SLinus Torvalds extern int pm_suspend_disk(void);
181da177e4SLinus Torvalds 
191da177e4SLinus Torvalds #else
201da177e4SLinus Torvalds static inline int pm_suspend_disk(void)
211da177e4SLinus Torvalds {
221da177e4SLinus Torvalds 	return -EPERM;
231da177e4SLinus Torvalds }
241da177e4SLinus Torvalds #endif
25a6d70980SStephen Hemminger 
2649c3df6aSVivek Goyal extern int pfn_is_nosave(unsigned long);
2749c3df6aSVivek Goyal 
28a6d70980SStephen Hemminger extern struct mutex pm_mutex;
29a6d70980SStephen Hemminger 
301da177e4SLinus Torvalds #define power_attr(_name) \
311da177e4SLinus Torvalds static struct subsys_attribute _name##_attr = {	\
321da177e4SLinus Torvalds 	.attr	= {				\
331da177e4SLinus Torvalds 		.name = __stringify(_name),	\
341da177e4SLinus Torvalds 		.mode = 0644,			\
351da177e4SLinus Torvalds 	},					\
361da177e4SLinus Torvalds 	.show	= _name##_show,			\
371da177e4SLinus Torvalds 	.store	= _name##_store,		\
381da177e4SLinus Torvalds }
391da177e4SLinus Torvalds 
40823bccfcSGreg Kroah-Hartman extern struct kset power_subsys;
411da177e4SLinus Torvalds 
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;
469a154d9dSRafael J. Wysocki extern sector_t swsusp_resume_block;
47f577eb30SRafael J. Wysocki 
4825761b6eSRafael J. Wysocki extern asmlinkage int swsusp_arch_suspend(void);
4925761b6eSRafael J. Wysocki extern asmlinkage int swsusp_arch_resume(void);
5025761b6eSRafael J. Wysocki 
5174dfd666SRafael J. Wysocki extern int create_basic_memory_bitmaps(void);
5274dfd666SRafael J. Wysocki extern void free_basic_memory_bitmaps(void);
5372a97e08SRafael J. Wysocki extern unsigned int count_data_pages(void);
54f577eb30SRafael J. Wysocki 
55fb13a28bSRafael J. Wysocki /**
56fb13a28bSRafael J. Wysocki  *	Auxiliary structure used for reading the snapshot image data and
57fb13a28bSRafael J. Wysocki  *	metadata from and writing them to the list of page backup entries
58fb13a28bSRafael J. Wysocki  *	(PBEs) which is the main data structure of swsusp.
59fb13a28bSRafael J. Wysocki  *
60fb13a28bSRafael J. Wysocki  *	Using struct snapshot_handle we can transfer the image, including its
61fb13a28bSRafael J. Wysocki  *	metadata, as a continuous sequence of bytes with the help of
62fb13a28bSRafael J. Wysocki  *	snapshot_read_next() and snapshot_write_next().
63fb13a28bSRafael J. Wysocki  *
64fb13a28bSRafael J. Wysocki  *	The code that writes the image to a storage or transfers it to
65fb13a28bSRafael J. Wysocki  *	the user land is required to use snapshot_read_next() for this
66fb13a28bSRafael J. Wysocki  *	purpose and it should not make any assumptions regarding the internal
67fb13a28bSRafael J. Wysocki  *	structure of the image.  Similarly, the code that reads the image from
68fb13a28bSRafael J. Wysocki  *	a storage or transfers it from the user land is required to use
69fb13a28bSRafael J. Wysocki  *	snapshot_write_next().
70fb13a28bSRafael J. Wysocki  *
71fb13a28bSRafael J. Wysocki  *	This may allow us to change the internal structure of the image
72fb13a28bSRafael J. Wysocki  *	in the future with considerably less effort.
73fb13a28bSRafael J. Wysocki  */
74fb13a28bSRafael J. Wysocki 
75f577eb30SRafael J. Wysocki struct snapshot_handle {
76fb13a28bSRafael J. Wysocki 	loff_t		offset;	/* number of the last byte ready for reading
77fb13a28bSRafael J. Wysocki 				 * or writing in the sequence
78fb13a28bSRafael J. Wysocki 				 */
79fb13a28bSRafael J. Wysocki 	unsigned int	cur;	/* number of the block of PAGE_SIZE bytes the
80fb13a28bSRafael J. Wysocki 				 * next operation will refer to (ie. current)
81fb13a28bSRafael J. Wysocki 				 */
82fb13a28bSRafael J. Wysocki 	unsigned int	cur_offset;	/* offset with respect to the current
83fb13a28bSRafael J. Wysocki 					 * block (for the next operation)
84fb13a28bSRafael J. Wysocki 					 */
85fb13a28bSRafael J. Wysocki 	unsigned int	prev;	/* number of the block of PAGE_SIZE bytes that
86fb13a28bSRafael J. Wysocki 				 * was the current one previously
87fb13a28bSRafael J. Wysocki 				 */
88fb13a28bSRafael J. Wysocki 	void		*buffer;	/* address of the block to read from
89fb13a28bSRafael J. Wysocki 					 * or write to
90fb13a28bSRafael J. Wysocki 					 */
91fb13a28bSRafael J. Wysocki 	unsigned int	buf_offset;	/* location to read from or write to,
92fb13a28bSRafael J. Wysocki 					 * given as a displacement from 'buffer'
93fb13a28bSRafael J. Wysocki 					 */
94fb13a28bSRafael J. Wysocki 	int		sync_read;	/* Set to one to notify the caller of
95fb13a28bSRafael J. Wysocki 					 * snapshot_write_next() that it may
96fb13a28bSRafael J. Wysocki 					 * need to call wait_on_bio_chain()
97fb13a28bSRafael J. Wysocki 					 */
98f577eb30SRafael J. Wysocki };
99f577eb30SRafael J. Wysocki 
100fb13a28bSRafael J. Wysocki /* This macro returns the address from/to which the caller of
101fb13a28bSRafael J. Wysocki  * snapshot_read_next()/snapshot_write_next() is allowed to
102fb13a28bSRafael J. Wysocki  * read/write data after the function returns
103fb13a28bSRafael J. Wysocki  */
104f577eb30SRafael J. Wysocki #define data_of(handle)	((handle).buffer + (handle).buf_offset)
105f577eb30SRafael J. Wysocki 
106b788db79SRafael J. Wysocki extern unsigned int snapshot_additional_pages(struct zone *zone);
107f577eb30SRafael J. Wysocki extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
108f577eb30SRafael J. Wysocki extern int snapshot_write_next(struct snapshot_handle *handle, size_t count);
1098357376dSRafael J. Wysocki extern void snapshot_write_finalize(struct snapshot_handle *handle);
110b788db79SRafael J. Wysocki extern int snapshot_image_loaded(struct snapshot_handle *handle);
11161159a31SRafael J. Wysocki 
11237b2ba12SRafael J. Wysocki /*
11337b2ba12SRafael J. Wysocki  * This structure is used to pass the values needed for the identification
11437b2ba12SRafael J. Wysocki  * of the resume swap area from a user space to the kernel via the
11537b2ba12SRafael J. Wysocki  * SNAPSHOT_SET_SWAP_AREA ioctl
11637b2ba12SRafael J. Wysocki  */
11737b2ba12SRafael J. Wysocki struct resume_swap_area {
11837b2ba12SRafael J. Wysocki 	loff_t offset;
11937b2ba12SRafael J. Wysocki 	u_int32_t dev;
12037b2ba12SRafael J. Wysocki } __attribute__((packed));
12137b2ba12SRafael J. Wysocki 
1226e1819d6SRafael J. Wysocki #define SNAPSHOT_IOC_MAGIC	'3'
1236e1819d6SRafael J. Wysocki #define SNAPSHOT_FREEZE			_IO(SNAPSHOT_IOC_MAGIC, 1)
1246e1819d6SRafael J. Wysocki #define SNAPSHOT_UNFREEZE		_IO(SNAPSHOT_IOC_MAGIC, 2)
1256e1819d6SRafael J. Wysocki #define SNAPSHOT_ATOMIC_SNAPSHOT	_IOW(SNAPSHOT_IOC_MAGIC, 3, void *)
1266e1819d6SRafael J. Wysocki #define SNAPSHOT_ATOMIC_RESTORE		_IO(SNAPSHOT_IOC_MAGIC, 4)
1276e1819d6SRafael J. Wysocki #define SNAPSHOT_FREE			_IO(SNAPSHOT_IOC_MAGIC, 5)
1286e1819d6SRafael J. Wysocki #define SNAPSHOT_SET_IMAGE_SIZE		_IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long)
1296e1819d6SRafael J. Wysocki #define SNAPSHOT_AVAIL_SWAP		_IOR(SNAPSHOT_IOC_MAGIC, 7, void *)
1306e1819d6SRafael J. Wysocki #define SNAPSHOT_GET_SWAP_PAGE		_IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
1316e1819d6SRafael J. Wysocki #define SNAPSHOT_FREE_SWAP_PAGES	_IO(SNAPSHOT_IOC_MAGIC, 9)
1326e1819d6SRafael J. Wysocki #define SNAPSHOT_SET_SWAP_FILE		_IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
1339b238205SLuca Tettamanti #define SNAPSHOT_S2RAM			_IO(SNAPSHOT_IOC_MAGIC, 11)
1343592695cSStefan Seyfried #define SNAPSHOT_PMOPS			_IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
13537b2ba12SRafael J. Wysocki #define SNAPSHOT_SET_SWAP_AREA		_IOW(SNAPSHOT_IOC_MAGIC, 13, \
13637b2ba12SRafael J. Wysocki 							struct resume_swap_area)
13737b2ba12SRafael J. Wysocki #define SNAPSHOT_IOC_MAXNR	13
1383592695cSStefan Seyfried 
1393592695cSStefan Seyfried #define PMOPS_PREPARE	1
1403592695cSStefan Seyfried #define PMOPS_ENTER	2
1413592695cSStefan Seyfried #define PMOPS_FINISH	3
1426e1819d6SRafael J. Wysocki 
1430709db60SRafael J. Wysocki /* If unset, the snapshot device cannot be open. */
1440709db60SRafael J. Wysocki extern atomic_t snapshot_device_available;
1450709db60SRafael J. Wysocki 
146*d1d241ccSRafael J. Wysocki extern sector_t alloc_swapdev_block(int swap);
147*d1d241ccSRafael J. Wysocki extern void free_all_swap_pages(int swap);
148*d1d241ccSRafael J. Wysocki extern int swsusp_swap_in_use(void);
14961159a31SRafael J. Wysocki 
15074c7e2efSRandy Dunlap extern int swsusp_check(void);
15161159a31SRafael J. Wysocki extern int swsusp_shrink_memory(void);
15274c7e2efSRandy Dunlap extern void swsusp_free(void);
15361159a31SRafael J. Wysocki extern int swsusp_suspend(void);
15461159a31SRafael J. Wysocki extern int swsusp_resume(void);
15574c7e2efSRandy Dunlap extern int swsusp_read(void);
15674c7e2efSRandy Dunlap extern int swsusp_write(void);
15774c7e2efSRandy Dunlap extern void swsusp_close(void);
1589b238205SLuca Tettamanti extern int suspend_enter(suspend_state_t state);
1590d3a9abeSRafael J. Wysocki 
1600d3a9abeSRafael J. Wysocki struct timeval;
1610d3a9abeSRafael J. Wysocki extern void swsusp_show_speed(struct timeval *, struct timeval *,
1620d3a9abeSRafael J. Wysocki 				unsigned int, char *);
163