1 /******************************************************************************
4 * Linux-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
37 #ifndef __HYPERCALL_H__
38 #define __HYPERCALL_H__
40 #include <linux/string.h> /* memcpy() */
42 #ifndef __HYPERVISOR_H__
43 # error "please don't include this file directly"
47 #define STR(x) __STR(x)
50 #define HYPERCALL_STR(name) \
51 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
53 #define HYPERCALL_STR(name) \
54 "mov hypercall_stubs,%%rax; " \
55 "add $("STR(__HYPERVISOR_##name)" * 32),%%rax; " \
59 #define _hypercall0(type, name) \
70 #define _hypercall1(type, name, a1) \
75 : "=a" (__res), "=D" (__ign1) \
81 #define _hypercall2(type, name, a1, a2) \
83 long __res, __ign1, __ign2; \
86 : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \
87 : "1" ((long)(a1)), "2" ((long)(a2)) \
92 #define _hypercall3(type, name, a1, a2, a3) \
94 long __res, __ign1, __ign2, __ign3; \
97 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
99 : "1" ((long)(a1)), "2" ((long)(a2)), \
105 #define _hypercall4(type, name, a1, a2, a3, a4) \
107 long __res, __ign1, __ign2, __ign3; \
110 HYPERCALL_STR(name) \
111 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
113 : "1" ((long)(a1)), "2" ((long)(a2)), \
114 "3" ((long)(a3)), "g" ((long)(a4)) \
115 : "memory", "r10" ); \
119 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
121 long __res, __ign1, __ign2, __ign3; \
123 "movq %7,%%r10; movq %8,%%r8; " \
124 HYPERCALL_STR(name) \
125 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
127 : "1" ((long)(a1)), "2" ((long)(a2)), \
128 "3" ((long)(a3)), "g" ((long)(a4)), \
130 : "memory", "r10", "r8" ); \
135 HYPERVISOR_set_trap_table(
138 return _hypercall1(int, set_trap_table, table);
142 HYPERVISOR_mmu_update(
143 mmu_update_t *req, int count, int *success_count, domid_t domid)
145 return _hypercall4(int, mmu_update, req, count, success_count, domid);
149 HYPERVISOR_mmuext_op(
150 struct mmuext_op *op, int count, int *success_count, domid_t domid)
152 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
157 unsigned long *frame_list, int entries)
159 return _hypercall2(int, set_gdt, frame_list, entries);
163 HYPERVISOR_stack_switch(
164 unsigned long ss, unsigned long esp)
166 return _hypercall2(int, stack_switch, ss, esp);
170 HYPERVISOR_set_callbacks(
171 unsigned long event_address, unsigned long failsafe_address,
172 unsigned long syscall_address)
174 return _hypercall3(int, set_callbacks,
175 event_address, failsafe_address, syscall_address);
179 HYPERVISOR_fpu_taskswitch(
182 return _hypercall1(int, fpu_taskswitch, set);
186 HYPERVISOR_sched_op_compat(
187 int cmd, unsigned long arg)
189 return _hypercall2(int, sched_op_compat, cmd, arg);
196 return _hypercall2(int, sched_op, cmd, arg);
200 HYPERVISOR_set_timer_op(
203 return _hypercall1(long, set_timer_op, timeout);
210 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
211 return _hypercall1(int, dom0_op, dom0_op);
215 HYPERVISOR_set_debugreg(
216 int reg, unsigned long value)
218 return _hypercall2(int, set_debugreg, reg, value);
221 static inline unsigned long
222 HYPERVISOR_get_debugreg(
225 return _hypercall1(unsigned long, get_debugreg, reg);
229 HYPERVISOR_update_descriptor(
230 unsigned long ma, unsigned long word)
232 return _hypercall2(int, update_descriptor, ma, word);
236 HYPERVISOR_memory_op(
237 unsigned int cmd, void *arg)
239 return _hypercall2(int, memory_op, cmd, arg);
243 HYPERVISOR_multicall(
244 void *call_list, int nr_calls)
246 return _hypercall2(int, multicall, call_list, nr_calls);
250 HYPERVISOR_update_va_mapping(
251 unsigned long va, pte_t new_val, unsigned long flags)
253 return _hypercall3(int, update_va_mapping, va, new_val.pte, flags);
257 HYPERVISOR_event_channel_op(
260 int rc = _hypercall2(int, event_channel_op, cmd, arg);
261 if (unlikely(rc == -ENOSYS)) {
264 memcpy(&op.u, arg, sizeof(op.u));
265 rc = _hypercall1(int, event_channel_op_compat, &op);
266 memcpy(arg, &op.u, sizeof(op.u));
275 return _hypercall2(int, acm_op, cmd, arg);
279 HYPERVISOR_xen_version(
282 return _hypercall2(int, xen_version, cmd, arg);
286 HYPERVISOR_console_io(
287 int cmd, int count, char *str)
289 return _hypercall3(int, console_io, cmd, count, str);
293 HYPERVISOR_physdev_op(
296 int rc = _hypercall2(int, physdev_op, cmd, arg);
297 if (unlikely(rc == -ENOSYS)) {
298 struct physdev_op op;
300 memcpy(&op.u, arg, sizeof(op.u));
301 rc = _hypercall1(int, physdev_op_compat, &op);
302 memcpy(arg, &op.u, sizeof(op.u));
308 HYPERVISOR_grant_table_op(
309 unsigned int cmd, void *uop, unsigned int count)
311 return _hypercall3(int, grant_table_op, cmd, uop, count);
315 HYPERVISOR_update_va_mapping_otherdomain(
316 unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
318 return _hypercall4(int, update_va_mapping_otherdomain, va,
319 new_val.pte, flags, domid);
323 HYPERVISOR_vm_assist(
324 unsigned int cmd, unsigned int type)
326 return _hypercall2(int, vm_assist, cmd, type);
331 int cmd, int vcpuid, void *extra_args)
333 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
337 HYPERVISOR_set_segment_base(
338 int reg, unsigned long value)
340 return _hypercall2(int, set_segment_base, reg, value);
347 struct sched_shutdown sched_shutdown = {
348 .reason = SHUTDOWN_suspend
351 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
352 &sched_shutdown, srec);
355 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
356 SHUTDOWN_suspend, srec);
363 unsigned long op, void *arg)
365 return _hypercall2(int, nmi_op, op, arg);
368 static inline unsigned long
372 return _hypercall2(unsigned long, hvm_op, op, arg);
376 HYPERVISOR_callback_op(
379 return _hypercall2(int, callback_op, cmd, arg);
383 HYPERVISOR_xenoprof_op(
386 return _hypercall2(int, xenoprof_op, op, arg);
389 #endif /* __HYPERCALL_H__ */