blob: d293485c1a6002595434284bfbaebd92e49767ce [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
Christophe Leroyec0c4642018-07-05 16:24:57 +000020#include <asm/asm-compat.h>
21
Alexander Grafd8d164a92014-05-15 14:38:03 +020022#define SHADOW_SLB_ENTRY_LEN 0x10
23#define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x)
24#define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8)
Alexander Graf5126ed32009-11-02 12:02:29 +000025
26/******************************************************************************
27 * *
28 * Entry code *
29 * *
30 *****************************************************************************/
31
Alexander Graf53e5b8b2010-04-16 00:11:48 +020032.macro LOAD_GUEST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000033
34 /* Required state:
35 *
36 * MSR = ~IR|DR
37 * R13 = PACA
Alexander Graf7e57cba2010-01-08 02:58:03 +010038 * R1 = host R1
39 * R2 = host R2
Alexander Graf53e5b8b2010-04-16 00:11:48 +020040 * R3 = shadow vcpu
Paul Mackerras02143942011-07-23 17:41:44 +100041 * all other volatile GPRS = free except R4, R6
Alexander Graf53e5b8b2010-04-16 00:11:48 +020042 * SVCPU[CR] = guest CR
43 * SVCPU[XER] = guest XER
44 * SVCPU[CTR] = guest CTR
45 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +000046 */
47
Alexander Grafd8d164a92014-05-15 14:38:03 +020048BEGIN_FW_FTR_SECTION
Alexander Graf5126ed32009-11-02 12:02:29 +000049
Alexander Grafd8d164a92014-05-15 14:38:03 +020050 /* Declare SLB shadow as 0 entries big */
Alexander Graf5126ed32009-11-02 12:02:29 +000051
Alexander Grafd8d164a92014-05-15 14:38:03 +020052 ld r11, PACA_SLBSHADOWPTR(r13)
53 li r8, 0
54 stb r8, 3(r11)
Alexander Graf5126ed32009-11-02 12:02:29 +000055
Alexander Grafd8d164a92014-05-15 14:38:03 +020056END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
Alexander Graf5126ed32009-11-02 12:02:29 +000057
58 /* Flush SLB */
59
Paul Mackerrasbc1bc4e2013-06-22 17:14:11 +100060 li r10, 0
61 slbmte r10, r10
Alexander Graf5126ed32009-11-02 12:02:29 +000062 slbia
63
Alexander Graf5126ed32009-11-02 12:02:29 +000064 /* Fill SLB with our shadow */
65
Alexander Graf53e5b8b2010-04-16 00:11:48 +020066 lbz r12, SVCPU_SLB_MAX(r3)
Alexander Graf5126ed32009-11-02 12:02:29 +000067 mulli r12, r12, 16
Alexander Graf53e5b8b2010-04-16 00:11:48 +020068 addi r12, r12, SVCPU_SLB
69 add r12, r12, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000070
71 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
Alexander Graf53e5b8b2010-04-16 00:11:48 +020072 li r11, SVCPU_SLB
73 add r11, r11, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000074
75slb_loop_enter:
76
77 ld r10, 0(r11)
78
Alexander Grafd8d164a92014-05-15 14:38:03 +020079 andis. r9, r10, SLB_ESID_V@h
Alexander Graf5126ed32009-11-02 12:02:29 +000080 beq slb_loop_enter_skip
81
82 ld r9, 8(r11)
83 slbmte r9, r10
84
85slb_loop_enter_skip:
86 addi r11, r11, 16
87 cmpd cr0, r11, r12
88 blt slb_loop_enter
89
90slb_do_enter:
91
Alexander Graf53e5b8b2010-04-16 00:11:48 +020092.endm
Alexander Graf5126ed32009-11-02 12:02:29 +000093
94/******************************************************************************
95 * *
96 * Exit code *
97 * *
98 *****************************************************************************/
99
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200100.macro LOAD_HOST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +0000101
102 /* Register usage at this point:
103 *
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200104 * R1 = host R1
105 * R2 = host R2
106 * R12 = exit handler id
107 * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
108 * SVCPU.* = guest *
109 * SVCPU[CR] = guest CR
110 * SVCPU[XER] = guest XER
111 * SVCPU[CTR] = guest CTR
112 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +0000113 *
114 */
115
Alexander Grafd8d164a92014-05-15 14:38:03 +0200116 /* Remove all SLB entries that are in use. */
Alexander Graf5126ed32009-11-02 12:02:29 +0000117
Nicholas Piggin93897a12017-10-21 14:32:30 +1000118 li r0, 0
Alexander Graf207438d2014-05-15 14:36:05 +0200119 slbmte r0, r0
Alexander Graf5126ed32009-11-02 12:02:29 +0000120 slbia
Alexander Graf5126ed32009-11-02 12:02:29 +0000121
Alexander Grafd8d164a92014-05-15 14:38:03 +0200122 /* Restore bolted entries from the shadow */
Alexander Graf5126ed32009-11-02 12:02:29 +0000123
124 ld r11, PACA_SLBSHADOWPTR(r13)
125
Alexander Grafd8d164a92014-05-15 14:38:03 +0200126BEGIN_FW_FTR_SECTION
127
128 /* Declare SLB shadow as SLB_NUM_BOLTED entries big */
129
130 li r8, SLB_NUM_BOLTED
131 stb r8, 3(r11)
132
133END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
134
135 /* Manually load all entries from shadow SLB */
136
137 li r8, SLBSHADOW_SAVEAREA
138 li r7, SLBSHADOW_SAVEAREA + 8
139
140 .rept SLB_NUM_BOLTED
141 LDX_BE r10, r11, r8
142 cmpdi r10, 0
143 beq 1f
144 LDX_BE r9, r11, r7
145 slbmte r9, r10
1461: addi r7, r7, SHADOW_SLB_ENTRY_LEN
147 addi r8, r8, SHADOW_SLB_ENTRY_LEN
148 .endr
149
150 isync
151 sync
Alexander Graf5126ed32009-11-02 12:02:29 +0000152
153slb_do_exit:
154
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200155.endm