Debian Codegraph @

src/soc/intel/meteorlake/cpu.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <cpu/cpu.h>
5 #include <cpu/intel/common/common.h>
6 #include <cpu/intel/microcode.h>
7 #include <cpu/intel/smm_reloc.h>
8 #include <cpu/intel/turbo.h>
9 #include <cpu/x86/lapic.h>
10 #include <cpu/x86/mp.h>
11 #include <cpu/x86/msr.h>
12 #include <device/pci.h>
13 #include <fsp/api.h>
14 #include <intelblocks/acpi.h>
15 #include <intelblocks/cpulib.h>
16 #include <intelblocks/mp_init.h>
17 #include <intelblocks/msr.h>
18 #include <soc/cpu.h>
19 #include <soc/msr.h>
20 #include <soc/pci_devs.h>
21 #include <soc/soc_chip.h>
22 #include <soc/soc_info.h>
23 #include <static.h>
24
25 bool cpu_soc_is_in_untrusted_mode(void)
26 {
27 msr_t msr;
28
29 msr = rdmsr(MSR_BIOS_DONE);
30 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
31 }
32
33 void cpu_soc_bios_done(void)
34 {
35 msr_t msr;
36
37 msr = rdmsr(MSR_BIOS_DONE);
38 msr.lo |= ENABLE_IA_UNTRUSTED;
39 wrmsr(MSR_BIOS_DONE, msr);
40 }
41
42 uint8_t get_supported_lpm_mask(void)
43 {
44 const config_t *conf = config_of_soc();
45 if (!conf->s0ix_enable)
46 return 0;
47
48 return LPM_S0i2_0 | LPM_S0i2_1 | LPM_S0i2_2;
49 }
50
51 static void soc_fsp_load(void)
52 {
53 fsps_load();
54 }
55
56 static void configure_misc(void)
57 {
58 msr_t msr;
59
60 config_t *conf = (config_t *)config_of_soc();
61
62 msr = rdmsr(IA32_MISC_ENABLE);
63 msr.lo |= (1 << 0); /* Fast String enable */
64 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
65 wrmsr(IA32_MISC_ENABLE, msr);
66
67 /* Set EIST status */
68 cpu_set_eist(conf->eist_enable);
69
70 /* Disable Thermal interrupts */
71 msr.lo = 0;
72 msr.hi = 0;
73 wrmsr(IA32_THERM_INTERRUPT, msr);
74
75 /* Enable package critical interrupt only */
76 msr.lo = 1 << 4;
77 msr.hi = 0;
78 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
79
80 /* Enable PROCHOT and Power Performance Platform Override */
81 msr = rdmsr(MSR_POWER_CTL);
82 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input*/
83 msr.lo |= (1 << 23); /* Lock it */
84 msr.lo |= (1 << 18); /* Power Performance Platform Override */
85 wrmsr(MSR_POWER_CTL, msr);
86 }
87
88 enum core_type get_soc_cpu_type(void)
89 {
90 if (cpu_is_hybrid_supported())
91 return cpu_get_cpu_type();
92 else
93 return CPUID_CORE_TYPE_INTEL_CORE;
94 }
95
96 bool soc_is_nominal_freq_supported(void)
97 {
98 return true;
99 }
100
101 static void enable_x2apic(void)
102 {
103 if (!CONFIG(X2APIC_LATE_WORKAROUND))
104 return;
105
106 enable_lapic_mode(true);
107 }
108
109 /* All CPUs including BSP will run the following function. */
110 void soc_core_init(struct device *cpu)
111 {
112 /* Clear out pending MCEs */
113 /* TODO(adurbin): This should only be done on a cold boot. Also, some
114 * of these banks are core vs package scope. For now every CPU clears
115 * every bank. */
116 mca_configure();
117
118 enable_x2apic();
119
120 enable_lapic_tpr();
121
122 /* Configure Enhanced SpeedStep and Thermal Sensors */
123 configure_misc();
124
125 enable_pm_timer_emulation();
126
127 /* Enable Direct Cache Access */
128 configure_dca_cap();
129
130 /* Set energy policy */
131 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
132
133 const config_t *conf = config_of_soc();
134 /* Set energy-performance preference */
135 if (conf->enable_energy_perf_pref)
136 if (check_energy_perf_cap())
137 set_energy_perf_pref(conf->energy_perf_pref_value);
138
139 /* Enable Turbo */
140 enable_turbo();
141
142 /* Set core type in struct cpu_info */
143 set_dev_core_type();
144
145 if (CONFIG(INTEL_TME) && is_tme_supported())
146 set_tme_core_activate();
147
148 if (CONFIG(DROP_CPU_FEATURE_PROGRAM_IN_FSP)) {
149 /* Disable 3-strike error */
150 if (CONFIG(SOC_INTEL_METEORLAKE_PRE_PRODUCTION_SILICON))
151 disable_three_strike_error();
152 else
153 disable_signaling_three_strike_event();
154
155 set_aesni_lock();
156
157 /* Enable VMX */
158 set_feature_ctrl_vmx_arg(CONFIG(ENABLE_VMX) && !conf->disable_vmx);
159
160 /* Feature control lock configure */
161 set_feature_ctrl_lock();
162 }
163 }
164
165 static void per_cpu_smm_trigger(void)
166 {
167 /* Relocate the SMM handler. */
168 smm_relocate();
169 }
170
171 static void pre_mp_init(void)
172 {
173 soc_fsp_load();
174
175 const config_t *conf = config_of_soc();
176 if (conf->enable_energy_perf_pref) {
177 if (check_energy_perf_cap())
178 enable_energy_perf_pref();
179 else
180 printk(BIOS_WARNING, "Energy Performance Preference not supported!\n");
181 }
182 }
183
184 static void post_mp_init(void)
185 {
186 /* Set Max Ratio */
187 cpu_set_max_ratio();
188
189 /*
190 * 1. Now that all APs have been relocated as well as the BSP let SMIs
191 * start flowing.
192 * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT
193 * to avoid shutdown hang due to lack of init on certain IP in FSP-S.
194 */
195 global_smi_enable_no_pwrbtn();
196 }
197
198 static const struct mp_ops mp_ops = {
199 /*
200 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
201 * that are set prior to ramstage.
202 * Real MTRRs programming are being done after resource allocation.
203 */
204 .pre_mp_init = pre_mp_init,
205 .get_cpu_count = get_cpu_count,
206 .get_smm_info = smm_info,
207 .get_microcode_info = get_microcode_info,
208 .pre_mp_smm_init = smm_initialize,
209 .per_cpu_smm_trigger = per_cpu_smm_trigger,
210 .relocation_handler = smm_relocation_handler,
211 .post_mp_init = post_mp_init,
212 };
213
214 void mp_init_cpus(struct bus *cpu_bus)
215 {
216 if (mp_init_with_smm(cpu_bus, &mp_ops))
217 printk(BIOS_ERR, "MP initialization failure.\n");
218
219 /* Thermal throttle activation offset */
220 configure_tcc_thermal_target();
221 }
222
223 int soc_skip_ucode_update(u32 current_patch_id, u32 new_patch_id)
224 {
225 if (!CONFIG(CHROMEOS))
226 return 0;
227 /*
228 * Locked RO Descriptor Implications:
229 *
230 * - A locked descriptor signals the RO binary is fixed; the FIT will load the
231 * RO's microcode during system reset.
232 * - Attempts to load newer microcode from the RW CBFS will cause a boot-time
233 * delay (~60ms, core-dependent), as the microcode must be reloaded on BSP+APs.
234 * - The kernel can load microcode updates without impacting AP FW boot time.
235 * - Skipping RW CBFS microcode loading is low-risk when the RO is locked,
236 * prioritizing fast boot times.
237 */
238 if (CONFIG(LOCK_MANAGEMENT_ENGINE) && current_patch_id)
239 return 1;
240
241 return 0;
242 }