GNU Linux-libre 4.9.301-gnu1
[releases.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         mtspr   SPRN_PCR,r0
32         mfspr   r3,SPRN_LPCR
33         bl      __init_LPCR
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         mtspr   SPRN_PCR,r0
46         mfspr   r3,SPRN_LPCR
47         bl      __init_LPCR
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         mtspr   SPRN_PCR,r0
63         mfspr   r3,SPRN_LPCR
64         ori     r3, r3, LPCR_PECEDH
65         bl      __init_LPCR
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         mtspr   SPRN_PCR,r0
85         mfspr   r3,SPRN_LPCR
86         ori     r3, r3, LPCR_PECEDH
87         bl      __init_LPCR
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_LPID,r0
104         mtspr   SPRN_PID,r0
105         mtspr   SPRN_PCR,r0
106         mfspr   r3,SPRN_LPCR
107         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
108         or      r3, r3, r4
109         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
110         andc    r3, r3, r4
111         bl      __init_LPCR
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_LPID,r0
128         mtspr   SPRN_PID,r0
129         mtspr   SPRN_PCR,r0
130         mfspr   r3,SPRN_LPCR
131         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE)
132         or      r3, r3, r4
133         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
134         andc    r3, r3, r4
135         bl      __init_LPCR
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:
154         /* Setup a sane LPCR:
155          *   Called with initial LPCR in R3
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,1
167         rldimi  r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
168         ori     r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
169         li      r5,4
170         rldimi  r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
171         clrrdi  r3,r3,1         /* clear HDICE */
172         li      r5,4
173         rldimi  r3,r5, LPCR_VC_SH, 0
174         li      r5,0x10
175         rldimi  r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
176         mtspr   SPRN_LPCR,r3
177         isync
178         blr
179
180 __init_FSCR:
181         mfspr   r3,SPRN_FSCR
182         ori     r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
183         mtspr   SPRN_FSCR,r3
184         blr
185
186 __init_HFSCR:
187         mfspr   r3,SPRN_HFSCR
188         ori     r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
189                       HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB
190         mtspr   SPRN_HFSCR,r3
191         blr
192
193 /*
194  * Clear the TLB using the specified IS form of tlbiel instruction
195  * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
196  */
197 __init_tlb_power7:
198         li      r6,POWER7_TLB_SETS
199         mtctr   r6
200         li      r7,0xc00        /* IS field = 0b11 */
201         ptesync
202 2:      tlbiel  r7
203         addi    r7,r7,0x1000
204         bdnz    2b
205         ptesync
206 1:      blr
207
208 __init_tlb_power8:
209         li      r6,POWER8_TLB_SETS
210         mtctr   r6
211         li      r7,0xc00        /* IS field = 0b11 */
212         ptesync
213 2:      tlbiel  r7
214         addi    r7,r7,0x1000
215         bdnz    2b
216         ptesync
217 1:      blr
218
219 __init_tlb_power9:
220         li      r6,POWER9_TLB_SETS_HASH
221         mtctr   r6
222         li      r7,0xc00        /* IS field = 0b11 */
223         ptesync
224 2:      tlbiel  r7
225         addi    r7,r7,0x1000
226         bdnz    2b
227         ptesync
228 1:      blr
229
230 __init_PMU_HV:
231         li      r5,0
232         mtspr   SPRN_MMCRC,r5
233         blr
234
235 __init_PMU_HV_ISA207:
236         li      r5,0
237         mtspr   SPRN_MMCRH,r5
238         blr
239
240 __init_PMU:
241         li      r5,0
242         mtspr   SPRN_MMCRA,r5
243         mtspr   SPRN_MMCR0,r5
244         mtspr   SPRN_MMCR1,r5
245         mtspr   SPRN_MMCR2,r5
246         blr
247
248 __init_PMU_ISA207:
249         li      r5,0
250         mtspr   SPRN_MMCRS,r5
251         blr