book3s_hv_interrupts.S 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #include <asm/asm-compat.h>
  30. #include <asm/feature-fixups.h>
  31. /*****************************************************************************
  32. * *
  33. * Guest entry / exit code that is in kernel module memory (vmalloc) *
  34. * *
  35. ****************************************************************************/
  36. /* Registers:
  37. * none
  38. */
  39. _GLOBAL(__kvmppc_vcore_entry)
  40. /* Write correct stack frame */
  41. mflr r0
  42. std r0,PPC_LR_STKOFF(r1)
  43. /* Save host state to the stack */
  44. stdu r1, -SWITCH_FRAME_SIZE(r1)
  45. /* Save non-volatile registers (r14 - r31) and CR */
  46. SAVE_NVGPRS(r1)
  47. mfcr r3
  48. std r3, _CCR(r1)
  49. /* Save host DSCR */
  50. mfspr r3, SPRN_DSCR
  51. std r3, HSTATE_DSCR(r13)
  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. /* Save host PMU registers */
  58. bl kvmhv_save_host_pmu
  59. /*
  60. * Put whatever is in the decrementer into the
  61. * hypervisor decrementer.
  62. */
  63. BEGIN_FTR_SECTION
  64. ld r5, HSTATE_KVM_VCORE(r13)
  65. ld r6, VCORE_KVM(r5)
  66. ld r9, KVM_HOST_LPCR(r6)
  67. andis. r9, r9, LPCR_LD@h
  68. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  69. mfspr r8,SPRN_DEC
  70. mftb r7
  71. BEGIN_FTR_SECTION
  72. /* On POWER9, don't sign-extend if host LPCR[LD] bit is set */
  73. bne 32f
  74. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  75. extsw r8,r8
  76. 32: mtspr SPRN_HDEC,r8
  77. add r8,r8,r7
  78. std r8,HSTATE_DECEXP(r13)
  79. /* Jump to partition switch code */
  80. bl kvmppc_hv_entry_trampoline
  81. nop
  82. /*
  83. * We return here in virtual mode after the guest exits
  84. * with something that we can't handle in real mode.
  85. * Interrupts are still hard-disabled.
  86. */
  87. /*
  88. * Register usage at this point:
  89. *
  90. * R1 = host R1
  91. * R2 = host R2
  92. * R3 = trap number on this thread
  93. * R12 = exit handler id
  94. * R13 = PACA
  95. */
  96. /* Restore non-volatile host registers (r14 - r31) and CR */
  97. REST_NVGPRS(r1)
  98. ld r4, _CCR(r1)
  99. mtcr r4
  100. addi r1, r1, SWITCH_FRAME_SIZE
  101. ld r0, PPC_LR_STKOFF(r1)
  102. mtlr r0
  103. blr
  104. _GLOBAL(kvmhv_save_host_pmu)
  105. BEGIN_FTR_SECTION
  106. /* Work around P8 PMAE bug */
  107. li r3, -1
  108. clrrdi r3, r3, 10
  109. mfspr r8, SPRN_MMCR2
  110. mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
  111. isync
  112. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  113. li r3, 1
  114. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  115. mfspr r7, SPRN_MMCR0 /* save MMCR0 */
  116. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
  117. mfspr r6, SPRN_MMCRA
  118. /* Clear MMCRA in order to disable SDAR updates */
  119. li r5, 0
  120. mtspr SPRN_MMCRA, r5
  121. isync
  122. lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
  123. cmpwi r5, 0
  124. beq 31f /* skip if not */
  125. mfspr r5, SPRN_MMCR1
  126. mfspr r9, SPRN_SIAR
  127. mfspr r10, SPRN_SDAR
  128. std r7, HSTATE_MMCR0(r13)
  129. std r5, HSTATE_MMCR1(r13)
  130. std r6, HSTATE_MMCRA(r13)
  131. std r9, HSTATE_SIAR(r13)
  132. std r10, HSTATE_SDAR(r13)
  133. BEGIN_FTR_SECTION
  134. mfspr r9, SPRN_SIER
  135. std r8, HSTATE_MMCR2(r13)
  136. std r9, HSTATE_SIER(r13)
  137. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  138. mfspr r3, SPRN_PMC1
  139. mfspr r5, SPRN_PMC2
  140. mfspr r6, SPRN_PMC3
  141. mfspr r7, SPRN_PMC4
  142. mfspr r8, SPRN_PMC5
  143. mfspr r9, SPRN_PMC6
  144. stw r3, HSTATE_PMC1(r13)
  145. stw r5, HSTATE_PMC2(r13)
  146. stw r6, HSTATE_PMC3(r13)
  147. stw r7, HSTATE_PMC4(r13)
  148. stw r8, HSTATE_PMC5(r13)
  149. stw r9, HSTATE_PMC6(r13)
  150. 31: blr