book3s_hv_interrupts.S 3.7 KB

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