book3s_rmhandlers.S 4.6 KB

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