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> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/asm-offsets.h> |
| 25 | #include <asm/exception-64s.h> |
| 26 | |
| 27 | /***************************************************************************** |
| 28 | * * |
| 29 | * Real Mode handlers that need to be in low physical memory * |
| 30 | * * |
| 31 | ****************************************************************************/ |
| 32 | |
| 33 | |
| 34 | .macro INTERRUPT_TRAMPOLINE intno |
| 35 | |
| 36 | .global kvmppc_trampoline_\intno |
| 37 | kvmppc_trampoline_\intno: |
| 38 | |
| 39 | mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */ |
| 40 | |
| 41 | /* |
| 42 | * First thing to do is to find out if we're coming |
| 43 | * from a KVM guest or a Linux process. |
| 44 | * |
| 45 | * To distinguish, we check a magic byte in the PACA |
| 46 | */ |
| 47 | mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */ |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 48 | std r12, PACA_KVM_SCRATCH0(r13) |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 49 | mfcr r12 |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 50 | stw r12, PACA_KVM_SCRATCH1(r13) |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 51 | lbz r12, PACA_KVM_IN_GUEST(r13) |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame^] | 52 | cmpwi r12, KVM_GUEST_MODE_NONE |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 53 | bne ..kvmppc_handler_hasmagic_\intno |
| 54 | /* No KVM guest? Then jump back to the Linux handler! */ |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 55 | lwz r12, PACA_KVM_SCRATCH1(r13) |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 56 | mtcr r12 |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 57 | ld r12, PACA_KVM_SCRATCH0(r13) |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 58 | mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */ |
| 59 | b kvmppc_resume_\intno /* Get back original handler */ |
| 60 | |
| 61 | /* Now we know we're handling a KVM guest */ |
| 62 | ..kvmppc_handler_hasmagic_\intno: |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame^] | 63 | |
| 64 | /* Should we just skip the faulting instruction? */ |
| 65 | cmpwi r12, KVM_GUEST_MODE_SKIP |
| 66 | beq kvmppc_handler_skip_ins |
| 67 | |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 68 | /* Let's store which interrupt we're handling */ |
| 69 | li r12, \intno |
| 70 | |
| 71 | /* Jump into the SLB exit code that goes to the highmem handler */ |
| 72 | b kvmppc_handler_trampoline_exit |
| 73 | |
| 74 | .endm |
| 75 | |
| 76 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET |
| 77 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK |
| 78 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE |
| 79 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT |
| 80 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE |
| 81 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT |
| 82 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL |
| 83 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT |
| 84 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM |
| 85 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL |
| 86 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER |
| 87 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL |
| 88 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE |
| 89 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON |
| 90 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC |
| 91 | INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX |
| 92 | |
| 93 | /* |
Alexander Graf | b4433a7 | 2010-01-08 02:58:04 +0100 | [diff] [blame^] | 94 | * Bring us back to the faulting code, but skip the |
| 95 | * faulting instruction. |
| 96 | * |
| 97 | * This is a generic exit path from the interrupt |
| 98 | * trampolines above. |
| 99 | * |
| 100 | * Input Registers: |
| 101 | * |
| 102 | * R12 = free |
| 103 | * R13 = PACA |
| 104 | * PACA.KVM.SCRATCH0 = guest R12 |
| 105 | * PACA.KVM.SCRATCH1 = guest CR |
| 106 | * SPRG_SCRATCH0 = guest R13 |
| 107 | * |
| 108 | */ |
| 109 | kvmppc_handler_skip_ins: |
| 110 | |
| 111 | /* Patch the IP to the next instruction */ |
| 112 | mfsrr0 r12 |
| 113 | addi r12, r12, 4 |
| 114 | mtsrr0 r12 |
| 115 | |
| 116 | /* Clean up all state */ |
| 117 | lwz r12, PACA_KVM_SCRATCH1(r13) |
| 118 | mtcr r12 |
| 119 | ld r12, PACA_KVM_SCRATCH0(r13) |
| 120 | mfspr r13, SPRN_SPRG_SCRATCH0 |
| 121 | |
| 122 | /* And get back into the code */ |
| 123 | RFI |
| 124 | |
| 125 | /* |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 126 | * This trampoline brings us back to a real mode handler |
| 127 | * |
| 128 | * Input Registers: |
| 129 | * |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 130 | * R5 = SRR0 |
| 131 | * R6 = SRR1 |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 132 | * LR = real-mode IP |
| 133 | * |
| 134 | */ |
| 135 | .global kvmppc_handler_lowmem_trampoline |
| 136 | kvmppc_handler_lowmem_trampoline: |
| 137 | |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 138 | mtsrr0 r5 |
| 139 | mtsrr1 r6 |
Alexander Graf | c862125 | 2009-10-30 05:47:09 +0000 | [diff] [blame] | 140 | blr |
| 141 | kvmppc_handler_lowmem_trampoline_end: |
| 142 | |
| 143 | .global kvmppc_trampoline_lowmem |
| 144 | kvmppc_trampoline_lowmem: |
| 145 | .long kvmppc_handler_lowmem_trampoline - _stext |
| 146 | |
| 147 | .global kvmppc_trampoline_enter |
| 148 | kvmppc_trampoline_enter: |
| 149 | .long kvmppc_handler_trampoline_enter - _stext |
| 150 | |
| 151 | #include "book3s_64_slb.S" |
| 152 | |