1 /******************************************************************************
4 * FreeBSD-specific hypervisor handling.
6 * Copyright (c) 2002-2004, K A Fraser
9 * Benjamin Liu <benjamin.liu@intel.com>
10 * Jun Nakajima <jun.nakajima@intel.com>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation; or, when distributed
15 * separately from the Linux kernel or incorporated into other
16 * software packages, subject to the following license:
18 * Permission is hereby granted, free of charge, to any person obtaining a copy
19 * of this source file (the "Software"), to deal in the Software without
20 * restriction, including without limitation the rights to use, copy, modify,
21 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
22 * and to permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
25 * The above copyright notice and this permission notice shall be included in
26 * all copies or substantial portions of the Software.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
33 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
39 #ifndef __MACHINE_XEN_HYPERCALL_H__
40 #define __MACHINE_XEN_HYPERCALL_H__
42 #include <sys/systm.h>
44 #ifndef __XEN_HYPERVISOR_H__
45 # error "please don't include this file directly"
49 #define STR(x) __STR(x)
51 #define CONFIG_XEN_COMPAT 0x030002
55 #define HYPERCALL_STR(name) \
56 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
58 #define HYPERCALL_STR(name) \
59 "mov $("STR(__HYPERVISOR_##name)" * 32),%%eax; "\
60 "add hypercall_stubs(%%rip),%%rax; " \
64 #define _hypercall0(type, name) \
75 #define _hypercall1(type, name, a1) \
81 : "=a" (__res), "=D" (__ign1) \
87 #define _hypercall2(type, name, a1, a2) \
90 long __ign1, __ign2; \
93 : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \
94 : "1" ((long)(a1)), "2" ((long)(a2)) \
99 #define _hypercall3(type, name, a1, a2, a3) \
102 long __ign1, __ign2, __ign3; \
104 HYPERCALL_STR(name) \
105 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
107 : "1" ((long)(a1)), "2" ((long)(a2)), \
113 #define _hypercall4(type, name, a1, a2, a3, a4) \
116 long __ign1, __ign2, __ign3; \
117 register long __arg4 __asm__("r10") = (long)(a4); \
119 HYPERCALL_STR(name) \
120 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
121 "=d" (__ign3), "+r" (__arg4) \
122 : "1" ((long)(a1)), "2" ((long)(a2)), \
128 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
131 long __ign1, __ign2, __ign3; \
132 register long __arg4 __asm__("r10") = (long)(a4); \
133 register long __arg5 __asm__("r8") = (long)(a5); \
135 HYPERCALL_STR(name) \
136 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
137 "=d" (__ign3), "+r" (__arg4), "+r" (__arg5) \
138 : "1" ((long)(a1)), "2" ((long)(a2)), \
144 static inline int __must_check
145 HYPERVISOR_set_trap_table(
146 const trap_info_t *table)
148 return _hypercall1(int, set_trap_table, table);
151 static inline int __must_check
152 HYPERVISOR_mmu_update(
153 mmu_update_t *req, unsigned int count, unsigned int *success_count,
156 return _hypercall4(int, mmu_update, req, count, success_count, domid);
159 static inline int __must_check
160 HYPERVISOR_mmuext_op(
161 struct mmuext_op *op, unsigned int count, unsigned int *success_count,
164 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
167 static inline int __must_check
169 unsigned long *frame_list, unsigned int entries)
171 return _hypercall2(int, set_gdt, frame_list, entries);
174 static inline int __must_check
175 HYPERVISOR_stack_switch(
176 unsigned long ss, unsigned long esp)
178 return _hypercall2(int, stack_switch, ss, esp);
181 static inline int __must_check
182 HYPERVISOR_set_callbacks(
183 unsigned long event_address, unsigned long failsafe_address,
184 unsigned long syscall_address)
186 return _hypercall3(int, set_callbacks,
187 event_address, failsafe_address, syscall_address);
191 HYPERVISOR_fpu_taskswitch(
194 return _hypercall1(int, fpu_taskswitch, set);
197 static inline int __must_check
198 HYPERVISOR_sched_op_compat(
199 int cmd, unsigned long arg)
201 return _hypercall2(int, sched_op_compat, cmd, arg);
204 static inline int __must_check
208 return _hypercall2(int, sched_op, cmd, arg);
211 static inline long __must_check
212 HYPERVISOR_set_timer_op(
215 return _hypercall1(long, set_timer_op, timeout);
218 static inline int __must_check
219 HYPERVISOR_platform_op(
220 struct xen_platform_op *platform_op)
222 platform_op->interface_version = XENPF_INTERFACE_VERSION;
223 return _hypercall1(int, platform_op, platform_op);
226 static inline int __must_check
227 HYPERVISOR_set_debugreg(
228 unsigned int reg, unsigned long value)
230 return _hypercall2(int, set_debugreg, reg, value);
233 static inline unsigned long __must_check
234 HYPERVISOR_get_debugreg(
237 return _hypercall1(unsigned long, get_debugreg, reg);
240 static inline int __must_check
241 HYPERVISOR_update_descriptor(
242 unsigned long ma, unsigned long word)
244 return _hypercall2(int, update_descriptor, ma, word);
247 static inline int __must_check
248 HYPERVISOR_memory_op(
249 unsigned int cmd, void *arg)
251 return _hypercall2(int, memory_op, cmd, arg);
254 static inline int __must_check
255 HYPERVISOR_multicall(
256 multicall_entry_t *call_list, unsigned int nr_calls)
258 return _hypercall2(int, multicall, call_list, nr_calls);
261 static inline int __must_check
262 HYPERVISOR_update_va_mapping(
263 unsigned long va, uint64_t new_val, unsigned long flags)
265 return _hypercall3(int, update_va_mapping, va, new_val, flags);
268 static inline int __must_check
269 HYPERVISOR_event_channel_op(
272 int rc = _hypercall2(int, event_channel_op, cmd, arg);
274 #if CONFIG_XEN_COMPAT <= 0x030002
275 if (__predict_false(rc == -ENOXENSYS)) {
278 memcpy(&op.u, arg, sizeof(op.u));
279 rc = _hypercall1(int, event_channel_op_compat, &op);
280 memcpy(arg, &op.u, sizeof(op.u));
287 static inline int __must_check
288 HYPERVISOR_xen_version(
291 return _hypercall2(int, xen_version, cmd, arg);
294 static inline int __must_check
295 HYPERVISOR_console_io(
296 int cmd, unsigned int count, char *str)
298 return _hypercall3(int, console_io, cmd, count, str);
301 static inline int __must_check
302 HYPERVISOR_physdev_op(
305 int rc = _hypercall2(int, physdev_op, cmd, arg);
307 #if CONFIG_XEN_COMPAT <= 0x030002
308 if (__predict_false(rc == -ENOXENSYS)) {
309 struct physdev_op op;
311 memcpy(&op.u, arg, sizeof(op.u));
312 rc = _hypercall1(int, physdev_op_compat, &op);
313 memcpy(arg, &op.u, sizeof(op.u));
320 static inline int __must_check
321 HYPERVISOR_grant_table_op(
322 unsigned int cmd, void *uop, unsigned int count)
324 return _hypercall3(int, grant_table_op, cmd, uop, count);
327 static inline int __must_check
328 HYPERVISOR_update_va_mapping_otherdomain(
329 unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid)
331 return _hypercall4(int, update_va_mapping_otherdomain, va,
332 new_val, flags, domid);
335 static inline int __must_check
336 HYPERVISOR_vm_assist(
337 unsigned int cmd, unsigned int type)
339 return _hypercall2(int, vm_assist, cmd, type);
342 static inline int __must_check
344 int cmd, unsigned int vcpuid, void *extra_args)
346 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
349 static inline int __must_check
350 HYPERVISOR_set_segment_base(
351 int reg, unsigned long value)
353 return _hypercall2(int, set_segment_base, reg, value);
356 static inline int __must_check
360 struct sched_shutdown sched_shutdown = {
361 .reason = SHUTDOWN_suspend
364 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
365 &sched_shutdown, srec);
367 #if CONFIG_XEN_COMPAT <= 0x030002
368 if (rc == -ENOXENSYS)
369 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
370 SHUTDOWN_suspend, srec);
376 #if CONFIG_XEN_COMPAT <= 0x030002
379 unsigned long op, void *arg)
381 return _hypercall2(int, nmi_op, op, arg);
386 static inline unsigned long __must_check
390 return _hypercall2(unsigned long, hvm_op, op, arg);
394 static inline int __must_check
395 HYPERVISOR_callback_op(
396 int cmd, const void *arg)
398 return _hypercall2(int, callback_op, cmd, arg);
401 static inline int __must_check
402 HYPERVISOR_xenoprof_op(
405 return _hypercall2(int, xenoprof_op, op, arg);
408 static inline int __must_check
410 unsigned long op, void *args)
412 return _hypercall2(int, kexec_op, op, args);
417 #endif /* __MACHINE_XEN_HYPERCALL_H__ */