book3s_hv_interrupts.S 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
  5. *
  6. * Derived from book3s_interrupts.S, which is:
  7. * Copyright SUSE Linux Products GmbH 2009
  8. *
  9. * Authors: Alexander Graf <agraf@suse.de>
  10. */
  11. #include <linux/linkage.h>
  12. #include <asm/ppc_asm.h>
  13. #include <asm/kvm_asm.h>
  14. #include <asm/reg.h>
  15. #include <asm/page.h>
  16. #include <asm/asm-offsets.h>
  17. #include <asm/exception-64s.h>
  18. #include <asm/ppc-opcode.h>
  19. #include <asm/asm-compat.h>
  20. #include <asm/feature-fixups.h>
  21. /*****************************************************************************
  22. * *
  23. * Guest entry / exit code that is in kernel module memory (vmalloc) *
  24. * *
  25. ****************************************************************************/
  26. /* Registers:
  27. * none
  28. */
  29. _GLOBAL(__kvmppc_vcore_entry)
  30. /* Write correct stack frame */
  31. mflr r0
  32. std r0,PPC_LR_STKOFF(r1)
  33. /* Save host state to the stack */
  34. stdu r1, -SWITCH_FRAME_SIZE(r1)
  35. /* Save non-volatile registers (r14 - r31) and CR */
  36. SAVE_NVGPRS(r1)
  37. mfcr r3
  38. std r3, _CCR(r1)
  39. /* Save host DSCR */
  40. mfspr r3, SPRN_DSCR
  41. std r3, HSTATE_DSCR(r13)
  42. BEGIN_FTR_SECTION
  43. /* Save host DABR */
  44. mfspr r3, SPRN_DABR
  45. std r3, HSTATE_DABR(r13)
  46. END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
  47. /* Save host PMU registers */
  48. bl kvmhv_save_host_pmu
  49. /*
  50. * Put whatever is in the decrementer into the
  51. * hypervisor decrementer.
  52. * Because of a hardware deviation in P8,
  53. * we need to set LPCR[HDICE] before writing HDEC.
  54. */
  55. ld r5, HSTATE_KVM_VCORE(r13)
  56. ld r6, VCORE_KVM(r5)
  57. ld r9, KVM_HOST_LPCR(r6)
  58. ori r8, r9, LPCR_HDICE
  59. mtspr SPRN_LPCR, r8
  60. isync
  61. mfspr r8,SPRN_DEC
  62. mftb r7
  63. extsw r8,r8
  64. mtspr SPRN_HDEC,r8
  65. add r8,r8,r7
  66. std r8,HSTATE_DECEXP(r13)
  67. /* Jump to partition switch code */
  68. bl kvmppc_hv_entry_trampoline
  69. nop
  70. /*
  71. * We return here in virtual mode after the guest exits
  72. * with something that we can't handle in real mode.
  73. * Interrupts are still hard-disabled.
  74. */
  75. /*
  76. * Register usage at this point:
  77. *
  78. * R1 = host R1
  79. * R2 = host R2
  80. * R3 = trap number on this thread
  81. * R12 = exit handler id
  82. * R13 = PACA
  83. */
  84. /* Restore non-volatile host registers (r14 - r31) and CR */
  85. REST_NVGPRS(r1)
  86. ld r4, _CCR(r1)
  87. mtcr r4
  88. addi r1, r1, SWITCH_FRAME_SIZE
  89. ld r0, PPC_LR_STKOFF(r1)
  90. mtlr r0
  91. blr
  92. /*
  93. * void kvmhv_save_host_pmu(void)
  94. */
  95. SYM_FUNC_START_LOCAL(kvmhv_save_host_pmu)
  96. BEGIN_FTR_SECTION
  97. /* Work around P8 PMAE bug */
  98. li r3, -1
  99. clrrdi r3, r3, 10
  100. mfspr r8, SPRN_MMCR2
  101. mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
  102. isync
  103. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  104. li r3, 1
  105. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  106. mfspr r7, SPRN_MMCR0 /* save MMCR0 */
  107. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
  108. mfspr r6, SPRN_MMCRA
  109. /* Clear MMCRA in order to disable SDAR updates */
  110. li r5, 0
  111. mtspr SPRN_MMCRA, r5
  112. isync
  113. lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
  114. cmpwi r5, 0
  115. beq 31f /* skip if not */
  116. mfspr r5, SPRN_MMCR1
  117. mfspr r9, SPRN_SIAR
  118. mfspr r10, SPRN_SDAR
  119. std r7, HSTATE_MMCR0(r13)
  120. std r5, HSTATE_MMCR1(r13)
  121. std r6, HSTATE_MMCRA(r13)
  122. std r9, HSTATE_SIAR(r13)
  123. std r10, HSTATE_SDAR(r13)
  124. BEGIN_FTR_SECTION
  125. mfspr r9, SPRN_SIER
  126. std r8, HSTATE_MMCR2(r13)
  127. std r9, HSTATE_SIER(r13)
  128. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  129. mfspr r3, SPRN_PMC1
  130. mfspr r5, SPRN_PMC2
  131. mfspr r6, SPRN_PMC3
  132. mfspr r7, SPRN_PMC4
  133. mfspr r8, SPRN_PMC5
  134. mfspr r9, SPRN_PMC6
  135. stw r3, HSTATE_PMC1(r13)
  136. stw r5, HSTATE_PMC2(r13)
  137. stw r6, HSTATE_PMC3(r13)
  138. stw r7, HSTATE_PMC4(r13)
  139. stw r8, HSTATE_PMC5(r13)
  140. stw r9, HSTATE_PMC6(r13)
  141. 31: blr
  142. SYM_FUNC_END(kvmhv_save_host_pmu)