1 /****************************************************************************** 2 * hypervisor.h 3 * 4 * Linux-specific hypervisor handling. 5 * 6 * Copyright (c) 2002, K A Fraser 7 * 8 * $FreeBSD$ 9 */ 10 11 #ifndef __XEN_HYPERVISOR_H__ 12 #define __XEN_HYPERVISOR_H__ 13 14 #include <sys/cdefs.h> 15 #include <sys/systm.h> 16 #include <xen/interface/xen.h> 17 #include <xen/interface/platform.h> 18 #include <xen/interface/event_channel.h> 19 #include <xen/interface/physdev.h> 20 #include <xen/interface/sched.h> 21 #include <xen/interface/callback.h> 22 #include <xen/interface/memory.h> 23 #include <machine/xen/hypercall.h> 24 25 extern uint64_t get_system_time(int ticks); 26 27 static inline int 28 HYPERVISOR_console_write(const char *str, int count) 29 { 30 return HYPERVISOR_console_io(CONSOLEIO_write, count, str); 31 } 32 33 static inline int 34 HYPERVISOR_yield(void) 35 { 36 int rc = HYPERVISOR_sched_op(SCHEDOP_yield, NULL); 37 38 #if CONFIG_XEN_COMPAT <= 0x030002 39 if (rc == -ENOXENSYS) 40 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0); 41 #endif 42 return (rc); 43 } 44 45 static inline int 46 HYPERVISOR_block( 47 void) 48 { 49 int rc = HYPERVISOR_sched_op(SCHEDOP_block, NULL); 50 51 #if CONFIG_XEN_COMPAT <= 0x030002 52 if (rc == -ENOXENSYS) 53 rc = HYPERVISOR_sched_op_compat(SCHEDOP_block, 0); 54 #endif 55 return (rc); 56 } 57 58 static inline void 59 HYPERVISOR_shutdown(unsigned int reason) 60 { 61 struct sched_shutdown sched_shutdown = { 62 .reason = reason 63 }; 64 65 HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown); 66 #if CONFIG_XEN_COMPAT <= 0x030002 67 HYPERVISOR_sched_op_compat(SCHEDOP_shutdown, reason); 68 #endif 69 } 70 71 static inline void 72 HYPERVISOR_crash(void) 73 { 74 HYPERVISOR_shutdown(SHUTDOWN_crash); 75 /* NEVER REACHED */ 76 for (;;) ; /* eliminate noreturn error */ 77 } 78 79 /* Transfer control to hypervisor until an event is detected on one */ 80 /* of the specified ports or the specified number of ticks elapse */ 81 static inline int 82 HYPERVISOR_poll( 83 evtchn_port_t *ports, unsigned int nr_ports, int ticks) 84 { 85 int rc; 86 struct sched_poll sched_poll = { 87 .nr_ports = nr_ports, 88 .timeout = get_system_time(ticks) 89 }; 90 set_xen_guest_handle(sched_poll.ports, ports); 91 92 rc = HYPERVISOR_sched_op(SCHEDOP_poll, &sched_poll); 93 #if CONFIG_XEN_COMPAT <= 0x030002 94 if (rc == -ENOXENSYS) 95 rc = HYPERVISOR_sched_op_compat(SCHEDOP_yield, 0); 96 #endif 97 return (rc); 98 } 99 100 #endif /* __XEN_HYPERVISOR_H__ */ 101