GNU Linux-libre 4.4.284-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
19 /* Entry: r3 = crap, r4 = ptr to cputable entry
20  *
21  * Note that we can be called twice for pseudo-PVRs
22  */
23 _GLOBAL(__setup_cpu_power7)
24         mflr    r11
25         bl      __init_hvmode_206
26         mtlr    r11
27         beqlr
28         li      r0,0
29         mtspr   SPRN_LPID,r0
30         mtspr   SPRN_PCR,r0
31         mfspr   r3,SPRN_LPCR
32         bl      __init_LPCR
33         bl      __init_tlb_power7
34         mtlr    r11
35         blr
36
37 _GLOBAL(__restore_cpu_power7)
38         mflr    r11
39         mfmsr   r3
40         rldicl. r0,r3,4,63
41         beqlr
42         li      r0,0
43         mtspr   SPRN_LPID,r0
44         mtspr   SPRN_PCR,r0
45         mfspr   r3,SPRN_LPCR
46         bl      __init_LPCR
47         bl      __init_tlb_power7
48         mtlr    r11
49         blr
50
51 _GLOBAL(__setup_cpu_power8)
52         mflr    r11
53         bl      __init_FSCR
54         bl      __init_PMU
55         bl      __init_hvmode_206
56         mtlr    r11
57         beqlr
58         li      r0,0
59         mtspr   SPRN_LPID,r0
60         mtspr   SPRN_PCR,r0
61         mfspr   r3,SPRN_LPCR
62         ori     r3, r3, LPCR_PECEDH
63         bl      __init_LPCR
64         bl      __init_HFSCR
65         bl      __init_tlb_power8
66         bl      __init_PMU_HV
67         mtlr    r11
68         blr
69
70 _GLOBAL(__restore_cpu_power8)
71         mflr    r11
72         bl      __init_FSCR
73         bl      __init_PMU
74         mfmsr   r3
75         rldicl. r0,r3,4,63
76         mtlr    r11
77         beqlr
78         li      r0,0
79         mtspr   SPRN_LPID,r0
80         mtspr   SPRN_PCR,r0
81         mfspr   r3,SPRN_LPCR
82         ori     r3, r3, LPCR_PECEDH
83         bl      __init_LPCR
84         bl      __init_HFSCR
85         bl      __init_tlb_power8
86         bl      __init_PMU_HV
87         mtlr    r11
88         blr
89
90 __init_hvmode_206:
91         /* Disable CPU_FTR_HVMODE and exit if MSR:HV is not set */
92         mfmsr   r3
93         rldicl. r0,r3,4,63
94         bnelr
95         ld      r5,CPU_SPEC_FEATURES(r4)
96         LOAD_REG_IMMEDIATE(r6,CPU_FTR_HVMODE)
97         xor     r5,r5,r6
98         std     r5,CPU_SPEC_FEATURES(r4)
99         blr
100
101 __init_LPCR:
102         /* Setup a sane LPCR:
103          *   Called with initial LPCR in R3
104          *
105          *   LPES = 0b01 (HSRR0/1 used for 0x500)
106          *   PECE = 0b111
107          *   DPFD = 4
108          *   HDICE = 0
109          *   VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
110          *   VRMASD = 0b10000 (L=1, LP=00)
111          *
112          * Other bits untouched for now
113          */
114         li      r5,1
115         rldimi  r3,r5, LPCR_LPES_SH, 64-LPCR_LPES_SH-2
116         ori     r3,r3,(LPCR_PECE0|LPCR_PECE1|LPCR_PECE2)
117         li      r5,4
118         rldimi  r3,r5, LPCR_DPFD_SH, 64-LPCR_DPFD_SH-3
119         clrrdi  r3,r3,1         /* clear HDICE */
120         li      r5,4
121         rldimi  r3,r5, LPCR_VC_SH, 0
122         li      r5,0x10
123         rldimi  r3,r5, LPCR_VRMASD_SH, 64-LPCR_VRMASD_SH-5
124         mtspr   SPRN_LPCR,r3
125         isync
126         blr
127
128 __init_FSCR:
129         mfspr   r3,SPRN_FSCR
130         ori     r3,r3,FSCR_TAR|FSCR_DSCR|FSCR_EBB
131         mtspr   SPRN_FSCR,r3
132         blr
133
134 __init_HFSCR:
135         mfspr   r3,SPRN_HFSCR
136         ori     r3,r3,HFSCR_TAR|HFSCR_TM|HFSCR_BHRB|HFSCR_PM|\
137                       HFSCR_DSCR|HFSCR_VECVSX|HFSCR_FP|HFSCR_EBB
138         mtspr   SPRN_HFSCR,r3
139         blr
140
141 /*
142  * Clear the TLB using the specified IS form of tlbiel instruction
143  * (invalidate by congruence class). P7 has 128 CCs., P8 has 512.
144  */
145 __init_tlb_power7:
146         li      r6,128
147         mtctr   r6
148         li      r7,0xc00        /* IS field = 0b11 */
149         ptesync
150 2:      tlbiel  r7
151         addi    r7,r7,0x1000
152         bdnz    2b
153         ptesync
154 1:      blr
155
156 __init_tlb_power8:
157         li      r6,512
158         mtctr   r6
159         li      r7,0xc00        /* IS field = 0b11 */
160         ptesync
161 2:      tlbiel  r7
162         addi    r7,r7,0x1000
163         bdnz    2b
164         ptesync
165 1:      blr
166
167 __init_PMU_HV:
168         li      r5,0
169         mtspr   SPRN_MMCRC,r5
170         mtspr   SPRN_MMCRH,r5
171         blr
172
173 __init_PMU:
174         li      r5,0
175         mtspr   SPRN_MMCRS,r5
176         mtspr   SPRN_MMCRA,r5
177         mtspr   SPRN_MMCR0,r5
178         mtspr   SPRN_MMCR1,r5
179         mtspr   SPRN_MMCR2,r5
180         blr