hvCall.S 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_IFCLR(CPU_FTR_PURR);
  28. /*
  29. * postcall is performed immediately before function return which
  30. * allows liberal use of volatile registers.
  31. */
  32. #define HCALL_INST_POSTCALL \
  33. ld r4,STK_PARM(r3)(r1); /* validate opcode */ \
  34. cmpldi cr7,r4,MAX_HCALL_OPCODE; \
  35. bgt- cr7,1f; \
  36. \
  37. /* get time and PURR snapshots after hcall */ \
  38. mftb r7; /* timebase after */ \
  39. BEGIN_FTR_SECTION; \
  40. mfspr r8,SPRN_PURR; /* PURR after */ \
  41. ld r6,STK_PARM(r6)(r1); /* PURR before */ \
  42. subf r6,r6,r8; /* delta */ \
  43. END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \
  44. ld r5,STK_PARM(r5)(r1); /* timebase before */ \
  45. subf r5,r5,r7; /* time delta */ \
  46. \
  47. /* calculate address of stat structure r4 = opcode */ \
  48. srdi r4,r4,2; /* index into array */ \
  49. mulli r4,r4,HCALL_STAT_SIZE; \
  50. LOAD_REG_ADDR(r7, per_cpu__hcall_stats); \
  51. add r4,r4,r7; \
  52. ld r7,PACA_DATA_OFFSET(r13); /* per cpu offset */ \
  53. add r4,r4,r7; \
  54. \
  55. /* update stats */ \
  56. ld r7,HCALL_STAT_CALLS(r4); /* count */ \
  57. addi r7,r7,1; \
  58. std r7,HCALL_STAT_CALLS(r4); \
  59. ld r7,HCALL_STAT_TB(r4); /* timebase */ \
  60. add r7,r7,r5; \
  61. std r7,HCALL_STAT_TB(r4); \
  62. BEGIN_FTR_SECTION; \
  63. ld r7,HCALL_STAT_PURR(r4); /* PURR */ \
  64. add r7,r7,r6; \
  65. std r7,HCALL_STAT_PURR(r4); \
  66. END_FTR_SECTION_IFCLR(CPU_FTR_PURR); \
  67. 1:
  68. #else
  69. #define HCALL_INST_PRECALL
  70. #define HCALL_INST_POSTCALL
  71. #endif
  72. .text
  73. _GLOBAL(plpar_hcall_norets)
  74. HMT_MEDIUM
  75. mfcr r0
  76. stw r0,8(r1)
  77. HCALL_INST_PRECALL
  78. HVSC /* invoke the hypervisor */
  79. HCALL_INST_POSTCALL
  80. lwz r0,8(r1)
  81. mtcrf 0xff,r0
  82. blr /* return r3 = status */
  83. _GLOBAL(plpar_hcall)
  84. HMT_MEDIUM
  85. mfcr r0
  86. stw r0,8(r1)
  87. HCALL_INST_PRECALL
  88. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  89. mr r4,r5
  90. mr r5,r6
  91. mr r6,r7
  92. mr r7,r8
  93. mr r8,r9
  94. mr r9,r10
  95. HVSC /* invoke the hypervisor */
  96. ld r12,STK_PARM(r4)(r1)
  97. std r4, 0(r12)
  98. std r5, 8(r12)
  99. std r6, 16(r12)
  100. std r7, 24(r12)
  101. HCALL_INST_POSTCALL
  102. lwz r0,8(r1)
  103. mtcrf 0xff,r0
  104. blr /* return r3 = status */
  105. _GLOBAL(plpar_hcall9)
  106. HMT_MEDIUM
  107. mfcr r0
  108. stw r0,8(r1)
  109. HCALL_INST_PRECALL
  110. std r4,STK_PARM(r4)(r1) /* Save ret buffer */
  111. mr r4,r5
  112. mr r5,r6
  113. mr r6,r7
  114. mr r7,r8
  115. mr r8,r9
  116. mr r9,r10
  117. ld r10,STK_PARM(r11)(r1) /* put arg7 in R10 */
  118. ld r11,STK_PARM(r12)(r1) /* put arg8 in R11 */
  119. ld r12,STK_PARM(r13)(r1) /* put arg9 in R12 */
  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. std r8, 32(r12)
  127. std r9, 40(r12)
  128. std r10,48(r12)
  129. std r11,56(r12)
  130. std r12,64(r12)
  131. HCALL_INST_POSTCALL
  132. lwz r0,8(r1)
  133. mtcrf 0xff,r0
  134. blr /* return r3 = status */