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)
46 #define HYPERCALL_STR(name) \
47 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)"
49 #define HYPERCALL_STR(name) \
50 "mov hypercall_stubs,%%eax; " \
51 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \
55 #define _hypercall0(type, name) \
66 #define _hypercall1(type, name, a1) \
71 : "=a" (__res), "=b" (__ign1) \
77 #define _hypercall2(type, name, a1, a2) \
79 long __res, __ign1, __ign2; \
82 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \
83 : "1" ((long)(a1)), "2" ((long)(a2)) \
88 #define _hypercall3(type, name, a1, a2, a3) \
90 long __res, __ign1, __ign2, __ign3; \
93 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
95 : "1" ((long)(a1)), "2" ((long)(a2)), \
101 #define _hypercall4(type, name, a1, a2, a3, a4) \
103 long __res, __ign1, __ign2, __ign3, __ign4; \
105 HYPERCALL_STR(name) \
106 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
107 "=d" (__ign3), "=S" (__ign4) \
108 : "1" ((long)(a1)), "2" ((long)(a2)), \
109 "3" ((long)(a3)), "4" ((long)(a4)) \
114 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
116 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \
118 HYPERCALL_STR(name) \
119 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
120 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \
121 : "1" ((long)(a1)), "2" ((long)(a2)), \
122 "3" ((long)(a3)), "4" ((long)(a4)), \
129 HYPERVISOR_set_trap_table(
132 return _hypercall1(int, set_trap_table, table);
136 HYPERVISOR_mmu_update(
137 mmu_update_t *req, int count, int *success_count, domid_t domid)
139 return _hypercall4(int, mmu_update, req, count, success_count, domid);
143 HYPERVISOR_mmuext_op(
144 struct mmuext_op *op, int count, int *success_count, domid_t domid)
146 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
151 unsigned long *frame_list, int entries)
153 return _hypercall2(int, set_gdt, frame_list, entries);
157 HYPERVISOR_stack_switch(
158 unsigned long ss, unsigned long esp)
160 return _hypercall2(int, stack_switch, ss, esp);
164 HYPERVISOR_set_callbacks(
165 unsigned long event_selector, unsigned long event_address,
166 unsigned long failsafe_selector, unsigned long failsafe_address)
168 return _hypercall4(int, set_callbacks,
169 event_selector, event_address,
170 failsafe_selector, failsafe_address);
174 HYPERVISOR_fpu_taskswitch(
177 return _hypercall1(int, fpu_taskswitch, set);
181 HYPERVISOR_sched_op_compat(
182 int cmd, unsigned long arg)
184 return _hypercall2(int, sched_op_compat, cmd, arg);
191 return _hypercall2(int, sched_op, cmd, arg);
195 HYPERVISOR_set_timer_op(
198 unsigned long timeout_hi = (unsigned long)(timeout>>32);
199 unsigned long timeout_lo = (unsigned long)timeout;
200 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
207 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
208 return _hypercall1(int, dom0_op, dom0_op);
212 HYPERVISOR_set_debugreg(
213 int reg, unsigned long value)
215 return _hypercall2(int, set_debugreg, reg, value);
218 static inline unsigned long
219 HYPERVISOR_get_debugreg(
222 return _hypercall1(unsigned long, get_debugreg, reg);
226 HYPERVISOR_update_descriptor(
229 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32);
233 HYPERVISOR_memory_op(
234 unsigned int cmd, void *arg)
236 return _hypercall2(int, memory_op, cmd, arg);
240 HYPERVISOR_multicall(
241 void *call_list, int nr_calls)
243 return _hypercall2(int, multicall, call_list, nr_calls);
247 HYPERVISOR_update_va_mapping(
248 unsigned long va, pte_t new_val, unsigned long flags)
250 unsigned long pte_hi = 0;
251 #ifdef CONFIG_X86_PAE
252 pte_hi = new_val.pte_high;
254 return _hypercall4(int, update_va_mapping, va,
255 new_val.pte_low, pte_hi, flags);
259 HYPERVISOR_event_channel_op(
262 int rc = _hypercall2(int, event_channel_op, cmd, arg);
263 if (unlikely(rc == -ENOSYS)) {
266 memcpy(&op.u, arg, sizeof(op.u));
267 rc = _hypercall1(int, event_channel_op_compat, &op);
268 memcpy(arg, &op.u, sizeof(op.u));
277 return _hypercall2(int, acm_op, cmd, arg);
281 HYPERVISOR_xen_version(
284 return _hypercall2(int, xen_version, cmd, arg);
288 HYPERVISOR_console_io(
289 int cmd, int count, char *str)
291 return _hypercall3(int, console_io, cmd, count, str);
295 HYPERVISOR_physdev_op(
298 int rc = _hypercall2(int, physdev_op, cmd, arg);
299 if (unlikely(rc == -ENOSYS)) {
300 struct physdev_op op;
302 memcpy(&op.u, arg, sizeof(op.u));
303 rc = _hypercall1(int, physdev_op_compat, &op);
304 memcpy(arg, &op.u, sizeof(op.u));
310 HYPERVISOR_grant_table_op(
311 unsigned int cmd, void *uop, unsigned int count)
313 return _hypercall3(int, grant_table_op, cmd, uop, count);
317 HYPERVISOR_update_va_mapping_otherdomain(
318 unsigned long va, pte_t new_val, unsigned long flags, domid_t domid)
320 unsigned long pte_hi = 0;
321 #ifdef CONFIG_X86_PAE
322 pte_hi = new_val.pte_high;
324 return _hypercall5(int, update_va_mapping_otherdomain, va,
325 new_val.pte_low, pte_hi, flags, domid);
329 HYPERVISOR_vm_assist(
330 unsigned int cmd, unsigned int type)
332 return _hypercall2(int, vm_assist, cmd, type);
337 int cmd, int vcpuid, void *extra_args)
339 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
346 struct sched_shutdown sched_shutdown = {
347 .reason = SHUTDOWN_suspend
350 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
351 &sched_shutdown, srec);
354 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
355 SHUTDOWN_suspend, srec);
362 unsigned long op, void *arg)
364 return _hypercall2(int, nmi_op, op, arg);
367 static inline unsigned long
371 return _hypercall2(unsigned long, hvm_op, op, arg);
375 HYPERVISOR_callback_op(
378 return _hypercall2(int, callback_op, cmd, arg);
382 HYPERVISOR_xenoprof_op(
385 return _hypercall2(int, xenoprof_op, op, arg);
389 #endif /* __HYPERCALL_H__ */