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