hvCall.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /*
  2. * This file contains the generic code to perform a call to the
  3. * pSeries LPAR hypervisor.
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. #include <asm/hvcall.h>
  11. #include <asm/processor.h>
  12. #include <asm/ppc_asm.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/ptrace.h>
  15. #define STK_PARM(i) (48 + ((i)-3)*8)
  16. #ifdef CONFIG_TRACEPOINTS
  17. .section ".toc","aw"
  18. .globl hcall_tracepoint_refcount
  19. hcall_tracepoint_refcount:
  20. .llong 0
  21. .section ".text"
  22. /*
  23. * precall must preserve all registers. use unused STK_PARM()
  24. * areas to save snapshots and opcode. We branch around this
  25. * in early init (eg when populating the MMU hashtable) by using an
  26. * unconditional cpu feature.
  27. */
  28. #define HCALL_INST_PRECALL(FIRST_REG) \
  29. BEGIN_FTR_SECTION; \
  30. b 1f; \
  31. END_FTR_SECTION(0, 1); \
  32. ld r12,hcall_tracepoint_refcount@toc(r2); \
  33. cmpdi r12,0; \
  34. beq+ 1f; \
  35. mflr r0; \
  36. std r3,STK_PARM(r3)(r1); \
  37. std r4,STK_PARM(r4)(r1); \
  38. std r5,STK_PARM(r5)(r1); \
  39. std r6,STK_PARM(r6)(r1); \
  40. std r7,STK_PARM(r7)(r1); \
  41. std r8,STK_PARM(r8)(r1); \
  42. std r9,STK_PARM(r9)(r1); \
  43. std r10,STK_PARM(r10)(r1); \
  44. std r0,16(r1); \
  45. addi r4,r1,STK_PARM(FIRST_REG); \
  46. stdu r1,-STACK_FRAME_OVERHEAD(r1); \
  47. bl .__trace_hcall_entry; \
  48. addi r1,r1,STACK_FRAME_OVERHEAD; \
  49. ld r0,16(r1); \
  50. ld r3,STK_PARM(r3)(r1); \
  51. ld r4,STK_PARM(r4)(r1); \
  52. ld r5,STK_PARM(r5)(r1); \
  53. ld r6,STK_PARM(r6)(r1); \
  54. ld r7,STK_PARM(r7)(r1); \
  55. ld r8,STK_PARM(r8)(r1); \
  56. ld r9,STK_PARM(r9)(r1); \
  57. ld r10,STK_PARM(r10)(r1); \
  58. mtlr r0; \
  59. 1:
  60. /*
  61. * postcall is performed immediately before function return which
  62. * allows liberal use of volatile registers. We branch around this
  63. * in early init (eg when populating the MMU hashtable) by using an
  64. * unconditional cpu feature.
  65. */
  66. #define __HCALL_INST_POSTCALL \
  67. BEGIN_FTR_SECTION; \
  68. b 1f; \
  69. END_FTR_SECTION(0, 1); \
  70. ld r12,hcall_tracepoint_refcount@toc(r2); \
  71. cmpdi r12,0; \
  72. beq+ 1f; \
  73. mflr r0; \
  74. ld r6,STK_PARM(r3)(r1); \
  75. std r3,STK_PARM(r3)(r1); \
  76. mr r4,r3; \
  77. mr r3,r6; \
  78. std r0,16(r1); \
  79. stdu r1,-STACK_FRAME_OVERHEAD(r1); \
  80. bl .__trace_hcall_exit; \
  81. addi r1,r1,STACK_FRAME_OVERHEAD; \
  82. ld r0,16(r1); \
  83. ld r3,STK_PARM(r3)(r1); \
  84. mtlr r0; \
  85. 1:
  86. #define HCALL_INST_POSTCALL_NORETS \
  87. li r5,0; \
  88. __HCALL_INST_POSTCALL
  89. #define HCALL_INST_POSTCALL(BUFREG) \
  90. mr r5,BUFREG; \
  91. __HCALL_INST_POSTCALL
  92. #else
  93. #define HCALL_INST_PRECALL(FIRST_ARG)
  94. #define HCALL_INST_POSTCALL_NORETS
  95. #define HCALL_INST_POSTCALL(BUFREG)
  96. #endif
  97. .text
  98. _GLOBAL(plpar_hcall_norets)
  99. HMT_MEDIUM
  100. mfcr r0
  101. stw r0,8(r1)
  102. HCALL_INST_PRECALL(r4)
  103. HVSC /* invoke the hypervisor */
  104. HCALL_INST_POSTCALL_NORETS
  105. lwz r0,8(r1)
  106. mtcrf 0xff,r0
  107. blr /* return r3 = status */
  108. _GLOBAL(plpar_hcall)
  109. HMT_MEDIUM
  110. mfcr r0
  111. stw r0,8(r1)
  112. HCALL_INST_PRECALL(r5)
  113. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  114. mr r4,r5
  115. mr r5,r6
  116. mr r6,r7
  117. mr r7,r8
  118. mr r8,r9
  119. mr r9,r10
  120. HVSC /* invoke the hypervisor */
  121. ld r12,STK_PARM(r4)(r1)
  122. std r4, 0(r12)
  123. std r5, 8(r12)
  124. std r6, 16(r12)
  125. std r7, 24(r12)
  126. HCALL_INST_POSTCALL(r12)
  127. lwz r0,8(r1)
  128. mtcrf 0xff,r0
  129. blr /* return r3 = status */
  130. /*
  131. * plpar_hcall_raw can be called in real mode. kexec/kdump need some
  132. * hypervisor calls to be executed in real mode. So plpar_hcall_raw
  133. * does not access the per cpu hypervisor call statistics variables,
  134. * since these variables may not be present in the RMO region.
  135. */
  136. _GLOBAL(plpar_hcall_raw)
  137. HMT_MEDIUM
  138. mfcr r0
  139. stw r0,8(r1)
  140. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  141. mr r4,r5
  142. mr r5,r6
  143. mr r6,r7
  144. mr r7,r8
  145. mr r8,r9
  146. mr r9,r10
  147. HVSC /* invoke the hypervisor */
  148. ld r12,STK_PARM(r4)(r1)
  149. std r4, 0(r12)
  150. std r5, 8(r12)
  151. std r6, 16(r12)
  152. std r7, 24(r12)
  153. lwz r0,8(r1)
  154. mtcrf 0xff,r0
  155. blr /* return r3 = status */
  156. _GLOBAL(plpar_hcall9)
  157. HMT_MEDIUM
  158. mfcr r0
  159. stw r0,8(r1)
  160. HCALL_INST_PRECALL(r5)
  161. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  162. mr r4,r5
  163. mr r5,r6
  164. mr r6,r7
  165. mr r7,r8
  166. mr r8,r9
  167. mr r9,r10
  168. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  169. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  170. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  171. HVSC /* invoke the hypervisor */
  172. mr r0,r12
  173. ld r12,STK_PARM(r4)(r1)
  174. std r4, 0(r12)
  175. std r5, 8(r12)
  176. std r6, 16(r12)
  177. std r7, 24(r12)
  178. std r8, 32(r12)
  179. std r9, 40(r12)
  180. std r10,48(r12)
  181. std r11,56(r12)
  182. std r0, 64(r12)
  183. HCALL_INST_POSTCALL(r12)
  184. lwz r0,8(r1)
  185. mtcrf 0xff,r0
  186. blr /* return r3 = status */
  187. /* See plpar_hcall_raw to see why this is needed */
  188. _GLOBAL(plpar_hcall9_raw)
  189. HMT_MEDIUM
  190. mfcr r0
  191. stw r0,8(r1)
  192. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  193. mr r4,r5
  194. mr r5,r6
  195. mr r6,r7
  196. mr r7,r8
  197. mr r8,r9
  198. mr r9,r10
  199. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  200. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  201. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  202. HVSC /* invoke the hypervisor */
  203. mr r0,r12
  204. ld r12,STK_PARM(r4)(r1)
  205. std r4, 0(r12)
  206. std r5, 8(r12)
  207. std r6, 16(r12)
  208. std r7, 24(r12)
  209. std r8, 32(r12)
  210. std r9, 40(r12)
  211. std r10,48(r12)
  212. std r11,56(r12)
  213. std r0, 64(r12)
  214. lwz r0,8(r1)
  215. mtcrf 0xff,r0
  216. blr /* return r3 = status */