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.
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.
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.
15 * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com>
17 * Derived from book3s_interrupts.S, which is:
18 * Copyright SUSE Linux Products GmbH 2009
20 * Authors: Alexander Graf <agraf@suse.de>
23 #include <asm/ppc_asm.h>
24 #include <asm/kvm_asm.h>
27 #include <asm/asm-offsets.h>
28 #include <asm/exception-64s.h>
29 #include <asm/ppc-opcode.h>
31 /*****************************************************************************
33 * Guest entry / exit code that is in kernel module memory (vmalloc) *
35 ****************************************************************************/
40 _GLOBAL(__kvmppc_vcore_entry)
42 /* Write correct stack frame */
44 std r0,PPC_LR_STKOFF(r1)
46 /* Save host state to the stack */
47 stdu r1, -SWITCH_FRAME_SIZE(r1)
49 /* Save non-volatile registers (r14 - r31) */
55 std r3, HSTATE_DSCR(r13)
56 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_206)
60 std r3, HSTATE_DABR(r13)
62 /* Hard-disable interrupts */
64 std r10, HSTATE_HOST_MSR(r13)
69 /* Save host PMU registers and load guest PMU registers */
70 /* R4 is live here (vcpu pointer) but not r3 or r5 */
72 sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */
73 mfspr r7, SPRN_MMCR0 /* save MMCR0 */
74 mtspr SPRN_MMCR0, r3 /* freeze all counters, disable interrupts */
76 ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */
77 lbz r5, LPPACA_PMCINUSE(r3)
79 beq 31f /* skip if not */
82 std r7, HSTATE_MMCR(r13)
83 std r5, HSTATE_MMCR + 8(r13)
84 std r6, HSTATE_MMCR + 16(r13)
94 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
95 stw r3, HSTATE_PMC(r13)
96 stw r5, HSTATE_PMC + 4(r13)
97 stw r6, HSTATE_PMC + 8(r13)
98 stw r7, HSTATE_PMC + 12(r13)
99 stw r8, HSTATE_PMC + 16(r13)
100 stw r9, HSTATE_PMC + 20(r13)
102 stw r10, HSTATE_PMC + 24(r13)
103 stw r11, HSTATE_PMC + 28(r13)
104 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
108 * Put whatever is in the decrementer into the
109 * hypervisor decrementer.
116 std r8,HSTATE_DECEXP(r13)
119 * On PPC970, if the guest vcpu has an external interrupt pending,
120 * send ourselves an IPI so as to interrupt the guest once it
121 * enables interrupts. (It must have interrupts disabled,
122 * otherwise we would already have delivered the interrupt.)
125 ld r0, VCPU_PENDING_EXC(r4)
126 li r7, (1 << BOOK3S_IRQPRIO_EXTERNAL)
127 oris r7, r7, (1 << BOOK3S_IRQPRIO_EXTERNAL_LEVEL)@h
131 lhz r3, PACAPACAINDEX(r13)
132 bl smp_send_reschedule
136 END_FTR_SECTION_IFSET(CPU_FTR_ARCH_201)
138 /* Jump to partition switch code */
139 bl .kvmppc_hv_entry_trampoline
143 * We return here in virtual mode after the guest exits
144 * with something that we can't handle in real mode.
145 * Interrupts are enabled again at this point.
148 .global kvmppc_handler_highmem
149 kvmppc_handler_highmem:
152 * Register usage at this point:
156 * R12 = exit handler id
160 /* Restore non-volatile host registers (r14 - r31) */
163 addi r1, r1, SWITCH_FRAME_SIZE
164 ld r0, PPC_LR_STKOFF(r1)