]> asedeno.scripts.mit.edu Git - linux.git/blob - arch/powerpc/kvm/book3s_64_slb.S
d293485c1a6002595434284bfbaebd92e49767ce
[linux.git] / arch / powerpc / kvm / book3s_64_slb.S
1 /*
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/asm-compat.h>
21
22 #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)
25
26 /******************************************************************************
27  *                                                                            *
28  *                               Entry code                                   *
29  *                                                                            *
30  *****************************************************************************/
31
32 .macro LOAD_GUEST_SEGMENTS
33
34         /* Required state:
35          *
36          * MSR = ~IR|DR
37          * R13 = PACA
38          * R1 = host R1
39          * R2 = host R2
40          * R3 = shadow vcpu
41          * all other volatile GPRS = free except R4, R6
42          * SVCPU[CR]  = guest CR
43          * SVCPU[XER] = guest XER
44          * SVCPU[CTR] = guest CTR
45          * SVCPU[LR]  = guest LR
46          */
47
48 BEGIN_FW_FTR_SECTION
49
50         /* Declare SLB shadow as 0 entries big */
51
52         ld      r11, PACA_SLBSHADOWPTR(r13)
53         li      r8, 0
54         stb     r8, 3(r11)
55
56 END_FW_FTR_SECTION_IFSET(FW_FEATURE_LPAR)
57
58         /* Flush SLB */
59
60         li      r10, 0
61         slbmte  r10, r10
62         slbia
63
64         /* Fill SLB with our shadow */
65
66         lbz     r12, SVCPU_SLB_MAX(r3)
67         mulli   r12, r12, 16
68         addi    r12, r12, SVCPU_SLB
69         add     r12, r12, r3
70
71         /* for (r11 = kvm_slb; r11 < kvm_slb + kvm_slb_size; r11+=slb_entry) */
72         li      r11, SVCPU_SLB
73         add     r11, r11, r3
74
75 slb_loop_enter:
76
77         ld      r10, 0(r11)
78
79         andis.  r9, r10, SLB_ESID_V@h
80         beq     slb_loop_enter_skip
81
82         ld      r9, 8(r11)
83         slbmte  r9, r10
84
85 slb_loop_enter_skip:
86         addi    r11, r11, 16
87         cmpd    cr0, r11, r12
88         blt     slb_loop_enter
89
90 slb_do_enter:
91
92 .endm
93
94 /******************************************************************************
95  *                                                                            *
96  *                               Exit code                                    *
97  *                                                                            *
98  *****************************************************************************/
99
100 .macro LOAD_HOST_SEGMENTS
101
102         /* Register usage at this point:
103          *
104          * 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
113          *
114          */
115
116         /* Remove all SLB entries that are in use. */
117
118         li      r0, 0
119         slbmte  r0, r0
120         slbia
121
122         /* Restore bolted entries from the shadow */
123
124         ld      r11, PACA_SLBSHADOWPTR(r13)
125
126 BEGIN_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
133 END_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
146 1:      addi    r7, r7, SHADOW_SLB_ENTRY_LEN
147         addi    r8, r8, SHADOW_SLB_ENTRY_LEN
148         .endr
149
150         isync
151         sync
152
153 slb_do_exit:
154
155 .endm