hypercall.h revision 273476
1/****************************************************************************** 2 * hypercall.h 3 * 4 * Linux-specific hypervisor handling. 5 * 6 * Copyright (c) 2002-2004, K A Fraser 7 * 8 * This file may be distributed separately from the Linux kernel, or 9 * incorporated into other software packages, subject to the following license: 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a copy 12 * of this source file (the "Software"), to deal in the Software without 13 * restriction, including without limitation the rights to use, copy, modify, 14 * merge, publish, distribute, sublicense, and/or sell copies of the Software, 15 * and to permit persons to whom the Software is furnished to do so, subject to 16 * the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be included in 19 * all copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 27 * IN THE SOFTWARE. 28 */ 29 30#ifndef __HYPERCALL_H__ 31#define __HYPERCALL_H__ 32 33#include <sys/systm.h> 34#include <xen/interface/xen.h> 35#include <xen/interface/sched.h> 36 37extern char *hypercall_page; 38 39#define __STR(x) #x 40#define STR(x) __STR(x) 41#define ENOXENSYS 38 42#define CONFIG_XEN_COMPAT 0x030002 43 44#define HYPERCALL_STR(name) \ 45 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" 46 47#define _hypercall0(type, name) \ 48({ \ 49 long __res; \ 50 __asm__ volatile ( \ 51 HYPERCALL_STR(name) \ 52 : "=a" (__res) \ 53 : \ 54 : "memory" ); \ 55 (type)__res; \ 56}) 57 58#define _hypercall1(type, name, a1) \ 59({ \ 60 long __res, __ign1; \ 61 __asm__ volatile ( \ 62 HYPERCALL_STR(name) \ 63 : "=a" (__res), "=b" (__ign1) \ 64 : "1" ((long)(a1)) \ 65 : "memory" ); \ 66 (type)__res; \ 67}) 68 69#define _hypercall2(type, name, a1, a2) \ 70({ \ 71 long __res, __ign1, __ign2; \ 72 __asm__ volatile ( \ 73 HYPERCALL_STR(name) \ 74 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ 75 : "1" ((long)(a1)), "2" ((long)(a2)) \ 76 : "memory" ); \ 77 (type)__res; \ 78}) 79 80#define _hypercall3(type, name, a1, a2, a3) \ 81({ \ 82 long __res, __ign1, __ign2, __ign3; \ 83 __asm__ volatile ( \ 84 HYPERCALL_STR(name) \ 85 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 86 "=d" (__ign3) \ 87 : "1" ((long)(a1)), "2" ((long)(a2)), \ 88 "3" ((long)(a3)) \ 89 : "memory" ); \ 90 (type)__res; \ 91}) 92 93#define _hypercall4(type, name, a1, a2, a3, a4) \ 94({ \ 95 long __res, __ign1, __ign2, __ign3, __ign4; \ 96 __asm__ volatile ( \ 97 HYPERCALL_STR(name) \ 98 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 99 "=d" (__ign3), "=S" (__ign4) \ 100 : "1" ((long)(a1)), "2" ((long)(a2)), \ 101 "3" ((long)(a3)), "4" ((long)(a4)) \ 102 : "memory" ); \ 103 (type)__res; \ 104}) 105 106#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ 107({ \ 108 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ 109 __asm__ volatile ( \ 110 HYPERCALL_STR(name) \ 111 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 112 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ 113 : "1" ((long)(a1)), "2" ((long)(a2)), \ 114 "3" ((long)(a3)), "4" ((long)(a4)), \ 115 "5" ((long)(a5)) \ 116 : "memory" ); \ 117 (type)__res; \ 118}) 119 120static inline long 121privcmd_hypercall(long op, long a1, long a2, long a3, long a4, long a5) 122{ 123 long __res, __ign1, __ign2, __ign3, __ign4, __ign5, __call; 124 125 __call = (long)&hypercall_page + (op * 32); 126 __asm__ volatile ( 127 "call *%[call]" 128 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), 129 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) 130 : "1" ((long)(a1)), "2" ((long)(a2)), 131 "3" ((long)(a3)), "4" ((long)(a4)), 132 "5" ((long)(a5)), [call] "a" (__call) 133 : "memory" ); 134 135 return __res; 136} 137 138static inline int 139HYPERVISOR_set_trap_table( 140 trap_info_t *table) 141{ 142 return _hypercall1(int, set_trap_table, table); 143} 144 145static inline int 146HYPERVISOR_mmu_update( 147 mmu_update_t *req, int count, int *success_count, domid_t domid) 148{ 149 return _hypercall4(int, mmu_update, req, count, success_count, domid); 150} 151 152static inline int 153HYPERVISOR_mmuext_op( 154 mmuext_op_t *op, int count, int *success_count, domid_t domid) 155{ 156 return _hypercall4(int, mmuext_op, op, count, success_count, domid); 157} 158 159static inline int 160HYPERVISOR_set_gdt( 161 unsigned long *frame_list, int entries) 162{ 163 return _hypercall2(int, set_gdt, frame_list, entries); 164} 165 166static inline int 167HYPERVISOR_stack_switch( 168 unsigned long ss, unsigned long esp) 169{ 170 return _hypercall2(int, stack_switch, ss, esp); 171} 172 173static inline int 174HYPERVISOR_set_callbacks( 175 unsigned long event_selector, unsigned long event_address, 176 unsigned long failsafe_selector, unsigned long failsafe_address) 177{ 178 return _hypercall4(int, set_callbacks, 179 event_selector, event_address, 180 failsafe_selector, failsafe_address); 181} 182 183static inline int 184HYPERVISOR_fpu_taskswitch( 185 int set) 186{ 187 return _hypercall1(int, fpu_taskswitch, set); 188} 189 190static inline int 191HYPERVISOR_sched_op_compat( 192 int cmd, unsigned long arg) 193{ 194 return _hypercall2(int, sched_op_compat, cmd, arg); 195} 196 197static inline int 198HYPERVISOR_sched_op( 199 int cmd, void *arg) 200{ 201 return _hypercall2(int, sched_op, cmd, arg); 202} 203 204static inline long 205HYPERVISOR_set_timer_op( 206 uint64_t timeout) 207{ 208 unsigned long timeout_hi = (unsigned long)(timeout>>32); 209 unsigned long timeout_lo = (unsigned long)timeout; 210 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); 211} 212#if 0 213static inline int 214HYPERVISOR_platform_op( 215 struct xen_platform_op *platform_op) 216{ 217 platform_op->interface_version = XENPF_INTERFACE_VERSION; 218 return _hypercall1(int, platform_op, platform_op); 219} 220#endif 221static inline int 222HYPERVISOR_set_debugreg( 223 int reg, unsigned long value) 224{ 225 return _hypercall2(int, set_debugreg, reg, value); 226} 227 228static inline unsigned long 229HYPERVISOR_get_debugreg( 230 int reg) 231{ 232 return _hypercall1(unsigned long, get_debugreg, reg); 233} 234 235static inline int 236HYPERVISOR_update_descriptor( 237 uint64_t ma, uint64_t desc) 238{ 239 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); 240} 241 242static inline int 243HYPERVISOR_memory_op( 244 unsigned int cmd, void *arg) 245{ 246 return _hypercall2(int, memory_op, cmd, arg); 247} 248 249#if defined(XEN) 250int HYPERVISOR_multicall(multicall_entry_t *, int); 251static inline int 252_HYPERVISOR_multicall( 253#else /* XENHVM */ 254static inline int 255HYPERVISOR_multicall( 256#endif 257 void *call_list, int nr_calls) 258{ 259 return _hypercall2(int, multicall, call_list, nr_calls); 260} 261 262static inline int 263HYPERVISOR_update_va_mapping( 264 unsigned long va, uint64_t new_val, unsigned long flags) 265{ 266 uint32_t hi, lo; 267 268 lo = (uint32_t)(new_val & 0xffffffff); 269 hi = (uint32_t)(new_val >> 32); 270 271 return _hypercall4(int, update_va_mapping, va, 272 lo, hi, flags); 273} 274 275static inline int 276HYPERVISOR_event_channel_op( 277 int cmd, void *arg) 278{ 279 int rc = _hypercall2(int, event_channel_op, cmd, arg); 280 281#if CONFIG_XEN_COMPAT <= 0x030002 282 if (__predict_false(rc == -ENOXENSYS)) { 283 struct evtchn_op op; 284 op.cmd = cmd; 285 memcpy(&op.u, arg, sizeof(op.u)); 286 rc = _hypercall1(int, event_channel_op_compat, &op); 287 memcpy(arg, &op.u, sizeof(op.u)); 288 } 289#endif 290 return (rc); 291} 292 293static inline int 294HYPERVISOR_xen_version( 295 int cmd, void *arg) 296{ 297 return _hypercall2(int, xen_version, cmd, arg); 298} 299 300static inline int 301HYPERVISOR_console_io( 302 int cmd, int count, char *str) 303{ 304 return _hypercall3(int, console_io, cmd, count, str); 305} 306 307static inline int 308HYPERVISOR_physdev_op( 309 int cmd, void *arg) 310{ 311 int rc = _hypercall2(int, physdev_op, cmd, arg); 312#if CONFIG_XEN_COMPAT <= 0x030002 313 if (__predict_false(rc == -ENOXENSYS)) { 314 struct physdev_op op; 315 op.cmd = cmd; 316 memcpy(&op.u, arg, sizeof(op.u)); 317 rc = _hypercall1(int, physdev_op_compat, &op); 318 memcpy(arg, &op.u, sizeof(op.u)); 319 } 320#endif 321 return (rc); 322} 323 324static inline int 325HYPERVISOR_grant_table_op( 326 unsigned int cmd, void *uop, unsigned int count) 327{ 328 return _hypercall3(int, grant_table_op, cmd, uop, count); 329} 330 331static inline int 332HYPERVISOR_update_va_mapping_otherdomain( 333 unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid) 334{ 335 uint32_t hi, lo; 336 337 lo = (uint32_t)(new_val & 0xffffffff); 338 hi = (uint32_t)(new_val >> 32); 339 340 return _hypercall5(int, update_va_mapping_otherdomain, va, 341 lo, hi, flags, domid); 342} 343 344static inline int 345HYPERVISOR_vm_assist( 346 unsigned int cmd, unsigned int type) 347{ 348 return _hypercall2(int, vm_assist, cmd, type); 349} 350 351static inline int 352HYPERVISOR_vcpu_op( 353 int cmd, int vcpuid, void *extra_args) 354{ 355 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); 356} 357 358static inline int 359HYPERVISOR_suspend( 360 unsigned long srec) 361{ 362 struct sched_shutdown sched_shutdown = { 363 .reason = SHUTDOWN_suspend 364 }; 365 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown, 366 &sched_shutdown, srec); 367#if CONFIG_XEN_COMPAT <= 0x030002 368 if (rc == -ENOXENSYS) 369 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown, 370 SHUTDOWN_suspend, srec); 371#endif 372 return (rc); 373} 374 375#if CONFIG_XEN_COMPAT <= 0x030002 376static inline int 377HYPERVISOR_nmi_op( 378 unsigned long op, void *arg) 379{ 380 return _hypercall2(int, nmi_op, op, arg); 381} 382#endif 383 384static inline int 385HYPERVISOR_callback_op( 386 int cmd, void *arg) 387{ 388 return _hypercall2(int, callback_op, cmd, arg); 389} 390 391#ifndef CONFIG_XEN 392static inline unsigned long 393HYPERVISOR_hvm_op( 394 int op, void *arg) 395{ 396 return _hypercall2(unsigned long, hvm_op, op, arg); 397} 398#endif 399 400static inline int 401HYPERVISOR_xenoprof_op( 402 int op, void *arg) 403{ 404 return _hypercall2(int, xenoprof_op, op, arg); 405} 406 407static inline int 408HYPERVISOR_kexec_op( 409 unsigned long op, void *args) 410{ 411 return _hypercall2(int, kexec_op, op, args); 412} 413#endif /* __HYPERCALL_H__ */ 414 415/* 416 * Local variables: 417 * c-file-style: "linux" 418 * indent-tabs-mode: t 419 * c-indent-level: 8 420 * c-basic-offset: 8 421 * tab-width: 8 422 * End: 423 */ 424