diff options
Diffstat (limited to 'drivers/xen/manage.c')
| -rw-r--r-- | drivers/xen/manage.c | 153 |
1 files changed, 86 insertions, 67 deletions
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index 24177272bcb..ebb292859b5 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
| @@ -34,42 +34,38 @@ enum shutdown_state { | |||
| 34 | /* Ignore multiple shutdown requests. */ | 34 | /* Ignore multiple shutdown requests. */ |
| 35 | static enum shutdown_state shutting_down = SHUTDOWN_INVALID; | 35 | static enum shutdown_state shutting_down = SHUTDOWN_INVALID; |
| 36 | 36 | ||
| 37 | #ifdef CONFIG_PM_SLEEP | 37 | struct suspend_info { |
| 38 | static int xen_hvm_suspend(void *data) | 38 | int cancelled; |
| 39 | { | 39 | unsigned long arg; /* extra hypercall argument */ |
| 40 | int err; | 40 | void (*pre)(void); |
| 41 | struct sched_shutdown r = { .reason = SHUTDOWN_suspend }; | 41 | void (*post)(int cancelled); |
| 42 | int *cancelled = data; | 42 | }; |
| 43 | |||
| 44 | BUG_ON(!irqs_disabled()); | ||
| 45 | |||
| 46 | err = sysdev_suspend(PMSG_SUSPEND); | ||
| 47 | if (err) { | ||
| 48 | printk(KERN_ERR "xen_hvm_suspend: sysdev_suspend failed: %d\n", | ||
| 49 | err); | ||
| 50 | return err; | ||
| 51 | } | ||
| 52 | |||
| 53 | *cancelled = HYPERVISOR_sched_op(SCHEDOP_shutdown, &r); | ||
| 54 | 43 | ||
| 55 | xen_hvm_post_suspend(*cancelled); | 44 | static void xen_hvm_post_suspend(int cancelled) |
| 45 | { | ||
| 46 | xen_arch_hvm_post_suspend(cancelled); | ||
| 56 | gnttab_resume(); | 47 | gnttab_resume(); |
| 48 | } | ||
| 57 | 49 | ||
| 58 | if (!*cancelled) { | 50 | static void xen_pre_suspend(void) |
| 59 | xen_irq_resume(); | 51 | { |
| 60 | xen_console_resume(); | 52 | xen_mm_pin_all(); |
| 61 | xen_timer_resume(); | 53 | gnttab_suspend(); |
| 62 | } | 54 | xen_arch_pre_suspend(); |
| 63 | 55 | } | |
| 64 | sysdev_resume(); | ||
| 65 | 56 | ||
| 66 | return 0; | 57 | static void xen_post_suspend(int cancelled) |
| 58 | { | ||
| 59 | xen_arch_post_suspend(cancelled); | ||
| 60 | gnttab_resume(); | ||
| 61 | xen_mm_unpin_all(); | ||
| 67 | } | 62 | } |
| 68 | 63 | ||
| 64 | #ifdef CONFIG_PM_SLEEP | ||
| 69 | static int xen_suspend(void *data) | 65 | static int xen_suspend(void *data) |
| 70 | { | 66 | { |
| 67 | struct suspend_info *si = data; | ||
| 71 | int err; | 68 | int err; |
| 72 | int *cancelled = data; | ||
| 73 | 69 | ||
| 74 | BUG_ON(!irqs_disabled()); | 70 | BUG_ON(!irqs_disabled()); |
| 75 | 71 | ||
| @@ -80,22 +76,20 @@ static int xen_suspend(void *data) | |||
| 80 | return err; | 76 | return err; |
| 81 | } | 77 | } |
| 82 | 78 | ||
| 83 | xen_mm_pin_all(); | 79 | if (si->pre) |
| 84 | gnttab_suspend(); | 80 | si->pre(); |
| 85 | xen_pre_suspend(); | ||
| 86 | 81 | ||
| 87 | /* | 82 | /* |
| 88 | * This hypercall returns 1 if suspend was cancelled | 83 | * This hypercall returns 1 if suspend was cancelled |
| 89 | * or the domain was merely checkpointed, and 0 if it | 84 | * or the domain was merely checkpointed, and 0 if it |
| 90 | * is resuming in a new domain. | 85 | * is resuming in a new domain. |
| 91 | */ | 86 | */ |
| 92 | *cancelled = HYPERVISOR_suspend(virt_to_mfn(xen_start_info)); | 87 | si->cancelled = HYPERVISOR_suspend(si->arg); |
| 93 | 88 | ||
| 94 | xen_post_suspend(*cancelled); | 89 | if (si->post) |
| 95 | gnttab_resume(); | 90 | si->post(si->cancelled); |
| 96 | xen_mm_unpin_all(); | ||
| 97 | 91 | ||
| 98 | if (!*cancelled) { | 92 | if (!si->cancelled) { |
| 99 | xen_irq_resume(); | 93 | xen_irq_resume(); |
| 100 | xen_console_resume(); | 94 | xen_console_resume(); |
| 101 | xen_timer_resume(); | 95 | xen_timer_resume(); |
| @@ -109,7 +103,7 @@ static int xen_suspend(void *data) | |||
| 109 | static void do_suspend(void) | 103 | static void do_suspend(void) |
| 110 | { | 104 | { |
| 111 | int err; | 105 | int err; |
| 112 | int cancelled = 1; | 106 | struct suspend_info si; |
| 113 | 107 | ||
| 114 | shutting_down = SHUTDOWN_SUSPEND; | 108 | shutting_down = SHUTDOWN_SUSPEND; |
| 115 | 109 | ||
| @@ -139,20 +133,29 @@ static void do_suspend(void) | |||
| 139 | goto out_resume; | 133 | goto out_resume; |
| 140 | } | 134 | } |
| 141 | 135 | ||
| 142 | if (xen_hvm_domain()) | 136 | si.cancelled = 1; |
| 143 | err = stop_machine(xen_hvm_suspend, &cancelled, cpumask_of(0)); | 137 | |
| 144 | else | 138 | if (xen_hvm_domain()) { |
| 145 | err = stop_machine(xen_suspend, &cancelled, cpumask_of(0)); | 139 | si.arg = 0UL; |
| 140 | si.pre = NULL; | ||
| 141 | si.post = &xen_hvm_post_suspend; | ||
| 142 | } else { | ||
| 143 | si.arg = virt_to_mfn(xen_start_info); | ||
| 144 | si.pre = &xen_pre_suspend; | ||
| 145 | si.post = &xen_post_suspend; | ||
| 146 | } | ||
| 147 | |||
| 148 | err = stop_machine(xen_suspend, &si, cpumask_of(0)); | ||
| 146 | 149 | ||
| 147 | dpm_resume_noirq(PMSG_RESUME); | 150 | dpm_resume_noirq(PMSG_RESUME); |
| 148 | 151 | ||
| 149 | if (err) { | 152 | if (err) { |
| 150 | printk(KERN_ERR "failed to start xen_suspend: %d\n", err); | 153 | printk(KERN_ERR "failed to start xen_suspend: %d\n", err); |
| 151 | cancelled = 1; | 154 | si.cancelled = 1; |
| 152 | } | 155 | } |
| 153 | 156 | ||
| 154 | out_resume: | 157 | out_resume: |
| 155 | if (!cancelled) { | 158 | if (!si.cancelled) { |
| 156 | xen_arch_resume(); | 159 | xen_arch_resume(); |
| 157 | xs_resume(); | 160 | xs_resume(); |
| 158 | } else | 161 | } else |
| @@ -172,12 +175,39 @@ out: | |||
| 172 | } | 175 | } |
| 173 | #endif /* CONFIG_PM_SLEEP */ | 176 | #endif /* CONFIG_PM_SLEEP */ |
| 174 | 177 | ||
| 178 | struct shutdown_handler { | ||
| 179 | const char *command; | ||
| 180 | void (*cb)(void); | ||
| 181 | }; | ||
| 182 | |||
| 183 | static void do_poweroff(void) | ||
| 184 | { | ||
| 185 | shutting_down = SHUTDOWN_POWEROFF; | ||
| 186 | orderly_poweroff(false); | ||
| 187 | } | ||
| 188 | |||
| 189 | static void do_reboot(void) | ||
| 190 | { | ||
| 191 | shutting_down = SHUTDOWN_POWEROFF; /* ? */ | ||
| 192 | ctrl_alt_del(); | ||
| 193 | } | ||
| 194 | |||
| 175 | static void shutdown_handler(struct xenbus_watch *watch, | 195 | static void shutdown_handler(struct xenbus_watch *watch, |
| 176 | const char **vec, unsigned int len) | 196 | const char **vec, unsigned int len) |
| 177 | { | 197 | { |
| 178 | char *str; | 198 | char *str; |
| 179 | struct xenbus_transaction xbt; | 199 | struct xenbus_transaction xbt; |
| 180 | int err; | 200 | int err; |
| 201 | static struct shutdown_handler handlers[] = { | ||
| 202 | { "poweroff", do_poweroff }, | ||
| 203 | { "halt", do_poweroff }, | ||
| 204 | { "reboot", do_reboot }, | ||
| 205 | #ifdef CONFIG_PM_SLEEP | ||
| 206 | { "suspend", do_suspend }, | ||
| 207 | #endif | ||
| 208 | {NULL, NULL}, | ||
| 209 | }; | ||
| 210 | static struct shutdown_handler *handler; | ||
| 181 | 211 | ||
| 182 | if (shutting_down != SHUTDOWN_INVALID) | 212 | if (shutting_down != SHUTDOWN_INVALID) |
| 183 | return; | 213 | return; |
| @@ -194,7 +224,14 @@ static void shutdown_handler(struct xenbus_watch *watch, | |||
| 194 | return; | 224 | return; |
| 195 | } | 225 | } |
| 196 | 226 | ||
| 197 | xenbus_write(xbt, "control", "shutdown", ""); | 227 | for (handler = &handlers[0]; handler->command; handler++) { |
| 228 | if (strcmp(str, handler->command) == 0) | ||
| 229 | break; | ||
| 230 | } | ||
| 231 | |||
| 232 | /* Only acknowledge commands which we are prepared to handle. */ | ||
| 233 | if (handler->cb) | ||
| 234 | xenbus_write(xbt, "control", "shutdown", ""); | ||
| 198 | 235 | ||
| 199 | err = xenbus_transaction_end(xbt, 0); | 236 | err = xenbus_transaction_end(xbt, 0); |
| 200 | if (err == -EAGAIN) { | 237 | if (err == -EAGAIN) { |
| @@ -202,17 +239,8 @@ static void shutdown_handler(struct xenbus_watch *watch, | |||
| 202 | goto again; | 239 | goto again; |
| 203 | } | 240 | } |
| 204 | 241 | ||
| 205 | if (strcmp(str, "poweroff") == 0 || | 242 | if (handler->cb) { |
| 206 | strcmp(str, "halt") == 0) { | 243 | handler->cb(); |
| 207 | shutting_down = SHUTDOWN_POWEROFF; | ||
| 208 | orderly_poweroff(false); | ||
| 209 | } else if (strcmp(str, "reboot") == 0) { | ||
| 210 | shutting_down = SHUTDOWN_POWEROFF; /* ? */ | ||
| 211 | ctrl_alt_del(); | ||
| 212 | #ifdef CONFIG_PM_SLEEP | ||
| 213 | } else if (strcmp(str, "suspend") == 0) { | ||
| 214 | do_suspend(); | ||
| 215 | #endif | ||
| 216 | } else { | 244 | } else { |
| 217 | printk(KERN_INFO "Ignoring shutdown request: %s\n", str); | 245 | printk(KERN_INFO "Ignoring shutdown request: %s\n", str); |
| 218 | shutting_down = SHUTDOWN_INVALID; | 246 | shutting_down = SHUTDOWN_INVALID; |
| @@ -291,27 +319,18 @@ static int shutdown_event(struct notifier_block *notifier, | |||
| 291 | return NOTIFY_DONE; | 319 | return NOTIFY_DONE; |
| 292 | } | 320 | } |
| 293 | 321 | ||
| 294 | static int __init __setup_shutdown_event(void) | ||
| 295 | { | ||
| 296 | /* Delay initialization in the PV on HVM case */ | ||
| 297 | if (xen_hvm_domain()) | ||
| 298 | return 0; | ||
| 299 | |||
| 300 | if (!xen_pv_domain()) | ||
| 301 | return -ENODEV; | ||
| 302 | |||
| 303 | return xen_setup_shutdown_event(); | ||
| 304 | } | ||
| 305 | |||
| 306 | int xen_setup_shutdown_event(void) | 322 | int xen_setup_shutdown_event(void) |
| 307 | { | 323 | { |
| 308 | static struct notifier_block xenstore_notifier = { | 324 | static struct notifier_block xenstore_notifier = { |
| 309 | .notifier_call = shutdown_event | 325 | .notifier_call = shutdown_event |
| 310 | }; | 326 | }; |
| 327 | |||
| 328 | if (!xen_domain()) | ||
| 329 | return -ENODEV; | ||
| 311 | register_xenstore_notifier(&xenstore_notifier); | 330 | register_xenstore_notifier(&xenstore_notifier); |
| 312 | 331 | ||
| 313 | return 0; | 332 | return 0; |
| 314 | } | 333 | } |
| 315 | EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); | 334 | EXPORT_SYMBOL_GPL(xen_setup_shutdown_event); |
| 316 | 335 | ||
| 317 | subsys_initcall(__setup_shutdown_event); | 336 | subsys_initcall(xen_setup_shutdown_event); |
