Debian Codegraph @

src/soc/intel/pantherlake/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 <intelblocks/pmclib.h>
19 #include <smbios.h>
20 #include <soc/cpu.h>
21 #include <soc/msr.h>
22 #include <soc/pci_devs.h>
23 #include <soc/soc_chip.h>
24 #include <static.h>
25
26 bool cpu_soc_is_in_untrusted_mode(void)
27 {
28 msr_t msr;
29
30 msr = rdmsr(MSR_BIOS_DONE);
31 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
32 }
33
34 void cpu_soc_bios_done(void)
35 {
36 msr_t msr;
37
38 msr = rdmsr(MSR_BIOS_DONE);
39 msr.lo |= ENABLE_IA_UNTRUSTED;
40 wrmsr(MSR_BIOS_DONE, msr);
41 }
42
43 uint8_t get_supported_lpm_mask(void)
44 {
45 const config_t *conf = config_of_soc();
46 if (!conf->s0ix_enable)
47 return 0;
48
49 return LPM_S0i2_0 | LPM_S0i2_1 | LPM_S0i2_2;
50 }
51
52 static void soc_fsp_load(void)
53 {
54 fsps_load();
55 }
56
57 static void configure_misc(void)
58 {
59 msr_t msr;
60
61 const struct soc_intel_pantherlake_config *conf = config_of_soc();
62
63 msr = rdmsr(IA32_MISC_ENABLE);
64 msr.lo |= FAST_STRINGS_ENABLE_BIT;
65 msr.lo |= TM1_TM2_EMTTM_ENABLE_BIT;
66 wrmsr(IA32_MISC_ENABLE, msr);
67
68 /* Set EIST status */
69 cpu_set_eist(conf->eist_enable);
70
71 /* Disable Thermal interrupts */
72 msr.lo = 0;
73 msr.hi = 0;
74 wrmsr(IA32_THERM_INTERRUPT, msr);
75
76 /* Enable package critical interrupt only */
77 msr.lo = CRITICAL_TEMP_INTERRUPT_ENABLE;
78 msr.hi = 0;
79 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
80
81 /* Enable PROCHOT and Power Performance Platform Override */
82 msr = rdmsr(MSR_POWER_CTL);
83 msr.lo |= ENABLE_BIDIR_PROCHOT;
84 msr.lo |= VR_THERM_ALERT_DISABLE_LOCK;
85 msr.lo |= PWR_PERF_PLATFORM_OVR;
86 wrmsr(MSR_POWER_CTL, msr);
87 }
88
89 enum core_type get_soc_cpu_type(void)
90 {
91 if (cpu_is_hybrid_supported())
92 return cpu_get_cpu_type();
93
94 return CPUID_CORE_TYPE_INTEL_CORE;
95 }
96
97 bool soc_is_nominal_freq_supported(void)
98 {
99 return true;
100 }
101
102 static void enable_x2apic(void)
103 {
104 if (!CONFIG(X2APIC_LATE_WORKAROUND))
105 return;
106
107 enable_lapic_mode(true);
108 }
109
110 /* All CPUs including BSP will run the following function. */
111 void soc_core_init(struct device *cpu)
112 {
113 /* Clear out pending MCEs */
114 mca_configure();
115
116 enable_x2apic();
117
118 enable_lapic_tpr();
119
120 /* Configure Enhanced SpeedStep and Thermal Sensors */
121 configure_misc();
122
123 enable_pm_timer_emulation();
124
125 /* Enable Direct Cache Access */
126 configure_dca_cap();
127
128 /* Set energy policy */
129 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
130
131 const struct soc_intel_pantherlake_config *conf = config_of_soc();
132 /* Set energy-performance preference */
133 if (conf != NULL && conf->enable_energy_perf_pref) {
134 if (check_energy_perf_cap())
135 set_energy_perf_pref(conf->energy_perf_pref_value);
136 }
137
138 /* Enable Turbo */
139 enable_turbo();
140
141 /* Set core type in struct cpu_info */
142 set_dev_core_type();
143
144 if (CONFIG(INTEL_TME) && is_tme_supported())
145 set_tme_core_activate();
146
147 if (CONFIG(DROP_CPU_FEATURE_PROGRAM_IN_FSP)) {
148 /* Disable 3-strike error */
149 disable_signaling_three_strike_event();
150
151 set_aesni_lock();
152
153 /* Enable VMX */
154 set_feature_ctrl_vmx_arg(CONFIG(ENABLE_VMX) && !conf->disable_vmx);
155
156 /* Feature control lock configure */
157 set_feature_ctrl_lock();
158 }
159 }
160
161 static void per_cpu_smm_trigger(void)
162 {
163 /* Relocate the SMM handler. */
164 smm_relocate();
165 }
166
167 static void pre_mp_init(void)
168 {
169 soc_fsp_load();
170
171 const struct soc_intel_pantherlake_config *conf = config_of_soc();
172 if (conf == NULL) {
173 printk(BIOS_ERR, "Configuration could not be retrieved.\n");
174 return;
175 }
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 }
243
244 /* Override SMBIOS type 4 processor serial numbers */
245 const char *smbios_processor_serial_number(void)
246 {
247 char *qdf = retrieve_soc_qdf_info_via_pmc_ipc();
248
249 if (qdf != NULL)
250 return qdf;
251 else
252 return "";
253 }