blob: 3589c4e3d49bbc62541538d19e030e9e4dc0ae41 [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
Alexander Grafd8d164a92014-05-15 14:38:03 +020020#define SHADOW_SLB_ENTRY_LEN 0x10
21#define OFFSET_ESID(x) (SHADOW_SLB_ENTRY_LEN * x)
22#define OFFSET_VSID(x) ((SHADOW_SLB_ENTRY_LEN * x) + 8)
Alexander Graf5126ed32009-11-02 12:02:29 +000023
24/******************************************************************************
25 * *
26 * Entry code *
27 * *
28 *****************************************************************************/
29
Alexander Graf53e5b8b2010-04-16 00:11:48 +020030.macro LOAD_GUEST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000031
32 /* Required state:
33 *
34 * MSR = ~IR|DR
35 * R13 = PACA
Alexander Graf7e57cba2010-01-08 02:58:03 +010036 * R1 = host R1
37 * R2 = host R2
Alexander Graf53e5b8b2010-04-16 00:11:48 +020038 * R3 = shadow vcpu
Paul Mackerras02143942011-07-23 17:41:44 +100039 * all other volatile GPRS = free except R4, R6
Alexander Graf53e5b8b2010-04-16 00:11:48 +020040 * SVCPU[CR] = guest CR
41 * SVCPU[XER] = guest XER
42 * SVCPU[CTR] = guest CTR
43 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +000044 */
45
Alexander Grafd8d164a92014-05-15 14:38:03 +020046BEGIN_FW_FTR_SECTION
Alexander Graf5126ed32009-11-02 12:02:29 +000047
Alexander Grafd8d164a92014-05-15 14:38:03 +020048 /* Declare SLB shadow as 0 entries big */
Alexander Graf5126ed32009-11-02 12:02:29 +000049
Alexander Grafd8d164a92014-05-15 14:38:03 +020050 ld r11, PACA_SLBSHADOWPTR(r13)
51 li r8, 0
52 stb r8, 3(r11)
Alexander Graf5126ed32009-11-02 12:02:29 +000053
Alexander Grafd8d164a92014-05-15 14:38:03 +020054END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
Alexander Graf5126ed32009-11-02 12:02:29 +000055
56 /* Flush SLB */
57
Paul Mackerrasbc1bc4e2013-06-22 17:14:11 +100058 li r10, 0
59 slbmte r10, r10
Alexander Graf5126ed32009-11-02 12:02:29 +000060 slbia
61
Alexander Graf5126ed32009-11-02 12:02:29 +000062 /* Fill SLB with our shadow */
63
Alexander Graf53e5b8b2010-04-16 00:11:48 +020064 lbz r12, SVCPU_SLB_MAX(r3)
Alexander Graf5126ed32009-11-02 12:02:29 +000065 mulli r12, r12, 16
Alexander Graf53e5b8b2010-04-16 00:11:48 +020066 addi r12, r12, SVCPU_SLB
67 add r12, r12, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000068
69 /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
Alexander Graf53e5b8b2010-04-16 00:11:48 +020070 li r11, SVCPU_SLB
71 add r11, r11, r3
Alexander Graf5126ed32009-11-02 12:02:29 +000072
73slb_loop_enter:
74
75 ld r10, 0(r11)
76
Alexander Grafd8d164a92014-05-15 14:38:03 +020077 andis. r9, r10, SLB_ESID_V@h
Alexander Graf5126ed32009-11-02 12:02:29 +000078 beq slb_loop_enter_skip
79
80 ld r9, 8(r11)
81 slbmte r9, r10
82
83slb_loop_enter_skip:
84 addi r11, r11, 16
85 cmpd cr0, r11, r12
86 blt slb_loop_enter
87
88slb_do_enter:
89
Alexander Graf53e5b8b2010-04-16 00:11:48 +020090.endm
Alexander Graf5126ed32009-11-02 12:02:29 +000091
92/******************************************************************************
93 * *
94 * Exit code *
95 * *
96 *****************************************************************************/
97
Alexander Graf53e5b8b2010-04-16 00:11:48 +020098.macro LOAD_HOST_SEGMENTS
Alexander Graf5126ed32009-11-02 12:02:29 +000099
100 /* Register usage at this point:
101 *
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200102 * R1 = host R1
103 * R2 = host R2
104 * R12 = exit handler id
105 * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64]
106 * SVCPU.* = guest *
107 * SVCPU[CR] = guest CR
108 * SVCPU[XER] = guest XER
109 * SVCPU[CTR] = guest CTR
110 * SVCPU[LR] = guest LR
Alexander Graf5126ed32009-11-02 12:02:29 +0000111 *
112 */
113
Alexander Grafd8d164a92014-05-15 14:38:03 +0200114 /* Remove all SLB entries that are in use. */
Alexander Graf5126ed32009-11-02 12:02:29 +0000115
Alexander Graf207438d2014-05-15 14:36:05 +0200116 li r0, r0
117 slbmte r0, r0
Alexander Graf5126ed32009-11-02 12:02:29 +0000118 slbia
Alexander Graf5126ed32009-11-02 12:02:29 +0000119
Alexander Grafd8d164a92014-05-15 14:38:03 +0200120 /* Restore bolted entries from the shadow */
Alexander Graf5126ed32009-11-02 12:02:29 +0000121
122 ld r11, PACA_SLBSHADOWPTR(r13)
123
Alexander Grafd8d164a92014-05-15 14:38:03 +0200124BEGIN_FW_FTR_SECTION
125
126 /* Declare SLB shadow as SLB_NUM_BOLTED entries big */
127
128 li r8, SLB_NUM_BOLTED
129 stb r8, 3(r11)
130
131END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
132
133 /* Manually load all entries from shadow SLB */
134
135 li r8, SLBSHADOW_SAVEAREA
136 li r7, SLBSHADOW_SAVEAREA + 8
137
138 .rept SLB_NUM_BOLTED
139 LDX_BE r10, r11, r8
140 cmpdi r10, 0
141 beq 1f
142 LDX_BE r9, r11, r7
143 slbmte r9, r10
1441: addi r7, r7, SHADOW_SLB_ENTRY_LEN
145 addi r8, r8, SHADOW_SLB_ENTRY_LEN
146 .endr
147
148 isync
149 sync
Alexander Graf5126ed32009-11-02 12:02:29 +0000150
151slb_do_exit:
152
Alexander Graf53e5b8b2010-04-16 00:11:48 +0200153.endm