103#include <sys/param.h>
104#include <sys/systm.h>
105#include <sys/kernel.h>
106#include <sys/malloc.h>
112#include <sys/fcntl.h>
113#include <sys/filedesc.h>
115#include <sys/module.h>
116#include <sys/mount.h>
117#include <sys/namei.h>
119#include <sys/reboot.h>
121#include <sys/sched.h>
122#include <sys/taskqueue.h>
123#include <sys/types.h>
124#include <sys/vnode.h>
125#include <sys/sched.h>
127#include <sys/eventhandler.h>
128#include <sys/timetc.h>
130#include <geom/geom.h>
132#include <machine/_inttypes.h>
133#if defined(__amd64__) || defined(__i386__)
134#include <machine/intr_machdep.h>
136#include <x86/apicvar.h>
140#include <vm/vm_extern.h>
141#include <vm/vm_kern.h>
143#include <xen/xen-os.h>
144#include <xen/blkif.h>
145#include <xen/evtchn.h>
146#include <xen/gnttab.h>
147#include <xen/xen_intr.h>
151#include <contrib/xen/event_channel.h>
152#include <contrib/xen/grant_table.h>
154#include <xen/xenbus/xenbusvar.h>
190 shutdown_nice(RB_POWEROFF|RB_HALT);
199#if !defined(__amd64__) && !defined(__i386__)
203 printf(
"WARNING: xen/control: Suspend not supported!\n");
210 cpuset_t cpu_suspend_map;
213 EVENTHANDLER_INVOKE(power_suspend_early);
218 EVENTHANDLER_INVOKE(power_suspend);
220#ifdef EARLY_AP_STARTUP
221 MPASS(mp_ncpus == 1 || smp_started);
222 thread_lock(curthread);
223 sched_bind(curthread, 0);
224 thread_unlock(curthread);
227 thread_lock(curthread);
228 sched_bind(curthread, 0);
229 thread_unlock(curthread);
232 KASSERT((PCPU_GET(cpuid) == 0), (
"Not running on CPU#0"));
238 if (DEVICE_SUSPEND(root_bus) != 0) {
240 printf(
"%s: device_suspend failed\n", __func__);
245#ifdef EARLY_AP_STARTUP
251 cpu_suspend_map = all_cpus;
252 CPU_CLR(PCPU_GET(cpuid), &cpu_suspend_map);
253 if (!CPU_EMPTY(&cpu_suspend_map))
254 suspend_cpus(cpu_suspend_map);
256 CPU_ZERO(&cpu_suspend_map);
263 cpu_suspend_map = all_cpus;
264 CPU_CLR(PCPU_GET(cpuid), &cpu_suspend_map);
265 if (!CPU_EMPTY(&cpu_suspend_map))
266 suspend_cpus(cpu_suspend_map);
281 xen_hvm_resume(
false);
294 if (!CPU_EMPTY(&cpu_suspend_map)) {
299 resume_cpus(cpu_suspend_map);
300#if defined(__amd64__) || defined(__i386__)
302 lapic_ipi_vectored(IPI_BITMAP_VECTOR, APIC_IPI_DEST_ALL);
311 DEVICE_RESUME(root_bus);
317 timecounter->tc_get_timecount(timecounter);
318 inittodr(time_second);
320#ifdef EARLY_AP_STARTUP
321 thread_lock(curthread);
322 sched_unbind(curthread);
323 thread_unlock(curthread);
326 thread_lock(curthread);
327 sched_unbind(curthread);
328 thread_unlock(curthread);
335 EVENTHANDLER_INVOKE(power_resume);
338 printf(
"System resumed after suspension\n");
346 panic(
"Xen directed crash");
353 if (howto & RB_POWEROFF)
354 HYPERVISOR_shutdown(SHUTDOWN_poweroff);
355 else if (howto & RB_POWERCYCLE)
356 HYPERVISOR_shutdown(SHUTDOWN_reboot);
369 error =
xs_read(XST_NIL,
"control",
"shutdown",
370 &result_len, (
void **)&result);
371 if (error != 0 || result_len == 0)
375 error =
xs_write(XST_NIL,
"control",
"shutdown",
"");
377 printf(
"unable to ack shutdown request, proceeding anyway\n");
381 while (reason < last_reason) {
382 if (!strcmp(result, reason->
name)) {
389 free(result, M_XENSTORE);
406 BUS_ADD_CHILD(parent, 0, driver->name, 0);
419 device_set_desc(dev,
"Xen Control Device");
421 return (BUS_PROBE_NOWILDCARD);
437 xctrl = device_get_softc(dev);
442 xctrl->
xctrl_watch.callback_data = (uintptr_t)xctrl;
470 xctrl = device_get_softc(dev);
static xctrl_shutdown_handler_t xctrl_crash
DEFINE_CLASS_0(xctrl, xctrl_driver, xctrl_methods, sizeof(struct xctrl_softc))
static void xctrl_identify(driver_t *driver __unused, device_t parent)
Identify instances of this device type in the system.
DRIVER_MODULE(xctrl, xenstore, xctrl_driver, xctrl_devclass, NULL, NULL)
devclass_t xctrl_devclass
static const struct xctrl_shutdown_reason xctrl_shutdown_reasons[]
static void shutdown_final(void *arg, int howto)
bool xen_suspend_cancelled
static xctrl_shutdown_handler_t xctrl_suspend
static device_method_t xctrl_methods[]
void() xctrl_shutdown_handler_t(void)
static xctrl_shutdown_handler_t xctrl_reboot
static void xctrl_on_watch_event(struct xs_watch *watch, const char **vec, unsigned int len)
static int xctrl_probe(device_t dev)
Probe for the existence of the Xen Control device.
static int xctrl_attach(device_t dev)
Attach the Xen control device.
static int xctrl_detach(device_t dev)
Detach the Xen control device.
static xctrl_shutdown_handler_t xctrl_poweroff
int gnttab_resume(device_t dev)
xctrl_shutdown_handler_t * handler
struct xs_watch xctrl_watch
static int xs_watch(const char *path, const char *token)
int xs_write(struct xs_transaction t, const char *dir, const char *node, const char *string)
int xs_read(struct xs_transaction t, const char *dir, const char *node, u_int *len, void **result)
void xs_unregister_watch(struct xs_watch *watch)
int xs_register_watch(struct xs_watch *watch)