1 /* $NetBSD: hypercalls.h,v 1.9 2009/07/29 12:02:06 cegger Exp $ */
4 * Copyright (c) 2006 Manuel Bouyer.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * Communication to/from hypervisor.
32 * Copyright (c) 2002-2004, K A Fraser
34 * Permission is hereby granted, free of charge, to any person obtaining a copy
35 * of this source file (the "Software"), to deal in the Software without
36 * restriction, including without limitation the rights to use, copy, modify,
37 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
38 * and to permit persons to whom the Software is furnished to do so, subject to
39 * the following conditions:
41 * The above copyright notice and this permission notice shall be included in
42 * all copies or substantial portions of the Software.
44 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
46 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
47 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
48 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
49 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
54 #ifndef _XENI386_HYPERVISOR_H_
55 #define _XENI386_HYPERVISOR_H_
57 * Assembler stubs for hyper-calls.
60 #include <machine/pte.h> /* pt_entry_t */
62 #if !defined(XEN_COMPAT_030001)
63 /* hypercall via the hypercall call page */
65 #define _str(x) __str(x)
66 #define _hypercall(name, input_const, output_const) \
68 "call hypercall_page + ("_str(name)" * 32)" \
73 /* traditionnal hypercall via int 0x82 */
74 #define _hypercall(name, input_const, output_const) \
78 : "0" (name), input_const \
82 #define _harg(...) __VA_ARGS__
86 HYPERVISOR_set_trap_table(trap_info_t
*table
)
91 _hypercall(__HYPERVISOR_set_trap_table
, _harg("1" (table
)),
92 _harg("=a" (ret
), "=b" (ign1
)));
98 HYPERVISOR_set_gdt(unsigned long *frame_list
, int entries
)
101 unsigned long ign1
, ign2
;
103 _hypercall(__HYPERVISOR_set_gdt
, _harg("1" (frame_list
), "2" (entries
)),
104 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
110 HYPERVISOR_stack_switch(unsigned long ss
, unsigned long esp
)
113 unsigned long ign1
, ign2
;
115 _hypercall(__HYPERVISOR_stack_switch
, _harg("1" (ss
), "2" (esp
)),
116 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
122 HYPERVISOR_set_callbacks(
123 unsigned long event_selector
, unsigned long event_address
,
124 unsigned long failsafe_selector
, unsigned long failsafe_address
)
127 unsigned long ign1
, ign2
, ign3
, ign4
;
129 _hypercall(__HYPERVISOR_set_callbacks
,
130 _harg("1" (event_selector
),"2" (event_address
),
131 "3" (failsafe_selector
), "4" (failsafe_address
)),
132 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
)));
137 #if __XEN_INTERFACE_VERSION__ < 0x00030204
139 HYPERVISOR_dom0_op(dom0_op_t
*dom0_op
)
144 dom0_op
->interface_version
= DOM0_INTERFACE_VERSION
;
145 _hypercall(__HYPERVISOR_dom0_op
, _harg("1" (dom0_op
)),
146 _harg("=a" (ret
), "=b" (ign1
)));
150 #endif /* __XEN_INTERFACE_VERSION__ */
153 HYPERVISOR_set_debugreg(int reg
, unsigned long value
)
156 unsigned long ign1
, ign2
;
158 _hypercall(__HYPERVISOR_set_debugreg
, _harg("1" (reg
), "2" (value
)),
159 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
164 static __inline
unsigned long
165 HYPERVISOR_get_debugreg(int reg
)
170 _hypercall(__HYPERVISOR_get_debugreg
, _harg("1" (reg
)),
171 _harg("=a" (ret
), "=b" (ign1
)));
177 HYPERVISOR_machine_check(struct xen_mc
*mc
)
182 mc
->interface_version
= XEN_MCA_INTERFACE_VERSION
;
183 _hypercall(__HYPERVISOR_mca
, _harg("1" (mc
)),
184 _harg("=a" (ret
), "=b" (ign1
)));
190 HYPERVISOR_hvm_op(int cmd
, void *arg
)
193 unsigned long ign1
, ign2
;
195 _hypercall(__HYPERVISOR_hvm_op
, _harg("1" (cmd
), "2" (arg
)),
196 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
202 HYPERVISOR_mmu_update(mmu_update_t
*req
, int count
, int *success_count
,
206 unsigned long ign1
, ign2
, ign3
, ign4
;
208 _hypercall(__HYPERVISOR_mmu_update
,
209 _harg("1" (req
), "2" (count
), "3" (success_count
), "4" (domid
)),
210 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
)));
216 HYPERVISOR_mmuext_op(struct mmuext_op
*op
, int count
, int *success_count
,
220 unsigned long ign1
, ign2
, ign3
, ign4
;
222 _hypercall(__HYPERVISOR_mmuext_op
,
223 _harg("1" (op
), "2" (count
), "3" (success_count
), "4" (domid
)),
224 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
)));
231 HYPERVISOR_fpu_taskswitch(int set
)
236 _hypercall(__HYPERVISOR_fpu_taskswitch
, _harg("1" (set
)),
237 _harg("=a" (ret
), "=b" (ign1
)));
242 /* Xen2 compat: always i38HYPERVISOR_fpu_taskswitch(1) */
244 HYPERVISOR_fpu_taskswitch(void)
248 _hypercall(__HYPERVISOR_fpu_taskswitch
, _harg("1" (1)),
249 _harg("=a" (ret
), "=b" (ign1
)));
256 HYPERVISOR_update_descriptor(uint64_t ma
, uint32_t word1
, uint32_t word2
)
259 unsigned long ign1
, ign2
, ign3
, ign4
;
260 int ma1
= ma
& 0xffffffff;
261 int ma2
= (ma
>> 32) & 0xffffffff;
263 _hypercall(__HYPERVISOR_update_descriptor
,
264 _harg("1" (ma1
), "2" (ma2
), "3" (word1
), "4" (word2
)),
265 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
)));
271 HYPERVISOR_memory_op(unsigned int cmd
, void *arg
)
274 unsigned long ign1
, ign2
;
276 _hypercall(__HYPERVISOR_memory_op
, _harg("1" (cmd
), "2" (arg
)),
277 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
283 HYPERVISOR_update_va_mapping(unsigned long page_nr
, pt_entry_t new_val
,
287 unsigned long ign1
, ign2
, ign3
, ign4
;
288 unsigned long pte_low
, pte_hi
;
290 pte_low
= new_val
& 0xffffffff;
292 pte_hi
= new_val
>> 32;
297 _hypercall(__HYPERVISOR_update_va_mapping
,
298 _harg("1" (page_nr
), "2" (pte_low
), "3" (pte_hi
), "4" (flags
)),
299 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
)));
302 if (__predict_false(ret
< 0))
303 panic("Failed update VA mapping: %08lx, %08lx, %08lx",
304 page_nr
, new_val
, flags
);
311 HYPERVISOR_xen_version(int cmd
, void *arg
)
314 unsigned long ign1
, ign2
;
316 _hypercall(__HYPERVISOR_xen_version
, _harg("1" (cmd
), "2" (arg
)),
317 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
323 HYPERVISOR_grant_table_op(unsigned int cmd
, void *uop
, unsigned int count
)
326 unsigned long ign1
, ign2
, ign3
;
328 _hypercall(__HYPERVISOR_grant_table_op
,
329 _harg("1" (cmd
), "2" (uop
), "3" (count
)),
330 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
)));
336 HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr
,
337 pt_entry_t new_val
, unsigned long flags
, domid_t domid
)
340 unsigned long ign1
, ign2
, ign3
, ign4
, ign5
;
341 unsigned long pte_low
, pte_hi
;
343 pte_low
= new_val
& 0xffffffff;
345 pte_hi
= new_val
>> 32;
350 _hypercall(__HYPERVISOR_update_va_mapping_otherdomain
,
351 _harg("1" (page_nr
), "2" (pte_low
), "3" (pte_hi
), "4" (flags
), "5" (domid
)),
352 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
), "=S" (ign4
),
359 HYPERVISOR_vcpu_op(int cmd
, int vcpuid
, void *extra_args
)
362 unsigned long ign1
, ign2
, ign3
;
364 _hypercall(__HYPERVISOR_vcpu_op
,
365 _harg("1" (cmd
), "2" (vcpuid
), "3" (extra_args
)),
366 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
)));
372 HYPERVISOR_yield(void)
375 unsigned long ign1
, ign2
;
377 _hypercall(__HYPERVISOR_sched_op
, _harg("1" (SCHEDOP_yield
), "2" (0)),
378 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
384 HYPERVISOR_block(void)
387 unsigned long ign1
, ign2
;
389 _hypercall(__HYPERVISOR_sched_op
, _harg("1" (SCHEDOP_block
), "2" (0)),
390 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
396 HYPERVISOR_shutdown(void)
399 unsigned long ign1
, ign2
;
401 _hypercall(__HYPERVISOR_sched_op
,
402 _harg("1" (SCHEDOP_shutdown
), "2" (SHUTDOWN_poweroff
)),
403 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
409 HYPERVISOR_crash(void)
412 unsigned long ign1
, ign2
;
414 _hypercall(__HYPERVISOR_sched_op
,
415 _harg("1" (SCHEDOP_shutdown
), "2" (SHUTDOWN_crash
)),
416 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
422 HYPERVISOR_reboot(void)
425 unsigned long ign1
, ign2
;
427 _hypercall(__HYPERVISOR_sched_op
,
428 _harg("1" (SCHEDOP_shutdown
), "2" (SHUTDOWN_reboot
)),
429 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
435 HYPERVISOR_suspend(unsigned long srec
)
438 unsigned long ign1
, ign2
, ign3
;
440 _hypercall(__HYPERVISOR_sched_op
,
441 _harg("1" (SCHEDOP_shutdown
), "2" (SHUTDOWN_suspend
), "3" (srec
)),
442 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
)));
448 HYPERVISOR_set_timer_op(uint64_t timeout
)
451 unsigned long timeout_hi
= (unsigned long)(timeout
>>32);
452 unsigned long timeout_lo
= (unsigned long)timeout
;
453 unsigned long ign1
, ign2
;
455 _hypercall(__HYPERVISOR_set_timer_op
,
456 _harg("1" (timeout_lo
), "2" (timeout_hi
)),
457 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
463 HYPERVISOR_platform_op(struct xen_platform_op
*platform_op
)
468 platform_op
->interface_version
= XENPF_INTERFACE_VERSION
;
469 _hypercall(__HYPERVISOR_platform_op
, _harg("1" (platform_op
)),
470 _harg("=a" (ret
), "=b" (ign1
)));
476 HYPERVISOR_multicall(void *call_list
, int nr_calls
)
479 unsigned long ign1
, ign2
;
481 _hypercall(__HYPERVISOR_multicall
,
482 _harg("1" (call_list
), "2" (nr_calls
)),
483 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
490 HYPERVISOR_event_channel_op(void *op
)
495 _hypercall(__HYPERVISOR_event_channel_op
, _harg("1" (op
)),
496 _harg("=a" (ret
), "=b" (ign1
)));
502 HYPERVISOR_console_io(int cmd
, int count
, char *str
)
505 unsigned long ign1
, ign2
, ign3
;
507 _hypercall(__HYPERVISOR_console_io
,
508 _harg("1" (cmd
), "2" (count
), "3" (str
)),
509 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
), "=d" (ign3
)));
515 HYPERVISOR_physdev_op(void *physdev_op
)
520 _hypercall(__HYPERVISOR_physdev_op
, _harg("1" (physdev_op
)),
521 _harg("=a" (ret
), "=b" (ign1
)));
527 HYPERVISOR_vm_assist(unsigned int cmd
, unsigned int type
)
530 unsigned long ign1
, ign2
;
532 _hypercall(__HYPERVISOR_vm_assist
, _harg("1" (cmd
), "2" (type
)),
533 _harg("=a" (ret
), "=b" (ign1
), "=c" (ign2
)));
537 #endif /* _XENI386_HYPERVISOR_H_ */