You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

xen.h 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _BITS_XEN_H
  2. #define _BITS_XEN_H
  3. /** @file
  4. *
  5. * Xen interface
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. /* Hypercall registers */
  10. #ifdef __aarch64__
  11. #define XEN_HC "x16"
  12. #define XEN_REG1 "x0"
  13. #define XEN_REG2 "x1"
  14. #define XEN_REG3 "x2"
  15. #define XEN_REG4 "x3"
  16. #define XEN_REG5 "x4"
  17. #else
  18. #define XEN_HC "r12"
  19. #define XEN_REG1 "r0"
  20. #define XEN_REG2 "r1"
  21. #define XEN_REG3 "r2"
  22. #define XEN_REG4 "r3"
  23. #define XEN_REG5 "r4"
  24. #endif
  25. /**
  26. * Issue hypercall with one argument
  27. *
  28. * @v xen Xen hypervisor
  29. * @v hypercall Hypercall number
  30. * @v arg1 First argument
  31. * @ret retval Return value
  32. */
  33. static inline __attribute__ (( always_inline )) unsigned long
  34. xen_hypercall_1 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
  35. unsigned long arg1 ) {
  36. register unsigned long hc asm ( XEN_HC ) = hypercall;
  37. register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
  38. __asm__ __volatile__ ( "hvc %1"
  39. : "+r" ( reg1 )
  40. : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
  41. : "memory", "cc" );
  42. return reg1;
  43. }
  44. /**
  45. * Issue hypercall with two arguments
  46. *
  47. * @v xen Xen hypervisor
  48. * @v hypercall Hypercall number
  49. * @v arg1 First argument
  50. * @v arg2 Second argument
  51. * @ret retval Return value
  52. */
  53. static inline __attribute__ (( always_inline )) unsigned long
  54. xen_hypercall_2 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
  55. unsigned long arg1, unsigned long arg2 ) {
  56. register unsigned long hc asm ( XEN_HC ) = hypercall;
  57. register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
  58. register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
  59. __asm__ __volatile__ ( "hvc %2"
  60. : "+r" ( reg1 ), "+r" ( reg2 )
  61. : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
  62. : "memory", "cc" );
  63. return reg1;
  64. }
  65. /**
  66. * Issue hypercall with three arguments
  67. *
  68. * @v xen Xen hypervisor
  69. * @v hypercall Hypercall number
  70. * @v arg1 First argument
  71. * @v arg2 Second argument
  72. * @v arg3 Third argument
  73. * @ret retval Return value
  74. */
  75. static inline __attribute__ (( always_inline )) unsigned long
  76. xen_hypercall_3 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
  77. unsigned long arg1, unsigned long arg2, unsigned long arg3 ) {
  78. register unsigned long hc asm ( XEN_HC ) = hypercall;
  79. register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
  80. register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
  81. register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
  82. __asm__ __volatile__ ( "hvc %3"
  83. : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 )
  84. : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
  85. : "memory", "cc" );
  86. return reg1;
  87. }
  88. /**
  89. * Issue hypercall with four arguments
  90. *
  91. * @v xen Xen hypervisor
  92. * @v hypercall Hypercall number
  93. * @v arg1 First argument
  94. * @v arg2 Second argument
  95. * @v arg3 Third argument
  96. * @v arg4 Fourth argument
  97. * @ret retval Return value
  98. */
  99. static inline __attribute__ (( always_inline )) unsigned long
  100. xen_hypercall_4 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
  101. unsigned long arg1, unsigned long arg2, unsigned long arg3,
  102. unsigned long arg4 ) {
  103. register unsigned long hc asm ( XEN_HC ) = hypercall;
  104. register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
  105. register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
  106. register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
  107. register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
  108. __asm__ __volatile__ ( "hvc %4"
  109. : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ),
  110. "+r" ( reg4 )
  111. : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
  112. : "memory", "cc" );
  113. return reg1;
  114. }
  115. /**
  116. * Issue hypercall with five arguments
  117. *
  118. * @v xen Xen hypervisor
  119. * @v hypercall Hypercall number
  120. * @v arg1 First argument
  121. * @v arg2 Second argument
  122. * @v arg3 Third argument
  123. * @v arg4 Fourth argument
  124. * @v arg5 Fifth argument
  125. * @ret retval Return value
  126. */
  127. static inline __attribute__ (( always_inline )) unsigned long
  128. xen_hypercall_5 ( struct xen_hypervisor *xen __unused, unsigned int hypercall,
  129. unsigned long arg1, unsigned long arg2, unsigned long arg3,
  130. unsigned long arg4, unsigned long arg5 ) {
  131. register unsigned long hc asm ( XEN_HC ) = hypercall;
  132. register unsigned long reg1 asm ( XEN_REG1 ) = arg1;
  133. register unsigned long reg2 asm ( XEN_REG2 ) = arg2;
  134. register unsigned long reg3 asm ( XEN_REG3 ) = arg3;
  135. register unsigned long reg4 asm ( XEN_REG4 ) = arg4;
  136. register unsigned long reg5 asm ( XEN_REG5 ) = arg5;
  137. __asm__ __volatile__ ( "hvc %5"
  138. : "+r" ( reg1 ), "+r" ( reg2 ), "+r" ( reg3 ),
  139. "+r" ( reg4 ), "+r" ( reg5 )
  140. : "i" ( XEN_HYPERCALL_TAG ), "r" ( hc )
  141. : "memory", "cc" );
  142. return reg1;
  143. }
  144. #endif /* _BITS_XEN_H */