hvCall.S 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. std r12,32(r1); \
  34. cmpdi r12,0; \
  35. beq+ 1f; \
  36. mflr r0; \
  37. std r3,STK_PARM(r3)(r1); \
  38. std r4,STK_PARM(r4)(r1); \
  39. std r5,STK_PARM(r5)(r1); \
  40. std r6,STK_PARM(r6)(r1); \
  41. std r7,STK_PARM(r7)(r1); \
  42. std r8,STK_PARM(r8)(r1); \
  43. std r9,STK_PARM(r9)(r1); \
  44. std r10,STK_PARM(r10)(r1); \
  45. std r0,16(r1); \
  46. addi r4,r1,STK_PARM(FIRST_REG); \
  47. stdu r1,-STACK_FRAME_OVERHEAD(r1); \
  48. bl .__trace_hcall_entry; \
  49. addi r1,r1,STACK_FRAME_OVERHEAD; \
  50. ld r0,16(r1); \
  51. ld r3,STK_PARM(r3)(r1); \
  52. ld r4,STK_PARM(r4)(r1); \
  53. ld r5,STK_PARM(r5)(r1); \
  54. ld r6,STK_PARM(r6)(r1); \
  55. ld r7,STK_PARM(r7)(r1); \
  56. ld r8,STK_PARM(r8)(r1); \
  57. ld r9,STK_PARM(r9)(r1); \
  58. ld r10,STK_PARM(r10)(r1); \
  59. mtlr r0; \
  60. 1:
  61. /*
  62. * postcall is performed immediately before function return which
  63. * allows liberal use of volatile registers. We branch around this
  64. * in early init (eg when populating the MMU hashtable) by using an
  65. * unconditional cpu feature.
  66. */
  67. #define __HCALL_INST_POSTCALL \
  68. BEGIN_FTR_SECTION; \
  69. b 1f; \
  70. END_FTR_SECTION(0, 1); \
  71. ld r12,32(r1); \
  72. cmpdi r12,0; \
  73. beq+ 1f; \
  74. mflr r0; \
  75. ld r6,STK_PARM(r3)(r1); \
  76. std r3,STK_PARM(r3)(r1); \
  77. mr r4,r3; \
  78. mr r3,r6; \
  79. std r0,16(r1); \
  80. stdu r1,-STACK_FRAME_OVERHEAD(r1); \
  81. bl .__trace_hcall_exit; \
  82. addi r1,r1,STACK_FRAME_OVERHEAD; \
  83. ld r0,16(r1); \
  84. ld r3,STK_PARM(r3)(r1); \
  85. mtlr r0; \
  86. 1:
  87. #define HCALL_INST_POSTCALL_NORETS \
  88. li r5,0; \
  89. __HCALL_INST_POSTCALL
  90. #define HCALL_INST_POSTCALL(BUFREG) \
  91. mr r5,BUFREG; \
  92. __HCALL_INST_POSTCALL
  93. #else
  94. #define HCALL_INST_PRECALL(FIRST_ARG)
  95. #define HCALL_INST_POSTCALL_NORETS
  96. #define HCALL_INST_POSTCALL(BUFREG)
  97. #endif
  98. .text
  99. _GLOBAL(plpar_hcall_norets)
  100. HMT_MEDIUM
  101. mfcr r0
  102. stw r0,8(r1)
  103. HCALL_INST_PRECALL(r4)
  104. HVSC /* invoke the hypervisor */
  105. HCALL_INST_POSTCALL_NORETS
  106. lwz r0,8(r1)
  107. mtcrf 0xff,r0
  108. blr /* return r3 = status */
  109. _GLOBAL(plpar_hcall)
  110. HMT_MEDIUM
  111. mfcr r0
  112. stw r0,8(r1)
  113. HCALL_INST_PRECALL(r5)
  114. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  115. mr r4,r5
  116. mr r5,r6
  117. mr r6,r7
  118. mr r7,r8
  119. mr r8,r9
  120. mr r9,r10
  121. HVSC /* invoke the hypervisor */
  122. ld r12,STK_PARM(r4)(r1)
  123. std r4, 0(r12)
  124. std r5, 8(r12)
  125. std r6, 16(r12)
  126. std r7, 24(r12)
  127. HCALL_INST_POSTCALL(r12)
  128. lwz r0,8(r1)
  129. mtcrf 0xff,r0
  130. blr /* return r3 = status */
  131. /*
  132. * plpar_hcall_raw can be called in real mode. kexec/kdump need some
  133. * hypervisor calls to be executed in real mode. So plpar_hcall_raw
  134. * does not access the per cpu hypervisor call statistics variables,
  135. * since these variables may not be present in the RMO region.
  136. */
  137. _GLOBAL(plpar_hcall_raw)
  138. HMT_MEDIUM
  139. mfcr r0
  140. stw r0,8(r1)
  141. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  142. mr r4,r5
  143. mr r5,r6
  144. mr r6,r7
  145. mr r7,r8
  146. mr r8,r9
  147. mr r9,r10
  148. HVSC /* invoke the hypervisor */
  149. ld r12,STK_PARM(r4)(r1)
  150. std r4, 0(r12)
  151. std r5, 8(r12)
  152. std r6, 16(r12)
  153. std r7, 24(r12)
  154. lwz r0,8(r1)
  155. mtcrf 0xff,r0
  156. blr /* return r3 = status */
  157. _GLOBAL(plpar_hcall9)
  158. HMT_MEDIUM
  159. mfcr r0
  160. stw r0,8(r1)
  161. HCALL_INST_PRECALL(r5)
  162. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  163. mr r4,r5
  164. mr r5,r6
  165. mr r6,r7
  166. mr r7,r8
  167. mr r8,r9
  168. mr r9,r10
  169. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  170. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  171. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  172. HVSC /* invoke the hypervisor */
  173. mr r0,r12
  174. ld r12,STK_PARM(r4)(r1)
  175. std r4, 0(r12)
  176. std r5, 8(r12)
  177. std r6, 16(r12)
  178. std r7, 24(r12)
  179. std r8, 32(r12)
  180. std r9, 40(r12)
  181. std r10,48(r12)
  182. std r11,56(r12)
  183. std r0, 64(r12)
  184. HCALL_INST_POSTCALL(r12)
  185. lwz r0,8(r1)
  186. mtcrf 0xff,r0
  187. blr /* return r3 = status */
  188. /* See plpar_hcall_raw to see why this is needed */
  189. _GLOBAL(plpar_hcall9_raw)
  190. HMT_MEDIUM
  191. mfcr r0
  192. stw r0,8(r1)
  193. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  194. mr r4,r5
  195. mr r5,r6
  196. mr r6,r7
  197. mr r7,r8
  198. mr r8,r9
  199. mr r9,r10
  200. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  201. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  202. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  203. HVSC /* invoke the hypervisor */
  204. mr r0,r12
  205. ld r12,STK_PARM(r4)(r1)
  206. std r4, 0(r12)
  207. std r5, 8(r12)
  208. std r6, 16(r12)
  209. std r7, 24(r12)
  210. std r8, 32(r12)
  211. std r9, 40(r12)
  212. std r10,48(r12)
  213. std r11,56(r12)
  214. std r0, 64(r12)
  215. lwz r0,8(r1)
  216. mtcrf 0xff,r0
  217. blr /* return r3 = status */