1 /* SPDX-License-Identifier: GPL-2.0-only */
4 * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
6 * Derived from book3s_interrupts.S, which is:
7 * Copyright SUSE Linux Products GmbH 2009
9 * Authors: Alexander Graf <agraf@suse.de>
12 #include <asm/ppc_asm.h>
13 #include <asm/kvm_asm.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/exception-64s.h>
18 #include <asm/ppc-opcode.h>
19 #include <asm/asm-compat.h>
20 #include <asm/feature-fixups.h>
22 /*****************************************************************************
24 * Guest entry / exit code that is in kernel module memory (vmalloc) *
26 ****************************************************************************/
31 _GLOBAL(__kvmppc_vcore_entry)
33 /* Write correct stack frame */
35 std r0,PPC_LR_STKOFF(r1)
37 /* Save host state to the stack */
38 stdu r1, -SWITCH_FRAME_SIZE(r1)
40 /* Save non-volatile registers (r14 - r31) and CR */
47 std r3, HSTATE_DSCR(r13)
52 std r3, HSTATE_DABR(r13)
53 END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
55 /* Save host PMU registers */
56 bl kvmhv_save_host_pmu
59 * Put whatever is in the decrementer into the
60 * hypervisor decrementer.
61 * Because of a hardware deviation in P8 and P9,
62 * we need to set LPCR[HDICE] before writing HDEC.
64 ld r5, HSTATE_KVM_VCORE(r13)
66 ld r9, KVM_HOST_LPCR(r6)
67 ori r8, r9, LPCR_HDICE
70 andis. r0, r9, LPCR_LD@h
74 /* On POWER9, don't sign-extend if host LPCR[LD] bit is set */
76 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
78 32: mtspr SPRN_HDEC,r8
80 std r8,HSTATE_DECEXP(r13)
82 /* Jump to partition switch code */
83 bl kvmppc_hv_entry_trampoline
87 * We return here in virtual mode after the guest exits
88 * with something that we can't handle in real mode.
89 * Interrupts are still hard-disabled.
93 * Register usage at this point:
97 * R3 = trap number on this thread
98 * R12 = exit handler id
102 /* Restore non-volatile host registers (r14 - r31) and CR */
107 addi r1, r1, SWITCH_FRAME_SIZE
108 ld r0, PPC_LR_STKOFF(r1)
112 _GLOBAL(kvmhv_save_host_pmu)
114 /* Work around P8 PMAE bug */
118 mtspr SPRN_MMCR2, r3 /* freeze all counters using MMCR2 */
120 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
122 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
123 mfspr r7, SPRN_MMCR0 /* save MMCR0 */
124 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
126 /* Clear MMCRA in order to disable SDAR updates */
130 lbz r5, PACA_PMCINUSE(r13) /* is the host using the PMU? */
132 beq 31f /* skip if not */
136 std r7, HSTATE_MMCR0(r13)
137 std r5, HSTATE_MMCR1(r13)
138 std r6, HSTATE_MMCRA(r13)
139 std r9, HSTATE_SIAR(r13)
140 std r10, HSTATE_SDAR(r13)
143 std r8, HSTATE_MMCR2(r13)
144 std r9, HSTATE_SIER(r13)
145 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
150 std r5, HSTATE_MMCR3(r13)
151 std r6, HSTATE_SIER2(r13)
152 std r7, HSTATE_SIER3(r13)
153 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_31)
160 stw r3, HSTATE_PMC1(r13)
161 stw r5, HSTATE_PMC2(r13)
162 stw r6, HSTATE_PMC3(r13)
163 stw r7, HSTATE_PMC4(r13)
164 stw r8, HSTATE_PMC5(r13)
165 stw r9, HSTATE_PMC6(r13)