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.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, MMCR0_FC);
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_FC | 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_AMOR, ~0);
141 mtspr(SPRN_PCR, PCR_MASK);
142 init_LPCR_ISA206(mfspr(SPRN_LPCR), LPCR_LPES1 >> LPCR_LPES_SH);
145 void __restore_cpu_power7(void)
154 mtspr(SPRN_AMOR, ~0);
155 mtspr(SPRN_PCR, PCR_MASK);
156 init_LPCR_ISA206(mfspr(SPRN_LPCR), LPCR_LPES1 >> LPCR_LPES_SH);
159 void __setup_cpu_power8(unsigned long offset, struct cpu_spec *t)
165 if (!init_hvmode_206(t))
169 mtspr(SPRN_AMOR, ~0);
170 mtspr(SPRN_PCR, PCR_MASK);
171 init_LPCR_ISA206(mfspr(SPRN_LPCR) | LPCR_PECEDH, 0); /* LPES = 0 */
174 init_PMU_HV_ISA207();
177 void __restore_cpu_power8(void)
190 mtspr(SPRN_AMOR, ~0);
191 mtspr(SPRN_PCR, PCR_MASK);
192 init_LPCR_ISA206(mfspr(SPRN_LPCR) | LPCR_PECEDH, 0); /* LPES = 0 */
195 init_PMU_HV_ISA207();
198 void __setup_cpu_power9(unsigned long offset, struct cpu_spec *t)
203 if (!init_hvmode_206(t))
206 mtspr(SPRN_PSSCR, 0);
209 mtspr(SPRN_AMOR, ~0);
210 mtspr(SPRN_PCR, PCR_MASK);
211 init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
212 LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
217 void __restore_cpu_power9(void)
228 mtspr(SPRN_PSSCR, 0);
231 mtspr(SPRN_AMOR, ~0);
232 mtspr(SPRN_PCR, PCR_MASK);
233 init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
234 LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
239 void __setup_cpu_power10(unsigned long offset, struct cpu_spec *t)
245 if (!init_hvmode_206(t))
248 mtspr(SPRN_PSSCR, 0);
251 mtspr(SPRN_AMOR, ~0);
252 mtspr(SPRN_PCR, PCR_MASK);
253 init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
254 LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);
259 void __restore_cpu_power10(void)
271 mtspr(SPRN_PSSCR, 0);
274 mtspr(SPRN_AMOR, ~0);
275 mtspr(SPRN_PCR, PCR_MASK);
276 init_LPCR_ISA300((mfspr(SPRN_LPCR) | LPCR_PECEDH | LPCR_PECE_HVEE |\
277 LPCR_HVICE | LPCR_HEIC) & ~(LPCR_UPRT | LPCR_HR), 0);