book3s_rmhandlers.S 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 SUSE Linux Products GmbH 2009
  16. *
  17. * Authors: Alexander Graf <agraf@suse.de>
  18. */
  19. #include <asm/ppc_asm.h>
  20. #include <asm/kvm_asm.h>
  21. #include <asm/reg.h>
  22. #include <asm/mmu.h>
  23. #include <asm/page.h>
  24. #include <asm/asm-offsets.h>
  25. #ifdef CONFIG_PPC_BOOK3S_64
  26. #include <asm/exception-64s.h>
  27. #endif
  28. /*****************************************************************************
  29. * *
  30. * Real Mode handlers that need to be in low physical memory *
  31. * *
  32. ****************************************************************************/
  33. #if defined(CONFIG_PPC_BOOK3S_64)
  34. #define FUNC(name) GLUE(.,name)
  35. #elif defined(CONFIG_PPC_BOOK3S_32)
  36. #define FUNC(name) name
  37. .macro INTERRUPT_TRAMPOLINE intno
  38. .global kvmppc_trampoline_\intno
  39. kvmppc_trampoline_\intno:
  40. mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
  41. /*
  42. * First thing to do is to find out if we're coming
  43. * from a KVM guest or a Linux process.
  44. *
  45. * To distinguish, we check a magic byte in the PACA/current
  46. */
  47. mfspr r13, SPRN_SPRG_THREAD
  48. lwz r13, THREAD_KVM_SVCPU(r13)
  49. /* PPC32 can have a NULL pointer - let's check for that */
  50. mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
  51. mfcr r12
  52. cmpwi r13, 0
  53. bne 1f
  54. 2: mtcr r12
  55. mfspr r12, SPRN_SPRG_SCRATCH1
  56. mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
  57. b kvmppc_resume_\intno /* Get back original handler */
  58. 1: tophys(r13, r13)
  59. stw r12, HSTATE_SCRATCH1(r13)
  60. mfspr r12, SPRN_SPRG_SCRATCH1
  61. stw r12, HSTATE_SCRATCH0(r13)
  62. lbz r12, HSTATE_IN_GUEST(r13)
  63. cmpwi r12, KVM_GUEST_MODE_NONE
  64. bne ..kvmppc_handler_hasmagic_\intno
  65. /* No KVM guest? Then jump back to the Linux handler! */
  66. lwz r12, HSTATE_SCRATCH1(r13)
  67. b 2b
  68. /* Now we know we're handling a KVM guest */
  69. ..kvmppc_handler_hasmagic_\intno:
  70. /* Should we just skip the faulting instruction? */
  71. cmpwi r12, KVM_GUEST_MODE_SKIP
  72. beq kvmppc_handler_skip_ins
  73. /* Let's store which interrupt we're handling */
  74. li r12, \intno
  75. /* Jump into the SLB exit code that goes to the highmem handler */
  76. b kvmppc_handler_trampoline_exit
  77. .endm
  78. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
  79. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
  80. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
  81. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
  82. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
  83. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
  84. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
  85. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
  86. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
  87. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
  88. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
  89. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
  90. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
  91. /*
  92. * Bring us back to the faulting code, but skip the
  93. * faulting instruction.
  94. *
  95. * This is a generic exit path from the interrupt
  96. * trampolines above.
  97. *
  98. * Input Registers:
  99. *
  100. * R12 = free
  101. * R13 = Shadow VCPU (PACA)
  102. * HSTATE.SCRATCH0 = guest R12
  103. * HSTATE.SCRATCH1 = guest CR
  104. * SPRG_SCRATCH0 = guest R13
  105. *
  106. */
  107. kvmppc_handler_skip_ins:
  108. /* Patch the IP to the next instruction */
  109. mfsrr0 r12
  110. addi r12, r12, 4
  111. mtsrr0 r12
  112. /* Clean up all state */
  113. lwz r12, HSTATE_SCRATCH1(r13)
  114. mtcr r12
  115. PPC_LL r12, HSTATE_SCRATCH0(r13)
  116. GET_SCRATCH0(r13)
  117. /* And get back into the code */
  118. RFI
  119. #endif
  120. /*
  121. * Call kvmppc_handler_trampoline_enter in real mode
  122. *
  123. * On entry, r4 contains the guest shadow MSR
  124. * MSR.EE has to be 0 when calling this function
  125. */
  126. _GLOBAL(kvmppc_entry_trampoline)
  127. mfmsr r5
  128. LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
  129. toreal(r7)
  130. li r6, MSR_IR | MSR_DR
  131. andc r6, r5, r6 /* Clear DR and IR in MSR value */
  132. #ifdef CONFIG_PPC_BOOK3S_32
  133. /*
  134. * Set EE in HOST_MSR so that it's enabled when we get into our
  135. * C exit handler function. On 64-bit we delay enabling
  136. * interrupts until we have finished transferring stuff
  137. * to or from the PACA.
  138. */
  139. ori r5, r5, MSR_EE
  140. #endif
  141. mtsrr0 r7
  142. mtsrr1 r6
  143. RFI
  144. #if defined(CONFIG_PPC_BOOK3S_32)
  145. #define STACK_LR INT_FRAME_SIZE+4
  146. /* load_up_xxx have to run with MSR_DR=0 on Book3S_32 */
  147. #define MSR_EXT_START \
  148. PPC_STL r20, _NIP(r1); \
  149. mfmsr r20; \
  150. LOAD_REG_IMMEDIATE(r3, MSR_DR|MSR_EE); \
  151. andc r3,r20,r3; /* Disable DR,EE */ \
  152. mtmsr r3; \
  153. sync
  154. #define MSR_EXT_END \
  155. mtmsr r20; /* Enable DR,EE */ \
  156. sync; \
  157. PPC_LL r20, _NIP(r1)
  158. #elif defined(CONFIG_PPC_BOOK3S_64)
  159. #define STACK_LR _LINK
  160. #define MSR_EXT_START
  161. #define MSR_EXT_END
  162. #endif
  163. /*
  164. * Activate current's external feature (FPU/Altivec/VSX)
  165. */
  166. #define define_load_up(what) \
  167. \
  168. _GLOBAL(kvmppc_load_up_ ## what); \
  169. PPC_STLU r1, -INT_FRAME_SIZE(r1); \
  170. mflr r3; \
  171. PPC_STL r3, STACK_LR(r1); \
  172. MSR_EXT_START; \
  173. \
  174. bl FUNC(load_up_ ## what); \
  175. \
  176. MSR_EXT_END; \
  177. PPC_LL r3, STACK_LR(r1); \
  178. mtlr r3; \
  179. addi r1, r1, INT_FRAME_SIZE; \
  180. blr
  181. define_load_up(fpu)
  182. #ifdef CONFIG_ALTIVEC
  183. define_load_up(altivec)
  184. #endif
  185. #include "book3s_segment.S"