1 /******************************************************************************
4 * Linux-specific hypervisor handling.
6 * Copyright (c) 2002-2004, K A Fraser
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation; or, when distributed
11 * separately from the Linux kernel or incorporated into other
12 * software packages, subject to the following license:
14 * Permission is hereby granted, free of charge, to any person obtaining a copy
15 * of this source file (the "Software"), to deal in the Software without
16 * restriction, including without limitation the rights to use, copy, modify,
17 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
18 * and to permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
21 * The above copyright notice and this permission notice shall be included in
22 * all copies or substantial portions of the Software.
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
33 #ifndef __HYPERCALL_H__
34 #define __HYPERCALL_H__
36 #include <linux/string.h> /* memcpy() */
38 #ifndef __HYPERVISOR_H__
39 # error "please don't include this file directly"
43 #define STR(x) __STR(x)
45 #define _hypercall0(type, name) \
49 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
56 #define _hypercall1(type, name, a1) \
60 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
61 : "=a" (__res), "=b" (__ign1) \
67 #define _hypercall2(type, name, a1, a2) \
69 long __res, __ign1, __ign2; \
71 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
72 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \
73 : "1" ((long)(a1)), "2" ((long)(a2)) \
78 #define _hypercall3(type, name, a1, a2, a3) \
80 long __res, __ign1, __ign2, __ign3; \
82 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
83 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
85 : "1" ((long)(a1)), "2" ((long)(a2)), \
91 #define _hypercall4(type, name, a1, a2, a3, a4) \
93 long __res, __ign1, __ign2, __ign3, __ign4; \
95 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
96 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
97 "=d" (__ign3), "=S" (__ign4) \
98 : "1" ((long)(a1)), "2" ((long)(a2)), \
99 "3" ((long)(a3)), "4" ((long)(a4)) \
104 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
106 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \
108 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"\
109 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
110 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \
111 : "1" ((long)(a1)), "2" ((long)(a2)), \
112 "3" ((long)(a3)), "4" ((long)(a4)), \
119 HYPERVISOR_set_trap_table(
122 return _hypercall1(int, set_trap_table, table);
126 HYPERVISOR_mmu_update(
127 mmu_update_t *req, int count, int *success_count, domid_t domid)
129 return _hypercall4(int, mmu_update, req, count, success_count, domid);
133 HYPERVISOR_mmuext_op(
134 struct mmuext_op *op, int count, int *success_count, domid_t domid)
136 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
141 unsigned long *frame_list, int entries)
143 return _hypercall2(int, set_gdt, frame_list, entries);
147 HYPERVISOR_stack_switch(
148 unsigned long ss, unsigned long esp)
150 return _hypercall2(int, stack_switch, ss, esp);
154 HYPERVISOR_set_callbacks(
155 unsigned long event_selector, unsigned long event_address,
156 unsigned long failsafe_selector, unsigned long failsafe_address)
158 return _hypercall4(int, set_callbacks,
159 event_selector, event_address,
160 failsafe_selector, failsafe_address);
164 HYPERVISOR_fpu_taskswitch(
167 return _hypercall1(int, fpu_taskswitch, set);
171 HYPERVISOR_sched_op_compat(
172 int cmd, unsigned long arg)
174 return _hypercall2(int, sched_op_compat, cmd, arg);
181 return _hypercall2(int, sched_op, cmd, arg);
185 HYPERVISOR_set_timer_op(
188 unsigned long timeout_hi = (unsigned long)(timeout>>32);
189 unsigned long timeout_lo = (unsigned long)timeout;
190 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
197 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
198 return _hypercall1(int, dom0_op, dom0_op);
202 HYPERVISOR_set_debugreg(
203 int reg, unsigned long value)
205 return _hypercall2(int, set_debugreg, reg, value);
208 static inline unsigned long
209 HYPERVISOR_get_debugreg(
212 return _hypercall1(unsigned long, get_debugreg, reg);
216 HYPERVISOR_update_descriptor(
219 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
223 HYPERVISOR_memory_op(
224 unsigned int cmd, void *arg)
226 return _hypercall2(int, memory_op, cmd, arg);
230 HYPERVISOR_multicall(
231 void *call_list, int nr_calls)
233 return _hypercall2(int, multicall, call_list, nr_calls);
237 HYPERVISOR_update_va_mapping(
238 unsigned long va, pte_t new_val, unsigned long flags)
240 unsigned long pte_hi = 0;
241 #ifdef CONFIG_X86_PAE
242 pte_hi = new_val.pte_high;
244 return _hypercall4(int, update_va_mapping, va,
245 new_val.pte_low, pte_hi, flags);
249 HYPERVISOR_event_channel_op(
252 int rc = _hypercall2(int, event_channel_op, cmd, arg);
253 if (unlikely(rc == -ENOSYS)) {
256 memcpy(&op.u, arg, sizeof(op.u));
257 rc = _hypercall1(int, event_channel_op_compat, &op);
258 memcpy(arg, &op.u, sizeof(op.u));
267 return _hypercall2(int, acm_op, cmd, arg);
271 HYPERVISOR_xen_version(
274 return _hypercall2(int, xen_version, cmd, arg);
278 HYPERVISOR_console_io(
279 int cmd, int count, char *str)
281 return _hypercall3(int, console_io, cmd, count, str);
285 HYPERVISOR_physdev_op(
288 int rc = _hypercall2(int, physdev_op, cmd, arg);
289 if (unlikely(rc == -ENOSYS)) {
290 struct physdev_op op;
292 memcpy(&op.u, arg, sizeof(op.u));
293 rc = _hypercall1(int, physdev_op_compat, &op);
294 memcpy(arg, &op.u, sizeof(op.u));
300 HYPERVISOR_grant_table_op(
301 unsigned int cmd, void *uop, unsigned int count)
303 return _hypercall3(int, grant_table_op, cmd, uop, count);
307 HYPERVISOR_update_va_mapping_otherdomain(
308 unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
310 unsigned long pte_hi = 0;
311 #ifdef CONFIG_X86_PAE
312 pte_hi = new_val.pte_high;
314 return _hypercall5(int, update_va_mapping_otherdomain, va,
315 new_val.pte_low, pte_hi, flags, domid);
319 HYPERVISOR_vm_assist(
320 unsigned int cmd, unsigned int type)
322 return _hypercall2(int, vm_assist, cmd, type);
327 int cmd, int vcpuid, void *extra_args)
329 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
336 struct sched_shutdown sched_shutdown = {
337 .reason = SHUTDOWN_suspend
340 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
341 &sched_shutdown, srec);
344 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
345 SHUTDOWN_suspend, srec);
352 unsigned long op, void *arg)
354 return _hypercall2(int, nmi_op, op, arg);
358 HYPERVISOR_callback_op(
361 return _hypercall2(int, callback_op, cmd, arg);
365 HYPERVISOR_xenoprof_op(
368 return _hypercall2(int, xenoprof_op, op, arg);
372 #endif /* __HYPERCALL_H__ */