2 * Copyright (C) 2004-2007 Nigel Cunningham (nigel at suspend2 net)
5 #include <linux/suspend.h>
6 #include <linux/utsname.h>
8 #include "tuxonice_builtin.h"
11 struct new_utsname uts
;
13 unsigned long num_physpages
;
15 unsigned long image_pages
;
18 } __attribute__((aligned(PAGE_SIZE
)));
22 #ifdef CONFIG_SOFTWARE_SUSPEND
23 extern char resume_file
[256];
25 * Keep some memory free so that I/O operations can succeed without paging
26 * [Might this be more than 4 MB?]
28 #define PAGES_FOR_IO ((4096 * 1024) >> PAGE_SHIFT)
30 * Keep 1 MB of memory free so that device drivers can allocate some pages in
31 * their .suspend() routines without breaking the suspend to disk.
33 #define SPARE_PAGES ((1024 * 1024) >> PAGE_SHIFT)
35 extern struct hibernation_ops
*hibernation_ops
;
38 extern int pfn_is_nosave(unsigned long);
40 extern struct mutex pm_mutex
;
42 #define power_attr(_name) \
43 static struct subsys_attribute _name##_attr = { \
45 .name = __stringify(_name), \
48 .show = _name##_show, \
49 .store = _name##_store, \
52 extern struct kset power_subsys
;
54 extern struct pbe
*restore_pblist
;
56 /* Preferred image size in bytes (default 500 MB) */
57 extern unsigned long image_size
;
58 extern int in_suspend
;
59 extern dev_t swsusp_resume_device
;
60 extern sector_t swsusp_resume_block
;
62 extern asmlinkage
int swsusp_arch_suspend(void);
63 extern asmlinkage
int swsusp_arch_resume(void);
65 extern int create_basic_memory_bitmaps(void);
66 extern void free_basic_memory_bitmaps(void);
67 extern unsigned int count_data_pages(void);
70 * Auxiliary structure used for reading the snapshot image data and
71 * metadata from and writing them to the list of page backup entries
72 * (PBEs) which is the main data structure of swsusp.
74 * Using struct snapshot_handle we can transfer the image, including its
75 * metadata, as a continuous sequence of bytes with the help of
76 * snapshot_read_next() and snapshot_write_next().
78 * The code that writes the image to a storage or transfers it to
79 * the user land is required to use snapshot_read_next() for this
80 * purpose and it should not make any assumptions regarding the internal
81 * structure of the image. Similarly, the code that reads the image from
82 * a storage or transfers it from the user land is required to use
83 * snapshot_write_next().
85 * This may allow us to change the internal structure of the image
86 * in the future with considerably less effort.
89 struct snapshot_handle
{
90 loff_t offset
; /* number of the last byte ready for reading
91 * or writing in the sequence
93 unsigned int cur
; /* number of the block of PAGE_SIZE bytes the
94 * next operation will refer to (ie. current)
96 unsigned int cur_offset
; /* offset with respect to the current
97 * block (for the next operation)
99 unsigned int prev
; /* number of the block of PAGE_SIZE bytes that
100 * was the current one previously
102 void *buffer
; /* address of the block to read from
105 unsigned int buf_offset
; /* location to read from or write to,
106 * given as a displacement from 'buffer'
108 int sync_read
; /* Set to one to notify the caller of
109 * snapshot_write_next() that it may
110 * need to call wait_on_bio_chain()
114 /* This macro returns the address from/to which the caller of
115 * snapshot_read_next()/snapshot_write_next() is allowed to
116 * read/write data after the function returns
118 #define data_of(handle) ((handle).buffer + (handle).buf_offset)
120 extern unsigned int snapshot_additional_pages(struct zone
*zone
);
121 extern int snapshot_read_next(struct snapshot_handle
*handle
, size_t count
);
122 extern int snapshot_write_next(struct snapshot_handle
*handle
, size_t count
);
123 extern void snapshot_write_finalize(struct snapshot_handle
*handle
);
124 extern int snapshot_image_loaded(struct snapshot_handle
*handle
);
127 * This structure is used to pass the values needed for the identification
128 * of the resume swap area from a user space to the kernel via the
129 * SNAPSHOT_SET_SWAP_AREA ioctl
131 struct resume_swap_area
{
134 } __attribute__((packed
));
136 #define SNAPSHOT_IOC_MAGIC '3'
137 #define SNAPSHOT_FREEZE _IO(SNAPSHOT_IOC_MAGIC, 1)
138 #define SNAPSHOT_UNFREEZE _IO(SNAPSHOT_IOC_MAGIC, 2)
139 #define SNAPSHOT_ATOMIC_SNAPSHOT _IOW(SNAPSHOT_IOC_MAGIC, 3, void *)
140 #define SNAPSHOT_ATOMIC_RESTORE _IO(SNAPSHOT_IOC_MAGIC, 4)
141 #define SNAPSHOT_FREE _IO(SNAPSHOT_IOC_MAGIC, 5)
142 #define SNAPSHOT_SET_IMAGE_SIZE _IOW(SNAPSHOT_IOC_MAGIC, 6, unsigned long)
143 #define SNAPSHOT_AVAIL_SWAP _IOR(SNAPSHOT_IOC_MAGIC, 7, void *)
144 #define SNAPSHOT_GET_SWAP_PAGE _IOR(SNAPSHOT_IOC_MAGIC, 8, void *)
145 #define SNAPSHOT_FREE_SWAP_PAGES _IO(SNAPSHOT_IOC_MAGIC, 9)
146 #define SNAPSHOT_SET_SWAP_FILE _IOW(SNAPSHOT_IOC_MAGIC, 10, unsigned int)
147 #define SNAPSHOT_S2RAM _IO(SNAPSHOT_IOC_MAGIC, 11)
148 #define SNAPSHOT_PMOPS _IOW(SNAPSHOT_IOC_MAGIC, 12, unsigned int)
149 #define SNAPSHOT_SET_SWAP_AREA _IOW(SNAPSHOT_IOC_MAGIC, 13, \
150 struct resume_swap_area)
151 #define SNAPSHOT_IOC_MAXNR 13
153 #define PMOPS_PREPARE 1
154 #define PMOPS_ENTER 2
155 #define PMOPS_FINISH 3
157 /* If unset, the snapshot device cannot be open. */
158 extern atomic_t snapshot_device_available
;
160 extern sector_t
alloc_swapdev_block(int swap
);
161 extern void free_all_swap_pages(int swap
);
162 extern int swsusp_swap_in_use(void);
164 extern int swsusp_check(void);
165 extern int swsusp_shrink_memory(void);
166 extern void swsusp_free(void);
167 extern int swsusp_suspend(void);
168 extern int swsusp_resume(void);
169 extern int swsusp_read(void);
170 extern int swsusp_write(void);
171 extern void swsusp_close(void);
172 extern int suspend_enter(suspend_state_t state
);
175 extern void swsusp_show_speed(struct timeval
*, struct timeval
*,
176 unsigned int, char *);
177 extern struct page
*saveable_page(unsigned long pfn
);
178 #ifdef CONFIG_HIGHMEM
179 extern struct page
*saveable_highmem_page(unsigned long pfn
);
181 static inline void *saveable_highmem_page(unsigned long pfn
) { return NULL
; }
184 #define PBES_PER_PAGE (PAGE_SIZE / sizeof(struct pbe))