Merge branches 'pm-domains', 'pm-kconfig', 'pm-cpuidle' and 'powercap'
[sfrench/cifs-2.6.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         mtspr   SPRN_PID,r0
106         mfspr   r3,SPRN_LPCR
107         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE  | LPCR_HEIC)
108         or      r3, r3, r4
109         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
110         andc    r3, r3, r4
111         li      r4,0 /* LPES = 0 */
112         bl      __init_LPCR_ISA300
113         bl      __init_HFSCR
114         bl      __init_tlb_power9
115         bl      __init_PMU_HV
116         mtlr    r11
117         blr
118
119 _GLOBAL(__restore_cpu_power9)
120         mflr    r11
121         bl      __init_FSCR
122         bl      __init_PMU
123         mfmsr   r3
124         rldicl. r0,r3,4,63
125         mtlr    r11
126         beqlr
127         li      r0,0
128         mtspr   SPRN_PSSCR,r0
129         mtspr   SPRN_LPID,r0
130         mtspr   SPRN_PID,r0
131         mfspr   r3,SPRN_LPCR
132         LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
133         or      r3, r3, r4
134         LOAD_REG_IMMEDIATE(r4, LPCR_UPRT | LPCR_HR)
135         andc    r3, r3, r4
136         li      r4,0 /* LPES = 0 */
137         bl      __init_LPCR_ISA300
138         bl      __init_HFSCR
139         bl      __init_tlb_power9
140         bl      __init_PMU_HV
141         mtlr    r11
142         blr
143
144 __init_hvmode_206:
145         /* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
146         mfmsr   r3
147         rldicl. r0,r3,4,63
148         bnelr
149         ld      r5,CPU_SPEC_FEATURES(r4)
150         LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
151         xor     r5,r5,r6
152         std     r5,CPU_SPEC_FEATURES(r4)
153         blr
154
155 __init_LPCR_ISA206:
156         /* Setup a sane LPCR:
157          *   Called with initial LPCR in R3 and desired LPES 2-bit value in R4
158          *
159          *   LPES = 0b01 (HSRR0/1 used for 0x500)
160          *   PECE = 0b111
161          *   DPFD = 4
162          *   HDICE = 0
163          *   VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
164          *   VRMASD = 0b10000 (L=1, LP=00)
165          *
166          * Other bits untouched for now
167          */
168         li      r5,0x10
169         rldimi  r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
170
171         /* POWER9 has no VRMASD */
172 __init_LPCR_ISA300:
173         rldimi  r3,r4, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
174         ori     r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
175         li      r5,4
176         rldimi  r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
177         clrrdi  r3,r3,1         /* clear HDICE */
178         li      r5,4
179         rldimi  r3,r5, LPCR_VC_SH, 0
180         mtspr   SPRN_LPCR,r3
181         isync
182         blr
183
184 __init_FSCR:
185         mfspr   r3,SPRN_FSCR
186         ori     r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
187         mtspr   SPRN_FSCR,r3
188         blr
189
190 __init_HFSCR:
191         mfspr   r3,SPRN_HFSCR
192         ori     r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
193                       HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB|HFSCR_MSGP
194         mtspr   SPRN_HFSCR,r3
195         blr
196
197 /*
198  * Clear the TLB using the specified IS form of tlbiel instruction
199  * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
200  */
201 __init_tlb_power7:
202         li      r6,POWER7_TLB_SETS
203         mtctr   r6
204         li      r7,0xc00        /* IS field = 0b11 */
205         ptesync
206 2:      tlbiel  r7
207         addi    r7,r7,0x1000
208         bdnz    2b
209         ptesync
210 1:      blr
211
212 __init_tlb_power8:
213         li      r6,POWER8_TLB_SETS
214         mtctr   r6
215         li      r7,0xc00        /* IS field = 0b11 */
216         ptesync
217 2:      tlbiel  r7
218         addi    r7,r7,0x1000
219         bdnz    2b
220         ptesync
221 1:      blr
222
223 /*
224  * Flush the TLB in hash mode. Hash must flush with RIC=2 once for process
225  * and one for partition scope to clear process and partition table entries.
226  */
227 __init_tlb_power9:
228         li      r6,POWER9_TLB_SETS_HASH - 1
229         mtctr   r6
230         li      r7,0xc00        /* IS field = 0b11 */
231         li      r8,0
232         ptesync
233         PPC_TLBIEL(7, 8, 2, 1, 0)
234         PPC_TLBIEL(7, 8, 2, 0, 0)
235 2:      addi    r7,r7,0x1000
236         PPC_TLBIEL(7, 8, 0, 0, 0)
237         bdnz    2b
238         ptesync
239 1:      blr
240
241 __init_PMU_HV:
242         li      r5,0
243         mtspr   SPRN_MMCRC,r5
244         blr
245
246 __init_PMU_HV_ISA207:
247         li      r5,0
248         mtspr   SPRN_MMCRH,r5
249         blr
250
251 __init_PMU:
252         li      r5,0
253         mtspr   SPRN_MMCRA,r5
254         mtspr   SPRN_MMCR0,r5
255         mtspr   SPRN_MMCR1,r5
256         mtspr   SPRN_MMCR2,r5
257         blr
258
259 __init_PMU_ISA207:
260         li      r5,0
261         mtspr   SPRN_MMCRS,r5
262         blr