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/errno.h>
37 #include <linux/string.h>
39 #include <xen/interface/xen.h>
40 #include <xen/interface/sched.h>
41 #include <xen/interface/physdev.h>
43 extern struct { char _entry
[32]; } hypercall_page
[];
45 #define _hypercall0(type, name) \
51 : [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
56 #define _hypercall1(type, name, a1) \
61 : "=a" (__res), "=b" (__ign1) \
63 [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
68 #define _hypercall2(type, name, a1, a2) \
70 long __res, __ign1, __ign2; \
73 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \
74 : "1" ((long)(a1)), "2" ((long)(a2)), \
75 [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
80 #define _hypercall3(type, name, a1, a2, a3) \
82 long __res, __ign1, __ign2, __ign3; \
85 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
87 : "1" ((long)(a1)), "2" ((long)(a2)), \
89 [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
94 #define _hypercall4(type, name, a1, a2, a3, a4) \
96 long __res, __ign1, __ign2, __ign3, __ign4; \
99 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
100 "=d" (__ign3), "=S" (__ign4) \
101 : "1" ((long)(a1)), "2" ((long)(a2)), \
102 "3" ((long)(a3)), "4" ((long)(a4)), \
103 [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
108 #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
110 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \
113 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \
114 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \
115 : "1" ((long)(a1)), "2" ((long)(a2)), \
116 "3" ((long)(a3)), "4" ((long)(a4)), \
118 [call] "m" (hypercall_page[__HYPERVISOR_##name]) \
124 HYPERVISOR_set_trap_table(struct trap_info
*table
)
126 return _hypercall1(int, set_trap_table
, table
);
130 HYPERVISOR_mmu_update(struct mmu_update
*req
, int count
,
131 int *success_count
, domid_t domid
)
133 return _hypercall4(int, mmu_update
, req
, count
, success_count
, domid
);
137 HYPERVISOR_mmuext_op(struct mmuext_op
*op
, int count
,
138 int *success_count
, domid_t domid
)
140 return _hypercall4(int, mmuext_op
, op
, count
, success_count
, domid
);
144 HYPERVISOR_set_gdt(unsigned long *frame_list
, int entries
)
146 return _hypercall2(int, set_gdt
, frame_list
, entries
);
150 HYPERVISOR_stack_switch(unsigned long ss
, unsigned long esp
)
152 return _hypercall2(int, stack_switch
, ss
, esp
);
156 HYPERVISOR_set_callbacks(unsigned long event_selector
,
157 unsigned long event_address
,
158 unsigned long failsafe_selector
,
159 unsigned long failsafe_address
)
161 return _hypercall4(int, set_callbacks
,
162 event_selector
, event_address
,
163 failsafe_selector
, failsafe_address
);
167 HYPERVISOR_fpu_taskswitch(int set
)
169 return _hypercall1(int, fpu_taskswitch
, set
);
173 HYPERVISOR_sched_op(int cmd
, unsigned long arg
)
175 return _hypercall2(int, sched_op
, cmd
, arg
);
179 HYPERVISOR_set_timer_op(u64 timeout
)
181 unsigned long timeout_hi
= (unsigned long)(timeout
>>32);
182 unsigned long timeout_lo
= (unsigned long)timeout
;
183 return _hypercall2(long, set_timer_op
, timeout_lo
, timeout_hi
);
187 HYPERVISOR_set_debugreg(int reg
, unsigned long value
)
189 return _hypercall2(int, set_debugreg
, reg
, value
);
192 static inline unsigned long
193 HYPERVISOR_get_debugreg(int reg
)
195 return _hypercall1(unsigned long, get_debugreg
, reg
);
199 HYPERVISOR_update_descriptor(u64 ma
, u64 desc
)
201 return _hypercall4(int, update_descriptor
, ma
, ma
>>32, desc
, desc
>>32);
205 HYPERVISOR_memory_op(unsigned int cmd
, void *arg
)
207 return _hypercall2(int, memory_op
, cmd
, arg
);
211 HYPERVISOR_multicall(void *call_list
, int nr_calls
)
213 return _hypercall2(int, multicall
, call_list
, nr_calls
);
217 HYPERVISOR_update_va_mapping(unsigned long va
, pte_t new_val
,
220 unsigned long pte_hi
= 0;
221 #ifdef CONFIG_X86_PAE
222 pte_hi
= new_val
.pte_high
;
224 return _hypercall4(int, update_va_mapping
, va
,
225 new_val
.pte_low
, pte_hi
, flags
);
229 HYPERVISOR_event_channel_op(int cmd
, void *arg
)
231 int rc
= _hypercall2(int, event_channel_op
, cmd
, arg
);
232 if (unlikely(rc
== -ENOSYS
)) {
235 memcpy(&op
.u
, arg
, sizeof(op
.u
));
236 rc
= _hypercall1(int, event_channel_op_compat
, &op
);
237 memcpy(arg
, &op
.u
, sizeof(op
.u
));
243 HYPERVISOR_xen_version(int cmd
, void *arg
)
245 return _hypercall2(int, xen_version
, cmd
, arg
);
249 HYPERVISOR_console_io(int cmd
, int count
, char *str
)
251 return _hypercall3(int, console_io
, cmd
, count
, str
);
255 HYPERVISOR_physdev_op(int cmd
, void *arg
)
257 int rc
= _hypercall2(int, physdev_op
, cmd
, arg
);
258 if (unlikely(rc
== -ENOSYS
)) {
259 struct physdev_op op
;
261 memcpy(&op
.u
, arg
, sizeof(op
.u
));
262 rc
= _hypercall1(int, physdev_op_compat
, &op
);
263 memcpy(arg
, &op
.u
, sizeof(op
.u
));
269 HYPERVISOR_grant_table_op(unsigned int cmd
, void *uop
, unsigned int count
)
271 return _hypercall3(int, grant_table_op
, cmd
, uop
, count
);
275 HYPERVISOR_update_va_mapping_otherdomain(unsigned long va
, pte_t new_val
,
276 unsigned long flags
, domid_t domid
)
278 unsigned long pte_hi
= 0;
279 #ifdef CONFIG_X86_PAE
280 pte_hi
= new_val
.pte_high
;
282 return _hypercall5(int, update_va_mapping_otherdomain
, va
,
283 new_val
.pte_low
, pte_hi
, flags
, domid
);
287 HYPERVISOR_vm_assist(unsigned int cmd
, unsigned int type
)
289 return _hypercall2(int, vm_assist
, cmd
, type
);
293 HYPERVISOR_vcpu_op(int cmd
, int vcpuid
, void *extra_args
)
295 return _hypercall3(int, vcpu_op
, cmd
, vcpuid
, extra_args
);
299 HYPERVISOR_suspend(unsigned long srec
)
301 return _hypercall3(int, sched_op
, SCHEDOP_shutdown
,
302 SHUTDOWN_suspend
, srec
);
306 HYPERVISOR_nmi_op(unsigned long op
, unsigned long arg
)
308 return _hypercall2(int, nmi_op
, op
, arg
);
312 MULTI_update_va_mapping(struct multicall_entry
*mcl
, unsigned long va
,
313 pte_t new_val
, unsigned long flags
)
315 mcl
->op
= __HYPERVISOR_update_va_mapping
;
317 #ifdef CONFIG_X86_PAE
318 mcl
->args
[1] = new_val
.pte_low
;
319 mcl
->args
[2] = new_val
.pte_high
;
321 mcl
->args
[1] = new_val
.pte_low
;
324 mcl
->args
[3] = flags
;
328 MULTI_grant_table_op(struct multicall_entry
*mcl
, unsigned int cmd
,
329 void *uop
, unsigned int count
)
331 mcl
->op
= __HYPERVISOR_grant_table_op
;
333 mcl
->args
[1] = (unsigned long)uop
;
334 mcl
->args
[2] = count
;
338 MULTI_update_va_mapping_otherdomain(struct multicall_entry
*mcl
, unsigned long va
,
339 pte_t new_val
, unsigned long flags
,
342 mcl
->op
= __HYPERVISOR_update_va_mapping_otherdomain
;
344 #ifdef CONFIG_X86_PAE
345 mcl
->args
[1] = new_val
.pte_low
;
346 mcl
->args
[2] = new_val
.pte_high
;
348 mcl
->args
[1] = new_val
.pte_low
;
351 mcl
->args
[3] = flags
;
352 mcl
->args
[4] = domid
;
356 MULTI_update_descriptor(struct multicall_entry
*mcl
, u64 maddr
,
357 struct desc_struct desc
)
359 mcl
->op
= __HYPERVISOR_update_descriptor
;
360 mcl
->args
[0] = maddr
;
361 mcl
->args
[1] = maddr
>> 32;
362 mcl
->args
[2] = desc
.a
;
363 mcl
->args
[3] = desc
.b
;
367 MULTI_memory_op(struct multicall_entry
*mcl
, unsigned int cmd
, void *arg
)
369 mcl
->op
= __HYPERVISOR_memory_op
;
371 mcl
->args
[1] = (unsigned long)arg
;
375 MULTI_mmu_update(struct multicall_entry
*mcl
, struct mmu_update
*req
,
376 int count
, int *success_count
, domid_t domid
)
378 mcl
->op
= __HYPERVISOR_mmu_update
;
379 mcl
->args
[0] = (unsigned long)req
;
380 mcl
->args
[1] = count
;
381 mcl
->args
[2] = (unsigned long)success_count
;
382 mcl
->args
[3] = domid
;
386 MULTI_mmuext_op(struct multicall_entry
*mcl
, struct mmuext_op
*op
, int count
,
387 int *success_count
, domid_t domid
)
389 mcl
->op
= __HYPERVISOR_mmuext_op
;
390 mcl
->args
[0] = (unsigned long)op
;
391 mcl
->args
[1] = count
;
392 mcl
->args
[2] = (unsigned long)success_count
;
393 mcl
->args
[3] = domid
;
397 MULTI_set_gdt(struct multicall_entry
*mcl
, unsigned long *frames
, int entries
)
399 mcl
->op
= __HYPERVISOR_set_gdt
;
400 mcl
->args
[0] = (unsigned long)frames
;
401 mcl
->args
[1] = entries
;
405 MULTI_stack_switch(struct multicall_entry
*mcl
,
406 unsigned long ss
, unsigned long esp
)
408 mcl
->op
= __HYPERVISOR_stack_switch
;
413 #endif /* __HYPERCALL_H__ */