blob: b45b750fa77a6f0a9626d0306251882771dd5676 [file] [log] [blame]
Thomas Gleixnerd94d71c2019-05-29 07:12:40 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Alexander Grafc8621252009-10-30 05:47:09 +00002/*
Alexander Grafc8621252009-10-30 05:47:09 +00003 *
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 Mackerras177339d2011-07-23 17:41:11 +100012#include <asm/mmu.h>
Alexander Grafc8621252009-10-30 05:47:09 +000013#include <asm/page.h>
14#include <asm/asm-offsets.h>
Christophe Leroyec0c4642018-07-05 16:24:57 +000015#include <asm/asm-compat.h>
Alexander Graf8c3a4e02010-04-16 00:11:46 +020016
17#ifdef CONFIG_PPC_BOOK3S_64
Alexander Grafc8621252009-10-30 05:47:09 +000018#include <asm/exception-64s.h>
Alexander Graf8c3a4e02010-04-16 00:11:46 +020019#endif
Alexander Grafc8621252009-10-30 05:47:09 +000020
21/*****************************************************************************
22 * *
23 * Real Mode handlers that need to be in low physical memory *
24 * *
25 ****************************************************************************/
26
Alexander Graf8c3a4e02010-04-16 00:11:46 +020027#if defined(CONFIG_PPC_BOOK3S_64)
28
Michael Ellermanf55d9662016-06-06 22:26:10 +053029#ifdef PPC64_ELF_ABI_v2
Alexander Graf55ab1692014-06-16 14:37:53 +020030#define FUNC(name) name
31#else
Alexander Graf8c3a4e02010-04-16 00:11:46 +020032#define FUNC(name) GLUE(.,name)
Alexander Graf55ab1692014-06-16 14:37:53 +020033#endif
Alexander Graf8c3a4e02010-04-16 00:11:46 +020034
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000035#elif defined(CONFIG_PPC_BOOK3S_32)
Alexander Graf8c3a4e02010-04-16 00:11:46 +020036
Alexander Graf8c3a4e02010-04-16 00:11:46 +020037#define FUNC(name) name
38
Christophe Leroy120c0512020-11-08 16:57:36 +000039#define RFI_TO_KERNEL rfi
40#define RFI_TO_GUEST rfi
Nicholas Piggin222f20f2018-01-10 03:07:15 +110041
Alexander Grafc8621252009-10-30 05:47:09 +000042.macro INTERRUPT_TRAMPOLINE intno
43
44.global kvmppc_trampoline_\intno
45kvmppc_trampoline_\intno:
46
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000047 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
Alexander Grafc8621252009-10-30 05:47:09 +000048
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 Graf8c3a4e02010-04-16 00:11:46 +020053 * To distinguish, we check a magic byte in the PACA/current
Alexander Grafc8621252009-10-30 05:47:09 +000054 */
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000055 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 Grafc8621252009-10-30 05:47:09 +000059 mfcr r12
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000060 cmpwi r13, 0
61 bne 1f
622: 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
671: tophys(r13, r13)
Paul Mackerras3c42bf82011-06-29 00:20:58 +000068 stw r12, HSTATE_SCRATCH1(r13)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000069 mfspr r12, SPRN_SPRG_SCRATCH1
Paul Mackerras3c42bf82011-06-29 00:20:58 +000070 stw r12, HSTATE_SCRATCH0(r13)
71 lbz r12, HSTATE_IN_GUEST(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +010072 cmpwi r12, KVM_GUEST_MODE_NONE
Alexander Grafc8621252009-10-30 05:47:09 +000073 bne ..kvmppc_handler_hasmagic_\intno
74 /* No KVM guest? Then jump back to the Linux handler! */
Paul Mackerras3c42bf82011-06-29 00:20:58 +000075 lwz r12, HSTATE_SCRATCH1(r13)
Paul Mackerrasb01c8b52011-06-29 00:18:26 +000076 b 2b
Alexander Grafc8621252009-10-30 05:47:09 +000077
78 /* Now we know we're handling a KVM guest */
79..kvmppc_handler_hasmagic_\intno:
Alexander Grafb4433a72010-01-08 02:58:04 +010080
81 /* Should we just skip the faulting instruction? */
82 cmpwi r12, KVM_GUEST_MODE_SKIP
83 beq kvmppc_handler_skip_ins
84
Alexander Grafc8621252009-10-30 05:47:09 +000085 /* 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
93INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
94INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
95INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
Alexander Grafc8621252009-10-30 05:47:09 +000096INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
Alexander Grafc8621252009-10-30 05:47:09 +000097INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
98INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
99INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
100INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
101INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
102INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
103INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
104INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
105INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
Alexander Graf8c3a4e02010-04-16 00:11:46 +0200106
Alexander Grafc8621252009-10-30 05:47:09 +0000107/*
Alexander Grafb4433a72010-01-08 02:58:04 +0100108 * 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 Graf8c3a4e02010-04-16 00:11:46 +0200116 * R12 = free
117 * R13 = Shadow VCPU (PACA)
Paul Mackerras3c42bf82011-06-29 00:20:58 +0000118 * HSTATE.SCRATCH0 = guest R12
119 * HSTATE.SCRATCH1 = guest CR
Alexander Graf8c3a4e02010-04-16 00:11:46 +0200120 * SPRG_SCRATCH0 = guest R13
Alexander Grafb4433a72010-01-08 02:58:04 +0100121 *
122 */
123kvmppc_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 Mackerras3c42bf82011-06-29 00:20:58 +0000131 lwz r12, HSTATE_SCRATCH1(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +0100132 mtcr r12
Paul Mackerras3c42bf82011-06-29 00:20:58 +0000133 PPC_LL r12, HSTATE_SCRATCH0(r13)
Paul Mackerras673b1892011-04-05 13:59:58 +1000134 GET_SCRATCH0(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +0100135
136 /* And get back into the code */
Nicholas Piggin222f20f2018-01-10 03:07:15 +1100137 RFI_TO_KERNEL
Paul Mackerrasb01c8b52011-06-29 00:18:26 +0000138#endif
Alexander Grafb4433a72010-01-08 02:58:04 +0100139
140/*
Paul Mackerras02143942011-07-23 17:41:44 +1000141 * Call kvmppc_handler_trampoline_enter in real mode
Alexander Grafc8621252009-10-30 05:47:09 +0000142 *
Paul Mackerras02143942011-07-23 17:41:44 +1000143 * On entry, r4 contains the guest shadow MSR
Alexander Grafbd2be682012-08-13 01:04:19 +0200144 * MSR.EE has to be 0 when calling this function
Alexander Grafc8621252009-10-30 05:47:09 +0000145 */
Anton Blanchard6ed179b2014-06-12 18:16:53 +1000146_GLOBAL_TOC(kvmppc_entry_trampoline)
Paul Mackerras02143942011-07-23 17:41:44 +1000147 mfmsr r5
148 LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
149 toreal(r7)
Alexander Grafc8621252009-10-30 05:47:09 +0000150
Paul Mackerras02143942011-07-23 17:41:44 +1000151 li r6, MSR_IR | MSR_DR
Alexander Grafbd2be682012-08-13 01:04:19 +0200152 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 Graf3d3319b2013-11-29 02:32:31 +0100155 * C exit handler function.
Alexander Grafbd2be682012-08-13 01:04:19 +0200156 */
157 ori r5, r5, MSR_EE
158 mtsrr0 r7
Alexander Graf7e57cba2010-01-08 02:58:03 +0100159 mtsrr1 r6
Nicholas Piggin222f20f2018-01-10 03:07:15 +1100160 RFI_TO_KERNEL
Alexander Graf021ec9c2010-01-08 02:58:06 +0100161
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200162#include "book3s_segment.S"