book3s_rmhandlers.S 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. *
  4. * Copyright SUSE Linux Products GmbH 2009
  5. *
  6. * Authors: Alexander Graf <agraf@suse.de>
  7. */
  8. #include <asm/ppc_asm.h>
  9. #include <asm/kvm_asm.h>
  10. #include <asm/reg.h>
  11. #include <asm/mmu.h>
  12. #include <asm/page.h>
  13. #include <asm/asm-offsets.h>
  14. #include <asm/asm-compat.h>
  15. #ifdef CONFIG_PPC_BOOK3S_64
  16. #include <asm/exception-64s.h>
  17. #endif
  18. /*****************************************************************************
  19. * *
  20. * Real Mode handlers that need to be in low physical memory *
  21. * *
  22. ****************************************************************************/
  23. #if defined(CONFIG_PPC_BOOK3S_64)
  24. #ifdef PPC64_ELF_ABI_v2
  25. #define FUNC(name) name
  26. #else
  27. #define FUNC(name) GLUE(.,name)
  28. #endif
  29. #elif defined(CONFIG_PPC_BOOK3S_32)
  30. #define FUNC(name) name
  31. #define RFI_TO_KERNEL RFI
  32. #define RFI_TO_GUEST RFI
  33. .macro INTERRUPT_TRAMPOLINE intno
  34. .global kvmppc_trampoline_\intno
  35. kvmppc_trampoline_\intno:
  36. mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
  37. /*
  38. * First thing to do is to find out if we're coming
  39. * from a KVM guest or a Linux process.
  40. *
  41. * To distinguish, we check a magic byte in the PACA/current
  42. */
  43. mfspr r13, SPRN_SPRG_THREAD
  44. lwz r13, THREAD_KVM_SVCPU(r13)
  45. /* PPC32 can have a NULL pointer - let's check for that */
  46. mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
  47. mfcr r12
  48. cmpwi r13, 0
  49. bne 1f
  50. 2: mtcr r12
  51. mfspr r12, SPRN_SPRG_SCRATCH1
  52. mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
  53. b kvmppc_resume_\intno /* Get back original handler */
  54. 1: tophys(r13, r13)
  55. stw r12, HSTATE_SCRATCH1(r13)
  56. mfspr r12, SPRN_SPRG_SCRATCH1
  57. stw r12, HSTATE_SCRATCH0(r13)
  58. lbz r12, HSTATE_IN_GUEST(r13)
  59. cmpwi r12, KVM_GUEST_MODE_NONE
  60. bne ..kvmppc_handler_hasmagic_\intno
  61. /* No KVM guest? Then jump back to the Linux handler! */
  62. lwz r12, HSTATE_SCRATCH1(r13)
  63. b 2b
  64. /* Now we know we're handling a KVM guest */
  65. ..kvmppc_handler_hasmagic_\intno:
  66. /* Should we just skip the faulting instruction? */
  67. cmpwi r12, KVM_GUEST_MODE_SKIP
  68. beq kvmppc_handler_skip_ins
  69. /* Let's store which interrupt we're handling */
  70. li r12, \intno
  71. /* Jump into the SLB exit code that goes to the highmem handler */
  72. b kvmppc_handler_trampoline_exit
  73. .endm
  74. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
  75. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
  76. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
  77. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
  78. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
  79. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
  80. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
  81. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
  82. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
  83. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
  84. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
  85. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
  86. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
  87. /*
  88. * Bring us back to the faulting code, but skip the
  89. * faulting instruction.
  90. *
  91. * This is a generic exit path from the interrupt
  92. * trampolines above.
  93. *
  94. * Input Registers:
  95. *
  96. * R12 = free
  97. * R13 = Shadow VCPU (PACA)
  98. * HSTATE.SCRATCH0 = guest R12
  99. * HSTATE.SCRATCH1 = guest CR
  100. * SPRG_SCRATCH0 = guest R13
  101. *
  102. */
  103. kvmppc_handler_skip_ins:
  104. /* Patch the IP to the next instruction */
  105. mfsrr0 r12
  106. addi r12, r12, 4
  107. mtsrr0 r12
  108. /* Clean up all state */
  109. lwz r12, HSTATE_SCRATCH1(r13)
  110. mtcr r12
  111. PPC_LL r12, HSTATE_SCRATCH0(r13)
  112. GET_SCRATCH0(r13)
  113. /* And get back into the code */
  114. RFI_TO_KERNEL
  115. #endif
  116. /*
  117. * Call kvmppc_handler_trampoline_enter in real mode
  118. *
  119. * On entry, r4 contains the guest shadow MSR
  120. * MSR.EE has to be 0 when calling this function
  121. */
  122. _GLOBAL_TOC(kvmppc_entry_trampoline)
  123. mfmsr r5
  124. LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
  125. toreal(r7)
  126. li r6, MSR_IR | MSR_DR
  127. andc r6, r5, r6 /* Clear DR and IR in MSR value */
  128. /*
  129. * Set EE in HOST_MSR so that it's enabled when we get into our
  130. * C exit handler function.
  131. */
  132. ori r5, r5, MSR_EE
  133. mtsrr0 r7
  134. mtsrr1 r6
  135. RFI_TO_KERNEL
  136. #include "book3s_segment.S"