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