blob: 54217ea5646f63765cc64ccf2db68fbd57c7dbed [file] [log] [blame]
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
Elyes Haouasdef74aa2022-10-31 13:44:40 +01003#include <assert.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07004#include <console/console.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +01005#include <cpu/cpu.h>
6#include <cpu/intel/common/common.h>
7#include <cpu/intel/smm_reloc.h>
8#include <cpu/intel/turbo.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07009#include <cpu/x86/lapic.h>
10#include <cpu/x86/mp.h>
11#include <cpu/x86/msr.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +010012#include <device/pci.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070013#include <fsp/api.h>
Elyes Haouasdef74aa2022-10-31 13:44:40 +010014#include <intelblocks/acpi.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070015#include <intelblocks/cpulib.h>
16#include <intelblocks/mp_init.h>
17#include <intelblocks/msr.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070018#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>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070023
24bool cpu_soc_is_in_untrusted_mode(void)
25{
26 msr_t msr;
27
28 msr = rdmsr(MSR_BIOS_DONE);
29 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
30}
31
Subrata Banik85e619c2022-12-05 20:52:38 +053032void cpu_soc_bios_done(void)
33{
34 msr_t msr;
35
36 msr = rdmsr(MSR_BIOS_DONE);
37 msr.lo |= ENABLE_IA_UNTRUSTED;
38 wrmsr(MSR_BIOS_DONE, msr);
39}
40
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070041uint8_t get_supported_lpm_mask(void)
42{
43 return LPM_S0i2_0 | LPM_S0i2_1 | LPM_S0i2_2;
44}
45
46static void soc_fsp_load(void)
47{
48 fsps_load();
49}
50
51static void configure_misc(void)
52{
53 msr_t msr;
54
55 config_t *conf = (config_t *)config_of_soc();
56
57 msr = rdmsr(IA32_MISC_ENABLE);
58 msr.lo |= (1 << 0); /* Fast String enable */
59 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
60 wrmsr(IA32_MISC_ENABLE, msr);
61
62 /* Set EIST status */
63 cpu_set_eist(conf->eist_enable);
64
65 /* Disable Thermal interrupts */
66 msr.lo = 0;
67 msr.hi = 0;
68 wrmsr(IA32_THERM_INTERRUPT, msr);
69
70 /* Enable package critical interrupt only */
71 msr.lo = 1 << 4;
72 msr.hi = 0;
73 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
74
Subrata Banik450699d2023-04-01 14:55:07 +053075 /* Enable PROCHOT and Power Performance Platform Override */
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070076 msr = rdmsr(MSR_POWER_CTL);
77 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input*/
78 msr.lo |= (1 << 23); /* Lock it */
Subrata Banik450699d2023-04-01 14:55:07 +053079 msr.lo |= (1 << 18); /* Power Performance Platform Override */
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070080 wrmsr(MSR_POWER_CTL, msr);
81}
82
83enum core_type get_soc_cpu_type(void)
84{
85 if (cpu_is_hybrid_supported())
86 return cpu_get_cpu_type();
87 else
88 return CPUID_CORE_TYPE_INTEL_CORE;
89}
90
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070091bool soc_is_nominal_freq_supported(void)
92{
93 return true;
94}
95
Subrata Banike96993d2022-07-09 22:06:45 +000096static void enable_x2apic(void)
97{
98 if (!CONFIG(X2APIC_LATE_WORKAROUND))
99 return;
100
101 enable_lapic_mode(true);
102}
103
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700104/* All CPUs including BSP will run the following function. */
105void soc_core_init(struct device *cpu)
106{
107 /* Clear out pending MCEs */
108 /* TODO(adurbin): This should only be done on a cold boot. Also, some
109 * of these banks are core vs package scope. For now every CPU clears
110 * every bank. */
111 mca_configure();
112
Subrata Banike96993d2022-07-09 22:06:45 +0000113 enable_x2apic();
114
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700115 enable_lapic_tpr();
116
117 /* Configure Enhanced SpeedStep and Thermal Sensors */
118 configure_misc();
119
120 enable_pm_timer_emulation();
121
122 /* Enable Direct Cache Access */
123 configure_dca_cap();
124
125 /* Set energy policy */
126 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
127
Subrata Banikd0d7f472023-04-01 14:48:15 +0530128 const config_t *conf = config_of_soc();
129 /* Set energy-performance preference */
130 if (conf->enable_energy_perf_pref)
131 if (check_energy_perf_cap())
132 set_energy_perf_pref(conf->energy_perf_pref_value);
133
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700134 /* Enable Turbo */
135 enable_turbo();
Tarun Tuli24a05472022-08-22 16:41:35 -0400136
Sridhar Siricilla2afac192023-03-30 10:18:13 +0530137 /* Set core type in struct cpu_info */
138 set_dev_core_type();
139
Tarun Tuli24a05472022-08-22 16:41:35 -0400140 if (CONFIG(INTEL_TME) && is_tme_supported())
141 set_tme_core_activate();
Subrata Banik6e911ee2023-04-01 16:32:26 +0530142
143 if (CONFIG(DROP_CPU_FEATURE_PROGRAM_IN_FSP)) {
144 /* Disable 3-strike error */
Subrata Banik8cf64472023-12-13 01:21:31 +0530145 if (CONFIG(SOC_INTEL_METEORLAKE_PRE_PRODUCTION_SILICON))
146 disable_three_strike_error();
147 else
148 disable_signaling_three_strike_event();
Subrata Banikd8fc4fa2023-04-01 20:36:15 +0530149
150 set_aesni_lock();
Subrata Banikad6073c2023-04-01 20:37:12 +0530151
152 /* Enable VMX */
153 set_feature_ctrl_vmx_arg(CONFIG(ENABLE_VMX) && !conf->disable_vmx);
Subrata Banik1d13fba2023-04-01 20:42:46 +0530154
155 /* Feature control lock configure */
156 set_feature_ctrl_lock();
Subrata Banik6e911ee2023-04-01 16:32:26 +0530157 }
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700158}
159
160static void per_cpu_smm_trigger(void)
161{
162 /* Relocate the SMM handler. */
163 smm_relocate();
164}
165
Subrata Banikd0d7f472023-04-01 14:48:15 +0530166static void pre_mp_init(void)
167{
168 soc_fsp_load();
169
170 const config_t *conf = config_of_soc();
171 if (conf->enable_energy_perf_pref) {
172 if (check_energy_perf_cap())
173 enable_energy_perf_pref();
174 else
175 printk(BIOS_WARNING, "Energy Performance Preference not supported!\n");
176 }
177}
178
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700179static void post_mp_init(void)
180{
181 /* Set Max Ratio */
182 cpu_set_max_ratio();
183
184 /*
185 * 1. Now that all APs have been relocated as well as the BSP let SMIs
186 * start flowing.
187 * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT
188 * to avoid shutdown hang due to lack of init on certain IP in FSP-S.
189 */
190 global_smi_enable_no_pwrbtn();
191}
192
193static const struct mp_ops mp_ops = {
194 /*
195 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
196 * that are set prior to ramstage.
197 * Real MTRRs programming are being done after resource allocation.
198 */
Subrata Banikd0d7f472023-04-01 14:48:15 +0530199 .pre_mp_init = pre_mp_init,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700200 .get_cpu_count = get_cpu_count,
201 .get_smm_info = smm_info,
202 .get_microcode_info = get_microcode_info,
203 .pre_mp_smm_init = smm_initialize,
204 .per_cpu_smm_trigger = per_cpu_smm_trigger,
205 .relocation_handler = smm_relocation_handler,
206 .post_mp_init = post_mp_init,
207};
208
Arthur Heymans829e8e62023-01-30 19:09:34 +0100209void mp_init_cpus(struct bus *cpu_bus)
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700210{
211 if (mp_init_with_smm(cpu_bus, &mp_ops))
212 printk(BIOS_ERR, "MP initialization failure.\n");
213
214 /* Thermal throttle activation offset */
215 configure_tcc_thermal_target();
216}