Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 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 | |
| 20 | #include <asm/ppc_asm.h> |
| 21 | #include <asm/kvm_asm.h> |
| 22 | #include <asm/reg.h> |
Paul Mackerras | 177339d | 2011-07-23 17:41:11 +1000 | [diff] [blame] | 23 | #include <asm/mmu.h> |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 24 | #include <asm/page.h> |
| 25 | #include <asm/asm-offsets.h> |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 26 | |
| 27 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 28 | #include <asm/exception-64s.h> |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 29 | #endif |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 30 | |
| 31 | /***************************************************************************** |
| 32 | * * |
| 33 | * Real Mode handlers that need to be in low physical memory * |
| 34 | * * |
| 35 | ****************************************************************************/ |
| 36 | |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 37 | #if defined(CONFIG_PPC_BOOK3S_64) |
| 38 | |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 39 | #define FUNC(name) GLUE(.,name) |
| 40 | |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 41 | #elif defined(CONFIG_PPC_BOOK3S_32) |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 42 | |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 43 | #define FUNC(name) name |
| 44 | |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 45 | .macro INTERRUPT_TRAMPOLINE intno |
| 46 | |
| 47 | .global kvmppc_trampoline_\intno |
| 48 | kvmppc_trampoline_\intno: |
| 49 | |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 50 | mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */ |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 51 | |
| 52 | /* |
| 53 | * First thing to do is to find out if we're coming |
| 54 | * from a KVM guest or a Linux process. |
| 55 | * |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 56 | * To distinguish, we check a magic byte in the PACA/current |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 57 | */ |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 58 | mfspr r13, SPRN_SPRG_THREAD |
| 59 | lwz r13, THREAD_KVM_SVCPU(r13) |
| 60 | /* PPC32 can have a NULL pointer - let's check for that */ |
| 61 | mtspr SPRN_SPRG_SCRATCH1, r12 /* Save r12 */ |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 62 | mfcr r12 |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 63 | cmpwi r13, 0 |
| 64 | bne 1f |
| 65 | 2: mtcr r12 |
| 66 | mfspr r12, SPRN_SPRG_SCRATCH1 |
| 67 | mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */ |
| 68 | b kvmppc_resume_\intno /* Get back original handler */ |
| 69 | |
| 70 | 1: tophys(r13, r13) |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 71 | stw r12, HSTATE_SCRATCH1(r13) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 72 | mfspr r12, SPRN_SPRG_SCRATCH1 |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 73 | stw r12, HSTATE_SCRATCH0(r13) |
| 74 | lbz r12, HSTATE_IN_GUEST(r13) |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 75 | cmpwi r12, KVM_GUEST_MODE_NONE |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 76 | bne ..kvmppc_handler_hasmagic_\intno |
| 77 | /* No KVM guest? Then jump back to the Linux handler! */ |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 78 | lwz r12, HSTATE_SCRATCH1(r13) |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 79 | b 2b |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 80 | |
| 81 | /* Now we know we're handling a KVM guest */ |
| 82 | ..kvmppc_handler_hasmagic_\intno: |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 83 | |
| 84 | /* Should we just skip the faulting instruction? */ |
| 85 | cmpwi r12, KVM_GUEST_MODE_SKIP |
| 86 | beq kvmppc_handler_skip_ins |
| 87 | |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 88 | /* Let's store which interrupt we're handling */ |
| 89 | li r12, \intno |
| 90 | |
| 91 | /* Jump into the SLB exit code that goes to the highmem handler */ |
| 92 | b kvmppc_handler_trampoline_exit |
| 93 | |
| 94 | .endm |
| 95 | |
| 96 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET |
| 97 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK |
| 98 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 99 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 100 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL |
| 101 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT |
| 102 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM |
| 103 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL |
| 104 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER |
| 105 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL |
| 106 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE |
| 107 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON |
| 108 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 109 | |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 110 | /* |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 111 | * Bring us back to the faulting code, but skip the |
| 112 | * faulting instruction. |
| 113 | * |
| 114 | * This is a generic exit path from the interrupt |
| 115 | * trampolines above. |
| 116 | * |
| 117 | * Input Registers: |
| 118 | * |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 119 | * R12 = free |
| 120 | * R13 = Shadow VCPU (PACA) |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 121 | * HSTATE.SCRATCH0 = guest R12 |
| 122 | * HSTATE.SCRATCH1 = guest CR |
Alexander Graf | 8c3a4e0 | 2010-04-16 00:11:46 +0200 | [diff] [blame] | 123 | * SPRG_SCRATCH0 = guest R13 |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 124 | * |
| 125 | */ |
| 126 | kvmppc_handler_skip_ins: |
| 127 | |
| 128 | /* Patch the IP to the next instruction */ |
| 129 | mfsrr0 r12 |
| 130 | addi r12, r12, 4 |
| 131 | mtsrr0 r12 |
| 132 | |
| 133 | /* Clean up all state */ |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 134 | lwz r12, HSTATE_SCRATCH1(r13) |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 135 | mtcr r12 |
Paul Mackerras | 3c42bf8 | 2011-06-29 00:20:58 +0000 | [diff] [blame] | 136 | PPC_LL r12, HSTATE_SCRATCH0(r13) |
Paul Mackerras | 673b189 | 2011-04-05 13:59:58 +1000 | [diff] [blame] | 137 | GET_SCRATCH0(r13) |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 138 | |
| 139 | /* And get back into the code */ |
| 140 | RFI |
Paul Mackerras | b01c8b5 | 2011-06-29 00:18:26 +0000 | [diff] [blame] | 141 | #endif |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame] | 142 | |
| 143 | /* |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 144 | * Call kvmppc_handler_trampoline_enter in real mode |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 145 | * |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 146 | * On entry, r4 contains the guest shadow MSR |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 147 | * MSR.EE has to be 0 when calling this function |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 148 | */ |
Anton Blanchard | 6ed179b | 2014-06-12 18:16:53 +1000 | [diff] [blame^] | 149 | _GLOBAL_TOC(kvmppc_entry_trampoline) |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 150 | mfmsr r5 |
| 151 | LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter) |
| 152 | toreal(r7) |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 153 | |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 154 | li r6, MSR_IR | MSR_DR |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 155 | andc r6, r5, r6 /* Clear DR and IR in MSR value */ |
| 156 | /* |
| 157 | * Set EE in HOST_MSR so that it's enabled when we get into our |
Alexander Graf | 3d3319b | 2013-11-29 02:32:31 +0100 | [diff] [blame] | 158 | * C exit handler function. |
Alexander Graf | bd2be68 | 2012-08-13 01:04:19 +0200 | [diff] [blame] | 159 | */ |
| 160 | ori r5, r5, MSR_EE |
| 161 | mtsrr0 r7 |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 162 | mtsrr1 r6 |
Alexander Graf | 021ec9c | 2010-01-08 02:58:06 +0100 | [diff] [blame] | 163 | RFI |
| 164 | |
Alexander Graf | 53e5b8b | 2010-04-16 00:11:48 +0200 | [diff] [blame] | 165 | #include "book3s_segment.S" |