blob: 56b983e7b7380c88a4199d68dc97fb2a6a0ec985 [file] [log] [blame]
Alexander Graf5126ed32009-11-02 12:02:29 +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#define SHADOW_SLB_ESID(num) (SLBSHADOW_SAVEAREA + (num * 0x10))
21#define SHADOW_SLB_VSID(num) (SLBSHADOW_SAVEAREA + (num * 0x10) + 0x8)
22#define UNBOLT_SLB_ENTRY(num) \
23 ld r9, SHADOW_SLB_ESID(num)(r12); \
24 /* Invalid? Skip. */; \
25 rldicl. r0, r9, 37, 63; \
26 beq slb_entry_skip_ ## num; \
27 xoris r9, r9, SLB_ESID_V@h; \
28 std r9, SHADOW_SLB_ESID(num)(r12); \
29 slb_entry_skip_ ## num:
30
31#define REBOLT_SLB_ENTRY(num) \
32 ld r10, SHADOW_SLB_ESID(num)(r11); \
33 cmpdi r10, 0; \
Alexander Grafb480f782010-01-04 22:19:22 +010034 beq slb_exit_skip_ ## num; \
Alexander Graf5126ed32009-11-02 12:02:29 +000035 oris r10, r10, SLB_ESID_V@h; \
36 ld r9, SHADOW_SLB_VSID(num)(r11); \
37 slbmte r9, r10; \
38 std r10, SHADOW_SLB_ESID(num)(r11); \
39slb_exit_skip_ ## num:
40
41/******************************************************************************
42 * *
43 * Entry code *
44 * *
45 *****************************************************************************/
46
Alexander Graf53e5b8b2010-04-16 00:11:48 +020047.macro LOAD_GUEST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000048
49 /* Required state:
50 *
51 * MSR = ~IR|DR
52 * R13 = PACA
Alexander Graf7e57cba2010-01-08 02:58:03 +010053 * R1 = host R1
54 * R2 = host R2
Alexander Graf53e5b8b2010-04-16 00:11:48 +020055 * R3 = shadow vcpu
Paul Mackerras02143942011-07-23 17:41:44 +100056 * all other volatile GPRS = free except R4, R6
Alexander Graf53e5b8b2010-04-16 00:11:48 +020057 * SVCPU[CR] = guest CR
58 * SVCPU[XER] = guest XER
59 * SVCPU[CTR] = guest CTR
60 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +000061 */
62
Alexander Graf5126ed32009-11-02 12:02:29 +000063 /* Remove LPAR shadow entries */
64
65#if SLB_NUM_BOLTED == 3
66
67 ld r12, PACA_SLBSHADOWPTR(r13)
68
69 /* Save off the first entry so we can slbie it later */
70 ld r10, SHADOW_SLB_ESID(0)(r12)
71 ld r11, SHADOW_SLB_VSID(0)(r12)
72
73 /* Remove bolted entries */
74 UNBOLT_SLB_ENTRY(0)
75 UNBOLT_SLB_ENTRY(1)
76 UNBOLT_SLB_ENTRY(2)
77
78#else
79#error unknown number of bolted entries
80#endif
81
82 /* Flush SLB */
83
84 slbia
85
86 /* r0 = esid & ESID_MASK */
87 rldicr r10, r10, 0, 35
88 /* r0 |= CLASS_BIT(VSID) */
89 rldic r12, r11, 56 - 36, 36
90 or r10, r10, r12
91 slbie r10
92
Alexander Graf5126ed32009-11-02 12:02:29 +000093 /* Fill SLB with our shadow */
94
Alexander Graf53e5b8b2010-04-16 00:11:48 +020095 lbz r12, SVCPU_SLB_MAX(r3)
Alexander Graf5126ed32009-11-02 12:02:29 +000096 mulli r12, r12, 16
Alexander Graf53e5b8b2010-04-16 00:11:48 +020097 addi r12, r12, SVCPU_SLB
98 add r12, r12, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000099
100 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200101 li r11, SVCPU_SLB
102 add r11, r11, r3
Alexander Graf5126ed32009-11-02 12:02:29 +0000103
104slb_loop_enter:
105
106 ld r10, 0(r11)
107
108 rldicl. r0, r10, 37, 63
109 beq slb_loop_enter_skip
110
111 ld r9, 8(r11)
112 slbmte r9, r10
113
114slb_loop_enter_skip:
115 addi r11, r11, 16
116 cmpd cr0, r11, r12
117 blt slb_loop_enter
118
119slb_do_enter:
120
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200121.endm
Alexander Graf5126ed32009-11-02 12:02:29 +0000122
123/******************************************************************************
124 * *
125 * Exit code *
126 * *
127 *****************************************************************************/
128
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200129.macro LOAD_HOST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +0000130
131 /* Register usage at this point:
132 *
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200133 * R1 = host R1
134 * R2 = host R2
135 * R12 = exit handler id
136 * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
137 * SVCPU.* = guest *
138 * SVCPU[CR] = guest CR
139 * SVCPU[XER] = guest XER
140 * SVCPU[CTR] = guest CTR
141 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +0000142 *
143 */
144
Alexander Graf5126ed32009-11-02 12:02:29 +0000145 /* Restore bolted entries from the shadow and fix it along the way */
146
147 /* We don't store anything in entry 0, so we don't need to take care of it */
148 slbia
149 isync
150
151#if SLB_NUM_BOLTED == 3
152
153 ld r11, PACA_SLBSHADOWPTR(r13)
154
155 REBOLT_SLB_ENTRY(0)
156 REBOLT_SLB_ENTRY(1)
157 REBOLT_SLB_ENTRY(2)
158
159#else
160#error unknown number of bolted entries
161#endif
162
163slb_do_exit:
164
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200165.endm