book3s_rmhandlers.S 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #define MTMSR_EERI(reg) mtmsrd (reg),1
  36. .globl kvmppc_skip_interrupt
  37. kvmppc_skip_interrupt:
  38. /*
  39. * Here all GPRs are unchanged from when the interrupt happened
  40. * except for r13, which is saved in SPRG_SCRATCH0.
  41. */
  42. mfspr r13, SPRN_SRR0
  43. addi r13, r13, 4
  44. mtspr SPRN_SRR0, r13
  45. GET_SCRATCH0(r13)
  46. rfid
  47. b .
  48. .globl kvmppc_skip_Hinterrupt
  49. kvmppc_skip_Hinterrupt:
  50. /*
  51. * Here all GPRs are unchanged from when the interrupt happened
  52. * except for r13, which is saved in SPRG_SCRATCH0.
  53. */
  54. mfspr r13, SPRN_HSRR0
  55. addi r13, r13, 4
  56. mtspr SPRN_HSRR0, r13
  57. GET_SCRATCH0(r13)
  58. hrfid
  59. b .
  60. #elif defined(CONFIG_PPC_BOOK3S_32)
  61. #define FUNC(name) name
  62. #define MTMSR_EERI(reg) mtmsr (reg)
  63. .macro INTERRUPT_TRAMPOLINE intno
  64. .global kvmppc_trampoline_\intno
  65. kvmppc_trampoline_\intno:
  66. mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
  67. /*
  68. * First thing to do is to find out if we're coming
  69. * from a KVM guest or a Linux process.
  70. *
  71. * To distinguish, we check a magic byte in the PACA/current
  72. */
  73. mfspr r13, SPRN_SPRG_THREAD
  74. lwz r13, THREAD_KVM_SVCPU(r13)
  75. /* PPC32 can have a NULL pointer - let's check for that */
  76. mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */
  77. mfcr r12
  78. cmpwi r13, 0
  79. bne 1f
  80. 2: mtcr r12
  81. mfspr r12, SPRN_SPRG_SCRATCH1
  82. mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
  83. b kvmppc_resume_\intno /* Get back original handler */
  84. 1: tophys(r13, r13)
  85. stw r12, HSTATE_SCRATCH1(r13)
  86. mfspr r12, SPRN_SPRG_SCRATCH1
  87. stw r12, HSTATE_SCRATCH0(r13)
  88. lbz r12, HSTATE_IN_GUEST(r13)
  89. cmpwi r12, KVM_GUEST_MODE_NONE
  90. bne ..kvmppc_handler_hasmagic_\intno
  91. /* No KVM guest? Then jump back to the Linux handler! */
  92. lwz r12, HSTATE_SCRATCH1(r13)
  93. b 2b
  94. /* Now we know we're handling a KVM guest */
  95. ..kvmppc_handler_hasmagic_\intno:
  96. /* Should we just skip the faulting instruction? */
  97. cmpwi r12, KVM_GUEST_MODE_SKIP
  98. beq kvmppc_handler_skip_ins
  99. /* Let's store which interrupt we're handling */
  100. li r12, \intno
  101. /* Jump into the SLB exit code that goes to the highmem handler */
  102. b kvmppc_handler_trampoline_exit
  103. .endm
  104. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
  105. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
  106. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
  107. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
  108. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
  109. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
  110. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
  111. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
  112. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
  113. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
  114. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
  115. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
  116. INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
  117. /*
  118. * Bring us back to the faulting code, but skip the
  119. * faulting instruction.
  120. *
  121. * This is a generic exit path from the interrupt
  122. * trampolines above.
  123. *
  124. * Input Registers:
  125. *
  126. * R12 = free
  127. * R13 = Shadow VCPU (PACA)
  128. * HSTATE.SCRATCH0 = guest R12
  129. * HSTATE.SCRATCH1 = guest CR
  130. * SPRG_SCRATCH0 = guest R13
  131. *
  132. */
  133. kvmppc_handler_skip_ins:
  134. /* Patch the IP to the next instruction */
  135. mfsrr0 r12
  136. addi r12, r12, 4
  137. mtsrr0 r12
  138. /* Clean up all state */
  139. lwz r12, HSTATE_SCRATCH1(r13)
  140. mtcr r12
  141. PPC_LL r12, HSTATE_SCRATCH0(r13)
  142. GET_SCRATCH0(r13)
  143. /* And get back into the code */
  144. RFI
  145. #endif
  146. /*
  147. * Call kvmppc_handler_trampoline_enter in real mode
  148. *
  149. * On entry, r4 contains the guest shadow MSR
  150. */
  151. _GLOBAL(kvmppc_entry_trampoline)
  152. mfmsr r5
  153. LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
  154. toreal(r7)
  155. li r9, MSR_RI
  156. ori r9, r9, MSR_EE
  157. andc r9, r5, r9 /* Clear EE and RI in MSR value */
  158. li r6, MSR_IR | MSR_DR
  159. ori r6, r6, MSR_EE
  160. andc r6, r5, r6 /* Clear EE, DR and IR in MSR value */
  161. MTMSR_EERI(r9) /* Clear EE and RI in MSR */
  162. mtsrr0 r7 /* before we set srr0/1 */
  163. mtsrr1 r6
  164. RFI
  165. #if defined(CONFIG_PPC_BOOK3S_32)
  166. #define STACK_LR INT_FRAME_SIZE+4
  167. /* load_up_xxx have to run with MSR_DR=0 on Book3S_32 */
  168. #define MSR_EXT_START \
  169. PPC_STL r20, _NIP(r1); \
  170. mfmsr r20; \
  171. LOAD_REG_IMMEDIATE(r3, MSR_DR|MSR_EE); \
  172. andc r3,r20,r3; /* Disable DR,EE */ \
  173. mtmsr r3; \
  174. sync
  175. #define MSR_EXT_END \
  176. mtmsr r20; /* Enable DR,EE */ \
  177. sync; \
  178. PPC_LL r20, _NIP(r1)
  179. #elif defined(CONFIG_PPC_BOOK3S_64)
  180. #define STACK_LR _LINK
  181. #define MSR_EXT_START
  182. #define MSR_EXT_END
  183. #endif
  184. /*
  185. * Activate current's external feature (FPU/Altivec/VSX)
  186. */
  187. #define define_load_up(what) \
  188. \
  189. _GLOBAL(kvmppc_load_up_ ## what); \
  190. PPC_STLU r1, -INT_FRAME_SIZE(r1); \
  191. mflr r3; \
  192. PPC_STL r3, STACK_LR(r1); \
  193. MSR_EXT_START; \
  194. \
  195. bl FUNC(load_up_ ## what); \
  196. \
  197. MSR_EXT_END; \
  198. PPC_LL r3, STACK_LR(r1); \
  199. mtlr r3; \
  200. addi r1, r1, INT_FRAME_SIZE; \
  201. blr
  202. define_load_up(fpu)
  203. #ifdef CONFIG_ALTIVEC
  204. define_load_up(altivec)
  205. #endif
  206. #ifdef CONFIG_VSX
  207. define_load_up(vsx)
  208. #endif
  209. #include "book3s_segment.S"