/arch/powerpc/kvm/book3s_hv_interrupts.S

http://github.com/mirrors/linux · Assembly · 155 lines · 92 code · 16 blank · 47 comment · 0 complexity · c0867ccc5b7b525d1766987b2acf0655 MD5 · raw file

  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 <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. */
  52. BEGIN_FTR_SECTION
  53. ld r5, HSTATE_KVM_VCORE(r13)
  54. ld r6, VCORE_KVM(r5)
  55. ld r9, KVM_HOST_LPCR(r6)
  56. andis. r9, r9, LPCR_LD@h
  57. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  58. mfspr r8,SPRN_DEC
  59. mftb r7
  60. BEGIN_FTR_SECTION
  61. /* On POWER9, don't sign-extend if host LPCR[LD] bit is set */
  62. bne 32f
  63. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
  64. extsw r8,r8
  65. 32: mtspr SPRN_HDEC,r8
  66. add r8,r8,r7
  67. std r8,HSTATE_DECEXP(r13)
  68. /* Jump to partition switch code */
  69. bl kvmppc_hv_entry_trampoline
  70. nop
  71. /*
  72. * We return here in virtual mode after the guest exits
  73. * with something that we can't handle in real mode.
  74. * Interrupts are still hard-disabled.
  75. */
  76. /*
  77. * Register usage at this point:
  78. *
  79. * R1 = host R1
  80. * R2 = host R2
  81. * R3 = trap number on this thread
  82. * R12 = exit handler id
  83. * R13 = PACA
  84. */
  85. /* Restore non-volatile host registers (r14 - r31) and CR */
  86. REST_NVGPRS(r1)
  87. ld r4, _CCR(r1)
  88. mtcr r4
  89. addi r1, r1, SWITCH_FRAME_SIZE
  90. ld r0, PPC_LR_STKOFF(r1)
  91. mtlr r0
  92. blr
  93. _GLOBAL(kvmhv_save_host_pmu)
  94. BEGIN_FTR_SECTION
  95. /* Work around P8 PMAE bug */
  96. li r3, -1
  97. clrrdi r3, r3, 10
  98. mfspr r8, SPRN_MMCR2
  99. mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
  100. isync
  101. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  102. li r3, 1
  103. sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
  104. mfspr r7, SPRN_MMCR0 /* save MMCR0 */
  105. mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
  106. mfspr r6, SPRN_MMCRA
  107. /* Clear MMCRA in order to disable SDAR updates */
  108. li r5, 0
  109. mtspr SPRN_MMCRA, r5
  110. isync
  111. lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
  112. cmpwi r5, 0
  113. beq 31f /* skip if not */
  114. mfspr r5, SPRN_MMCR1
  115. mfspr r9, SPRN_SIAR
  116. mfspr r10, SPRN_SDAR
  117. std r7, HSTATE_MMCR0(r13)
  118. std r5, HSTATE_MMCR1(r13)
  119. std r6, HSTATE_MMCRA(r13)
  120. std r9, HSTATE_SIAR(r13)
  121. std r10, HSTATE_SDAR(r13)
  122. BEGIN_FTR_SECTION
  123. mfspr r9, SPRN_SIER
  124. std r8, HSTATE_MMCR2(r13)
  125. std r9, HSTATE_SIER(r13)
  126. END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
  127. mfspr r3, SPRN_PMC1
  128. mfspr r5, SPRN_PMC2
  129. mfspr r6, SPRN_PMC3
  130. mfspr r7, SPRN_PMC4
  131. mfspr r8, SPRN_PMC5
  132. mfspr r9, SPRN_PMC6
  133. stw r3, HSTATE_PMC1(r13)
  134. stw r5, HSTATE_PMC2(r13)
  135. stw r6, HSTATE_PMC3(r13)
  136. stw r7, HSTATE_PMC4(r13)
  137. stw r8, HSTATE_PMC5(r13)
  138. stw r9, HSTATE_PMC6(r13)
  139. 31: blr