1 /******************************************************************************
4 * Linux-specific hypervisor handling.
6 * Copyright (c) 2002-2004, K A Fraser
8 * This file may be distributed separately from the Linux kernel, or
9 * incorporated into other software packages, subject to the following license:
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this source file (the "Software"), to deal in the Software without
13 * restriction, including without limitation the rights to use, copy, modify,
14 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
15 * and to permit persons to whom the Software is furnished to do so, subject to
16 * the following conditions:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30 #ifndef __HYPERCALL_H__
31 #define __HYPERCALL_H__
33 #include <sys/systm.h>
34 #include <xen/interface/xen.h>
35 #include <xen/interface/sched.h>
37 extern char *hypercall_page;
40 #define STR(x) __STR(x)
42 #define CONFIG_XEN_COMPAT 0x030002
44 #define HYPERCALL_STR(name) \
45 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
47 #define _hypercall0(type, name) \
58 #define _hypercall1(type, name, a1) \
63 : "=a" (__res), "=b" (__ign1) \
69 #define _hypercall2(type, name, a1, a2) \
71 long __res, __ign1, __ign2; \
74 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \
75 : "1" ((long)(a1)), "2" ((long)(a2)) \
80 #define _hypercall3(type, name, a1, a2, a3) \
82 long __res, __ign1, __ign2, __ign3; \
85 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
87 : "1" ((long)(a1)), "2" ((long)(a2)), \
93 #define _hypercall4(type, name, a1, a2, a3, a4) \
95 long __res, __ign1, __ign2, __ign3, __ign4; \
98 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
99 "=d" (__ign3), "=S" (__ign4) \
100 : "1" ((long)(a1)), "2" ((long)(a2)), \
101 "3" ((long)(a3)), "4" ((long)(a4)) \
106 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
108 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \
110 HYPERCALL_STR(name) \
111 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
112 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \
113 : "1" ((long)(a1)), "2" ((long)(a2)), \
114 "3" ((long)(a3)), "4" ((long)(a4)), \
121 privcmd_hypercall(long op, long a1, long a2, long a3, long a4, long a5)
123 long __res, __ign1, __ign2, __ign3, __ign4, __ign5, __call;
125 __call = (long)&hypercall_page + (op * 32);
128 : "=a" (__res), "=b" (__ign1), "=c" (__ign2),
129 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5)
130 : "1" ((long)(a1)), "2" ((long)(a2)),
131 "3" ((long)(a3)), "4" ((long)(a4)),
132 "5" ((long)(a5)), [call] "a" (__call)
139 HYPERVISOR_set_trap_table(
142 return _hypercall1(int, set_trap_table, table);
146 HYPERVISOR_mmu_update(
147 mmu_update_t *req, int count, int *success_count, domid_t domid)
149 return _hypercall4(int, mmu_update, req, count, success_count, domid);
153 HYPERVISOR_mmuext_op(
154 mmuext_op_t *op, int count, int *success_count, domid_t domid)
156 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
161 unsigned long *frame_list, int entries)
163 return _hypercall2(int, set_gdt, frame_list, entries);
167 HYPERVISOR_stack_switch(
168 unsigned long ss, unsigned long esp)
170 return _hypercall2(int, stack_switch, ss, esp);
174 HYPERVISOR_set_callbacks(
175 unsigned long event_selector, unsigned long event_address,
176 unsigned long failsafe_selector, unsigned long failsafe_address)
178 return _hypercall4(int, set_callbacks,
179 event_selector, event_address,
180 failsafe_selector, failsafe_address);
184 HYPERVISOR_fpu_taskswitch(
187 return _hypercall1(int, fpu_taskswitch, set);
191 HYPERVISOR_sched_op_compat(
192 int cmd, unsigned long arg)
194 return _hypercall2(int, sched_op_compat, cmd, arg);
201 return _hypercall2(int, sched_op, cmd, arg);
205 HYPERVISOR_set_timer_op(
208 unsigned long timeout_hi = (unsigned long)(timeout>>32);
209 unsigned long timeout_lo = (unsigned long)timeout;
210 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
214 HYPERVISOR_platform_op(
215 struct xen_platform_op *platform_op)
217 platform_op->interface_version = XENPF_INTERFACE_VERSION;
218 return _hypercall1(int, platform_op, platform_op);
222 HYPERVISOR_set_debugreg(
223 int reg, unsigned long value)
225 return _hypercall2(int, set_debugreg, reg, value);
228 static inline unsigned long
229 HYPERVISOR_get_debugreg(
232 return _hypercall1(unsigned long, get_debugreg, reg);
236 HYPERVISOR_update_descriptor(
237 uint64_t ma, uint64_t desc)
239 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
243 HYPERVISOR_memory_op(
244 unsigned int cmd, void *arg)
246 return _hypercall2(int, memory_op, cmd, arg);
250 HYPERVISOR_multicall(
251 void *call_list, int nr_calls)
253 return _hypercall2(int, multicall, call_list, nr_calls);
257 HYPERVISOR_update_va_mapping(
258 unsigned long va, uint64_t new_val, unsigned long flags)
262 lo = (uint32_t)(new_val & 0xffffffff);
263 hi = (uint32_t)(new_val >> 32);
265 return _hypercall4(int, update_va_mapping, va,
270 HYPERVISOR_event_channel_op(
273 int rc = _hypercall2(int, event_channel_op, cmd, arg);
275 #if CONFIG_XEN_COMPAT <= 0x030002
276 if (__predict_false(rc == -ENOXENSYS)) {
279 memcpy(&op.u, arg, sizeof(op.u));
280 rc = _hypercall1(int, event_channel_op_compat, &op);
281 memcpy(arg, &op.u, sizeof(op.u));
288 HYPERVISOR_xen_version(
291 return _hypercall2(int, xen_version, cmd, arg);
295 HYPERVISOR_console_io(
296 int cmd, int count, const char *str)
298 return _hypercall3(int, console_io, cmd, count, str);
302 HYPERVISOR_physdev_op(
305 int rc = _hypercall2(int, physdev_op, cmd, arg);
306 #if CONFIG_XEN_COMPAT <= 0x030002
307 if (__predict_false(rc == -ENOXENSYS)) {
308 struct physdev_op op;
310 memcpy(&op.u, arg, sizeof(op.u));
311 rc = _hypercall1(int, physdev_op_compat, &op);
312 memcpy(arg, &op.u, sizeof(op.u));
319 HYPERVISOR_grant_table_op(
320 unsigned int cmd, void *uop, unsigned int count)
322 return _hypercall3(int, grant_table_op, cmd, uop, count);
326 HYPERVISOR_update_va_mapping_otherdomain(
327 unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid)
331 lo = (uint32_t)(new_val & 0xffffffff);
332 hi = (uint32_t)(new_val >> 32);
334 return _hypercall5(int, update_va_mapping_otherdomain, va,
335 lo, hi, flags, domid);
339 HYPERVISOR_vm_assist(
340 unsigned int cmd, unsigned int type)
342 return _hypercall2(int, vm_assist, cmd, type);
347 int cmd, int vcpuid, void *extra_args)
349 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
356 struct sched_shutdown sched_shutdown = {
357 .reason = SHUTDOWN_suspend
359 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
360 &sched_shutdown, srec);
361 #if CONFIG_XEN_COMPAT <= 0x030002
362 if (rc == -ENOXENSYS)
363 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
364 SHUTDOWN_suspend, srec);
369 #if CONFIG_XEN_COMPAT <= 0x030002
372 unsigned long op, void *arg)
374 return _hypercall2(int, nmi_op, op, arg);
379 HYPERVISOR_callback_op(
382 return _hypercall2(int, callback_op, cmd, arg);
386 static inline unsigned long
390 return _hypercall2(unsigned long, hvm_op, op, arg);
395 HYPERVISOR_xenoprof_op(
398 return _hypercall2(int, xenoprof_op, op, arg);
403 unsigned long op, void *args)
405 return _hypercall2(int, kexec_op, op, args);
407 #endif /* __HYPERCALL_H__ */
411 * c-file-style: "linux"
412 * indent-tabs-mode: t