diff options
| author | Rafael J. Wysocki <rjw@sisk.pl> | 2007-07-19 04:47:36 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-07-19 13:04:42 -0400 |
| commit | b10d911749d37dccfa5873d2088aea3f074b9e45 (patch) | |
| tree | 56bd0ccb2861d7ae562d4e48a737727628358b42 /kernel/power | |
| parent | c2cf7d87d804c66e063829d5ca739053e901dc15 (diff) | |
PM: introduce hibernation and suspend notifiers
Make it possible to register hibernation and suspend notifiers, so that
subsystems can perform hibernation-related or suspend-related operations that
should not be carried out by device drivers' .suspend() and .resume()
routines.
[akpm@linux-foundation.org: build fixes]
[akpm@linux-foundation.org: cleanups]
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')
| -rw-r--r-- | kernel/power/disk.c | 16 | ||||
| -rw-r--r-- | kernel/power/main.c | 9 | ||||
| -rw-r--r-- | kernel/power/power.h | 10 | ||||
| -rw-r--r-- | kernel/power/user.c | 11 |
4 files changed, 39 insertions, 7 deletions
diff --git a/kernel/power/disk.c b/kernel/power/disk.c index 885c653509c9..324ac0188ce1 100644 --- a/kernel/power/disk.c +++ b/kernel/power/disk.c | |||
| @@ -281,9 +281,16 @@ int hibernate(void) | |||
| 281 | { | 281 | { |
| 282 | int error; | 282 | int error; |
| 283 | 283 | ||
| 284 | mutex_lock(&pm_mutex); | ||
| 284 | /* The snapshot device should not be opened while we're running */ | 285 | /* The snapshot device should not be opened while we're running */ |
| 285 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) | 286 | if (!atomic_add_unless(&snapshot_device_available, -1, 0)) { |
| 286 | return -EBUSY; | 287 | error = -EBUSY; |
| 288 | goto Unlock; | ||
| 289 | } | ||
| 290 | |||
| 291 | error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); | ||
| 292 | if (error) | ||
| 293 | goto Exit; | ||
| 287 | 294 | ||
| 288 | /* Allocate memory management structures */ | 295 | /* Allocate memory management structures */ |
| 289 | error = create_basic_memory_bitmaps(); | 296 | error = create_basic_memory_bitmaps(); |
| @@ -294,7 +301,6 @@ int hibernate(void) | |||
| 294 | if (error) | 301 | if (error) |
| 295 | goto Finish; | 302 | goto Finish; |
| 296 | 303 | ||
| 297 | mutex_lock(&pm_mutex); | ||
| 298 | if (hibernation_mode == HIBERNATION_TESTPROC) { | 304 | if (hibernation_mode == HIBERNATION_TESTPROC) { |
| 299 | printk("swsusp debug: Waiting for 5 seconds.\n"); | 305 | printk("swsusp debug: Waiting for 5 seconds.\n"); |
| 300 | mdelay(5000); | 306 | mdelay(5000); |
| @@ -316,12 +322,14 @@ int hibernate(void) | |||
| 316 | swsusp_free(); | 322 | swsusp_free(); |
| 317 | } | 323 | } |
| 318 | Thaw: | 324 | Thaw: |
| 319 | mutex_unlock(&pm_mutex); | ||
| 320 | unprepare_processes(); | 325 | unprepare_processes(); |
| 321 | Finish: | 326 | Finish: |
| 322 | free_basic_memory_bitmaps(); | 327 | free_basic_memory_bitmaps(); |
| 323 | Exit: | 328 | Exit: |
| 329 | pm_notifier_call_chain(PM_POST_HIBERNATION); | ||
| 324 | atomic_inc(&snapshot_device_available); | 330 | atomic_inc(&snapshot_device_available); |
| 331 | Unlock: | ||
| 332 | mutex_unlock(&pm_mutex); | ||
| 325 | return error; | 333 | return error; |
| 326 | } | 334 | } |
| 327 | 335 | ||
diff --git a/kernel/power/main.c b/kernel/power/main.c index fc45ed22620f..4d26ad394fb3 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c | |||
| @@ -23,6 +23,8 @@ | |||
| 23 | 23 | ||
| 24 | #include "power.h" | 24 | #include "power.h" |
| 25 | 25 | ||
| 26 | BLOCKING_NOTIFIER_HEAD(pm_chain_head); | ||
| 27 | |||
| 26 | /*This is just an arbitrary number */ | 28 | /*This is just an arbitrary number */ |
| 27 | #define FREE_PAGE_NUMBER (100) | 29 | #define FREE_PAGE_NUMBER (100) |
| 28 | 30 | ||
| @@ -78,6 +80,10 @@ static int suspend_prepare(suspend_state_t state) | |||
| 78 | if (!pm_ops || !pm_ops->enter) | 80 | if (!pm_ops || !pm_ops->enter) |
| 79 | return -EPERM; | 81 | return -EPERM; |
| 80 | 82 | ||
| 83 | error = pm_notifier_call_chain(PM_SUSPEND_PREPARE); | ||
| 84 | if (error) | ||
| 85 | goto Finish; | ||
| 86 | |||
| 81 | pm_prepare_console(); | 87 | pm_prepare_console(); |
| 82 | 88 | ||
| 83 | if (freeze_processes()) { | 89 | if (freeze_processes()) { |
| @@ -125,6 +131,8 @@ static int suspend_prepare(suspend_state_t state) | |||
| 125 | Thaw: | 131 | Thaw: |
| 126 | thaw_processes(); | 132 | thaw_processes(); |
| 127 | pm_restore_console(); | 133 | pm_restore_console(); |
| 134 | Finish: | ||
| 135 | pm_notifier_call_chain(PM_POST_SUSPEND); | ||
| 128 | return error; | 136 | return error; |
| 129 | } | 137 | } |
| 130 | 138 | ||
| @@ -176,6 +184,7 @@ static void suspend_finish(suspend_state_t state) | |||
| 176 | resume_console(); | 184 | resume_console(); |
| 177 | thaw_processes(); | 185 | thaw_processes(); |
| 178 | pm_restore_console(); | 186 | pm_restore_console(); |
| 187 | pm_notifier_call_chain(PM_POST_SUSPEND); | ||
| 179 | } | 188 | } |
| 180 | 189 | ||
| 181 | 190 | ||
diff --git a/kernel/power/power.h b/kernel/power/power.h index eab3603b7caf..01c2275b15b2 100644 --- a/kernel/power/power.h +++ b/kernel/power/power.h | |||
| @@ -173,5 +173,15 @@ extern void swsusp_close(void); | |||
| 173 | extern int suspend_enter(suspend_state_t state); | 173 | extern int suspend_enter(suspend_state_t state); |
| 174 | 174 | ||
| 175 | struct timeval; | 175 | struct timeval; |
| 176 | /* kernel/power/swsusp.c */ | ||
| 176 | extern void swsusp_show_speed(struct timeval *, struct timeval *, | 177 | extern void swsusp_show_speed(struct timeval *, struct timeval *, |
| 177 | unsigned int, char *); | 178 | unsigned int, char *); |
| 179 | |||
| 180 | /* kernel/power/main.c */ | ||
| 181 | extern struct blocking_notifier_head pm_chain_head; | ||
| 182 | |||
| 183 | static inline int pm_notifier_call_chain(unsigned long val) | ||
| 184 | { | ||
| 185 | return (blocking_notifier_call_chain(&pm_chain_head, val, NULL) | ||
| 186 | == NOTIFY_BAD) ? -EINVAL : 0; | ||
| 187 | } | ||
diff --git a/kernel/power/user.c b/kernel/power/user.c index 1f24f30b951b..7f19afe01b48 100644 --- a/kernel/power/user.c +++ b/kernel/power/user.c | |||
| @@ -151,10 +151,14 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, | |||
| 151 | if (data->frozen) | 151 | if (data->frozen) |
| 152 | break; | 152 | break; |
| 153 | mutex_lock(&pm_mutex); | 153 | mutex_lock(&pm_mutex); |
| 154 | if (freeze_processes()) { | 154 | error = pm_notifier_call_chain(PM_HIBERNATION_PREPARE); |
| 155 | thaw_processes(); | 155 | if (!error) { |
| 156 | error = -EBUSY; | 156 | error = freeze_processes(); |
| 157 | if (error) | ||
| 158 | thaw_processes(); | ||
| 157 | } | 159 | } |
| 160 | if (error) | ||
| 161 | pm_notifier_call_chain(PM_POST_HIBERNATION); | ||
| 158 | mutex_unlock(&pm_mutex); | 162 | mutex_unlock(&pm_mutex); |
| 159 | if (!error) | 163 | if (!error) |
| 160 | data->frozen = 1; | 164 | data->frozen = 1; |
| @@ -165,6 +169,7 @@ static int snapshot_ioctl(struct inode *inode, struct file *filp, | |||
| 165 | break; | 169 | break; |
| 166 | mutex_lock(&pm_mutex); | 170 | mutex_lock(&pm_mutex); |
| 167 | thaw_processes(); | 171 | thaw_processes(); |
| 172 | pm_notifier_call_chain(PM_POST_HIBERNATION); | ||
| 168 | mutex_unlock(&pm_mutex); | 173 | mutex_unlock(&pm_mutex); |
| 169 | data->frozen = 0; | 174 | data->frozen = 0; |
| 170 | break; | 175 | break; |
