hypercall.h revision 215818
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 37#define __STR(x) #x 38#define STR(x) __STR(x) 39#define ENOXENSYS 38 40#define CONFIG_XEN_COMPAT 0x030002 41 42 43#if defined(XEN) 44#define HYPERCALL_STR(name) \ 45 "call hypercall_page + ("STR(__HYPERVISOR_##name)" * 32)" 46#else 47#define HYPERCALL_STR(name) \ 48 "mov hypercall_stubs,%%eax; " \ 49 "add $("STR(__HYPERVISOR_##name)" * 32),%%eax; " \ 50 "call *%%eax" 51#endif 52 53#define _hypercall0(type, name) \ 54({ \ 55 long __res; \ 56 __asm__ volatile ( \ 57 HYPERCALL_STR(name) \ 58 : "=a" (__res) \ 59 : \ 60 : "memory" ); \ 61 (type)__res; \ 62}) 63 64#define _hypercall1(type, name, a1) \ 65({ \ 66 long __res, __ign1; \ 67 __asm__ volatile ( \ 68 HYPERCALL_STR(name) \ 69 : "=a" (__res), "=b" (__ign1) \ 70 : "1" ((long)(a1)) \ 71 : "memory" ); \ 72 (type)__res; \ 73}) 74 75#define _hypercall2(type, name, a1, a2) \ 76({ \ 77 long __res, __ign1, __ign2; \ 78 __asm__ volatile ( \ 79 HYPERCALL_STR(name) \ 80 : "=a" (__res), "=b" (__ign1), "=c" (__ign2) \ 81 : "1" ((long)(a1)), "2" ((long)(a2)) \ 82 : "memory" ); \ 83 (type)__res; \ 84}) 85 86#define _hypercall3(type, name, a1, a2, a3) \ 87({ \ 88 long __res, __ign1, __ign2, __ign3; \ 89 __asm__ volatile ( \ 90 HYPERCALL_STR(name) \ 91 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 92 "=d" (__ign3) \ 93 : "1" ((long)(a1)), "2" ((long)(a2)), \ 94 "3" ((long)(a3)) \ 95 : "memory" ); \ 96 (type)__res; \ 97}) 98 99#define _hypercall4(type, name, a1, a2, a3, a4) \ 100({ \ 101 long __res, __ign1, __ign2, __ign3, __ign4; \ 102 __asm__ volatile ( \ 103 HYPERCALL_STR(name) \ 104 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 105 "=d" (__ign3), "=S" (__ign4) \ 106 : "1" ((long)(a1)), "2" ((long)(a2)), \ 107 "3" ((long)(a3)), "4" ((long)(a4)) \ 108 : "memory" ); \ 109 (type)__res; \ 110}) 111 112#define _hypercall5(type, name, a1, a2, a3, a4, a5) \ 113({ \ 114 long __res, __ign1, __ign2, __ign3, __ign4, __ign5; \ 115 __asm__ volatile ( \ 116 HYPERCALL_STR(name) \ 117 : "=a" (__res), "=b" (__ign1), "=c" (__ign2), \ 118 "=d" (__ign3), "=S" (__ign4), "=D" (__ign5) \ 119 : "1" ((long)(a1)), "2" ((long)(a2)), \ 120 "3" ((long)(a3)), "4" ((long)(a4)), \ 121 "5" ((long)(a5)) \ 122 : "memory" ); \ 123 (type)__res; \ 124}) 125 126static inline int 127HYPERVISOR_set_trap_table( 128 trap_info_t *table) 129{ 130 return _hypercall1(int, set_trap_table, table); 131} 132 133static inline int 134HYPERVISOR_mmu_update( 135 mmu_update_t *req, int count, int *success_count, domid_t domid) 136{ 137 return _hypercall4(int, mmu_update, req, count, success_count, domid); 138} 139 140static inline int 141HYPERVISOR_mmuext_op( 142 mmuext_op_t *op, int count, int *success_count, domid_t domid) 143{ 144 return _hypercall4(int, mmuext_op, op, count, success_count, domid); 145} 146 147static inline int 148HYPERVISOR_set_gdt( 149 unsigned long *frame_list, int entries) 150{ 151 return _hypercall2(int, set_gdt, frame_list, entries); 152} 153 154static inline int 155HYPERVISOR_stack_switch( 156 unsigned long ss, unsigned long esp) 157{ 158 return _hypercall2(int, stack_switch, ss, esp); 159} 160 161static inline int 162HYPERVISOR_set_callbacks( 163 unsigned long event_selector, unsigned long event_address, 164 unsigned long failsafe_selector, unsigned long failsafe_address) 165{ 166 return _hypercall4(int, set_callbacks, 167 event_selector, event_address, 168 failsafe_selector, failsafe_address); 169} 170 171static inline int 172HYPERVISOR_fpu_taskswitch( 173 int set) 174{ 175 return _hypercall1(int, fpu_taskswitch, set); 176} 177 178static inline int 179HYPERVISOR_sched_op_compat( 180 int cmd, unsigned long arg) 181{ 182 return _hypercall2(int, sched_op_compat, cmd, arg); 183} 184 185static inline int 186HYPERVISOR_sched_op( 187 int cmd, void *arg) 188{ 189 return _hypercall2(int, sched_op, cmd, arg); 190} 191 192static inline long 193HYPERVISOR_set_timer_op( 194 uint64_t timeout) 195{ 196 unsigned long timeout_hi = (unsigned long)(timeout>>32); 197 unsigned long timeout_lo = (unsigned long)timeout; 198 return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi); 199} 200#if 0 201static inline int 202HYPERVISOR_platform_op( 203 struct xen_platform_op *platform_op) 204{ 205 platform_op->interface_version = XENPF_INTERFACE_VERSION; 206 return _hypercall1(int, platform_op, platform_op); 207} 208#endif 209static inline int 210HYPERVISOR_set_debugreg( 211 int reg, unsigned long value) 212{ 213 return _hypercall2(int, set_debugreg, reg, value); 214} 215 216static inline unsigned long 217HYPERVISOR_get_debugreg( 218 int reg) 219{ 220 return _hypercall1(unsigned long, get_debugreg, reg); 221} 222 223static inline int 224HYPERVISOR_update_descriptor( 225 uint64_t ma, uint64_t desc) 226{ 227 return _hypercall4(int, update_descriptor, ma, ma>>32, desc, desc>>32); 228} 229 230static inline int 231HYPERVISOR_memory_op( 232 unsigned int cmd, void *arg) 233{ 234 return _hypercall2(int, memory_op, cmd, arg); 235} 236 237int HYPERVISOR_multicall(multicall_entry_t *, int); 238static inline int 239_HYPERVISOR_multicall( 240 void *call_list, int nr_calls) 241{ 242 return _hypercall2(int, multicall, call_list, nr_calls); 243} 244 245static inline int 246HYPERVISOR_update_va_mapping( 247 unsigned long va, uint64_t new_val, unsigned long flags) 248{ 249 uint32_t hi, lo; 250 251 lo = (uint32_t)(new_val & 0xffffffff); 252 hi = (uint32_t)(new_val >> 32); 253 254 return _hypercall4(int, update_va_mapping, va, 255 lo, hi, flags); 256} 257 258static inline int 259HYPERVISOR_event_channel_op( 260 int cmd, void *arg) 261{ 262 int rc = _hypercall2(int, event_channel_op, cmd, arg); 263 264#if CONFIG_XEN_COMPAT <= 0x030002 265 if (__predict_false(rc == -ENOXENSYS)) { 266 struct evtchn_op op; 267 op.cmd = cmd; 268 memcpy(&op.u, arg, sizeof(op.u)); 269 rc = _hypercall1(int, event_channel_op_compat, &op); 270 memcpy(arg, &op.u, sizeof(op.u)); 271 } 272#endif 273 return (rc); 274} 275 276static inline int 277HYPERVISOR_xen_version( 278 int cmd, void *arg) 279{ 280 return _hypercall2(int, xen_version, cmd, arg); 281} 282 283static inline int 284HYPERVISOR_console_io( 285 int cmd, int count, char *str) 286{ 287 return _hypercall3(int, console_io, cmd, count, str); 288} 289 290static inline int 291HYPERVISOR_physdev_op( 292 int cmd, void *arg) 293{ 294 int rc = _hypercall2(int, physdev_op, cmd, arg); 295#if CONFIG_XEN_COMPAT <= 0x030002 296 if (__predict_false(rc == -ENOXENSYS)) { 297 struct physdev_op op; 298 op.cmd = cmd; 299 memcpy(&op.u, arg, sizeof(op.u)); 300 rc = _hypercall1(int, physdev_op_compat, &op); 301 memcpy(arg, &op.u, sizeof(op.u)); 302 } 303#endif 304 return (rc); 305} 306 307static inline int 308HYPERVISOR_grant_table_op( 309 unsigned int cmd, void *uop, unsigned int count) 310{ 311 return _hypercall3(int, grant_table_op, cmd, uop, count); 312} 313 314static inline int 315HYPERVISOR_update_va_mapping_otherdomain( 316 unsigned long va, uint64_t new_val, unsigned long flags, domid_t domid) 317{ 318 uint32_t hi, lo; 319 320 lo = (uint32_t)(new_val & 0xffffffff); 321 hi = (uint32_t)(new_val >> 32); 322 323 return _hypercall5(int, update_va_mapping_otherdomain, va, 324 lo, hi, flags, domid); 325} 326 327static inline int 328HYPERVISOR_vm_assist( 329 unsigned int cmd, unsigned int type) 330{ 331 return _hypercall2(int, vm_assist, cmd, type); 332} 333 334static inline int 335HYPERVISOR_vcpu_op( 336 int cmd, int vcpuid, void *extra_args) 337{ 338 return _hypercall3(int, vcpu_op, cmd, vcpuid, extra_args); 339} 340 341static inline int 342HYPERVISOR_suspend( 343 unsigned long srec) 344{ 345 struct sched_shutdown sched_shutdown = { 346 .reason = SHUTDOWN_suspend 347 }; 348 int rc = _hypercall3(int, sched_op, SCHEDOP_shutdown, 349 &sched_shutdown, srec); 350#if CONFIG_XEN_COMPAT <= 0x030002 351 if (rc == -ENOXENSYS) 352 rc = _hypercall3(int, sched_op_compat, SCHEDOP_shutdown, 353 SHUTDOWN_suspend, srec); 354#endif 355 return (rc); 356} 357 358#if CONFIG_XEN_COMPAT <= 0x030002 359static inline int 360HYPERVISOR_nmi_op( 361 unsigned long op, void *arg) 362{ 363 return _hypercall2(int, nmi_op, op, arg); 364} 365#endif 366 367static inline int 368HYPERVISOR_callback_op( 369 int cmd, void *arg) 370{ 371 return _hypercall2(int, callback_op, cmd, arg); 372} 373 374#ifndef CONFIG_XEN 375static inline unsigned long 376HYPERVISOR_hvm_op( 377 int op, void *arg) 378{ 379 return _hypercall2(unsigned long, hvm_op, op, arg); 380} 381#endif 382 383static inline int 384HYPERVISOR_xenoprof_op( 385 int op, void *arg) 386{ 387 return _hypercall2(int, xenoprof_op, op, arg); 388} 389 390static inline int 391HYPERVISOR_kexec_op( 392 unsigned long op, void *args) 393{ 394 return _hypercall2(int, kexec_op, op, args); 395} 396#endif /* __HYPERCALL_H__ */ 397 398/* 399 * Local variables: 400 * c-file-style: "linux" 401 * indent-tabs-mode: t 402 * c-indent-level: 8 403 * c-basic-offset: 8 404 * tab-width: 8 405 * End: 406 */ 407