control.c (255040) | control.c (255726) |
---|---|
1/*- 2 * Copyright (c) 2010 Justin T. Gibbs, Spectra Logic Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 75 unchanged lines hidden (view full) --- 84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 89 * SUCH DAMAGE. 90 */ 91#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2010 Justin T. Gibbs, Spectra Logic Corporation 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 75 unchanged lines hidden (view full) --- 84 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 85 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 86 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 87 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 88 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 89 * SUCH DAMAGE. 90 */ 91#include <sys/cdefs.h> |
92__FBSDID("$FreeBSD: head/sys/dev/xen/control/control.c 255040 2013-08-29 19:52:18Z gibbs $"); | 92__FBSDID("$FreeBSD: head/sys/dev/xen/control/control.c 255726 2013-09-20 05:06:03Z gibbs $"); |
93 94/** 95 * \file control.c 96 * 97 * \brief Device driver to repond to control domain events that impact 98 * this VM. 99 */ 100 --- 13 unchanged lines hidden (view full) --- 114#include <sys/namei.h> 115#include <sys/proc.h> 116#include <sys/reboot.h> 117#include <sys/rman.h> 118#include <sys/sched.h> 119#include <sys/taskqueue.h> 120#include <sys/types.h> 121#include <sys/vnode.h> | 93 94/** 95 * \file control.c 96 * 97 * \brief Device driver to repond to control domain events that impact 98 * this VM. 99 */ 100 --- 13 unchanged lines hidden (view full) --- 114#include <sys/namei.h> 115#include <sys/proc.h> 116#include <sys/reboot.h> 117#include <sys/rman.h> 118#include <sys/sched.h> 119#include <sys/taskqueue.h> 120#include <sys/types.h> 121#include <sys/vnode.h> |
122 123#ifndef XENHVM | |
124#include <sys/sched.h> 125#include <sys/smp.h> | 122#include <sys/sched.h> 123#include <sys/smp.h> |
126#endif | 124#include <sys/eventhandler.h> |
127 128#include <geom/geom.h> 129 130#include <machine/_inttypes.h> 131#include <machine/intr_machdep.h> 132 133#include <vm/vm.h> 134#include <vm/vm_extern.h> 135#include <vm/vm_kern.h> 136 137#include <xen/xen-os.h> 138#include <xen/blkif.h> 139#include <xen/evtchn.h> 140#include <xen/gnttab.h> 141#include <xen/xen_intr.h> 142 | 125 126#include <geom/geom.h> 127 128#include <machine/_inttypes.h> 129#include <machine/intr_machdep.h> 130 131#include <vm/vm.h> 132#include <vm/vm_extern.h> 133#include <vm/vm_kern.h> 134 135#include <xen/xen-os.h> 136#include <xen/blkif.h> 137#include <xen/evtchn.h> 138#include <xen/gnttab.h> 139#include <xen/xen_intr.h> 140 |
141#ifdef XENHVM 142#include <xen/hvm.h> 143#endif 144 |
|
143#include <xen/interface/event_channel.h> 144#include <xen/interface/grant_table.h> 145 146#include <xen/xenbus/xenbusvar.h> 147 148#include <machine/xen/xenvar.h> 149#include <machine/xen/xenfunc.h> 150 --- 43 unchanged lines hidden (view full) --- 194#ifndef XENHVM 195extern void xencons_suspend(void); 196extern void xencons_resume(void); 197 198/* Full PV mode suspension. */ 199static void 200xctrl_suspend() 201{ | 145#include <xen/interface/event_channel.h> 146#include <xen/interface/grant_table.h> 147 148#include <xen/xenbus/xenbusvar.h> 149 150#include <machine/xen/xenvar.h> 151#include <machine/xen/xenfunc.h> 152 --- 43 unchanged lines hidden (view full) --- 196#ifndef XENHVM 197extern void xencons_suspend(void); 198extern void xencons_resume(void); 199 200/* Full PV mode suspension. */ 201static void 202xctrl_suspend() 203{ |
202 int i, j, k, fpp; | 204 int i, j, k, fpp, suspend_cancelled; |
203 unsigned long max_pfn, start_info_mfn; 204 205 EVENTHANDLER_INVOKE(power_suspend); 206 207#ifdef SMP 208 struct thread *td; 209 cpuset_t map; 210 u_int cpuid; --- 48 unchanged lines hidden (view full) --- 259 xen_start_info->console.domU.mfn = MFNTOPFN(xen_start_info->console.domU.mfn); 260 261 /* 262 * We'll stop somewhere inside this hypercall. When it returns, 263 * we'll start resuming after the restore. 264 */ 265 start_info_mfn = VTOMFN(xen_start_info); 266 pmap_suspend(); | 205 unsigned long max_pfn, start_info_mfn; 206 207 EVENTHANDLER_INVOKE(power_suspend); 208 209#ifdef SMP 210 struct thread *td; 211 cpuset_t map; 212 u_int cpuid; --- 48 unchanged lines hidden (view full) --- 261 xen_start_info->console.domU.mfn = MFNTOPFN(xen_start_info->console.domU.mfn); 262 263 /* 264 * We'll stop somewhere inside this hypercall. When it returns, 265 * we'll start resuming after the restore. 266 */ 267 start_info_mfn = VTOMFN(xen_start_info); 268 pmap_suspend(); |
267 HYPERVISOR_suspend(start_info_mfn); | 269 suspend_cancelled = HYPERVISOR_suspend(start_info_mfn); |
268 pmap_resume(); 269 270 pmap_kenter_ma((vm_offset_t) shared_info, xen_start_info->shared_info); 271 HYPERVISOR_shared_info = shared_info; 272 273 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 274 VTOMFN(xen_pfn_to_mfn_frame_list_list); 275 --- 6 unchanged lines hidden (view full) --- 282 j = 0; 283 } 284 xen_pfn_to_mfn_frame_list[k][j] = 285 VTOMFN(&xen_phys_machine[i]); 286 } 287 HYPERVISOR_shared_info->arch.max_pfn = max_pfn; 288 289 gnttab_resume(); | 270 pmap_resume(); 271 272 pmap_kenter_ma((vm_offset_t) shared_info, xen_start_info->shared_info); 273 HYPERVISOR_shared_info = shared_info; 274 275 HYPERVISOR_shared_info->arch.pfn_to_mfn_frame_list_list = 276 VTOMFN(xen_pfn_to_mfn_frame_list_list); 277 --- 6 unchanged lines hidden (view full) --- 284 j = 0; 285 } 286 xen_pfn_to_mfn_frame_list[k][j] = 287 VTOMFN(&xen_phys_machine[i]); 288 } 289 HYPERVISOR_shared_info->arch.max_pfn = max_pfn; 290 291 gnttab_resume(); |
290 intr_resume(); | 292 intr_resume(suspend_cancelled != 0); |
291 local_irq_enable(); 292 xencons_resume(); 293 294#ifdef CONFIG_SMP 295 for_each_cpu(i) 296 vcpu_prepare(i); 297 298#endif --- 27 unchanged lines hidden (view full) --- 326 */ 327 if (howto & (RB_HALT | RB_POWEROFF)) 328 HYPERVISOR_shutdown(SHUTDOWN_poweroff); 329 else 330 HYPERVISOR_shutdown(SHUTDOWN_reboot); 331} 332 333#else | 293 local_irq_enable(); 294 xencons_resume(); 295 296#ifdef CONFIG_SMP 297 for_each_cpu(i) 298 vcpu_prepare(i); 299 300#endif --- 27 unchanged lines hidden (view full) --- 328 */ 329 if (howto & (RB_HALT | RB_POWEROFF)) 330 HYPERVISOR_shutdown(SHUTDOWN_poweroff); 331 else 332 HYPERVISOR_shutdown(SHUTDOWN_reboot); 333} 334 335#else |
334extern void xenpci_resume(void); | |
335 336/* HVM mode suspension. */ 337static void 338xctrl_suspend() 339{ | 336 337/* HVM mode suspension. */ 338static void 339xctrl_suspend() 340{ |
341#ifdef SMP 342 cpuset_t cpu_suspend_map; 343#endif |
|
340 int suspend_cancelled; 341 342 EVENTHANDLER_INVOKE(power_suspend); 343 | 344 int suspend_cancelled; 345 346 EVENTHANDLER_INVOKE(power_suspend); 347 |
348 if (smp_started) { 349 thread_lock(curthread); 350 sched_bind(curthread, 0); 351 thread_unlock(curthread); 352 } 353 KASSERT((PCPU_GET(cpuid) == 0), ("Not running on CPU#0")); 354 |
|
344 /* | 355 /* |
356 * Clear our XenStore node so the toolstack knows we are 357 * responding to the suspend request. 358 */ 359 xs_write(XST_NIL, "control", "shutdown", ""); 360 361 /* |
|
345 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 346 * drivers need this. 347 */ 348 mtx_lock(&Giant); 349 if (DEVICE_SUSPEND(root_bus) != 0) { 350 mtx_unlock(&Giant); 351 printf("%s: device_suspend failed\n", __func__); 352 return; 353 } 354 mtx_unlock(&Giant); 355 | 362 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 363 * drivers need this. 364 */ 365 mtx_lock(&Giant); 366 if (DEVICE_SUSPEND(root_bus) != 0) { 367 mtx_unlock(&Giant); 368 printf("%s: device_suspend failed\n", __func__); 369 return; 370 } 371 mtx_unlock(&Giant); 372 |
373#ifdef SMP 374 if (smp_started) { 375 /* 376 * Suspend other CPUs. This prevents IPIs while we 377 * are resuming, and will allow us to reset per-cpu 378 * vcpu_info on resume. 379 */ 380 cpu_suspend_map = all_cpus; 381 CPU_CLR(PCPU_GET(cpuid), &cpu_suspend_map); 382 if (!CPU_EMPTY(&cpu_suspend_map)) 383 suspend_cpus(cpu_suspend_map); 384 } 385#endif 386 |
|
356 /* 357 * Prevent any races with evtchn_interrupt() handler. 358 */ 359 disable_intr(); 360 intr_suspend(); | 387 /* 388 * Prevent any races with evtchn_interrupt() handler. 389 */ 390 disable_intr(); 391 intr_suspend(); |
392 xen_hvm_suspend(); |
|
361 362 suspend_cancelled = HYPERVISOR_suspend(0); 363 | 393 394 suspend_cancelled = HYPERVISOR_suspend(0); 395 |
364 intr_resume(); | 396 xen_hvm_resume(suspend_cancelled != 0); 397 intr_resume(suspend_cancelled != 0); 398 enable_intr(); |
365 366 /* | 399 400 /* |
367 * Re-enable interrupts and put the scheduler back to normal. | 401 * Reset grant table info. |
368 */ | 402 */ |
369 enable_intr(); | 403 gnttab_resume(); |
370 | 404 |
405#ifdef SMP 406 if (smp_started && !CPU_EMPTY(&cpu_suspend_map)) { 407 /* 408 * Now that event channels have been initialized, 409 * resume CPUs. 410 */ 411 resume_cpus(cpu_suspend_map); 412 } 413#endif 414 |
|
371 /* 372 * FreeBSD really needs to add DEVICE_SUSPEND_CANCEL or 373 * similar. 374 */ 375 mtx_lock(&Giant); | 415 /* 416 * FreeBSD really needs to add DEVICE_SUSPEND_CANCEL or 417 * similar. 418 */ 419 mtx_lock(&Giant); |
376 if (!suspend_cancelled) 377 DEVICE_RESUME(root_bus); | 420 DEVICE_RESUME(root_bus); |
378 mtx_unlock(&Giant); 379 | 421 mtx_unlock(&Giant); 422 |
423 if (smp_started) { 424 thread_lock(curthread); 425 sched_unbind(curthread); 426 thread_unlock(curthread); 427 } 428 |
|
380 EVENTHANDLER_INVOKE(power_resume); | 429 EVENTHANDLER_INVOKE(power_resume); |
430 431 if (bootverbose) 432 printf("System resumed after suspension\n"); 433 |
|
381} 382#endif 383 384static void 385xctrl_crash() 386{ 387 panic("Xen directed crash"); 388} --- 133 unchanged lines hidden --- | 434} 435#endif 436 437static void 438xctrl_crash() 439{ 440 panic("Xen directed crash"); 441} --- 133 unchanged lines hidden --- |