1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright 2020, Jordan Niethe, IBM Corporation.
5 * This file contains low level CPU setup functions.
6 * Originally written in assembly by Benjamin Herrenschmidt & various other
11 #include <asm/synch.h>
12 #include <linux/bitops.h>
13 #include <asm/cputable.h>
14 #include <asm/cpu_setup_power.h>
16 /* Disable CPU_FTR_HVMODE and return false if MSR:HV is not set */
17 static bool init_hvmode_206(struct cpu_spec
*t
)
25 t
->cpu_features
&= ~(CPU_FTR_HVMODE
| CPU_FTR_P9_TM_HV_ASSIST
);
29 static void init_LPCR_ISA300(u64 lpcr
, u64 lpes
)
31 /* POWER9 has no VRMASD */
32 lpcr
|= (lpes
<< LPCR_LPES_SH
) & LPCR_LPES
;
33 lpcr
|= LPCR_PECE0
|LPCR_PECE1
|LPCR_PECE2
;
34 lpcr
|= (4ull << LPCR_DPFD_SH
) & LPCR_DPFD
;
35 lpcr
&= ~LPCR_HDICE
; /* clear HDICE */
36 lpcr
|= (4ull << LPCR_VC_SH
);
37 mtspr(SPRN_LPCR
, lpcr
);
43 * Called with initial LPCR and desired LPES 2-bit value
45 * LPES = 0b01 (HSRR0/1 used for 0x500)
49 * VC = 0b100 (VPM0=1, VPM1=0, ISL=0)
50 * VRMASD = 0b10000 (L=1, LP=00)
52 * Other bits untouched for now
54 static void init_LPCR_ISA206(u64 lpcr
, u64 lpes
)
56 lpcr
|= (0x10ull
<< LPCR_VRMASD_SH
) & LPCR_VRMASD
;
57 init_LPCR_ISA300(lpcr
, lpes
);
60 static void init_FSCR(void)
64 fscr
= mfspr(SPRN_FSCR
);
65 fscr
|= FSCR_TAR
|FSCR_EBB
;
66 mtspr(SPRN_FSCR
, fscr
);
69 static void init_FSCR_power9(void)
73 fscr
= mfspr(SPRN_FSCR
);
75 mtspr(SPRN_FSCR
, fscr
);
79 static void init_FSCR_power10(void)
83 fscr
= mfspr(SPRN_FSCR
);
85 mtspr(SPRN_FSCR
, fscr
);
89 static void init_HFSCR(void)
93 hfscr
= mfspr(SPRN_HFSCR
);
94 hfscr
|= HFSCR_TAR
|HFSCR_TM
|HFSCR_BHRB
|HFSCR_PM
|HFSCR_DSCR
|\
95 HFSCR_VECVSX
|HFSCR_FP
|HFSCR_EBB
|HFSCR_MSGP
;
96 mtspr(SPRN_HFSCR
, hfscr
);
99 static void init_PMU_HV(void)
101 mtspr(SPRN_MMCRC
, 0);
104 static void init_PMU_HV_ISA207(void)
106 mtspr(SPRN_MMCRH
, 0);
109 static void init_PMU(void)
111 mtspr(SPRN_MMCRA
, 0);
112 mtspr(SPRN_MMCR0
, 0);
113 mtspr(SPRN_MMCR1
, 0);
114 mtspr(SPRN_MMCR2
, 0);
117 static void init_PMU_ISA207(void)
119 mtspr(SPRN_MMCRS
, 0);
122 static void init_PMU_ISA31(void)
124 mtspr(SPRN_MMCR3
, 0);
125 mtspr(SPRN_MMCRA
, MMCRA_BHRB_DISABLE
);
126 mtspr(SPRN_MMCR0
, MMCR0_PMCCEXT
);
130 * Note that we can be called twice of pseudo-PVRs.
131 * The parameter offset is not used.
134 void __setup_cpu_power7(unsigned long offset
, struct cpu_spec
*t
)
136 if (!init_hvmode_206(t
))
140 mtspr(SPRN_PCR
, PCR_MASK
);
141 init_LPCR_ISA206(mfspr(SPRN_LPCR
), LPCR_LPES1
>> LPCR_LPES_SH
);
144 void __restore_cpu_power7(void)
153 mtspr(SPRN_PCR
, PCR_MASK
);
154 init_LPCR_ISA206(mfspr(SPRN_LPCR
), LPCR_LPES1
>> LPCR_LPES_SH
);
157 void __setup_cpu_power8(unsigned long offset
, struct cpu_spec
*t
)
163 if (!init_hvmode_206(t
))
167 mtspr(SPRN_PCR
, PCR_MASK
);
168 init_LPCR_ISA206(mfspr(SPRN_LPCR
) | LPCR_PECEDH
, 0); /* LPES = 0 */
171 init_PMU_HV_ISA207();
174 void __restore_cpu_power8(void)
187 mtspr(SPRN_PCR
, PCR_MASK
);
188 init_LPCR_ISA206(mfspr(SPRN_LPCR
) | LPCR_PECEDH
, 0); /* LPES = 0 */
191 init_PMU_HV_ISA207();
194 void __setup_cpu_power9(unsigned long offset
, struct cpu_spec
*t
)
199 if (!init_hvmode_206(t
))
202 mtspr(SPRN_PSSCR
, 0);
205 mtspr(SPRN_PCR
, PCR_MASK
);
206 init_LPCR_ISA300((mfspr(SPRN_LPCR
) | LPCR_PECEDH
| LPCR_PECE_HVEE
|\
207 LPCR_HVICE
| LPCR_HEIC
) & ~(LPCR_UPRT
| LPCR_HR
), 0);
212 void __restore_cpu_power9(void)
223 mtspr(SPRN_PSSCR
, 0);
226 mtspr(SPRN_PCR
, PCR_MASK
);
227 init_LPCR_ISA300((mfspr(SPRN_LPCR
) | LPCR_PECEDH
| LPCR_PECE_HVEE
|\
228 LPCR_HVICE
| LPCR_HEIC
) & ~(LPCR_UPRT
| LPCR_HR
), 0);
233 void __setup_cpu_power10(unsigned long offset
, struct cpu_spec
*t
)
239 if (!init_hvmode_206(t
))
242 mtspr(SPRN_PSSCR
, 0);
245 mtspr(SPRN_PCR
, PCR_MASK
);
246 init_LPCR_ISA300((mfspr(SPRN_LPCR
) | LPCR_PECEDH
| LPCR_PECE_HVEE
|\
247 LPCR_HVICE
| LPCR_HEIC
) & ~(LPCR_UPRT
| LPCR_HR
), 0);
252 void __restore_cpu_power10(void)
264 mtspr(SPRN_PSSCR
, 0);
267 mtspr(SPRN_PCR
, PCR_MASK
);
268 init_LPCR_ISA300((mfspr(SPRN_LPCR
) | LPCR_PECEDH
| LPCR_PECE_HVEE
|\
269 LPCR_HVICE
| LPCR_HEIC
) & ~(LPCR_UPRT
| LPCR_HR
), 0);