book3s_rmhandlers.S 4.7 KB

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