Linux-libre 4.14.2-gnu
[librecmc/linux-libre.git] / arch / powerpc / kernel / cpu_setup_power.S
1 /*
2  * This file contains low level CPU setup functions.
3  *    Copyright (C) 2003 Benjamin Herrenschmidt (benh@kernel.crashing.org)
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version
8  * 2 of the License, or (at your option) any later version.
9  *
10  */
11
12 #include <asm/processor.h>
13 #include <asm/page.h>
14 #include <asm/cputable.h>
15 #include <asm/ppc_asm.h>
16 #include <asm/asm-offsets.h>
17 #include <asm/cache.h>
18 #include <asm/book3s/64/mmu-hash.h>
19
20 /* Entry: r3 = crap, r4 = ptr to cputable entry
21  *
22  * Note that we can be called twice for pseudo-PVRs
23  */
24 _GLOBAL(__setup_cpu_power7)
25         mflr    r11
26         bl      __init_hvmode_206
27         mtlr    r11
28         beqlr
29         li      r0,0
30         mtspr   SPRN_LPID,r0
31         mfspr   r3,SPRN_LPCR
32         li      r4,(LPCR_LPES1 >> LPCR_LPES_SH)
33         bl      __init_LPCR_ISA206
34         bl      __init_tlb_power7
35         mtlr    r11
36         blr
37
38 _GLOBAL(__restore_cpu_power7)
39         mflr    r11
40         mfmsr   r3
41         rldicl. r0,r3,4,63
42         beqlr
43         li      r0,0
44         mtspr   SPRN_LPID,r0
45         mfspr   r3,SPRN_LPCR
46         li      r4,(LPCR_LPES1 >> LPCR_LPES_SH)
47         bl      __init_LPCR_ISA206
48         bl      __init_tlb_power7
49         mtlr    r11
50         blr
51
52 _GLOBAL(__setup_cpu_power8)
53         mflr    r11
54         bl      __init_FSCR
55         bl      __init_PMU
56         bl      __init_PMU_ISA207
57         bl      __init_hvmode_206
58         mtlr    r11
59         beqlr
60         li      r0,0
61         mtspr   SPRN_LPID,r0
62         mfspr   r3,SPRN_LPCR
63         ori     r3, r3, LPCR_PECEDH
64         li      r4,0 /* LPES = 0 */
65         bl      __init_LPCR_ISA206
66         bl      __init_HFSCR
67         bl      __init_tlb_power8
68         bl      __init_PMU_HV
69         bl      __init_PMU_HV_ISA207
70         mtlr    r11
71         blr
72
73 _GLOBAL(__restore_cpu_power8)
74         mflr    r11
75         bl      __init_FSCR
76         bl      __init_PMU
77         bl      __init_PMU_ISA207
78         mfmsr   r3
79         rldicl. r0,r3,4,63
80         mtlr    r11
81         beqlr
82         li      r0,0
83         mtspr   SPRN_LPID,r0
84         mfspr   r3,SPRN_LPCR
85         ori     r3, r3, LPCR_PECEDH
86         li      r4,0 /* LPES = 0 */
87         bl      __init_LPCR_ISA206
88         bl      __init_HFSCR
89         bl      __init_tlb_power8
90         bl      __init_PMU_HV
91         bl      __init_PMU_HV_ISA207
92         mtlr    r11
93         blr
94
95 _GLOBAL(__setup_cpu_power9)
96         mflr    r11
97         bl      __init_FSCR
98         bl      __init_PMU
99         bl      __init_hvmode_206
100         mtlr    r11
101         beqlr
102         li      r0,0
103         mtspr   SPRN_PSSCR,r0
104         mtspr   SPRN_LPID,r0
105         mfspr   r3,SPRN_LPCR
106         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE  | LPCR_HEIC)
107         or      r3, r3, r4
108         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
109         andc    r3, r3, r4
110         li      r4,0 /* LPES = 0 */
111         bl      __init_LPCR_ISA300
112         bl      __init_HFSCR
113         bl      __init_tlb_power9
114         bl      __init_PMU_HV
115         mtlr    r11
116         blr
117
118 _GLOBAL(__restore_cpu_power9)
119         mflr    r11
120         bl      __init_FSCR
121         bl      __init_PMU
122         mfmsr   r3
123         rldicl. r0,r3,4,63
124         mtlr    r11
125         beqlr
126         li      r0,0
127         mtspr   SPRN_PSSCR,r0
128         mtspr   SPRN_LPID,r0
129         mfspr   r3,SPRN_LPCR
130         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
131         or      r3, r3, r4
132         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
133         andc    r3, r3, r4
134         li      r4,0 /* LPES = 0 */
135         bl      __init_LPCR_ISA300
136         bl      __init_HFSCR
137         bl      __init_tlb_power9
138         bl      __init_PMU_HV
139         mtlr    r11
140         blr
141
142 __init_hvmode_206:
143         /* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
144         mfmsr   r3
145         rldicl. r0,r3,4,63
146         bnelr
147         ld      r5,CPU_SPEC_FEATURES(r4)
148         LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
149         xor     r5,r5,r6
150         std     r5,CPU_SPEC_FEATURES(r4)
151         blr
152
153 __init_LPCR_ISA206:
154         /* Setup a sane LPCR:
155          *   Called with initial LPCR in R3 and desired LPES 2-bit value in R4
156          *
157          *   LPES = 0b01 (HSRR0/1 used for 0x500)
158          *   PECE = 0b111
159          *   DPFD = 4
160          *   HDICE = 0
161          *   VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
162          *   VRMASD = 0b10000 (L=1, LP=00)
163          *
164          * Other bits untouched for now
165          */
166         li      r5,0x10
167         rldimi  r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
168
169         /* POWER9 has no VRMASD */
170 __init_LPCR_ISA300:
171         rldimi  r3,r4, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
172         ori     r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
173         li      r5,4
174         rldimi  r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
175         clrrdi  r3,r3,1         /* clear HDICE */
176         li      r5,4
177         rldimi  r3,r5, LPCR_VC_SH, 0
178         mtspr   SPRN_LPCR,r3
179         isync
180         blr
181
182 __init_FSCR:
183         mfspr   r3,SPRN_FSCR
184         ori     r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
185         mtspr   SPRN_FSCR,r3
186         blr
187
188 __init_HFSCR:
189         mfspr   r3,SPRN_HFSCR
190         ori     r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
191                       HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB|HFSCR_MSGP
192         mtspr   SPRN_HFSCR,r3
193         blr
194
195 /*
196  * Clear the TLB using the specified IS form of tlbiel instruction
197  * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
198  */
199 __init_tlb_power7:
200         li      r6,POWER7_TLB_SETS
201         mtctr   r6
202         li      r7,0xc00        /* IS field = 0b11 */
203         ptesync
204 2:      tlbiel  r7
205         addi    r7,r7,0x1000
206         bdnz    2b
207         ptesync
208 1:      blr
209
210 __init_tlb_power8:
211         li      r6,POWER8_TLB_SETS
212         mtctr   r6
213         li      r7,0xc00        /* IS field = 0b11 */
214         ptesync
215 2:      tlbiel  r7
216         addi    r7,r7,0x1000
217         bdnz    2b
218         ptesync
219 1:      blr
220
221 /*
222  * Flush the TLB in hash mode. Hash must flush with RIC=2 once for process
223  * and one for partition scope to clear process and partition table entries.
224  */
225 __init_tlb_power9:
226         li      r6,POWER9_TLB_SETS_HASH - 1
227         mtctr   r6
228         li      r7,0xc00        /* IS field = 0b11 */
229         li      r8,0
230         ptesync
231         PPC_TLBIEL(7, 8, 2, 1, 0)
232         PPC_TLBIEL(7, 8, 2, 0, 0)
233 2:      addi    r7,r7,0x1000
234         PPC_TLBIEL(7, 8, 0, 0, 0)
235         bdnz    2b
236         ptesync
237 1:      blr
238
239 __init_PMU_HV:
240         li      r5,0
241         mtspr   SPRN_MMCRC,r5
242         blr
243
244 __init_PMU_HV_ISA207:
245         li      r5,0
246         mtspr   SPRN_MMCRH,r5
247         blr
248
249 __init_PMU:
250         li      r5,0
251         mtspr   SPRN_MMCRA,r5
252         mtspr   SPRN_MMCR0,r5
253         mtspr   SPRN_MMCR1,r5
254         mtspr   SPRN_MMCR2,r5
255         blr
256
257 __init_PMU_ISA207:
258         li      r5,0
259         mtspr   SPRN_MMCRS,r5
260         blr