diff options
author | Rafael J. Wysocki <rjw@sisk.pl> | 2007-07-19 04:47:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-19 13:04:42 -0400 |
commit | 7777fab989b5d006903188c966058ebcd2d6342a (patch) | |
tree | cff336bf6bd4dd2f665709dbf07f4224ab9f2fbd /kernel/power/user.c | |
parent | 127067a9c994dff16b280f409cc7b18a54a63719 (diff) |
swsusp: remove code duplication between disk.c and user.c
Currently, much of the code in kernel/power/disk.c is duplicated in
kernel/power/user.c , mainly for historical reasons. By eliminating this code
duplication we can reduce the size of user.c quite substantially and remove
the maintenance difficulty resulting from it.
[bunk@stusta.de: kernel/power/disk.c: make code static]
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Acked-by: Pavel Machek <pavel@ucw.cz>
Cc: Nigel Cunningham <nigel@nigel.suspend2.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel/power/user.c')
-rw-r--r-- | kernel/power/user.c | 96 |
1 files changed, 7 insertions, 89 deletions
diff --git a/kernel/power/user.c b/kernel/power/user.c index 09468ec61124..bfed3b924093 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c | |||
@@ -128,83 +128,6 @@ static ssize_t snapshot_write(struct file *filp, const char __user *buf, | |||
128 | return res; | 128 | return res; |
129 | } | 129 | } |
130 | 130 | ||
131 | static inline int platform_prepare(void) | ||
132 | { | ||
133 | int error = 0; | ||
134 | |||
135 | if (hibernation_ops) | ||
136 | error = hibernation_ops->prepare(); | ||
137 | |||
138 | return error; | ||
139 | } | ||
140 | |||
141 | static inline void platform_finish(void) | ||
142 | { | ||
143 | if (hibernation_ops) | ||
144 | hibernation_ops->finish(); | ||
145 | } | ||
146 | |||
147 | static inline int snapshot_suspend(int platform_suspend) | ||
148 | { | ||
149 | int error; | ||
150 | |||
151 | mutex_lock(&pm_mutex); | ||
152 | /* Free memory before shutting down devices. */ | ||
153 | error = swsusp_shrink_memory(); | ||
154 | if (error) | ||
155 | goto Finish; | ||
156 | |||
157 | if (platform_suspend) { | ||
158 | error = platform_prepare(); | ||
159 | if (error) | ||
160 | goto Finish; | ||
161 | } | ||
162 | suspend_console(); | ||
163 | error = device_suspend(PMSG_FREEZE); | ||
164 | if (error) | ||
165 | goto Resume_devices; | ||
166 | |||
167 | error = disable_nonboot_cpus(); | ||
168 | if (!error) { | ||
169 | in_suspend = 1; | ||
170 | error = swsusp_suspend(); | ||
171 | } | ||
172 | enable_nonboot_cpus(); | ||
173 | Resume_devices: | ||
174 | if (platform_suspend) | ||
175 | platform_finish(); | ||
176 | |||
177 | device_resume(); | ||
178 | resume_console(); | ||
179 | Finish: | ||
180 | mutex_unlock(&pm_mutex); | ||
181 | return error; | ||
182 | } | ||
183 | |||
184 | static inline int snapshot_restore(void) | ||
185 | { | ||
186 | int error; | ||
187 | |||
188 | mutex_lock(&pm_mutex); | ||
189 | pm_prepare_console(); | ||
190 | suspend_console(); | ||
191 | error = device_suspend(PMSG_PRETHAW); | ||
192 | if (error) | ||
193 | goto Finish; | ||
194 | |||
195 | error = disable_nonboot_cpus(); | ||
196 | if (!error) | ||
197 | error = swsusp_resume(); | ||
198 | |||
199 | enable_nonboot_cpus(); | ||
200 | Finish: | ||
201 | device_resume(); | ||
202 | resume_console(); | ||
203 | pm_restore_console(); | ||
204 | mutex_unlock(&pm_mutex); | ||
205 | return error; | ||
206 | } | ||
207 | |||
208 | static int snapshot_ioctl(struct inode *inode, struct file *filp, | 131 | static int snapshot_ioctl(struct inode *inode, struct file *filp, |
209 | unsigned int cmd, unsigned long arg) | 132 | unsigned int cmd, unsigned long arg) |
210 | { | 133 | { |
@@ -251,7 +174,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, | |||
251 | error = -EPERM; | 174 | error = -EPERM; |
252 | break; | 175 | break; |
253 | } | 176 | } |
254 | error = snapshot_suspend(data->platform_suspend); | 177 | error = hibernation_snapshot(data->platform_suspend); |
255 | if (!error) | 178 | if (!error) |
256 | error = put_user(in_suspend, (unsigned int __user *)arg); | 179 | error = put_user(in_suspend, (unsigned int __user *)arg); |
257 | if (!error) | 180 | if (!error) |
@@ -265,7 +188,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, | |||
265 | error = -EPERM; | 188 | error = -EPERM; |
266 | break; | 189 | break; |
267 | } | 190 | } |
268 | error = snapshot_restore(); | 191 | error = hibernation_restore(); |
269 | break; | 192 | break; |
270 | 193 | ||
271 | case SNAPSHOT_FREE: | 194 | case SNAPSHOT_FREE: |
@@ -377,19 +300,14 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, | |||
377 | switch (arg) { | 300 | switch (arg) { |
378 | 301 | ||
379 | case PMOPS_PREPARE: | 302 | case PMOPS_PREPARE: |
380 | if (hibernation_ops) { | 303 | data->platform_suspend = 1; |
381 | data->platform_suspend = 1; | 304 | error = 0; |
382 | error = 0; | ||
383 | } else { | ||
384 | error = -ENOSYS; | ||
385 | } | ||
386 | break; | 305 | break; |
387 | 306 | ||
388 | case PMOPS_ENTER: | 307 | case PMOPS_ENTER: |
389 | if (data->platform_suspend) { | 308 | if (data->platform_suspend) |
390 | kernel_shutdown_prepare(SYSTEM_SUSPEND_DISK); | 309 | error = hibernation_platform_enter(); |
391 | error = hibernation_ops->enter(); | 310 | |
392 | } | ||
393 | break; | 311 | break; |
394 | 312 | ||
395 | case PMOPS_FINISH: | 313 | case PMOPS_FINISH: |