Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 3 | #include <assert.h> |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 4 | #include <console/console.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 5 | #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 Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 9 | #include <cpu/x86/lapic.h> |
| 10 | #include <cpu/x86/mp.h> |
| 11 | #include <cpu/x86/msr.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 12 | #include <device/pci.h> |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 13 | #include <fsp/api.h> |
Elyes Haouas | def74aa | 2022-10-31 13:44:40 +0100 | [diff] [blame] | 14 | #include <intelblocks/acpi.h> |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 15 | #include <intelblocks/cpulib.h> |
| 16 | #include <intelblocks/mp_init.h> |
| 17 | #include <intelblocks/msr.h> |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 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> |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 23 | |
| 24 | bool 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 Banik | 85e619c | 2022-12-05 20:52:38 +0530 | [diff] [blame] | 32 | void 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 Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 41 | uint8_t get_supported_lpm_mask(void) |
| 42 | { |
| 43 | return LPM_S0i2_0 | LPM_S0i2_1 | LPM_S0i2_2; |
| 44 | } |
| 45 | |
| 46 | static void soc_fsp_load(void) |
| 47 | { |
| 48 | fsps_load(); |
| 49 | } |
| 50 | |
| 51 | static 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 Banik | 450699d | 2023-04-01 14:55:07 +0530 | [diff] [blame] | 75 | /* Enable PROCHOT and Power Performance Platform Override */ |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 76 | 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 Banik | 450699d | 2023-04-01 14:55:07 +0530 | [diff] [blame] | 79 | msr.lo |= (1 << 18); /* Power Performance Platform Override */ |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 80 | wrmsr(MSR_POWER_CTL, msr); |
| 81 | } |
| 82 | |
| 83 | enum 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 Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 91 | bool soc_is_nominal_freq_supported(void) |
| 92 | { |
| 93 | return true; |
| 94 | } |
| 95 | |
Subrata Banik | e96993d | 2022-07-09 22:06:45 +0000 | [diff] [blame] | 96 | static void enable_x2apic(void) |
| 97 | { |
| 98 | if (!CONFIG(X2APIC_LATE_WORKAROUND)) |
| 99 | return; |
| 100 | |
| 101 | enable_lapic_mode(true); |
| 102 | } |
| 103 | |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 104 | /* All CPUs including BSP will run the following function. */ |
| 105 | void 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 Banik | e96993d | 2022-07-09 22:06:45 +0000 | [diff] [blame] | 113 | enable_x2apic(); |
| 114 | |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 115 | 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 Banik | d0d7f47 | 2023-04-01 14:48:15 +0530 | [diff] [blame] | 128 | 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 Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 134 | /* Enable Turbo */ |
| 135 | enable_turbo(); |
Tarun Tuli | 24a0547 | 2022-08-22 16:41:35 -0400 | [diff] [blame] | 136 | |
Sridhar Siricilla | 2afac19 | 2023-03-30 10:18:13 +0530 | [diff] [blame] | 137 | /* Set core type in struct cpu_info */ |
| 138 | set_dev_core_type(); |
| 139 | |
Tarun Tuli | 24a0547 | 2022-08-22 16:41:35 -0400 | [diff] [blame] | 140 | if (CONFIG(INTEL_TME) && is_tme_supported()) |
| 141 | set_tme_core_activate(); |
Subrata Banik | 6e911ee | 2023-04-01 16:32:26 +0530 | [diff] [blame] | 142 | |
| 143 | if (CONFIG(DROP_CPU_FEATURE_PROGRAM_IN_FSP)) { |
| 144 | /* Disable 3-strike error */ |
Subrata Banik | 8cf6447 | 2023-12-13 01:21:31 +0530 | [diff] [blame] | 145 | if (CONFIG(SOC_INTEL_METEORLAKE_PRE_PRODUCTION_SILICON)) |
| 146 | disable_three_strike_error(); |
| 147 | else |
| 148 | disable_signaling_three_strike_event(); |
Subrata Banik | d8fc4fa | 2023-04-01 20:36:15 +0530 | [diff] [blame] | 149 | |
| 150 | set_aesni_lock(); |
Subrata Banik | ad6073c | 2023-04-01 20:37:12 +0530 | [diff] [blame] | 151 | |
| 152 | /* Enable VMX */ |
| 153 | set_feature_ctrl_vmx_arg(CONFIG(ENABLE_VMX) && !conf->disable_vmx); |
Subrata Banik | 1d13fba | 2023-04-01 20:42:46 +0530 | [diff] [blame] | 154 | |
| 155 | /* Feature control lock configure */ |
| 156 | set_feature_ctrl_lock(); |
Subrata Banik | 6e911ee | 2023-04-01 16:32:26 +0530 | [diff] [blame] | 157 | } |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | static void per_cpu_smm_trigger(void) |
| 161 | { |
| 162 | /* Relocate the SMM handler. */ |
| 163 | smm_relocate(); |
| 164 | } |
| 165 | |
Subrata Banik | d0d7f47 | 2023-04-01 14:48:15 +0530 | [diff] [blame] | 166 | static 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 Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 179 | static 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 | |
| 193 | static 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 Banik | d0d7f47 | 2023-04-01 14:48:15 +0530 | [diff] [blame] | 199 | .pre_mp_init = pre_mp_init, |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 200 | .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 Heymans | 829e8e6 | 2023-01-30 19:09:34 +0100 | [diff] [blame] | 209 | void mp_init_cpus(struct bus *cpu_bus) |
Ravi Sarawadi | 91ffac8 | 2022-05-07 16:37:09 -0700 | [diff] [blame] | 210 | { |
| 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 | } |