hypercall.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /******************************************************************************
  2. * hypercall.h
  3. *
  4. * Linux-specific hypervisor handling.
  5. *
  6. * Copyright (c) 2002-2004, K A Fraser
  7. *
  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:
  13. *
  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:
  20. *
  21. * The above copyright notice and this permission notice shall be included in
  22. * all copies or substantial portions of the Software.
  23. *
  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
  30. * IN THE SOFTWARE.
  31. */
  32. #ifndef _ASM_IA64_XEN_HYPERCALL_H
  33. #define _ASM_IA64_XEN_HYPERCALL_H
  34. #include <xen/interface/xen.h>
  35. #include <xen/interface/physdev.h>
  36. #include <xen/interface/sched.h>
  37. #include <asm/xen/xcom_hcall.h>
  38. struct xencomm_handle;
  39. extern unsigned long __hypercall(unsigned long a1, unsigned long a2,
  40. unsigned long a3, unsigned long a4,
  41. unsigned long a5, unsigned long cmd);
  42. /*
  43. * Assembler stubs for hyper-calls.
  44. */
  45. #define _hypercall0(type, name) \
  46. ({ \
  47. long __res; \
  48. __res = __hypercall(0, 0, 0, 0, 0, __HYPERVISOR_##name);\
  49. (type)__res; \
  50. })
  51. #define _hypercall1(type, name, a1) \
  52. ({ \
  53. long __res; \
  54. __res = __hypercall((unsigned long)a1, \
  55. 0, 0, 0, 0, __HYPERVISOR_##name); \
  56. (type)__res; \
  57. })
  58. #define _hypercall2(type, name, a1, a2) \
  59. ({ \
  60. long __res; \
  61. __res = __hypercall((unsigned long)a1, \
  62. (unsigned long)a2, \
  63. 0, 0, 0, __HYPERVISOR_##name); \
  64. (type)__res; \
  65. })
  66. #define _hypercall3(type, name, a1, a2, a3) \
  67. ({ \
  68. long __res; \
  69. __res = __hypercall((unsigned long)a1, \
  70. (unsigned long)a2, \
  71. (unsigned long)a3, \
  72. 0, 0, __HYPERVISOR_##name); \
  73. (type)__res; \
  74. })
  75. #define _hypercall4(type, name, a1, a2, a3, a4) \
  76. ({ \
  77. long __res; \
  78. __res = __hypercall((unsigned long)a1, \
  79. (unsigned long)a2, \
  80. (unsigned long)a3, \
  81. (unsigned long)a4, \
  82. 0, __HYPERVISOR_##name); \
  83. (type)__res; \
  84. })
  85. #define _hypercall5(type, name, a1, a2, a3, a4, a5) \
  86. ({ \
  87. long __res; \
  88. __res = __hypercall((unsigned long)a1, \
  89. (unsigned long)a2, \
  90. (unsigned long)a3, \
  91. (unsigned long)a4, \
  92. (unsigned long)a5, \
  93. __HYPERVISOR_##name); \
  94. (type)__res; \
  95. })
  96. static inline int
  97. xencomm_arch_hypercall_sched_op(int cmd, struct xencomm_handle *arg)
  98. {
  99. return _hypercall2(int, sched_op, cmd, arg);
  100. }
  101. static inline long
  102. HYPERVISOR_set_timer_op(u64 timeout)
  103. {
  104. unsigned long timeout_hi = (unsigned long)(timeout >> 32);
  105. unsigned long timeout_lo = (unsigned long)timeout;
  106. return _hypercall2(long, set_timer_op, timeout_lo, timeout_hi);
  107. }
  108. static inline int
  109. xencomm_arch_hypercall_multicall(struct xencomm_handle *call_list,
  110. int nr_calls)
  111. {
  112. return _hypercall2(int, multicall, call_list, nr_calls);
  113. }
  114. static inline int
  115. xencomm_arch_hypercall_memory_op(unsigned int cmd, struct xencomm_handle *arg)
  116. {
  117. return _hypercall2(int, memory_op, cmd, arg);
  118. }
  119. static inline int
  120. xencomm_arch_hypercall_event_channel_op(int cmd, struct xencomm_handle *arg)
  121. {
  122. return _hypercall2(int, event_channel_op, cmd, arg);
  123. }
  124. static inline int
  125. xencomm_arch_hypercall_xen_version(int cmd, struct xencomm_handle *arg)
  126. {
  127. return _hypercall2(int, xen_version, cmd, arg);
  128. }
  129. static inline int
  130. xencomm_arch_hypercall_console_io(int cmd, int count,
  131. struct xencomm_handle *str)
  132. {
  133. return _hypercall3(int, console_io, cmd, count, str);
  134. }
  135. static inline int
  136. xencomm_arch_hypercall_physdev_op(int cmd, struct xencomm_handle *arg)
  137. {
  138. return _hypercall2(int, physdev_op, cmd, arg);
  139. }
  140. static inline int
  141. xencomm_arch_hypercall_grant_table_op(unsigned int cmd,
  142. struct xencomm_handle *uop,
  143. unsigned int count)
  144. {
  145. return _hypercall3(int, grant_table_op, cmd, uop, count);
  146. }
  147. int HYPERVISOR_grant_table_op(unsigned int cmd, void *uop, unsigned int count);
  148. extern int xencomm_arch_hypercall_suspend(struct xencomm_handle *arg);
  149. static inline int
  150. xencomm_arch_hypercall_callback_op(int cmd, struct xencomm_handle *arg)
  151. {
  152. return _hypercall2(int, callback_op, cmd, arg);
  153. }
  154. static inline long
  155. xencomm_arch_hypercall_vcpu_op(int cmd, int cpu, void *arg)
  156. {
  157. return _hypercall3(long, vcpu_op, cmd, cpu, arg);
  158. }
  159. static inline int
  160. HYPERVISOR_physdev_op(int cmd, void *arg)
  161. {
  162. switch (cmd) {
  163. case PHYSDEVOP_eoi:
  164. return _hypercall1(int, ia64_fast_eoi,
  165. ((struct physdev_eoi *)arg)->irq);
  166. default:
  167. return xencomm_hypercall_physdev_op(cmd, arg);
  168. }
  169. }
  170. static inline long
  171. xencomm_arch_hypercall_opt_feature(struct xencomm_handle *arg)
  172. {
  173. return _hypercall1(long, opt_feature, arg);
  174. }
  175. /* for balloon driver */
  176. #define HYPERVISOR_update_va_mapping(va, new_val, flags) (0)
  177. /* Use xencomm to do hypercalls. */
  178. #define HYPERVISOR_sched_op xencomm_hypercall_sched_op
  179. #define HYPERVISOR_event_channel_op xencomm_hypercall_event_channel_op
  180. #define HYPERVISOR_callback_op xencomm_hypercall_callback_op
  181. #define HYPERVISOR_multicall xencomm_hypercall_multicall
  182. #define HYPERVISOR_xen_version xencomm_hypercall_xen_version
  183. #define HYPERVISOR_console_io xencomm_hypercall_console_io
  184. #define HYPERVISOR_memory_op xencomm_hypercall_memory_op
  185. #define HYPERVISOR_suspend xencomm_hypercall_suspend
  186. #define HYPERVISOR_vcpu_op xencomm_hypercall_vcpu_op
  187. #define HYPERVISOR_opt_feature xencomm_hypercall_opt_feature
  188. /* to compile gnttab_copy_grant_page() in drivers/xen/core/gnttab.c */
  189. #define HYPERVISOR_mmu_update(req, count, success_count, domid) ({ BUG(); 0; })
  190. static inline int
  191. HYPERVISOR_shutdown(
  192. unsigned int reason)
  193. {
  194. struct sched_shutdown sched_shutdown = {
  195. .reason = reason
  196. };
  197. int rc = HYPERVISOR_sched_op(SCHEDOP_shutdown, &sched_shutdown);
  198. return rc;
  199. }
  200. /* for netfront.c, netback.c */
  201. #define MULTI_UVMFLAGS_INDEX 0 /* XXX any value */
  202. static inline void
  203. MULTI_update_va_mapping(
  204. struct multicall_entry *mcl, unsigned long va,
  205. pte_t new_val, unsigned long flags)
  206. {
  207. mcl->op = __HYPERVISOR_update_va_mapping;
  208. mcl->result = 0;
  209. }
  210. static inline void
  211. MULTI_grant_table_op(struct multicall_entry *mcl, unsigned int cmd,
  212. void *uop, unsigned int count)
  213. {
  214. mcl->op = __HYPERVISOR_grant_table_op;
  215. mcl->args[0] = cmd;
  216. mcl->args[1] = (unsigned long)uop;
  217. mcl->args[2] = count;
  218. }
  219. static inline void
  220. MULTI_mmu_update(struct multicall_entry *mcl, struct mmu_update *req,
  221. int count, int *success_count, domid_t domid)
  222. {
  223. mcl->op = __HYPERVISOR_mmu_update;
  224. mcl->args[0] = (unsigned long)req;
  225. mcl->args[1] = count;
  226. mcl->args[2] = (unsigned long)success_count;
  227. mcl->args[3] = domid;
  228. }
  229. #endif /* _ASM_IA64_XEN_HYPERCALL_H */