control.c (223758) | control.c (225704) |
---|---|
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 223758 2011-07-04 12:04:52Z attilio $"); | 92__FBSDID("$FreeBSD: head/sys/dev/xen/control/control.c 225704 2011-09-20 23:44:34Z 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 --- 9 unchanged lines hidden (view full) --- 110#include <sys/fcntl.h> 111#include <sys/filedesc.h> 112#include <sys/kdb.h> 113#include <sys/module.h> 114#include <sys/namei.h> 115#include <sys/proc.h> 116#include <sys/reboot.h> 117#include <sys/rman.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 --- 9 unchanged lines hidden (view full) --- 110#include <sys/fcntl.h> 111#include <sys/filedesc.h> 112#include <sys/kdb.h> 113#include <sys/module.h> 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> |
|
118#include <sys/taskqueue.h> 119#include <sys/types.h> 120#include <sys/vnode.h> 121 122#ifndef XENHVM 123#include <sys/sched.h> 124#include <sys/smp.h> 125#endif --- 70 unchanged lines hidden (view full) --- 196/* Full PV mode suspension. */ 197static void 198xctrl_suspend() 199{ 200 u_int cpuid; 201 int i, j, k, fpp; 202 unsigned long max_pfn, start_info_mfn; 203 | 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> 126#endif --- 70 unchanged lines hidden (view full) --- 197/* Full PV mode suspension. */ 198static void 199xctrl_suspend() 200{ 201 u_int cpuid; 202 int i, j, k, fpp; 203 unsigned long max_pfn, start_info_mfn; 204 |
205 EVENTHANDLER_INVOKE(power_suspend); 206 |
|
204#ifdef SMP 205 struct thread *td; 206 cpuset_t map; 207 /* 208 * Bind us to CPU 0 and stop any other VCPUs. 209 */ 210 td = curthread; 211 thread_lock(td); --- 4 unchanged lines hidden (view full) --- 216 217 map = all_cpus; 218 CPU_CLR(cpuid, &map); 219 CPU_NAND(&map, &stopped_cpus); 220 if (!CPU_EMPTY(&map)) 221 stop_cpus(map); 222#endif 223 | 207#ifdef SMP 208 struct thread *td; 209 cpuset_t map; 210 /* 211 * Bind us to CPU 0 and stop any other VCPUs. 212 */ 213 td = curthread; 214 thread_lock(td); --- 4 unchanged lines hidden (view full) --- 219 220 map = all_cpus; 221 CPU_CLR(cpuid, &map); 222 CPU_NAND(&map, &stopped_cpus); 223 if (!CPU_EMPTY(&map)) 224 stop_cpus(map); 225#endif 226 |
227 /* 228 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 229 * drivers need this. 230 */ 231 mtx_lock(&Giant); |
|
224 if (DEVICE_SUSPEND(root_bus) != 0) { | 232 if (DEVICE_SUSPEND(root_bus) != 0) { |
233 mtx_unlock(&Giant); |
|
225 printf("xen_suspend: device_suspend failed\n"); 226#ifdef SMP 227 if (!CPU_EMPTY(&map)) 228 restart_cpus(map); 229#endif 230 return; 231 } | 234 printf("xen_suspend: device_suspend failed\n"); 235#ifdef SMP 236 if (!CPU_EMPTY(&map)) 237 restart_cpus(map); 238#endif 239 return; 240 } |
241 mtx_unlock(&Giant); |
|
232 233 local_irq_disable(); 234 235 xencons_suspend(); 236 gnttab_suspend(); 237 238 max_pfn = HYPERVISOR_shared_info->arch.max_pfn; 239 --- 38 unchanged lines hidden (view full) --- 278 local_irq_enable(); 279 xencons_resume(); 280 281#ifdef CONFIG_SMP 282 for_each_cpu(i) 283 vcpu_prepare(i); 284 285#endif | 242 243 local_irq_disable(); 244 245 xencons_suspend(); 246 gnttab_suspend(); 247 248 max_pfn = HYPERVISOR_shared_info->arch.max_pfn; 249 --- 38 unchanged lines hidden (view full) --- 288 local_irq_enable(); 289 xencons_resume(); 290 291#ifdef CONFIG_SMP 292 for_each_cpu(i) 293 vcpu_prepare(i); 294 295#endif |
296 |
|
286 /* 287 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise 288 * the VCPU hotplug callback can race with our vcpu_prepare 289 */ | 297 /* 298 * Only resume xenbus /after/ we've prepared our VCPUs; otherwise 299 * the VCPU hotplug callback can race with our vcpu_prepare 300 */ |
301 mtx_lock(&Giant); |
|
290 DEVICE_RESUME(root_bus); | 302 DEVICE_RESUME(root_bus); |
303 mtx_unlock(&Giant); |
|
291 292#ifdef SMP 293 thread_lock(curthread); 294 sched_unbind(curthread); 295 thread_unlock(curthread); 296 if (!CPU_EMPTY(&map)) 297 restart_cpus(map); 298#endif | 304 305#ifdef SMP 306 thread_lock(curthread); 307 sched_unbind(curthread); 308 thread_unlock(curthread); 309 if (!CPU_EMPTY(&map)) 310 restart_cpus(map); 311#endif |
312 EVENTHANDLER_INVOKE(power_resume); |
|
299} 300 301static void 302xen_pv_shutdown_final(void *arg, int howto) 303{ 304 /* 305 * Inform the hypervisor that shutdown is complete. 306 * This is not necessary in HVM domains since Xen --- 10 unchanged lines hidden (view full) --- 317extern void xenpci_resume(void); 318 319/* HVM mode suspension. */ 320static void 321xctrl_suspend() 322{ 323 int suspend_cancelled; 324 | 313} 314 315static void 316xen_pv_shutdown_final(void *arg, int howto) 317{ 318 /* 319 * Inform the hypervisor that shutdown is complete. 320 * This is not necessary in HVM domains since Xen --- 10 unchanged lines hidden (view full) --- 331extern void xenpci_resume(void); 332 333/* HVM mode suspension. */ 334static void 335xctrl_suspend() 336{ 337 int suspend_cancelled; 338 |
339 EVENTHANDLER_INVOKE(power_suspend); 340 341 /* 342 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 343 * drivers need this. 344 */ 345 mtx_lock(&Giant); |
|
325 if (DEVICE_SUSPEND(root_bus)) { | 346 if (DEVICE_SUSPEND(root_bus)) { |
347 mtx_unlock(&Giant); |
|
326 printf("xen_suspend: device_suspend failed\n"); 327 return; 328 } | 348 printf("xen_suspend: device_suspend failed\n"); 349 return; 350 } |
351 mtx_unlock(&Giant); |
|
329 330 /* | 352 353 /* |
331 * Make sure we don't change cpus or switch to some other 332 * thread. for the duration. 333 */ 334 critical_enter(); 335 336 /* | |
337 * Prevent any races with evtchn_interrupt() handler. 338 */ | 354 * Prevent any races with evtchn_interrupt() handler. 355 */ |
339 irq_suspend(); | |
340 disable_intr(); | 356 disable_intr(); |
357 irq_suspend(); |
|
341 342 suspend_cancelled = HYPERVISOR_suspend(0); | 358 359 suspend_cancelled = HYPERVISOR_suspend(0); |
343 if (!suspend_cancelled) | 360 if (suspend_cancelled) 361 irq_resume(); 362 else |
344 xenpci_resume(); 345 346 /* 347 * Re-enable interrupts and put the scheduler back to normal. 348 */ 349 enable_intr(); | 363 xenpci_resume(); 364 365 /* 366 * Re-enable interrupts and put the scheduler back to normal. 367 */ 368 enable_intr(); |
350 critical_exit(); | |
351 352 /* 353 * FreeBSD really needs to add DEVICE_SUSPEND_CANCEL or 354 * similar. 355 */ | 369 370 /* 371 * FreeBSD really needs to add DEVICE_SUSPEND_CANCEL or 372 * similar. 373 */ |
374 mtx_lock(&Giant); |
|
356 if (!suspend_cancelled) 357 DEVICE_RESUME(root_bus); | 375 if (!suspend_cancelled) 376 DEVICE_RESUME(root_bus); |
377 mtx_unlock(&Giant); 378 379 EVENTHANDLER_INVOKE(power_resume); |
|
358} 359#endif 360 361static void 362xctrl_crash() 363{ 364 panic("Xen directed crash"); 365} --- 133 unchanged lines hidden --- | 380} 381#endif 382 383static void 384xctrl_crash() 385{ 386 panic("Xen directed crash"); 387} --- 133 unchanged lines hidden --- |