book3s_rmhandlers.S 4.7 KB

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