control.c (70d8f36aa445e4556ead4de32f9b7b4687d95098) | control.c (dcceabd3446483d8dc642c75bc71cf42ee7e1bc9) |
---|---|
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 --- 111 unchanged lines hidden (view full) --- 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 127 | 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 --- 111 unchanged lines hidden (view full) --- 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 127 |
128 | |
129#include <geom/geom.h> 130 131#include <machine/_inttypes.h> 132#include <machine/xen/xen-os.h> 133 134#include <vm/vm.h> 135#include <vm/vm_extern.h> 136#include <vm/vm_kern.h> 137 138#include <xen/blkif.h> 139#include <xen/evtchn.h> 140#include <xen/gnttab.h> 141#include <xen/xen_intr.h> 142 143#include <xen/interface/event_channel.h> 144#include <xen/interface/grant_table.h> 145 146#include <xen/xenbus/xenbusvar.h> 147 | 128#include <geom/geom.h> 129 130#include <machine/_inttypes.h> 131#include <machine/xen/xen-os.h> 132 133#include <vm/vm.h> 134#include <vm/vm_extern.h> 135#include <vm/vm_kern.h> 136 137#include <xen/blkif.h> 138#include <xen/evtchn.h> 139#include <xen/gnttab.h> 140#include <xen/xen_intr.h> 141 142#include <xen/interface/event_channel.h> 143#include <xen/interface/grant_table.h> 144 145#include <xen/xenbus/xenbusvar.h> 146 |
148#define NUM_ELEMENTS(x) (sizeof(x) / sizeof(*(x))) 149 | |
150/*--------------------------- Forward Declarations --------------------------*/ 151/** Function signature for shutdown event handlers. */ 152typedef void (xctrl_shutdown_handler_t)(void); 153 154static xctrl_shutdown_handler_t xctrl_poweroff; 155static xctrl_shutdown_handler_t xctrl_reboot; 156static xctrl_shutdown_handler_t xctrl_suspend; 157static xctrl_shutdown_handler_t xctrl_crash; 158static xctrl_shutdown_handler_t xctrl_halt; 159 160/*-------------------------- Private Data Structures -------------------------*/ 161/** Element type for lookup table of event name to handler. */ 162struct xctrl_shutdown_reason { 163 const char *name; 164 xctrl_shutdown_handler_t *handler; 165}; 166 167/** Lookup table for shutdown event name to handler. */ | 147/*--------------------------- Forward Declarations --------------------------*/ 148/** Function signature for shutdown event handlers. */ 149typedef void (xctrl_shutdown_handler_t)(void); 150 151static xctrl_shutdown_handler_t xctrl_poweroff; 152static xctrl_shutdown_handler_t xctrl_reboot; 153static xctrl_shutdown_handler_t xctrl_suspend; 154static xctrl_shutdown_handler_t xctrl_crash; 155static xctrl_shutdown_handler_t xctrl_halt; 156 157/*-------------------------- Private Data Structures -------------------------*/ 158/** Element type for lookup table of event name to handler. */ 159struct xctrl_shutdown_reason { 160 const char *name; 161 xctrl_shutdown_handler_t *handler; 162}; 163 164/** Lookup table for shutdown event name to handler. */ |
168static struct xctrl_shutdown_reason xctrl_shutdown_reasons[] = { | 165static const struct xctrl_shutdown_reason xctrl_shutdown_reasons[] = { |
169 { "poweroff", xctrl_poweroff }, 170 { "reboot", xctrl_reboot }, 171 { "suspend", xctrl_suspend }, 172 { "crash", xctrl_crash }, 173 { "halt", xctrl_halt }, 174}; 175 176struct xctrl_softc { --- 16 unchanged lines hidden (view full) --- 193#ifndef XENHVM 194extern void xencons_suspend(void); 195extern void xencons_resume(void); 196 197/* Full PV mode suspension. */ 198static void 199xctrl_suspend() 200{ | 166 { "poweroff", xctrl_poweroff }, 167 { "reboot", xctrl_reboot }, 168 { "suspend", xctrl_suspend }, 169 { "crash", xctrl_crash }, 170 { "halt", xctrl_halt }, 171}; 172 173struct xctrl_softc { --- 16 unchanged lines hidden (view full) --- 190#ifndef XENHVM 191extern void xencons_suspend(void); 192extern void xencons_resume(void); 193 194/* Full PV mode suspension. */ 195static void 196xctrl_suspend() 197{ |
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 207#ifdef SMP 208 struct thread *td; 209 cpuset_t map; | 198 int i, j, k, fpp; 199 unsigned long max_pfn, start_info_mfn; 200 201 EVENTHANDLER_INVOKE(power_suspend); 202 203#ifdef SMP 204 struct thread *td; 205 cpuset_t map; |
206 u_int cpuid; 207 |
|
210 /* 211 * Bind us to CPU 0 and stop any other VCPUs. 212 */ 213 td = curthread; 214 thread_lock(td); 215 sched_bind(td, 0); 216 thread_unlock(td); 217 cpuid = PCPU_GET(cpuid); --- 8 unchanged lines hidden (view full) --- 226 227 /* 228 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 229 * drivers need this. 230 */ 231 mtx_lock(&Giant); 232 if (DEVICE_SUSPEND(root_bus) != 0) { 233 mtx_unlock(&Giant); | 208 /* 209 * Bind us to CPU 0 and stop any other VCPUs. 210 */ 211 td = curthread; 212 thread_lock(td); 213 sched_bind(td, 0); 214 thread_unlock(td); 215 cpuid = PCPU_GET(cpuid); --- 8 unchanged lines hidden (view full) --- 224 225 /* 226 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 227 * drivers need this. 228 */ 229 mtx_lock(&Giant); 230 if (DEVICE_SUSPEND(root_bus) != 0) { 231 mtx_unlock(&Giant); |
234 printf("xen_suspend: device_suspend failed\n"); | 232 printf("%s: device_suspend failed\n", __func__); |
235#ifdef SMP 236 if (!CPU_EMPTY(&map)) 237 restart_cpus(map); 238#endif 239 return; 240 } 241 mtx_unlock(&Giant); 242 --- 95 unchanged lines hidden (view full) --- 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); | 233#ifdef SMP 234 if (!CPU_EMPTY(&map)) 235 restart_cpus(map); 236#endif 237 return; 238 } 239 mtx_unlock(&Giant); 240 --- 95 unchanged lines hidden (view full) --- 336 337 EVENTHANDLER_INVOKE(power_suspend); 338 339 /* 340 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since non-MPSAFE 341 * drivers need this. 342 */ 343 mtx_lock(&Giant); |
346 if (DEVICE_SUSPEND(root_bus)) { | 344 if (DEVICE_SUSPEND(root_bus) != 0) { |
347 mtx_unlock(&Giant); | 345 mtx_unlock(&Giant); |
348 printf("xen_suspend: device_suspend failed\n"); | 346 printf("%s: device_suspend failed\n", __func__); |
349 return; 350 } 351 mtx_unlock(&Giant); 352 353 /* 354 * Prevent any races with evtchn_interrupt() handler. 355 */ 356 disable_intr(); --- 34 unchanged lines hidden (view full) --- 391{ 392 shutdown_nice(RB_HALT); 393} 394 395/*------------------------------ Event Reception -----------------------------*/ 396static void 397xctrl_on_watch_event(struct xs_watch *watch, const char **vec, unsigned int len) 398{ | 347 return; 348 } 349 mtx_unlock(&Giant); 350 351 /* 352 * Prevent any races with evtchn_interrupt() handler. 353 */ 354 disable_intr(); --- 34 unchanged lines hidden (view full) --- 389{ 390 shutdown_nice(RB_HALT); 391} 392 393/*------------------------------ Event Reception -----------------------------*/ 394static void 395xctrl_on_watch_event(struct xs_watch *watch, const char **vec, unsigned int len) 396{ |
399 struct xctrl_shutdown_reason *reason; 400 struct xctrl_shutdown_reason *last_reason; | 397 const struct xctrl_shutdown_reason *reason; 398 const struct xctrl_shutdown_reason *last_reason; |
401 char *result; 402 int error; 403 int result_len; 404 405 error = xs_read(XST_NIL, "control", "shutdown", 406 &result_len, (void **)&result); 407 if (error != 0) 408 return; 409 410 reason = xctrl_shutdown_reasons; | 399 char *result; 400 int error; 401 int result_len; 402 403 error = xs_read(XST_NIL, "control", "shutdown", 404 &result_len, (void **)&result); 405 if (error != 0) 406 return; 407 408 reason = xctrl_shutdown_reasons; |
411 last_reason = reason + NUM_ELEMENTS(xctrl_shutdown_reasons); | 409 last_reason = reason + nitems(xctrl_shutdown_reasons); |
412 while (reason < last_reason) { 413 414 if (!strcmp(result, reason->name)) { 415 reason->handler(); 416 break; 417 } 418 reason++; 419 } --- 86 unchanged lines hidden (view full) --- 506/*-------------------- Private Device Attachment Data -----------------------*/ 507static device_method_t xctrl_methods[] = { 508 /* Device interface */ 509 DEVMETHOD(device_identify, xctrl_identify), 510 DEVMETHOD(device_probe, xctrl_probe), 511 DEVMETHOD(device_attach, xctrl_attach), 512 DEVMETHOD(device_detach, xctrl_detach), 513 | 410 while (reason < last_reason) { 411 412 if (!strcmp(result, reason->name)) { 413 reason->handler(); 414 break; 415 } 416 reason++; 417 } --- 86 unchanged lines hidden (view full) --- 504/*-------------------- Private Device Attachment Data -----------------------*/ 505static device_method_t xctrl_methods[] = { 506 /* Device interface */ 507 DEVMETHOD(device_identify, xctrl_identify), 508 DEVMETHOD(device_probe, xctrl_probe), 509 DEVMETHOD(device_attach, xctrl_attach), 510 DEVMETHOD(device_detach, xctrl_detach), 511 |
514 { 0, 0 } | 512 DEVMETHOD_END |
515}; 516 517DEFINE_CLASS_0(xctrl, xctrl_driver, xctrl_methods, sizeof(struct xctrl_softc)); 518devclass_t xctrl_devclass; 519 | 513}; 514 515DEFINE_CLASS_0(xctrl, xctrl_driver, xctrl_methods, sizeof(struct xctrl_softc)); 516devclass_t xctrl_devclass; 517 |
520DRIVER_MODULE(xctrl, xenstore, xctrl_driver, xctrl_devclass, 0, 0); | 518DRIVER_MODULE(xctrl, xenstore, xctrl_driver, xctrl_devclass, NULL, NULL); |