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 #ifndef __HYPERVISOR_H__
41 # error "please don't include this file directly"
44 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
45 # include <xen/interface/platform.h>
46 # include <xen/interface/arch-x86/xen-mca.h>
48 #if CONFIG_XEN_COMPAT <= 0x030002
49 # include <linux/string.h> /* memcpy() */
50 # include <xen/interface/event_channel.h>
51 # include <xen/interface/physdev.h>
55 #define HYPERCALL_ASM_OPERAND "%c"
56 #define HYPERCALL_LOCATION(op) (hypercall_page + (op) * 32)
57 #define HYPERCALL_C_OPERAND(name) "i" (HYPERCALL_LOCATION(__HYPERVISOR_##name))
59 #define HYPERCALL_ASM_OPERAND "*%"
60 #define HYPERCALL_LOCATION(op) (hypercall_stubs + (op) * 32)
61 #define HYPERCALL_C_OPERAND(name) "g" (HYPERCALL_LOCATION(__HYPERVISOR_##name))
64 #define HYPERCALL_ARG(arg, n) \
65 register typeof((arg)+0) __arg##n asm(HYPERCALL_arg##n) = (arg)
67 #define _hypercall0(type, name) \
71 "call " HYPERCALL_ASM_OPERAND "1" \
73 : HYPERCALL_C_OPERAND(name) \
78 #define _hypercall1(type, name, arg) \
81 HYPERCALL_ARG(arg, 1); \
83 "call " HYPERCALL_ASM_OPERAND "2" \
84 : "=a" (__res), "+r" (__arg1) \
85 : HYPERCALL_C_OPERAND(name) \
90 #define _hypercall2(type, name, a1, a2) \
93 HYPERCALL_ARG(a1, 1); \
94 HYPERCALL_ARG(a2, 2); \
96 "call " HYPERCALL_ASM_OPERAND "3" \
97 : "=a" (__res), "+r" (__arg1), "+r" (__arg2) \
98 : HYPERCALL_C_OPERAND(name) \
103 #define _hypercall3(type, name, a1, a2, a3) \
106 HYPERCALL_ARG(a1, 1); \
107 HYPERCALL_ARG(a2, 2); \
108 HYPERCALL_ARG(a3, 3); \
110 "call " HYPERCALL_ASM_OPERAND "4" \
111 : "=a" (__res), "+r" (__arg1), \
112 "+r" (__arg2), "+r" (__arg3) \
113 : HYPERCALL_C_OPERAND(name) \
118 #define _hypercall4(type, name, a1, a2, a3, a4) \
121 HYPERCALL_ARG(a1, 1); \
122 HYPERCALL_ARG(a2, 2); \
123 HYPERCALL_ARG(a3, 3); \
124 HYPERCALL_ARG(a4, 4); \
126 "call " HYPERCALL_ASM_OPERAND "5" \
127 : "=a" (__res), "+r" (__arg1), "+r" (__arg2), \
128 "+r" (__arg3), "+r" (__arg4) \
129 : HYPERCALL_C_OPERAND(name) \
134 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
137 HYPERCALL_ARG(a1, 1); \
138 HYPERCALL_ARG(a2, 2); \
139 HYPERCALL_ARG(a3, 3); \
140 HYPERCALL_ARG(a4, 4); \
141 HYPERCALL_ARG(a5, 5); \
143 "call " HYPERCALL_ASM_OPERAND "6" \
144 : "=a" (__res), "+r" (__arg1), "+r" (__arg2), \
145 "+r" (__arg3), "+r" (__arg4), "+r" (__arg5) \
146 : HYPERCALL_C_OPERAND(name) \
151 #define _hypercall(type, op, a1, a2, a3, a4, a5) \
154 HYPERCALL_ARG(a1, 1); \
155 HYPERCALL_ARG(a2, 2); \
156 HYPERCALL_ARG(a3, 3); \
157 HYPERCALL_ARG(a4, 4); \
158 HYPERCALL_ARG(a5, 5); \
161 : "=a" (__res), "+r" (__arg1), "+r" (__arg2), \
162 "+r" (__arg3), "+r" (__arg4), "+r" (__arg5) \
163 : "g" (HYPERCALL_LOCATION(op)) \
169 # include "hypercall_32.h"
171 # include "hypercall_64.h"
174 static inline int __must_check
175 HYPERVISOR_set_trap_table(
176 const trap_info_t *table)
178 return _hypercall1(int, set_trap_table, table);
181 static inline int __must_check
182 HYPERVISOR_mmu_update(
183 mmu_update_t *req, unsigned int count, unsigned int *success_count,
186 if (arch_use_lazy_mmu_mode())
187 return xen_multi_mmu_update(req, count, success_count, domid);
188 return _hypercall4(int, mmu_update, req, count, success_count, domid);
191 static inline int __must_check
192 HYPERVISOR_mmuext_op(
193 struct mmuext_op *op, unsigned int count, unsigned int *success_count,
196 if (arch_use_lazy_mmu_mode())
197 return xen_multi_mmuext_op(op, count, success_count, domid);
198 return _hypercall4(int, mmuext_op, op, count, success_count, domid);
201 static inline int __must_check
203 unsigned long *frame_list, unsigned int entries)
205 return _hypercall2(int, set_gdt, frame_list, entries);
208 static inline int __must_check
209 HYPERVISOR_stack_switch(
210 unsigned long ss, unsigned long esp)
212 return _hypercall2(int, stack_switch, ss, esp);
216 HYPERVISOR_fpu_taskswitch(
219 return _hypercall1(int, fpu_taskswitch, set);
222 #if CONFIG_XEN_COMPAT <= 0x030002
223 static inline int __must_check
224 HYPERVISOR_sched_op_compat(
225 int cmd, unsigned long arg)
227 return _hypercall2(int, sched_op_compat, cmd, arg);
231 static inline int __must_check
235 return _hypercall2(int, sched_op, cmd, arg);
238 #ifdef CONFIG_XEN_PRIVILEGED_GUEST
239 static inline int __must_check
240 HYPERVISOR_platform_op(
241 struct xen_platform_op *platform_op)
243 platform_op->interface_version = XENPF_INTERFACE_VERSION;
244 return _hypercall1(int, platform_op, platform_op);
247 static inline int __must_check
249 struct xen_mc *mc_op)
251 mc_op->interface_version = XEN_MCA_INTERFACE_VERSION;
252 return _hypercall1(int, mca, mc_op);
256 static inline int __must_check
257 HYPERVISOR_set_debugreg(
258 unsigned int reg, unsigned long value)
260 return _hypercall2(int, set_debugreg, reg, value);
263 static inline unsigned long __must_check
264 HYPERVISOR_get_debugreg(
267 return _hypercall1(unsigned long, get_debugreg, reg);
270 static inline int __must_check
271 HYPERVISOR_memory_op(
272 unsigned int cmd, void *arg)
274 if (arch_use_lazy_mmu_mode())
275 xen_multicall_flush();
276 return _hypercall2(int, memory_op, cmd, arg);
279 static inline int __must_check
280 HYPERVISOR_multicall(
281 multicall_entry_t *call_list, unsigned int nr_calls)
283 return _hypercall2(int, multicall, call_list, nr_calls);
286 static inline int __must_check
287 HYPERVISOR_event_channel_op(
290 int rc = _hypercall2(int, event_channel_op, cmd, arg);
292 #if CONFIG_XEN_COMPAT <= 0x030002
293 if (unlikely(rc == -ENOSYS)) {
296 memcpy(&op.u, arg, sizeof(op.u));
297 rc = _hypercall1(int, event_channel_op_compat, &op);
298 memcpy(arg, &op.u, sizeof(op.u));
305 static inline int __must_check
306 HYPERVISOR_xen_version(
309 return _hypercall2(int, xen_version, cmd, arg);
312 static inline int __must_check
313 HYPERVISOR_console_io(
314 int cmd, unsigned int count, char *str)
316 return _hypercall3(int, console_io, cmd, count, str);
319 static inline int __must_check
320 HYPERVISOR_physdev_op(
323 int rc = _hypercall2(int, physdev_op, cmd, arg);
325 #if CONFIG_XEN_COMPAT <= 0x030002
326 if (unlikely(rc == -ENOSYS)) {
327 struct physdev_op op;
329 memcpy(&op.u, arg, sizeof(op.u));
330 rc = _hypercall1(int, physdev_op_compat, &op);
331 memcpy(arg, &op.u, sizeof(op.u));
338 static inline int __must_check
339 HYPERVISOR_grant_table_op(
340 unsigned int cmd, void *uop, unsigned int count)
345 if (arch_use_lazy_mmu_mode())
346 xen_multicall_flush();
347 #ifdef GNTTABOP_map_grant_ref
348 if (cmd == GNTTABOP_map_grant_ref)
350 fixup = gnttab_pre_map_adjust(cmd, uop, count);
351 rc = _hypercall3(int, grant_table_op, cmd, uop, count);
352 if (rc == 0 && fixup)
353 rc = gnttab_post_map_adjust(uop, count);
357 static inline int __must_check
358 HYPERVISOR_vm_assist(
359 unsigned int cmd, unsigned int type)
361 return _hypercall2(int, vm_assist, cmd, type);
364 static inline int __must_check
366 int cmd, unsigned int vcpuid, void *extra_args)
368 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args);
371 static inline int __must_check
375 struct sched_shutdown sched_shutdown = {
376 .reason = SHUTDOWN_suspend
379 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown,
380 &sched_shutdown, srec);
382 #if CONFIG_XEN_COMPAT <= 0x030002
384 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown,
385 SHUTDOWN_suspend, srec);
391 #if CONFIG_XEN_COMPAT <= 0x030002
394 unsigned long op, void *arg)
396 return _hypercall2(int, nmi_op, op, arg);
401 static inline unsigned long __must_check
405 return _hypercall2(unsigned long, hvm_op, op, arg);
409 static inline int __must_check
410 HYPERVISOR_callback_op(
411 int cmd, const void *arg)
413 return _hypercall2(int, callback_op, cmd, arg);
416 static inline int __must_check
417 HYPERVISOR_xenoprof_op(
420 return _hypercall2(int, xenoprof_op, op, arg);
423 static inline int __must_check
425 unsigned long op, void *args)
427 return _hypercall2(int, kexec_op, op, args);
432 static inline int __must_check
436 return _hypercall1(int, tmem_op, (void *)op);
439 #endif /* __HYPERCALL_H__ */