book3s_rmhandlers.S 6.2 KB

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