No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / xen / include / i386 / hypercalls.h
blob2edb9ac18adf4a0144332cdd955fe6793d00c6dc
1 /* $NetBSD: hypercalls.h,v 1.9 2009/07/29 12:02:06 cegger Exp $ */
3 /*
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
8 * are met:
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
50 * IN THE SOFTWARE.
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 */
64 #define __str(x) #x
65 #define _str(x) __str(x)
66 #define _hypercall(name, input_const, output_const) \
67 __asm volatile ( \
68 "call hypercall_page + ("_str(name)" * 32)" \
69 : output_const \
70 : input_const \
71 : "memory" )
72 #else
73 /* traditionnal hypercall via int 0x82 */
74 #define _hypercall(name, input_const, output_const) \
75 __asm volatile ( \
76 TRAP_INSTR \
77 : output_const \
78 : "0" (name), input_const \
79 : "memory" )
80 #endif
82 #define _harg(...) __VA_ARGS__
85 static __inline int
86 HYPERVISOR_set_trap_table(trap_info_t *table)
88 int ret;
89 unsigned long ign1;
91 _hypercall(__HYPERVISOR_set_trap_table, _harg("1" (table)),
92 _harg("=a" (ret), "=b" (ign1)));
94 return ret;
97 static __inline int
98 HYPERVISOR_set_gdt(unsigned long *frame_list, int entries)
100 int ret;
101 unsigned long ign1, ign2;
103 _hypercall(__HYPERVISOR_set_gdt, _harg("1" (frame_list), "2" (entries)),
104 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
106 return ret;
109 static __inline int
110 HYPERVISOR_stack_switch(unsigned long ss, unsigned long esp)
112 int ret;
113 unsigned long ign1, ign2;
115 _hypercall(__HYPERVISOR_stack_switch, _harg("1" (ss), "2" (esp)),
116 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
118 return ret;
121 static __inline int
122 HYPERVISOR_set_callbacks(
123 unsigned long event_selector, unsigned long event_address,
124 unsigned long failsafe_selector, unsigned long failsafe_address)
126 int ret;
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)));
134 return ret;
137 #if __XEN_INTERFACE_VERSION__ < 0x00030204
138 static __inline int
139 HYPERVISOR_dom0_op(dom0_op_t *dom0_op)
141 int ret;
142 unsigned long ign1;
144 dom0_op->interface_version = DOM0_INTERFACE_VERSION;
145 _hypercall(__HYPERVISOR_dom0_op, _harg("1" (dom0_op)),
146 _harg("=a" (ret), "=b" (ign1)));
148 return ret;
150 #endif /* __XEN_INTERFACE_VERSION__ */
152 static __inline int
153 HYPERVISOR_set_debugreg(int reg, unsigned long value)
155 int ret;
156 unsigned long ign1, ign2;
158 _hypercall(__HYPERVISOR_set_debugreg, _harg("1" (reg), "2" (value)),
159 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
161 return ret;
164 static __inline unsigned long
165 HYPERVISOR_get_debugreg(int reg)
167 unsigned long ret;
168 unsigned long ign1;
170 _hypercall(__HYPERVISOR_get_debugreg, _harg("1" (reg)),
171 _harg("=a" (ret), "=b" (ign1)));
173 return ret;
176 static __inline int
177 HYPERVISOR_machine_check(struct xen_mc *mc)
179 int ret;
180 unsigned long ign1;
182 mc->interface_version = XEN_MCA_INTERFACE_VERSION;
183 _hypercall(__HYPERVISOR_mca, _harg("1" (mc)),
184 _harg("=a" (ret), "=b" (ign1)));
186 return ret;
189 static __inline int
190 HYPERVISOR_hvm_op(int cmd, void *arg)
192 int ret;
193 unsigned long ign1, ign2;
195 _hypercall(__HYPERVISOR_hvm_op, _harg("1" (cmd), "2" (arg)),
196 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
198 return ret;
201 static __inline int
202 HYPERVISOR_mmu_update(mmu_update_t *req, int count, int *success_count,
203 domid_t domid)
205 int ret;
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)));
212 return ret;
215 static __inline int
216 HYPERVISOR_mmuext_op(struct mmuext_op *op, int count, int *success_count,
217 domid_t domid)
219 int ret;
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)));
226 return ret;
229 #if 0
230 static __inline int
231 HYPERVISOR_fpu_taskswitch(int set)
233 long ret;
234 long ign1;
236 _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (set)),
237 _harg("=a" (ret), "=b" (ign1)));
239 return ret;
241 #else /* 0 */
242 /* Xen2 compat: always i38HYPERVISOR_fpu_taskswitch(1) */
243 static __inline int
244 HYPERVISOR_fpu_taskswitch(void)
246 long ret;
247 long ign1;
248 _hypercall(__HYPERVISOR_fpu_taskswitch, _harg("1" (1)),
249 _harg("=a" (ret), "=b" (ign1)));
251 return ret;
253 #endif /* 0 */
255 static __inline int
256 HYPERVISOR_update_descriptor(uint64_t ma, uint32_t word1, uint32_t word2)
258 int ret;
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)));
267 return ret;
270 static __inline int
271 HYPERVISOR_memory_op(unsigned int cmd, void *arg)
273 int ret;
274 unsigned long ign1, ign2;
276 _hypercall(__HYPERVISOR_memory_op, _harg("1" (cmd), "2" (arg)),
277 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
279 return ret;
282 static __inline int
283 HYPERVISOR_update_va_mapping(unsigned long page_nr, pt_entry_t new_val,
284 unsigned long flags)
286 int ret;
287 unsigned long ign1, ign2, ign3, ign4;
288 unsigned long pte_low, pte_hi;
290 pte_low = new_val & 0xffffffff;
291 #ifdef PAE
292 pte_hi = new_val >> 32;
293 #else
294 pte_hi = 0;
295 #endif
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)));
301 #ifdef notdef
302 if (__predict_false(ret < 0))
303 panic("Failed update VA mapping: %08lx, %08lx, %08lx",
304 page_nr, new_val, flags);
305 #endif
307 return ret;
310 static __inline int
311 HYPERVISOR_xen_version(int cmd, void *arg)
313 int ret;
314 unsigned long ign1, ign2;
316 _hypercall(__HYPERVISOR_xen_version, _harg("1" (cmd), "2" (arg)),
317 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
319 return ret;
322 static __inline int
323 HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count)
325 int ret;
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)));
332 return ret;
335 static __inline int
336 HYPERVISOR_update_va_mapping_otherdomain(unsigned long page_nr,
337 pt_entry_t new_val, unsigned long flags, domid_t domid)
339 int ret;
340 unsigned long ign1, ign2, ign3, ign4, ign5;
341 unsigned long pte_low, pte_hi;
343 pte_low = new_val & 0xffffffff;
344 #ifdef PAE
345 pte_hi = new_val >> 32;
346 #else
347 pte_hi = 0;
348 #endif
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),
353 "=D" (ign5)));
355 return ret;
358 static __inline int
359 HYPERVISOR_vcpu_op(int cmd, int vcpuid, void *extra_args)
361 long ret;
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)));
368 return ret;
371 static __inline long
372 HYPERVISOR_yield(void)
374 long ret;
375 unsigned long ign1, ign2;
377 _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_yield), "2" (0)),
378 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
380 return ret;
383 static __inline long
384 HYPERVISOR_block(void)
386 long ret;
387 unsigned long ign1, ign2;
389 _hypercall(__HYPERVISOR_sched_op, _harg("1" (SCHEDOP_block), "2" (0)),
390 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
392 return ret;
395 static __inline long
396 HYPERVISOR_shutdown(void)
398 long ret;
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)));
405 return ret;
408 static __inline long
409 HYPERVISOR_crash(void)
411 long ret;
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)));
418 return ret;
421 static __inline long
422 HYPERVISOR_reboot(void)
424 long ret;
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)));
431 return ret;
434 static __inline long
435 HYPERVISOR_suspend(unsigned long srec)
437 long ret;
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)));
444 return ret;
447 static __inline long
448 HYPERVISOR_set_timer_op(uint64_t timeout)
450 long ret;
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)));
459 return ret;
462 static __inline int
463 HYPERVISOR_platform_op(struct xen_platform_op *platform_op)
465 int ret;
466 unsigned long ign1;
468 platform_op->interface_version = XENPF_INTERFACE_VERSION;
469 _hypercall(__HYPERVISOR_platform_op, _harg("1" (platform_op)),
470 _harg("=a" (ret), "=b" (ign1)));
472 return ret;
475 static __inline int
476 HYPERVISOR_multicall(void *call_list, int nr_calls)
478 int ret;
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)));
485 return ret;
489 static __inline int
490 HYPERVISOR_event_channel_op(void *op)
492 int ret;
493 unsigned long ign1;
495 _hypercall(__HYPERVISOR_event_channel_op, _harg("1" (op)),
496 _harg("=a" (ret), "=b" (ign1)));
498 return ret;
501 static __inline int
502 HYPERVISOR_console_io(int cmd, int count, char *str)
504 int ret;
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)));
511 return ret;
514 static __inline int
515 HYPERVISOR_physdev_op(void *physdev_op)
517 int ret;
518 unsigned long ign1;
520 _hypercall(__HYPERVISOR_physdev_op, _harg("1" (physdev_op)),
521 _harg("=a" (ret), "=b" (ign1)));
523 return ret;
526 static __inline int
527 HYPERVISOR_vm_assist(unsigned int cmd, unsigned int type)
529 int ret;
530 unsigned long ign1, ign2;
532 _hypercall(__HYPERVISOR_vm_assist, _harg("1" (cmd), "2" (type)),
533 _harg("=a" (ret), "=b" (ign1), "=c" (ign2)));
535 return ret;
537 #endif /* _XENI386_HYPERVISOR_H_ */