hvCall.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #define STK_PARM(i) (48 + ((i)-3)*8)
  15. #ifdef CONFIG_HCALL_STATS
  16. /*
  17. * precall must preserve all registers. use unused STK_PARM()
  18. * areas to save snapshots and opcode.
  19. */
  20. #define HCALL_INST_PRECALL \
  21. std r3,STK_PARM(r3)(r1); /* save opcode */ \
  22. mftb r0; /* get timebase and */ \
  23. std r0,STK_PARM(r5)(r1); /* save for later */ \
  24. BEGIN_FTR_SECTION; \
  25. mfspr r0,SPRN_PURR; /* get PURR and */ \
  26. std r0,STK_PARM(r6)(r1); /* save for later */ \
  27. END_FTR_SECTION_IFSET(CPU_FTR_PURR);
  28. /*
  29. * postcall is performed immediately before function return which
  30. * allows liberal use of volatile registers. We branch around this
  31. * in early init (eg when populating the MMU hashtable) by using an
  32. * unconditional cpu feature.
  33. */
  34. #define HCALL_INST_POSTCALL \
  35. BEGIN_FTR_SECTION; \
  36. b 1f; \
  37. END_FTR_SECTION(0, 1); \
  38. ld r4,STK_PARM(r3)(r1); /* validate opcode */ \
  39. cmpldi cr7,r4,MAX_HCALL_OPCODE; \
  40. bgt- cr7,1f; \
  41. \
  42. /* get time and PURR snapshots after hcall */ \
  43. mftb r7; /* timebase after */ \
  44. BEGIN_FTR_SECTION; \
  45. mfspr r8,SPRN_PURR; /* PURR after */ \
  46. ld r6,STK_PARM(r6)(r1); /* PURR before */ \
  47. subf r6,r6,r8; /* delta */ \
  48. END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
  49. ld r5,STK_PARM(r5)(r1); /* timebase before */ \
  50. subf r5,r5,r7; /* time delta */ \
  51. \
  52. /* calculate address of stat structure r4 = opcode */ \
  53. srdi r4,r4,2; /* index into array */ \
  54. mulli r4,r4,HCALL_STAT_SIZE; \
  55. LOAD_REG_ADDR(r7, per_cpu__hcall_stats); \
  56. add r4,r4,r7; \
  57. ld r7,PACA_DATA_OFFSET(r13); /* per cpu offset */ \
  58. add r4,r4,r7; \
  59. \
  60. /* update stats */ \
  61. ld r7,HCALL_STAT_CALLS(r4); /* count */ \
  62. addi r7,r7,1; \
  63. std r7,HCALL_STAT_CALLS(r4); \
  64. ld r7,HCALL_STAT_TB(r4); /* timebase */ \
  65. add r7,r7,r5; \
  66. std r7,HCALL_STAT_TB(r4); \
  67. BEGIN_FTR_SECTION; \
  68. ld r7,HCALL_STAT_PURR(r4); /* PURR */ \
  69. add r7,r7,r6; \
  70. std r7,HCALL_STAT_PURR(r4); \
  71. END_FTR_SECTION_IFSET(CPU_FTR_PURR); \
  72. 1:
  73. #else
  74. #define HCALL_INST_PRECALL
  75. #define HCALL_INST_POSTCALL
  76. #endif
  77. .text
  78. _GLOBAL(plpar_hcall_norets)
  79. HMT_MEDIUM
  80. mfcr r0
  81. stw r0,8(r1)
  82. HCALL_INST_PRECALL
  83. HVSC /* invoke the hypervisor */
  84. HCALL_INST_POSTCALL
  85. lwz r0,8(r1)
  86. mtcrf 0xff,r0
  87. blr /* return r3 = status */
  88. _GLOBAL(plpar_hcall)
  89. HMT_MEDIUM
  90. mfcr r0
  91. stw r0,8(r1)
  92. HCALL_INST_PRECALL
  93. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  94. mr r4,r5
  95. mr r5,r6
  96. mr r6,r7
  97. mr r7,r8
  98. mr r8,r9
  99. mr r9,r10
  100. HVSC /* invoke the hypervisor */
  101. ld r12,STK_PARM(r4)(r1)
  102. std r4, 0(r12)
  103. std r5, 8(r12)
  104. std r6, 16(r12)
  105. std r7, 24(r12)
  106. HCALL_INST_POSTCALL
  107. lwz r0,8(r1)
  108. mtcrf 0xff,r0
  109. blr /* return r3 = status */
  110. /*
  111. * plpar_hcall_raw can be called in real mode. kexec/kdump need some
  112. * hypervisor calls to be executed in real mode. So plpar_hcall_raw
  113. * does not access the per cpu hypervisor call statistics variables,
  114. * since these variables may not be present in the RMO region.
  115. */
  116. _GLOBAL(plpar_hcall_raw)
  117. HMT_MEDIUM
  118. mfcr r0
  119. stw r0,8(r1)
  120. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  121. mr r4,r5
  122. mr r5,r6
  123. mr r6,r7
  124. mr r7,r8
  125. mr r8,r9
  126. mr r9,r10
  127. HVSC /* invoke the hypervisor */
  128. ld r12,STK_PARM(r4)(r1)
  129. std r4, 0(r12)
  130. std r5, 8(r12)
  131. std r6, 16(r12)
  132. std r7, 24(r12)
  133. lwz r0,8(r1)
  134. mtcrf 0xff,r0
  135. blr /* return r3 = status */
  136. _GLOBAL(plpar_hcall9)
  137. HMT_MEDIUM
  138. mfcr r0
  139. stw r0,8(r1)
  140. HCALL_INST_PRECALL
  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. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  149. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  150. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  151. HVSC /* invoke the hypervisor */
  152. mr r0,r12
  153. ld r12,STK_PARM(r4)(r1)
  154. std r4, 0(r12)
  155. std r5, 8(r12)
  156. std r6, 16(r12)
  157. std r7, 24(r12)
  158. std r8, 32(r12)
  159. std r9, 40(r12)
  160. std r10,48(r12)
  161. std r11,56(r12)
  162. std r0, 64(r12)
  163. HCALL_INST_POSTCALL
  164. lwz r0,8(r1)
  165. mtcrf 0xff,r0
  166. blr /* return r3 = status */