blob: 4d958dd21e597fafe9585d33d8ef02a1412021af [file] [log] [blame]
Thomas Gleixnerd94d71c2019-05-29 07:12:40 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Alexander Graf5126ed32009-11-02 12:02:29 +00002/*
Alexander Graf5126ed32009-11-02 12:02:29 +00003 *
4 * Copyright SUSE Linux Products GmbH 2009
5 *
6 * Authors: Alexander Graf <agraf@suse.de>
7 */
8
Christophe Leroyec0c4642018-07-05 16:24:57 +00009#include <asm/asm-compat.h>
Christophe Leroy2c86cd12018-07-05 16:25:01 +000010#include <asm/feature-fixups.h>
Christophe Leroyec0c4642018-07-05 16:24:57 +000011
Alexander Grafd8d164a92014-05-15 14:38:03 +020012#define SHADOW_SLB_ENTRY_LEN 0x10
13#define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x)
14#define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8)
Alexander Graf5126ed32009-11-02 12:02:29 +000015
16/******************************************************************************
17 * *
18 * Entry code *
19 * *
20 *****************************************************************************/
21
Alexander Graf53e5b8b2010-04-16 00:11:48 +020022.macro LOAD_GUEST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000023
24 /* Required state:
25 *
26 * MSR = ~IR|DR
27 * R13 = PACA
Alexander Graf7e57cba2010-01-08 02:58:03 +010028 * R1 = host R1
29 * R2 = host R2
Alexander Graf53e5b8b2010-04-16 00:11:48 +020030 * R3 = shadow vcpu
Paul Mackerras02143942011-07-23 17:41:44 +100031 * all other volatile GPRS = free except R4, R6
Alexander Graf53e5b8b2010-04-16 00:11:48 +020032 * SVCPU[CR] = guest CR
33 * SVCPU[XER] = guest XER
34 * SVCPU[CTR] = guest CTR
35 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +000036 */
37
Alexander Grafd8d164a92014-05-15 14:38:03 +020038BEGIN_FW_FTR_SECTION
Alexander Graf5126ed32009-11-02 12:02:29 +000039
Alexander Grafd8d164a92014-05-15 14:38:03 +020040 /* Declare SLB shadow as 0 entries big */
Alexander Graf5126ed32009-11-02 12:02:29 +000041
Alexander Grafd8d164a92014-05-15 14:38:03 +020042 ld r11, PACA_SLBSHADOWPTR(r13)
43 li r8, 0
44 stb r8, 3(r11)
Alexander Graf5126ed32009-11-02 12:02:29 +000045
Alexander Grafd8d164a92014-05-15 14:38:03 +020046END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
Alexander Graf5126ed32009-11-02 12:02:29 +000047
48 /* Flush SLB */
49
Paul Mackerrasbc1bc4e2013-06-22 17:14:11 +100050 li r10, 0
51 slbmte r10, r10
Alexander Graf5126ed32009-11-02 12:02:29 +000052 slbia
53
Alexander Graf5126ed32009-11-02 12:02:29 +000054 /* Fill SLB with our shadow */
55
Alexander Graf53e5b8b2010-04-16 00:11:48 +020056 lbz r12, SVCPU_SLB_MAX(r3)
Alexander Graf5126ed32009-11-02 12:02:29 +000057 mulli r12, r12, 16
Alexander Graf53e5b8b2010-04-16 00:11:48 +020058 addi r12, r12, SVCPU_SLB
59 add r12, r12, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000060
61 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
Alexander Graf53e5b8b2010-04-16 00:11:48 +020062 li r11, SVCPU_SLB
63 add r11, r11, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000064
65slb_loop_enter:
66
67 ld r10, 0(r11)
68
Alexander Grafd8d164a92014-05-15 14:38:03 +020069 andis. r9, r10, SLB_ESID_V@h
Alexander Graf5126ed32009-11-02 12:02:29 +000070 beq slb_loop_enter_skip
71
72 ld r9, 8(r11)
73 slbmte r9, r10
74
75slb_loop_enter_skip:
76 addi r11, r11, 16
77 cmpd cr0, r11, r12
78 blt slb_loop_enter
79
80slb_do_enter:
81
Alexander Graf53e5b8b2010-04-16 00:11:48 +020082.endm
Alexander Graf5126ed32009-11-02 12:02:29 +000083
84/******************************************************************************
85 * *
86 * Exit code *
87 * *
88 *****************************************************************************/
89
Alexander Graf53e5b8b2010-04-16 00:11:48 +020090.macro LOAD_HOST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000091
92 /* Register usage at this point:
93 *
Alexander Graf53e5b8b2010-04-16 00:11:48 +020094 * R1 = host R1
95 * R2 = host R2
96 * R12 = exit handler id
97 * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
98 * SVCPU.* = guest *
99 * SVCPU[CR] = guest CR
100 * SVCPU[XER] = guest XER
101 * SVCPU[CTR] = guest CTR
102 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +0000103 *
104 */
105
Alexander Grafd8d164a92014-05-15 14:38:03 +0200106 /* Remove all SLB entries that are in use. */
Alexander Graf5126ed32009-11-02 12:02:29 +0000107
Nicholas Piggin93897a12017-10-21 14:32:30 +1000108 li r0, 0
Alexander Graf207438d2014-05-15 14:36:05 +0200109 slbmte r0, r0
Alexander Graf5126ed32009-11-02 12:02:29 +0000110 slbia
Alexander Graf5126ed32009-11-02 12:02:29 +0000111
Alexander Grafd8d164a92014-05-15 14:38:03 +0200112 /* Restore bolted entries from the shadow */
Alexander Graf5126ed32009-11-02 12:02:29 +0000113
114 ld r11, PACA_SLBSHADOWPTR(r13)
115
Alexander Grafd8d164a92014-05-15 14:38:03 +0200116BEGIN_FW_FTR_SECTION
117
118 /* Declare SLB shadow as SLB_NUM_BOLTED entries big */
119
120 li r8, SLB_NUM_BOLTED
121 stb r8, 3(r11)
122
123END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
124
125 /* Manually load all entries from shadow SLB */
126
127 li r8, SLBSHADOW_SAVEAREA
128 li r7, SLBSHADOW_SAVEAREA + 8
129
130 .rept SLB_NUM_BOLTED
131 LDX_BE r10, r11, r8
132 cmpdi r10, 0
133 beq 1f
134 LDX_BE r9, r11, r7
135 slbmte r9, r10
1361: addi r7, r7, SHADOW_SLB_ENTRY_LEN
137 addi r8, r8, SHADOW_SLB_ENTRY_LEN
138 .endr
139
140 isync
141 sync
Alexander Graf5126ed32009-11-02 12:02:29 +0000142
143slb_do_exit:
144
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200145.endm