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"
48 extern char *hypercall_page;
51 #define STR(x) __STR(x)
53 #define CONFIG_XEN_COMPAT 0x030002
56 #define HYPERCALL_STR(name) \
57 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
59 #define _hypercall0(type, name) \
70 #define _hypercall1(type, name, a1) \
76 : "=a" (__res), "=D" (__ign1) \
82 #define _hypercall2(type, name, a1, a2) \
85 long __ign1, __ign2; \
88 : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \
89 : "1" ((long)(a1)), "2" ((long)(a2)) \
94 #define _hypercall3(type, name, a1, a2, a3) \
97 long __ign1, __ign2, __ign3; \
100 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
102 : "1" ((long)(a1)), "2" ((long)(a2)), \
108 #define _hypercall4(type, name, a1, a2, a3, a4) \
111 long __ign1, __ign2, __ign3; \
112 register long __arg4 __asm__("r10") = (long)(a4); \
114 HYPERCALL_STR(name) \
115 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
116 "=d" (__ign3), "+r" (__arg4) \
117 : "1" ((long)(a1)), "2" ((long)(a2)), \
123 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
126 long __ign1, __ign2, __ign3; \
127 register long __arg4 __asm__("r10") = (long)(a4); \
128 register long __arg5 __asm__("r8") = (long)(a5); \
130 HYPERCALL_STR(name) \
131 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
132 "=d" (__ign3), "+r" (__arg4), "+r" (__arg5) \
133 : "1" ((long)(a1)), "2" ((long)(a2)), \
140 privcmd_hypercall(long op, long a1, long a2, long a3, long a4, long a5)
143 long __ign1, __ign2, __ign3;
144 register long __arg4 __asm__("r10") = (long)(a4);
145 register long __arg5 __asm__("r8") = (long)(a5);
146 long __call = (long)&hypercall_page + (op * 32);
150 : "=a" (__res), "=D" (__ign1), "=S" (__ign2),
151 "=d" (__ign3), "+r" (__arg4), "+r" (__arg5)
152 : "1" ((long)(a1)), "2" ((long)(a2)),
153 "3" ((long)(a3)), [call] "a" (__call)
159 static inline int __must_check
160 HYPERVISOR_set_trap_table(
161 const trap_info_t *table)
163 return _hypercall1(int, set_trap_table, table);
166 static inline int __must_check
167 HYPERVISOR_mmu_update(
168 mmu_update_t *req, unsigned int count, unsigned int *success_count,
171 return _hypercall4(int, mmu_update, req, count, success_count, domid);
174 static inline int __must_check
175 HYPERVISOR_mmuext_op(
176 struct mmuext_op *op, unsigned int count, unsigned int *success_count,
179 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
182 static inline int __must_check
184 unsigned long *frame_list, unsigned int entries)
186 return _hypercall2(int, set_gdt, frame_list, entries);
189 static inline int __must_check
190 HYPERVISOR_stack_switch(
191 unsigned long ss, unsigned long esp)
193 return _hypercall2(int, stack_switch, ss, esp);
196 static inline int __must_check
197 HYPERVISOR_set_callbacks(
198 unsigned long event_address, unsigned long failsafe_address,
199 unsigned long syscall_address)
201 return _hypercall3(int, set_callbacks,
202 event_address, failsafe_address, syscall_address);
206 HYPERVISOR_fpu_taskswitch(
209 return _hypercall1(int, fpu_taskswitch, set);
212 static inline int __must_check
213 HYPERVISOR_sched_op_compat(
214 int cmd, unsigned long arg)
216 return _hypercall2(int, sched_op_compat, cmd, arg);
219 static inline int __must_check
223 return _hypercall2(int, sched_op, cmd, arg);
226 static inline long __must_check
227 HYPERVISOR_set_timer_op(
230 return _hypercall1(long, set_timer_op, timeout);
233 static inline int __must_check
234 HYPERVISOR_platform_op(
235 struct xen_platform_op *platform_op)
237 platform_op->interface_version = XENPF_INTERFACE_VERSION;
238 return _hypercall1(int, platform_op, platform_op);
241 static inline int __must_check
242 HYPERVISOR_set_debugreg(
243 unsigned int reg, unsigned long value)
245 return _hypercall2(int, set_debugreg, reg, value);
248 static inline unsigned long __must_check
249 HYPERVISOR_get_debugreg(
252 return _hypercall1(unsigned long, get_debugreg, reg);
255 static inline int __must_check
256 HYPERVISOR_update_descriptor(
257 unsigned long ma, unsigned long word)
259 return _hypercall2(int, update_descriptor, ma, word);
262 static inline int __must_check
263 HYPERVISOR_memory_op(
264 unsigned int cmd, void *arg)
266 return _hypercall2(int, memory_op, cmd, arg);
269 static inline int __must_check
270 HYPERVISOR_multicall(
271 multicall_entry_t *call_list, unsigned int nr_calls)
273 return _hypercall2(int, multicall, call_list, nr_calls);
276 static inline int __must_check
277 HYPERVISOR_update_va_mapping(
278 unsigned long va, uint64_t new_val, unsigned long flags)
280 return _hypercall3(int, update_va_mapping, va, new_val, flags);
283 static inline int __must_check
284 HYPERVISOR_event_channel_op(
287 int rc = _hypercall2(int, event_channel_op, cmd, arg);
289 #if CONFIG_XEN_COMPAT <= 0x030002
290 if (__predict_false(rc == -ENOXENSYS)) {
293 memcpy(&op.u, arg, sizeof(op.u));
294 rc = _hypercall1(int, event_channel_op_compat, &op);
295 memcpy(arg, &op.u, sizeof(op.u));
302 static inline int __must_check
303 HYPERVISOR_xen_version(
306 return _hypercall2(int, xen_version, cmd, arg);
309 static inline int __must_check
310 HYPERVISOR_console_io(
311 int cmd, unsigned int count, const char *str)
313 return _hypercall3(int, console_io, cmd, count, str);
316 static inline int __must_check
317 HYPERVISOR_physdev_op(
320 int rc = _hypercall2(int, physdev_op, cmd, arg);
322 #if CONFIG_XEN_COMPAT <= 0x030002
323 if (__predict_false(rc == -ENOXENSYS)) {
324 struct physdev_op op;
326 memcpy(&op.u, arg, sizeof(op.u));
327 rc = _hypercall1(int, physdev_op_compat, &op);
328 memcpy(arg, &op.u, sizeof(op.u));
335 static inline int __must_check
336 HYPERVISOR_grant_table_op(
337 unsigned int cmd, void *uop, unsigned int count)
339 return _hypercall3(int, grant_table_op, cmd, uop, count);
342 static inline int __must_check
343 HYPERVISOR_update_va_mapping_otherdomain(
344 unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid)
346 return _hypercall4(int, update_va_mapping_otherdomain, va,
347 new_val, flags, domid);
350 static inline int __must_check
351 HYPERVISOR_vm_assist(
352 unsigned int cmd, unsigned int type)
354 return _hypercall2(int, vm_assist, cmd, type);
357 static inline int __must_check
359 int cmd, unsigned int vcpuid, void *extra_args)
361 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
364 static inline int __must_check
365 HYPERVISOR_set_segment_base(
366 int reg, unsigned long value)
368 return _hypercall2(int, set_segment_base, reg, value);
371 static inline int __must_check
375 struct sched_shutdown sched_shutdown = {
376 .reason = SHUTDOWN_suspend
379 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
380 &sched_shutdown, srec);
382 #if CONFIG_XEN_COMPAT <= 0x030002
383 if (rc == -ENOXENSYS)
384 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
385 SHUTDOWN_suspend, srec);
391 #if CONFIG_XEN_COMPAT <= 0x030002
394 unsigned long op, void *arg)
396 return _hypercall2(int, nmi_op, op, arg);
401 static inline unsigned long __must_check
405 return _hypercall2(unsigned long, hvm_op, op, arg);
409 static inline int __must_check
410 HYPERVISOR_callback_op(
411 int cmd, const void *arg)
413 return _hypercall2(int, callback_op, cmd, arg);
416 static inline int __must_check
417 HYPERVISOR_xenoprof_op(
420 return _hypercall2(int, xenoprof_op, op, arg);
423 static inline int __must_check
425 unsigned long op, void *args)
427 return _hypercall2(int, kexec_op, op, args);
432 #endif /* __MACHINE_XEN_HYPERCALL_H__ */