blob: 4850a224e5bf230726ffb20bfa8c34aba5530d19 [file] [log] [blame]
Alexander Grafc8621252009-10-30 05:47:09 +00001/*
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 Mackerras177339d2011-07-23 17:41:11 +100023#include <asm/mmu.h>
Alexander Grafc8621252009-10-30 05:47:09 +000024#include <asm/page.h>
25#include <asm/asm-offsets.h>
Alexander Graf8c3a4e02010-04-16 00:11:46 +020026
27#ifdef CONFIG_PPC_BOOK3S_64
Alexander Grafc8621252009-10-30 05:47:09 +000028#include <asm/exception-64s.h>
Alexander Graf8c3a4e02010-04-16 00:11:46 +020029#endif
Alexander Grafc8621252009-10-30 05:47:09 +000030
31/*****************************************************************************
32 * *
33 * Real Mode handlers that need to be in low physical memory *
34 * *
35 ****************************************************************************/
36
Alexander Graf8c3a4e02010-04-16 00:11:46 +020037#if defined(CONFIG_PPC_BOOK3S_64)
38
Alexander Graf8c3a4e02010-04-16 00:11:46 +020039#define FUNC(name) GLUE(.,name)
40
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000041#elif defined(CONFIG_PPC_BOOK3S_32)
Alexander Graf8c3a4e02010-04-16 00:11:46 +020042
Alexander Graf8c3a4e02010-04-16 00:11:46 +020043#define FUNC(name) name
44
Alexander Grafc8621252009-10-30 05:47:09 +000045.macro INTERRUPT_TRAMPOLINE intno
46
47.global kvmppc_trampoline_\intno
48kvmppc_trampoline_\intno:
49
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000050 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
Alexander Grafc8621252009-10-30 05:47:09 +000051
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 Graf8c3a4e02010-04-16 00:11:46 +020056 * To distinguish, we check a magic byte in the PACA/current
Alexander Grafc8621252009-10-30 05:47:09 +000057 */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000058 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 Grafc8621252009-10-30 05:47:09 +000062 mfcr r12
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000063 cmpwi r13, 0
64 bne 1f
652: 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
701: tophys(r13, r13)
Paul Mackerras3c42bf82011-06-29 00:20:58 +000071 stw r12, HSTATE_SCRATCH1(r13)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000072 mfspr r12, SPRN_SPRG_SCRATCH1
Paul Mackerras3c42bf82011-06-29 00:20:58 +000073 stw r12, HSTATE_SCRATCH0(r13)
74 lbz r12, HSTATE_IN_GUEST(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +010075 cmpwi r12, KVM_GUEST_MODE_NONE
Alexander Grafc8621252009-10-30 05:47:09 +000076 bne ..kvmppc_handler_hasmagic_\intno
77 /* No KVM guest? Then jump back to the Linux handler! */
Paul Mackerras3c42bf82011-06-29 00:20:58 +000078 lwz r12, HSTATE_SCRATCH1(r13)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000079 b 2b
Alexander Grafc8621252009-10-30 05:47:09 +000080
81 /* Now we know we're handling a KVM guest */
82..kvmppc_handler_hasmagic_\intno:
Alexander Grafb4433a72010-01-08 02:58:04 +010083
84 /* Should we just skip the faulting instruction? */
85 cmpwi r12, KVM_GUEST_MODE_SKIP
86 beq kvmppc_handler_skip_ins
87
Alexander Grafc8621252009-10-30 05:47:09 +000088 /* 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
96INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
97INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
98INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
Alexander Grafc8621252009-10-30 05:47:09 +000099INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
Alexander Grafc8621252009-10-30 05:47:09 +0000100INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
101INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
102INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
103INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
104INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
105INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
106INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
107INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
108INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
Alexander Graf8c3a4e02010-04-16 00:11:46 +0200109
Alexander Grafc8621252009-10-30 05:47:09 +0000110/*
Alexander Grafb4433a72010-01-08 02:58:04 +0100111 * 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 Graf8c3a4e02010-04-16 00:11:46 +0200119 * R12 = free
120 * R13 = Shadow VCPU (PACA)
Paul Mackerras3c42bf82011-06-29 00:20:58 +0000121 * HSTATE.SCRATCH0 = guest R12
122 * HSTATE.SCRATCH1 = guest CR
Alexander Graf8c3a4e02010-04-16 00:11:46 +0200123 * SPRG_SCRATCH0 = guest R13
Alexander Grafb4433a72010-01-08 02:58:04 +0100124 *
125 */
126kvmppc_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 Mackerras3c42bf82011-06-29 00:20:58 +0000134 lwz r12, HSTATE_SCRATCH1(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +0100135 mtcr r12
Paul Mackerras3c42bf82011-06-29 00:20:58 +0000136 PPC_LL r12, HSTATE_SCRATCH0(r13)
Paul Mackerras673b1892011-04-05 13:59:58 +1000137 GET_SCRATCH0(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +0100138
139 /* And get back into the code */
140 RFI
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000141#endif
Alexander Grafb4433a72010-01-08 02:58:04 +0100142
143/*
Paul Mackerras02143942011-07-23 17:41:44 +1000144 * Call kvmppc_handler_trampoline_enter in real mode
Alexander Grafc8621252009-10-30 05:47:09 +0000145 *
Paul Mackerras02143942011-07-23 17:41:44 +1000146 * On entry, r4 contains the guest shadow MSR
Alexander Grafbd2be682012-08-13 01:04:19 +0200147 * MSR.EE has to be 0 when calling this function
Alexander Grafc8621252009-10-30 05:47:09 +0000148 */
Anton Blanchard6ed179b2014-06-12 18:16:53 +1000149_GLOBAL_TOC(kvmppc_entry_trampoline)
Paul Mackerras02143942011-07-23 17:41:44 +1000150 mfmsr r5
151 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
152 toreal(r7)
Alexander Grafc8621252009-10-30 05:47:09 +0000153
Paul Mackerras02143942011-07-23 17:41:44 +1000154 li r6, MSR_IR | MSR_DR
Alexander Grafbd2be682012-08-13 01:04:19 +0200155 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 Graf3d3319b2013-11-29 02:32:31 +0100158 * C exit handler function.
Alexander Grafbd2be682012-08-13 01:04:19 +0200159 */
160 ori r5, r5, MSR_EE
161 mtsrr0 r7
Alexander Graf7e57cba2010-01-08 02:58:03 +0100162 mtsrr1 r6
Alexander Graf021ec9c2010-01-08 02:58:06 +0100163 RFI
164
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200165#include "book3s_segment.S"