blob: e873796b1a2931eabd3c9ecb716a2c415eaba7f2 [file] [log] [blame]
Paul Mackerrasde56a942011-06-29 00:21:34 +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 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
16 *
17 * Derived from book3s_interrupts.S, which is:
18 * Copyright SUSE Linux Products GmbH 2009
19 *
20 * Authors: Alexander Graf <agraf@suse.de>
21 */
22
23#include <asm/ppc_asm.h>
24#include <asm/kvm_asm.h>
25#include <asm/reg.h>
26#include <asm/page.h>
27#include <asm/asm-offsets.h>
28#include <asm/exception-64s.h>
29#include <asm/ppc-opcode.h>
30
31/*****************************************************************************
32 * *
33 * Guest entry / exit code that is in kernel module memory (vmalloc) *
34 * *
35 ****************************************************************************/
36
37/* Registers:
Paul Mackerrase0b7ec02014-01-08 21:25:20 +110038 * none
Paul Mackerrasde56a942011-06-29 00:21:34 +000039 */
40_GLOBAL(__kvmppc_vcore_entry)
41
42 /* Write correct stack frame */
43 mflr r0
44 std r0,PPC_LR_STKOFF(r1)
45
46 /* Save host state to the stack */
47 stdu r1, -SWITCH_FRAME_SIZE(r1)
48
Paul Mackerrasa5ddea02012-02-03 00:53:21 +000049 /* Save non-volatile registers (r14 - r31) and CR */
Paul Mackerrasde56a942011-06-29 00:21:34 +000050 SAVE_NVGPRS(r1)
Paul Mackerrasa5ddea02012-02-03 00:53:21 +000051 mfcr r3
52 std r3, _CCR(r1)
Paul Mackerrasde56a942011-06-29 00:21:34 +000053
54 /* Save host DSCR */
Paul Mackerras9e368f22011-06-29 00:40:08 +000055BEGIN_FTR_SECTION
Paul Mackerrasde56a942011-06-29 00:21:34 +000056 mfspr r3, SPRN_DSCR
57 std r3, HSTATE_DSCR(r13)
Paul Mackerras9e368f22011-06-29 00:40:08 +000058END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
Paul Mackerrasde56a942011-06-29 00:21:34 +000059
Michael Neulingeee7ff92014-01-08 21:25:19 +110060BEGIN_FTR_SECTION
Paul Mackerrasde56a942011-06-29 00:21:34 +000061 /* Save host DABR */
62 mfspr r3, SPRN_DABR
63 std r3, HSTATE_DABR(r13)
Michael Neulingeee7ff92014-01-08 21:25:19 +110064END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
Paul Mackerrasde56a942011-06-29 00:21:34 +000065
66 /* Hard-disable interrupts */
67 mfmsr r10
68 std r10, HSTATE_HOST_MSR(r13)
69 rldicl r10,r10,48,1
70 rotldi r10,r10,16
71 mtmsrd r10,1
72
Paul Mackerras89436332012-03-02 01:38:23 +000073 /* Save host PMU registers */
Paul Mackerrasde56a942011-06-29 00:21:34 +000074 li r3, 1
75 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
76 mfspr r7, SPRN_MMCR0 /* save MMCR0 */
77 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
Paul Mackerras89436332012-03-02 01:38:23 +000078 mfspr r6, SPRN_MMCRA
79BEGIN_FTR_SECTION
80 /* On P7, clear MMCRA in order to disable SDAR updates */
81 li r5, 0
82 mtspr SPRN_MMCRA, r5
83END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
Paul Mackerrasde56a942011-06-29 00:21:34 +000084 isync
85 ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
86 lbz r5, LPPACA_PMCINUSE(r3)
87 cmpwi r5, 0
88 beq 31f /* skip if not */
89 mfspr r5, SPRN_MMCR1
Paul Mackerrasde56a942011-06-29 00:21:34 +000090 std r7, HSTATE_MMCR(r13)
91 std r5, HSTATE_MMCR + 8(r13)
92 std r6, HSTATE_MMCR + 16(r13)
93 mfspr r3, SPRN_PMC1
94 mfspr r5, SPRN_PMC2
95 mfspr r6, SPRN_PMC3
96 mfspr r7, SPRN_PMC4
97 mfspr r8, SPRN_PMC5
98 mfspr r9, SPRN_PMC6
Paul Mackerras9e368f22011-06-29 00:40:08 +000099BEGIN_FTR_SECTION
100 mfspr r10, SPRN_PMC7
101 mfspr r11, SPRN_PMC8
102END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
Paul Mackerrasde56a942011-06-29 00:21:34 +0000103 stw r3, HSTATE_PMC(r13)
104 stw r5, HSTATE_PMC + 4(r13)
105 stw r6, HSTATE_PMC + 8(r13)
106 stw r7, HSTATE_PMC + 12(r13)
107 stw r8, HSTATE_PMC + 16(r13)
108 stw r9, HSTATE_PMC + 20(r13)
Paul Mackerras9e368f22011-06-29 00:40:08 +0000109BEGIN_FTR_SECTION
110 stw r10, HSTATE_PMC + 24(r13)
111 stw r11, HSTATE_PMC + 28(r13)
112END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
Paul Mackerrasde56a942011-06-29 00:21:34 +000011331:
114
115 /*
116 * Put whatever is in the decrementer into the
117 * hypervisor decrementer.
118 */
119 mfspr r8,SPRN_DEC
120 mftb r7
121 mtspr SPRN_HDEC,r8
122 extsw r8,r8
123 add r8,r8,r7
124 std r8,HSTATE_DECEXP(r13)
125
Paul Mackerras3cc33d52013-04-15 20:28:01 +0000126#ifdef CONFIG_SMP
Paul Mackerras9e368f22011-06-29 00:40:08 +0000127 /*
128 * On PPC970, if the guest vcpu has an external interrupt pending,
129 * send ourselves an IPI so as to interrupt the guest once it
130 * enables interrupts. (It must have interrupts disabled,
131 * otherwise we would already have delivered the interrupt.)
Paul Mackerras3cc33d52013-04-15 20:28:01 +0000132 *
133 * XXX If this is a UP build, smp_send_reschedule is not available,
134 * so the interrupt will be delayed until the next time the vcpu
135 * enters the guest with interrupts enabled.
Paul Mackerras9e368f22011-06-29 00:40:08 +0000136 */
137BEGIN_FTR_SECTION
Paul Mackerrase0b7ec02014-01-08 21:25:20 +1100138 ld r4, HSTATE_KVM_VCPU(r13)
Paul Mackerras9e368f22011-06-29 00:40:08 +0000139 ld r0, VCPU_PENDING_EXC(r4)
140 li r7, (1 << BOOK3S_IRQPRIO_EXTERNAL)
141 oris r7, r7, (1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
142 and. r0, r0, r7
143 beq 32f
Paul Mackerras9e368f22011-06-29 00:40:08 +0000144 lhz r3, PACAPACAINDEX(r13)
145 bl smp_send_reschedule
146 nop
Paul Mackerras9e368f22011-06-29 00:40:08 +000014732:
148END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
Paul Mackerras3cc33d52013-04-15 20:28:01 +0000149#endif /* CONFIG_SMP */
Paul Mackerras9e368f22011-06-29 00:40:08 +0000150
Paul Mackerrasde56a942011-06-29 00:21:34 +0000151 /* Jump to partition switch code */
152 bl .kvmppc_hv_entry_trampoline
153 nop
154
155/*
156 * We return here in virtual mode after the guest exits
157 * with something that we can't handle in real mode.
158 * Interrupts are enabled again at this point.
159 */
160
Paul Mackerrasde56a942011-06-29 00:21:34 +0000161 /*
162 * Register usage at this point:
163 *
164 * R1 = host R1
165 * R2 = host R2
166 * R12 = exit handler id
167 * R13 = PACA
168 */
169
Paul Mackerrasa5ddea02012-02-03 00:53:21 +0000170 /* Restore non-volatile host registers (r14 - r31) and CR */
Paul Mackerrasde56a942011-06-29 00:21:34 +0000171 REST_NVGPRS(r1)
Paul Mackerrasa5ddea02012-02-03 00:53:21 +0000172 ld r4, _CCR(r1)
173 mtcr r4
Paul Mackerrasde56a942011-06-29 00:21:34 +0000174
175 addi r1, r1, SWITCH_FRAME_SIZE
176 ld r0, PPC_LR_STKOFF(r1)
177 mtlr r0
178 blr