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)
49 #define _hypercall0(type, name) \
53 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
60 #define _hypercall1(type, name, a1) \
64 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
65 : "=a" (__res), "=D" (__ign1) \
71 #define _hypercall2(type, name, a1, a2) \
73 long __res, __ign1, __ign2; \
75 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
76 : "=a" (__res), "=D" (__ign1), "=S" (__ign2) \
77 : "1" ((long)(a1)), "2" ((long)(a2)) \
82 #define _hypercall3(type, name, a1, a2, a3) \
84 long __res, __ign1, __ign2, __ign3; \
86 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
87 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
89 : "1" ((long)(a1)), "2" ((long)(a2)), \
95 #define _hypercall4(type, name, a1, a2, a3, a4) \
97 long __res, __ign1, __ign2, __ign3; \
100 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
101 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
103 : "1" ((long)(a1)), "2" ((long)(a2)), \
104 "3" ((long)(a3)), "g" ((long)(a4)) \
105 : "memory", "r10" ); \
109 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
111 long __res, __ign1, __ign2, __ign3; \
113 "movq %7,%%r10; movq %8,%%r8; " \
114 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
115 : "=a" (__res), "=D" (__ign1), "=S" (__ign2), \
117 : "1" ((long)(a1)), "2" ((long)(a2)), \
118 "3" ((long)(a3)), "g" ((long)(a4)), \
120 : "memory", "r10", "r8" ); \
125 HYPERVISOR_set_trap_table(
128 return _hypercall1(int, set_trap_table, table);
132 HYPERVISOR_mmu_update(
133 mmu_update_t *req, int count, int *success_count, domid_t domid)
135 return _hypercall4(int, mmu_update, req, count, success_count, domid);
139 HYPERVISOR_mmuext_op(
140 struct mmuext_op *op, int count, int *success_count, domid_t domid)
142 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
147 unsigned long *frame_list, int entries)
149 return _hypercall2(int, set_gdt, frame_list, entries);
153 HYPERVISOR_stack_switch(
154 unsigned long ss, unsigned long esp)
156 return _hypercall2(int, stack_switch, ss, esp);
160 HYPERVISOR_set_callbacks(
161 unsigned long event_address, unsigned long failsafe_address,
162 unsigned long syscall_address)
164 return _hypercall3(int, set_callbacks,
165 event_address, failsafe_address, syscall_address);
169 HYPERVISOR_fpu_taskswitch(
172 return _hypercall1(int, fpu_taskswitch, set);
176 HYPERVISOR_sched_op_compat(
177 int cmd, unsigned long arg)
179 return _hypercall2(int, sched_op_compat, cmd, arg);
186 return _hypercall2(int, sched_op, cmd, arg);
190 HYPERVISOR_set_timer_op(
193 return _hypercall1(long, set_timer_op, timeout);
200 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
201 return _hypercall1(int, dom0_op, dom0_op);
205 HYPERVISOR_set_debugreg(
206 int reg, unsigned long value)
208 return _hypercall2(int, set_debugreg, reg, value);
211 static inline unsigned long
212 HYPERVISOR_get_debugreg(
215 return _hypercall1(unsigned long, get_debugreg, reg);
219 HYPERVISOR_update_descriptor(
220 unsigned long ma, unsigned long word)
222 return _hypercall2(int, update_descriptor, ma, word);
226 HYPERVISOR_memory_op(
227 unsigned int cmd, void *arg)
229 return _hypercall2(int, memory_op, cmd, arg);
233 HYPERVISOR_multicall(
234 void *call_list, int nr_calls)
236 return _hypercall2(int, multicall, call_list, nr_calls);
240 HYPERVISOR_update_va_mapping(
241 unsigned long va, pte_t new_val, unsigned long flags)
243 return _hypercall3(int, update_va_mapping, va, new_val.pte, flags);
247 HYPERVISOR_event_channel_op(
250 int rc = _hypercall2(int, event_channel_op, cmd, arg);
251 if (unlikely(rc == -ENOSYS)) {
254 memcpy(&op.u, arg, sizeof(op.u));
255 rc = _hypercall1(int, event_channel_op_compat, &op);
256 memcpy(arg, &op.u, sizeof(op.u));
265 return _hypercall2(int, acm_op, cmd, arg);
269 HYPERVISOR_xen_version(
272 return _hypercall2(int, xen_version, cmd, arg);
276 HYPERVISOR_console_io(
277 int cmd, int count, char *str)
279 return _hypercall3(int, console_io, cmd, count, str);
283 HYPERVISOR_physdev_op(
286 int rc = _hypercall2(int, physdev_op, cmd, arg);
287 if (unlikely(rc == -ENOSYS)) {
288 struct physdev_op op;
290 memcpy(&op.u, arg, sizeof(op.u));
291 rc = _hypercall1(int, physdev_op_compat, &op);
292 memcpy(arg, &op.u, sizeof(op.u));
298 HYPERVISOR_grant_table_op(
299 unsigned int cmd, void *uop, unsigned int count)
301 return _hypercall3(int, grant_table_op, cmd, uop, count);
305 HYPERVISOR_update_va_mapping_otherdomain(
306 unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
308 return _hypercall4(int, update_va_mapping_otherdomain, va,
309 new_val.pte, flags, domid);
313 HYPERVISOR_vm_assist(
314 unsigned int cmd, unsigned int type)
316 return _hypercall2(int, vm_assist, cmd, type);
321 int cmd, int vcpuid, void *extra_args)
323 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
327 HYPERVISOR_set_segment_base(
328 int reg, unsigned long value)
330 return _hypercall2(int, set_segment_base, reg, value);
337 struct sched_shutdown sched_shutdown = {
338 .reason = SHUTDOWN_suspend
341 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
342 &sched_shutdown, srec);
345 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
346 SHUTDOWN_suspend, srec);
353 unsigned long op, void *arg)
355 return _hypercall2(int, nmi_op, op, arg);
359 HYPERVISOR_callback_op(
362 return _hypercall2(int, callback_op, cmd, arg);
366 HYPERVISOR_xenoprof_op(
369 return _hypercall2(int, xenoprof_op, op, arg);
372 #endif /* __HYPERCALL_H__ */