book3s_rmhandlers.S 4.6 KB
Newer Older
A
Alexander Graf 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License, version 2, as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright SUSE Linux Products GmbH 2009
 *
 * Authors: Alexander Graf <agraf@suse.de>
 */

#include <asm/ppc_asm.h>
#include <asm/kvm_asm.h>
#include <asm/reg.h>
23
#include <asm/mmu.h>
A
Alexander Graf 已提交
24 25
#include <asm/page.h>
#include <asm/asm-offsets.h>
26 27

#ifdef CONFIG_PPC_BOOK3S_64
A
Alexander Graf 已提交
28
#include <asm/exception-64s.h>
29
#endif
A
Alexander Graf 已提交
30 31 32 33 34 35 36

/*****************************************************************************
 *                                                                           *
 *        Real Mode handlers that need to be in low physical memory          *
 *                                                                           *
 ****************************************************************************/

37 38
#if defined(CONFIG_PPC_BOOK3S_64)

39 40 41
#if defined(_CALL_ELF) && _CALL_ELF == 2
#define FUNC(name) 		name
#else
42
#define FUNC(name) 		GLUE(.,name)
43
#endif
44

45
#elif defined(CONFIG_PPC_BOOK3S_32)
46 47 48

#define FUNC(name)		name

A
Alexander Graf 已提交
49 50 51 52 53
.macro INTERRUPT_TRAMPOLINE intno

.global kvmppc_trampoline_\intno
kvmppc_trampoline_\intno:

54
	mtspr	SPRN_SPRG_SCRATCH0, r13		/* Save r13 */
A
Alexander Graf 已提交
55 56 57 58 59

	/*
	 * First thing to do is to find out if we're coming
	 * from a KVM guest or a Linux process.
	 *
60
	 * To distinguish, we check a magic byte in the PACA/current
A
Alexander Graf 已提交
61
	 */
62 63 64 65
	mfspr	r13, SPRN_SPRG_THREAD
	lwz	r13, THREAD_KVM_SVCPU(r13)
	/* PPC32 can have a NULL pointer - let's check for that */
	mtspr   SPRN_SPRG_SCRATCH1, r12		/* Save r12 */
A
Alexander Graf 已提交
66
	mfcr	r12
67 68 69 70 71 72 73 74
	cmpwi	r13, 0
	bne	1f
2:	mtcr	r12
	mfspr	r12, SPRN_SPRG_SCRATCH1
	mfspr	r13, SPRN_SPRG_SCRATCH0		/* r13 = original r13 */
	b	kvmppc_resume_\intno		/* Get back original handler */

1:	tophys(r13, r13)
75
	stw	r12, HSTATE_SCRATCH1(r13)
76
	mfspr	r12, SPRN_SPRG_SCRATCH1
77 78
	stw	r12, HSTATE_SCRATCH0(r13)
	lbz	r12, HSTATE_IN_GUEST(r13)
79
	cmpwi	r12, KVM_GUEST_MODE_NONE
A
Alexander Graf 已提交
80 81
	bne	..kvmppc_handler_hasmagic_\intno
	/* No KVM guest? Then jump back to the Linux handler! */
82
	lwz	r12, HSTATE_SCRATCH1(r13)
83
	b	2b
A
Alexander Graf 已提交
84 85 86

	/* Now we know we're handling a KVM guest */
..kvmppc_handler_hasmagic_\intno:
87 88 89 90 91

	/* Should we just skip the faulting instruction? */
	cmpwi	r12, KVM_GUEST_MODE_SKIP
	beq	kvmppc_handler_skip_ins

A
Alexander Graf 已提交
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	/* Let's store which interrupt we're handling */
	li	r12, \intno

	/* Jump into the SLB exit code that goes to the highmem handler */
	b	kvmppc_handler_trampoline_exit

.endm

INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_SYSTEM_RESET
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_MACHINE_CHECK
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_DATA_STORAGE
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_INST_STORAGE
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_EXTERNAL
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_ALIGNMENT
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_PROGRAM
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_FP_UNAVAIL
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_DECREMENTER
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_SYSCALL
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_TRACE
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_PERFMON
INTERRUPT_TRAMPOLINE	BOOK3S_INTERRUPT_ALTIVEC
113

114 115 116 117 118 119 120 121 122
/*
 * Bring us back to the faulting code, but skip the
 * faulting instruction.
 *
 * This is a generic exit path from the interrupt
 * trampolines above.
 *
 * Input Registers:
 *
123 124
 * R12            = free
 * R13            = Shadow VCPU (PACA)
125 126
 * HSTATE.SCRATCH0 = guest R12
 * HSTATE.SCRATCH1 = guest CR
127
 * SPRG_SCRATCH0  = guest R13
128 129 130 131 132 133 134 135 136 137
 *
 */
kvmppc_handler_skip_ins:

	/* Patch the IP to the next instruction */
	mfsrr0	r12
	addi	r12, r12, 4
	mtsrr0	r12

	/* Clean up all state */
138
	lwz	r12, HSTATE_SCRATCH1(r13)
139
	mtcr	r12
140
	PPC_LL	r12, HSTATE_SCRATCH0(r13)
141
	GET_SCRATCH0(r13)
142 143 144

	/* And get back into the code */
	RFI
145
#endif
146

A
Alexander Graf 已提交
147
/*
148
 * Call kvmppc_handler_trampoline_enter in real mode
A
Alexander Graf 已提交
149
 *
150
 * On entry, r4 contains the guest shadow MSR
151
 * MSR.EE has to be 0 when calling this function
A
Alexander Graf 已提交
152
 */
153
_GLOBAL_TOC(kvmppc_entry_trampoline)
154 155 156 157 158
	mfmsr	r5
	LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
	toreal(r7)

	li	r6, MSR_IR | MSR_DR
159 160 161
	andc	r6, r5, r6	/* Clear DR and IR in MSR value */
	/*
	 * Set EE in HOST_MSR so that it's enabled when we get into our
162
	 * C exit handler function.
163 164 165
	 */
	ori	r5, r5, MSR_EE
	mtsrr0	r7
166
	mtsrr1	r6
167 168
	RFI

169
#include "book3s_segment.S"