blob: 9ad1c2645d6f7c2c6b1d96012aa47671127c87c7 [file] [log] [blame]
Alexander Grafc8621252009-10-30 05:47:09 +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 SUSE Linux Products GmbH 2009
16 *
17 * Authors: Alexander Graf <agraf@suse.de>
18 */
19
20#include <asm/ppc_asm.h>
21#include <asm/kvm_asm.h>
22#include <asm/reg.h>
23#include <asm/page.h>
24#include <asm/asm-offsets.h>
25#include <asm/exception-64s.h>
26
27/*****************************************************************************
28 * *
29 * Real Mode handlers that need to be in low physical memory *
30 * *
31 ****************************************************************************/
32
33
34.macro INTERRUPT_TRAMPOLINE intno
35
36.global kvmppc_trampoline_\intno
37kvmppc_trampoline_\intno:
38
39 mtspr SPRN_SPRG_SCRATCH0, r13 /* Save r13 */
40
41 /*
42 * First thing to do is to find out if we're coming
43 * from a KVM guest or a Linux process.
44 *
45 * To distinguish, we check a magic byte in the PACA
46 */
47 mfspr r13, SPRN_SPRG_PACA /* r13 = PACA */
Alexander Graf7e57cba2010-01-08 02:58:03 +010048 std r12, PACA_KVM_SCRATCH0(r13)
Alexander Grafc8621252009-10-30 05:47:09 +000049 mfcr r12
Alexander Graf7e57cba2010-01-08 02:58:03 +010050 stw r12, PACA_KVM_SCRATCH1(r13)
Alexander Grafc8621252009-10-30 05:47:09 +000051 lbz r12, PACA_KVM_IN_GUEST(r13)
Alexander Grafb4433a72010-01-08 02:58:04 +010052 cmpwi r12, KVM_GUEST_MODE_NONE
Alexander Grafc8621252009-10-30 05:47:09 +000053 bne ..kvmppc_handler_hasmagic_\intno
54 /* No KVM guest? Then jump back to the Linux handler! */
Alexander Graf7e57cba2010-01-08 02:58:03 +010055 lwz r12, PACA_KVM_SCRATCH1(r13)
Alexander Grafc8621252009-10-30 05:47:09 +000056 mtcr r12
Alexander Graf7e57cba2010-01-08 02:58:03 +010057 ld r12, PACA_KVM_SCRATCH0(r13)
Alexander Grafc8621252009-10-30 05:47:09 +000058 mfspr r13, SPRN_SPRG_SCRATCH0 /* r13 = original r13 */
59 b kvmppc_resume_\intno /* Get back original handler */
60
61 /* Now we know we're handling a KVM guest */
62..kvmppc_handler_hasmagic_\intno:
Alexander Grafb4433a72010-01-08 02:58:04 +010063
64 /* Should we just skip the faulting instruction? */
65 cmpwi r12, KVM_GUEST_MODE_SKIP
66 beq kvmppc_handler_skip_ins
67
Alexander Grafc8621252009-10-30 05:47:09 +000068 /* Let's store which interrupt we're handling */
69 li r12, \intno
70
71 /* Jump into the SLB exit code that goes to the highmem handler */
72 b kvmppc_handler_trampoline_exit
73
74.endm
75
76INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSTEM_RESET
77INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_MACHINE_CHECK
78INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_STORAGE
79INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DATA_SEGMENT
80INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_STORAGE
81INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_INST_SEGMENT
82INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_EXTERNAL
83INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALIGNMENT
84INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PROGRAM
85INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_FP_UNAVAIL
86INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_DECREMENTER
87INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_SYSCALL
88INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_TRACE
89INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_PERFMON
90INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC
91INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_VSX
92
93/*
Alexander Grafb4433a72010-01-08 02:58:04 +010094 * Bring us back to the faulting code, but skip the
95 * faulting instruction.
96 *
97 * This is a generic exit path from the interrupt
98 * trampolines above.
99 *
100 * Input Registers:
101 *
102 * R12 = free
103 * R13 = PACA
104 * PACA.KVM.SCRATCH0 = guest R12
105 * PACA.KVM.SCRATCH1 = guest CR
106 * SPRG_SCRATCH0 = guest R13
107 *
108 */
109kvmppc_handler_skip_ins:
110
111 /* Patch the IP to the next instruction */
112 mfsrr0 r12
113 addi r12, r12, 4
114 mtsrr0 r12
115
116 /* Clean up all state */
117 lwz r12, PACA_KVM_SCRATCH1(r13)
118 mtcr r12
119 ld r12, PACA_KVM_SCRATCH0(r13)
120 mfspr r13, SPRN_SPRG_SCRATCH0
121
122 /* And get back into the code */
123 RFI
124
125/*
Alexander Grafc8621252009-10-30 05:47:09 +0000126 * This trampoline brings us back to a real mode handler
127 *
128 * Input Registers:
129 *
Alexander Graf7e57cba2010-01-08 02:58:03 +0100130 * R5 = SRR0
131 * R6 = SRR1
Alexander Grafc8621252009-10-30 05:47:09 +0000132 * LR = real-mode IP
133 *
134 */
135.global kvmppc_handler_lowmem_trampoline
136kvmppc_handler_lowmem_trampoline:
137
Alexander Graf7e57cba2010-01-08 02:58:03 +0100138 mtsrr0 r5
139 mtsrr1 r6
Alexander Grafc8621252009-10-30 05:47:09 +0000140 blr
141kvmppc_handler_lowmem_trampoline_end:
142
143.global kvmppc_trampoline_lowmem
144kvmppc_trampoline_lowmem:
145 .long kvmppc_handler_lowmem_trampoline - _stext
146
147.global kvmppc_trampoline_enter
148kvmppc_trampoline_enter:
149 .long kvmppc_handler_trampoline_enter - _stext
150
151#include "book3s_64_slb.S"
152