book3s_hv_interrupts.S 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License, version 2, as
  4. * published by the Free Software Foundation.
  5. *
  6. * This program is distributed in the hope that it will be useful,
  7. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. * GNU General Public License for more details.
  10. *
  11. * You should have received a copy of the GNU General Public License
  12. * along with this program; if not, write to the Free Software
  13. * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. *
  15. * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
  16. *
  17. * Derived from book3s_interrupts.S, which is:
  18. * Copyright SUSE Linux Products GmbH 2009
  19. *
  20. * Authors: Alexander Graf <agraf@suse.de>
  21. */
  22. #include <asm/ppc_asm.h>
  23. #include <asm/kvm_asm.h>
  24. #include <asm/reg.h>
  25. #include <asm/page.h>
  26. #include <asm/asm-offsets.h>
  27. #include <asm/exception-64s.h>
  28. #include <asm/ppc-opcode.h>
  29. /*****************************************************************************
  30. * *
  31. * Guest entry / exit code that is in kernel module memory (vmalloc) *
  32. * *
  33. ****************************************************************************/
  34. /* Registers:
  35. * none
  36. */
  37. _GLOBAL(__kvmppc_vcore_entry)
  38. /* Write correct stack frame */
  39. mflr r0
  40. std r0,PPC_LR_STKOFF(r1)
  41. /* Save host state to the stack */
  42. stdu r1, -SWITCH_FRAME_SIZE(r1)
  43. /* Save non-volatile registers (r14 - r31) and CR */
  44. SAVE_NVGPRS(r1)
  45. mfcr r3
  46. std r3, _CCR(r1)
  47. /* Save host DSCR */
  48. BEGIN_FTR_SECTION
  49. mfspr r3, SPRN_DSCR
  50. std r3, HSTATE_DSCR(r13)
  51. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  52. BEGIN_FTR_SECTION
  53. /* Save host DABR */
  54. mfspr r3, SPRN_DABR
  55. std r3, HSTATE_DABR(r13)
  56. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  57. /* Hard-disable interrupts */
  58. mfmsr r10
  59. std r10, HSTATE_HOST_MSR(r13)
  60. rldicl r10,r10,48,1
  61. rotldi r10,r10,16
  62. mtmsrd r10,1
  63. /* Save host PMU registers */
  64. BEGIN_FTR_SECTION
  65. /* Work around P8 PMAE bug */
  66. li r3, -1
  67. clrrdi r3, r3, 10
  68. mfspr r8, SPRN_MMCR2
  69. mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
  70. isync
  71. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  72. li r3, 1
  73. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  74. mfspr r7, SPRN_MMCR0 /* save MMCR0 */
  75. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
  76. mfspr r6, SPRN_MMCRA
  77. BEGIN_FTR_SECTION
  78. /* On P7, clear MMCRA in order to disable SDAR updates */
  79. li r5, 0
  80. mtspr SPRN_MMCRA, r5
  81. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
  82. isync
  83. ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
  84. lbz r5, LPPACA_PMCINUSE(r3)
  85. cmpwi r5, 0
  86. beq 31f /* skip if not */
  87. mfspr r5, SPRN_MMCR1
  88. mfspr r9, SPRN_SIAR
  89. mfspr r10, SPRN_SDAR
  90. std r7, HSTATE_MMCR(r13)
  91. std r5, HSTATE_MMCR + 8(r13)
  92. std r6, HSTATE_MMCR + 16(r13)
  93. std r9, HSTATE_MMCR + 24(r13)
  94. std r10, HSTATE_MMCR + 32(r13)
  95. BEGIN_FTR_SECTION
  96. mfspr r9, SPRN_SIER
  97. std r8, HSTATE_MMCR + 40(r13)
  98. std r9, HSTATE_MMCR + 48(r13)
  99. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  100. mfspr r3, SPRN_PMC1
  101. mfspr r5, SPRN_PMC2
  102. mfspr r6, SPRN_PMC3
  103. mfspr r7, SPRN_PMC4
  104. mfspr r8, SPRN_PMC5
  105. mfspr r9, SPRN_PMC6
  106. BEGIN_FTR_SECTION
  107. mfspr r10, SPRN_PMC7
  108. mfspr r11, SPRN_PMC8
  109. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  110. stw r3, HSTATE_PMC(r13)
  111. stw r5, HSTATE_PMC + 4(r13)
  112. stw r6, HSTATE_PMC + 8(r13)
  113. stw r7, HSTATE_PMC + 12(r13)
  114. stw r8, HSTATE_PMC + 16(r13)
  115. stw r9, HSTATE_PMC + 20(r13)
  116. BEGIN_FTR_SECTION
  117. stw r10, HSTATE_PMC + 24(r13)
  118. stw r11, HSTATE_PMC + 28(r13)
  119. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  120. 31:
  121. /*
  122. * Put whatever is in the decrementer into the
  123. * hypervisor decrementer.
  124. */
  125. mfspr r8,SPRN_DEC
  126. mftb r7
  127. mtspr SPRN_HDEC,r8
  128. extsw r8,r8
  129. add r8,r8,r7
  130. std r8,HSTATE_DECEXP(r13)
  131. #ifdef CONFIG_SMP
  132. /*
  133. * On PPC970, if the guest vcpu has an external interrupt pending,
  134. * send ourselves an IPI so as to interrupt the guest once it
  135. * enables interrupts. (It must have interrupts disabled,
  136. * otherwise we would already have delivered the interrupt.)
  137. *
  138. * XXX If this is a UP build, smp_send_reschedule is not available,
  139. * so the interrupt will be delayed until the next time the vcpu
  140. * enters the guest with interrupts enabled.
  141. */
  142. BEGIN_FTR_SECTION
  143. ld r4, HSTATE_KVM_VCPU(r13)
  144. ld r0, VCPU_PENDING_EXC(r4)
  145. li r7, (1 << BOOK3S_IRQPRIO_EXTERNAL)
  146. oris r7, r7, (1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
  147. and. r0, r0, r7
  148. beq 32f
  149. lhz r3, PACAPACAINDEX(r13)
  150. bl smp_send_reschedule
  151. nop
  152. 32:
  153. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
  154. #endif /* CONFIG_SMP */
  155. /* Jump to partition switch code */
  156. bl kvmppc_hv_entry_trampoline
  157. nop
  158. /*
  159. * We return here in virtual mode after the guest exits
  160. * with something that we can't handle in real mode.
  161. * Interrupts are enabled again at this point.
  162. */
  163. /*
  164. * Register usage at this point:
  165. *
  166. * R1 = host R1
  167. * R2 = host R2
  168. * R12 = exit handler id
  169. * R13 = PACA
  170. */
  171. /* Restore non-volatile host registers (r14 - r31) and CR */
  172. REST_NVGPRS(r1)
  173. ld r4, _CCR(r1)
  174. mtcr r4
  175. addi r1, r1, SWITCH_FRAME_SIZE
  176. ld r0, PPC_LR_STKOFF(r1)
  177. mtlr r0
  178. blr