Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* |
| 4 | * This file is created based on Intel Alder Lake Processor CPU Datasheet |
| 5 | * Document number: 619501 |
| 6 | * Chapter number: 14 |
| 7 | */ |
| 8 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 9 | #include <console/console.h> |
| 10 | #include <device/pci.h> |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 11 | #include <device/pci_ids.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 12 | #include <cpu/x86/lapic.h> |
| 13 | #include <cpu/x86/mp.h> |
| 14 | #include <cpu/x86/msr.h> |
| 15 | #include <cpu/intel/smm_reloc.h> |
| 16 | #include <cpu/intel/turbo.h> |
Michael Niewöhner | 10ae1cf | 2020-10-11 14:05:32 +0200 | [diff] [blame] | 17 | #include <cpu/intel/common/common.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 18 | #include <fsp/api.h> |
| 19 | #include <intelblocks/cpulib.h> |
| 20 | #include <intelblocks/mp_init.h> |
| 21 | #include <intelblocks/msr.h> |
Sridhar Siricilla | 23e2cde | 2022-01-14 19:20:15 +0530 | [diff] [blame] | 22 | #include <intelblocks/acpi.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 23 | #include <soc/cpu.h> |
| 24 | #include <soc/msr.h> |
| 25 | #include <soc/pci_devs.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 26 | #include <soc/soc_chip.h> |
Felix Held | d27ef5b | 2021-10-20 20:18:12 +0200 | [diff] [blame] | 27 | #include <types.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 28 | |
Sridhar Siricilla | 23e2cde | 2022-01-14 19:20:15 +0530 | [diff] [blame] | 29 | enum alderlake_model { |
| 30 | ADL_MODEL_P_M = 0x9A, |
| 31 | ADL_MODEL_N = 0xBE, |
| 32 | }; |
| 33 | |
Subrata Banik | 56ab8e2 | 2022-01-07 13:40:19 +0000 | [diff] [blame] | 34 | bool cpu_soc_is_in_untrusted_mode(void) |
| 35 | { |
| 36 | msr_t msr; |
| 37 | |
| 38 | msr = rdmsr(MSR_BIOS_DONE); |
| 39 | return !!(msr.lo & ENABLE_IA_UNTRUSTED); |
| 40 | } |
| 41 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 42 | static void soc_fsp_load(void) |
| 43 | { |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 44 | fsps_load(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 45 | } |
| 46 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 47 | static void configure_misc(void) |
| 48 | { |
| 49 | msr_t msr; |
| 50 | |
Tim Wawrzynczak | b0d3a01 | 2021-12-02 16:19:29 -0700 | [diff] [blame] | 51 | const config_t *conf = config_of_soc(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 52 | |
| 53 | msr = rdmsr(IA32_MISC_ENABLE); |
| 54 | msr.lo |= (1 << 0); /* Fast String enable */ |
| 55 | msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */ |
| 56 | wrmsr(IA32_MISC_ENABLE, msr); |
| 57 | |
| 58 | /* Set EIST status */ |
| 59 | cpu_set_eist(conf->eist_enable); |
| 60 | |
| 61 | /* Disable Thermal interrupts */ |
| 62 | msr.lo = 0; |
| 63 | msr.hi = 0; |
| 64 | wrmsr(IA32_THERM_INTERRUPT, msr); |
| 65 | |
| 66 | /* Enable package critical interrupt only */ |
| 67 | msr.lo = 1 << 4; |
| 68 | msr.hi = 0; |
| 69 | wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr); |
| 70 | |
| 71 | /* Enable PROCHOT */ |
| 72 | msr = rdmsr(MSR_POWER_CTL); |
Angel Pons | 4d794bd | 2021-10-11 14:00:54 +0200 | [diff] [blame] | 73 | msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */ |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 74 | msr.lo |= (1 << 23); /* Lock it */ |
| 75 | wrmsr(MSR_POWER_CTL, msr); |
| 76 | } |
| 77 | |
Sridhar Siricilla | 23e2cde | 2022-01-14 19:20:15 +0530 | [diff] [blame] | 78 | enum core_type get_soc_cpu_type(void) |
| 79 | { |
| 80 | struct cpuinfo_x86 cpuinfo; |
| 81 | |
| 82 | if (cpu_is_hybrid_supported()) |
| 83 | return cpu_get_cpu_type(); |
| 84 | |
| 85 | get_fms(&cpuinfo, cpuid_eax(1)); |
| 86 | |
| 87 | if (cpuinfo.x86 == 0x6 && cpuinfo.x86_model == ADL_MODEL_N) |
| 88 | return CPUID_CORE_TYPE_INTEL_ATOM; |
| 89 | else |
| 90 | return CPUID_CORE_TYPE_INTEL_CORE; |
| 91 | } |
| 92 | |
Sridahr Siricilla | 73b90c6 | 2021-11-11 01:10:16 +0530 | [diff] [blame^] | 93 | void soc_get_scaling_factor(u16 *big_core_scal_factor, u16 *small_core_scal_factor) |
| 94 | { |
| 95 | *big_core_scal_factor = 127; |
| 96 | *small_core_scal_factor = 100; |
| 97 | } |
| 98 | |
| 99 | bool soc_is_nominal_freq_supported(void) |
| 100 | { |
| 101 | return true; |
| 102 | } |
| 103 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [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 | |
| 113 | /* Enable the local CPU apics */ |
| 114 | enable_lapic_tpr(); |
| 115 | setup_lapic(); |
| 116 | |
| 117 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 118 | configure_misc(); |
| 119 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 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 | |
| 128 | /* Enable Turbo */ |
| 129 | enable_turbo(); |
| 130 | } |
| 131 | |
| 132 | static void per_cpu_smm_trigger(void) |
| 133 | { |
| 134 | /* Relocate the SMM handler. */ |
| 135 | smm_relocate(); |
| 136 | } |
| 137 | |
| 138 | static void post_mp_init(void) |
| 139 | { |
| 140 | /* Set Max Ratio */ |
| 141 | cpu_set_max_ratio(); |
| 142 | |
| 143 | /* |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 144 | * 1. Now that all APs have been relocated as well as the BSP let SMIs |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 145 | * start flowing. |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 146 | * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT |
| 147 | * to avoid shutdown hang due to lack of init on certain IP in FSP-S. |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 148 | */ |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 149 | global_smi_enable_no_pwrbtn(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | static const struct mp_ops mp_ops = { |
| 153 | /* |
| 154 | * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP, |
| 155 | * that are set prior to ramstage. |
| 156 | * Real MTRRs programming are being done after resource allocation. |
| 157 | */ |
| 158 | .pre_mp_init = soc_fsp_load, |
| 159 | .get_cpu_count = get_cpu_count, |
| 160 | .get_smm_info = smm_info, |
| 161 | .get_microcode_info = get_microcode_info, |
| 162 | .pre_mp_smm_init = smm_initialize, |
| 163 | .per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 164 | .relocation_handler = smm_relocation_handler, |
| 165 | .post_mp_init = post_mp_init, |
| 166 | }; |
| 167 | |
| 168 | void soc_init_cpus(struct bus *cpu_bus) |
| 169 | { |
Felix Held | 4dd7d11 | 2021-10-20 23:31:43 +0200 | [diff] [blame] | 170 | /* TODO: Handle mp_init_with_smm failure? */ |
| 171 | mp_init_with_smm(cpu_bus, &mp_ops); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 172 | |
| 173 | /* Thermal throttle activation offset */ |
| 174 | configure_tcc_thermal_target(); |
| 175 | } |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 176 | |
| 177 | enum adl_cpu_type get_adl_cpu_type(void) |
| 178 | { |
| 179 | const uint16_t adl_m_mch_ids[] = { |
| 180 | PCI_DEVICE_ID_INTEL_ADL_M_ID_1, |
| 181 | PCI_DEVICE_ID_INTEL_ADL_M_ID_2, |
| 182 | }; |
| 183 | const uint16_t adl_p_mch_ids[] = { |
| 184 | PCI_DEVICE_ID_INTEL_ADL_P_ID_1, |
| 185 | PCI_DEVICE_ID_INTEL_ADL_P_ID_3, |
| 186 | PCI_DEVICE_ID_INTEL_ADL_P_ID_4, |
| 187 | PCI_DEVICE_ID_INTEL_ADL_P_ID_5, |
| 188 | PCI_DEVICE_ID_INTEL_ADL_P_ID_6, |
| 189 | PCI_DEVICE_ID_INTEL_ADL_P_ID_7, |
| 190 | PCI_DEVICE_ID_INTEL_ADL_P_ID_8, |
| 191 | PCI_DEVICE_ID_INTEL_ADL_P_ID_9, |
Kane Chen | 415eadb | 2022-01-17 10:03:29 +0800 | [diff] [blame] | 192 | PCI_DEVICE_ID_INTEL_ADL_P_ID_10 |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 193 | }; |
| 194 | const uint16_t adl_s_mch_ids[] = { |
| 195 | PCI_DEVICE_ID_INTEL_ADL_S_ID_1, |
| 196 | PCI_DEVICE_ID_INTEL_ADL_S_ID_2, |
| 197 | PCI_DEVICE_ID_INTEL_ADL_S_ID_3, |
| 198 | PCI_DEVICE_ID_INTEL_ADL_S_ID_4, |
| 199 | PCI_DEVICE_ID_INTEL_ADL_S_ID_5, |
| 200 | PCI_DEVICE_ID_INTEL_ADL_S_ID_6, |
| 201 | PCI_DEVICE_ID_INTEL_ADL_S_ID_7, |
| 202 | PCI_DEVICE_ID_INTEL_ADL_S_ID_8, |
| 203 | PCI_DEVICE_ID_INTEL_ADL_S_ID_9, |
| 204 | PCI_DEVICE_ID_INTEL_ADL_S_ID_10, |
| 205 | PCI_DEVICE_ID_INTEL_ADL_S_ID_11, |
| 206 | PCI_DEVICE_ID_INTEL_ADL_S_ID_12, |
| 207 | PCI_DEVICE_ID_INTEL_ADL_S_ID_13, |
| 208 | PCI_DEVICE_ID_INTEL_ADL_S_ID_14, |
| 209 | PCI_DEVICE_ID_INTEL_ADL_S_ID_15, |
| 210 | }; |
| 211 | |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 212 | const uint16_t adl_n_mch_ids[] = { |
| 213 | PCI_DEVICE_ID_INTEL_ADL_N_ID_1, |
| 214 | PCI_DEVICE_ID_INTEL_ADL_N_ID_2, |
Usha P | 8f2df28 | 2022-01-17 20:06:38 +0530 | [diff] [blame] | 215 | PCI_DEVICE_ID_INTEL_ADL_N_ID_3, |
| 216 | PCI_DEVICE_ID_INTEL_ADL_N_ID_4, |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 217 | }; |
| 218 | |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 219 | const uint16_t mchid = pci_s_read_config16(PCI_DEV(0, PCI_SLOT(SA_DEVFN_ROOT), |
| 220 | PCI_FUNC(SA_DEVFN_ROOT)), |
| 221 | PCI_DEVICE_ID); |
| 222 | |
| 223 | for (size_t i = 0; i < ARRAY_SIZE(adl_p_mch_ids); i++) { |
| 224 | if (adl_p_mch_ids[i] == mchid) |
| 225 | return ADL_P; |
| 226 | } |
| 227 | |
| 228 | for (size_t i = 0; i < ARRAY_SIZE(adl_m_mch_ids); i++) { |
| 229 | if (adl_m_mch_ids[i] == mchid) |
| 230 | return ADL_M; |
| 231 | } |
| 232 | |
| 233 | for (size_t i = 0; i < ARRAY_SIZE(adl_s_mch_ids); i++) { |
| 234 | if (adl_s_mch_ids[i] == mchid) |
| 235 | return ADL_S; |
| 236 | } |
| 237 | |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 238 | for (size_t i = 0; i < ARRAY_SIZE(adl_n_mch_ids); i++) { |
| 239 | if (adl_n_mch_ids[i] == mchid) |
| 240 | return ADL_N; |
| 241 | } |
| 242 | |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 243 | return ADL_UNKNOWN; |
| 244 | } |
Tim Wawrzynczak | e2b8f30 | 2021-07-19 15:35:47 -0600 | [diff] [blame] | 245 | |
| 246 | uint8_t get_supported_lpm_mask(void) |
| 247 | { |
| 248 | enum adl_cpu_type type = get_adl_cpu_type(); |
| 249 | switch (type) { |
| 250 | case ADL_M: /* fallthrough */ |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 251 | case ADL_N: |
Tim Wawrzynczak | e2b8f30 | 2021-07-19 15:35:47 -0600 | [diff] [blame] | 252 | case ADL_P: |
| 253 | return LPM_S0i2_0 | LPM_S0i3_0; |
| 254 | case ADL_S: |
| 255 | return LPM_S0i2_0 | LPM_S0i2_1; |
| 256 | default: |
| 257 | printk(BIOS_ERR, "Unknown ADL CPU type: %d\n", type); |
| 258 | return 0; |
| 259 | } |
| 260 | } |