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 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 93 | /* All CPUs including BSP will run the following function. */ |
| 94 | void soc_core_init(struct device *cpu) |
| 95 | { |
| 96 | /* Clear out pending MCEs */ |
| 97 | /* TODO(adurbin): This should only be done on a cold boot. Also, some |
| 98 | * of these banks are core vs package scope. For now every CPU clears |
| 99 | * every bank. */ |
| 100 | mca_configure(); |
| 101 | |
| 102 | /* Enable the local CPU apics */ |
| 103 | enable_lapic_tpr(); |
| 104 | setup_lapic(); |
| 105 | |
| 106 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 107 | configure_misc(); |
| 108 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 109 | enable_pm_timer_emulation(); |
| 110 | |
| 111 | /* Enable Direct Cache Access */ |
| 112 | configure_dca_cap(); |
| 113 | |
| 114 | /* Set energy policy */ |
| 115 | set_energy_perf_bias(ENERGY_POLICY_NORMAL); |
| 116 | |
| 117 | /* Enable Turbo */ |
| 118 | enable_turbo(); |
| 119 | } |
| 120 | |
| 121 | static void per_cpu_smm_trigger(void) |
| 122 | { |
| 123 | /* Relocate the SMM handler. */ |
| 124 | smm_relocate(); |
| 125 | } |
| 126 | |
| 127 | static void post_mp_init(void) |
| 128 | { |
| 129 | /* Set Max Ratio */ |
| 130 | cpu_set_max_ratio(); |
| 131 | |
| 132 | /* |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 133 | * 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] | 134 | * start flowing. |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 135 | * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT |
| 136 | * 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] | 137 | */ |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 138 | global_smi_enable_no_pwrbtn(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static const struct mp_ops mp_ops = { |
| 142 | /* |
| 143 | * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP, |
| 144 | * that are set prior to ramstage. |
| 145 | * Real MTRRs programming are being done after resource allocation. |
| 146 | */ |
| 147 | .pre_mp_init = soc_fsp_load, |
| 148 | .get_cpu_count = get_cpu_count, |
| 149 | .get_smm_info = smm_info, |
| 150 | .get_microcode_info = get_microcode_info, |
| 151 | .pre_mp_smm_init = smm_initialize, |
| 152 | .per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 153 | .relocation_handler = smm_relocation_handler, |
| 154 | .post_mp_init = post_mp_init, |
| 155 | }; |
| 156 | |
| 157 | void soc_init_cpus(struct bus *cpu_bus) |
| 158 | { |
Felix Held | 4dd7d11 | 2021-10-20 23:31:43 +0200 | [diff] [blame] | 159 | /* TODO: Handle mp_init_with_smm failure? */ |
| 160 | mp_init_with_smm(cpu_bus, &mp_ops); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 161 | |
| 162 | /* Thermal throttle activation offset */ |
| 163 | configure_tcc_thermal_target(); |
| 164 | } |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 165 | |
| 166 | enum adl_cpu_type get_adl_cpu_type(void) |
| 167 | { |
| 168 | const uint16_t adl_m_mch_ids[] = { |
| 169 | PCI_DEVICE_ID_INTEL_ADL_M_ID_1, |
| 170 | PCI_DEVICE_ID_INTEL_ADL_M_ID_2, |
| 171 | }; |
| 172 | const uint16_t adl_p_mch_ids[] = { |
| 173 | PCI_DEVICE_ID_INTEL_ADL_P_ID_1, |
| 174 | PCI_DEVICE_ID_INTEL_ADL_P_ID_3, |
| 175 | PCI_DEVICE_ID_INTEL_ADL_P_ID_4, |
| 176 | PCI_DEVICE_ID_INTEL_ADL_P_ID_5, |
| 177 | PCI_DEVICE_ID_INTEL_ADL_P_ID_6, |
| 178 | PCI_DEVICE_ID_INTEL_ADL_P_ID_7, |
| 179 | PCI_DEVICE_ID_INTEL_ADL_P_ID_8, |
| 180 | PCI_DEVICE_ID_INTEL_ADL_P_ID_9, |
Kane Chen | 415eadb | 2022-01-17 10:03:29 +0800 | [diff] [blame] | 181 | PCI_DEVICE_ID_INTEL_ADL_P_ID_10 |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 182 | }; |
| 183 | const uint16_t adl_s_mch_ids[] = { |
| 184 | PCI_DEVICE_ID_INTEL_ADL_S_ID_1, |
| 185 | PCI_DEVICE_ID_INTEL_ADL_S_ID_2, |
| 186 | PCI_DEVICE_ID_INTEL_ADL_S_ID_3, |
| 187 | PCI_DEVICE_ID_INTEL_ADL_S_ID_4, |
| 188 | PCI_DEVICE_ID_INTEL_ADL_S_ID_5, |
| 189 | PCI_DEVICE_ID_INTEL_ADL_S_ID_6, |
| 190 | PCI_DEVICE_ID_INTEL_ADL_S_ID_7, |
| 191 | PCI_DEVICE_ID_INTEL_ADL_S_ID_8, |
| 192 | PCI_DEVICE_ID_INTEL_ADL_S_ID_9, |
| 193 | PCI_DEVICE_ID_INTEL_ADL_S_ID_10, |
| 194 | PCI_DEVICE_ID_INTEL_ADL_S_ID_11, |
| 195 | PCI_DEVICE_ID_INTEL_ADL_S_ID_12, |
| 196 | PCI_DEVICE_ID_INTEL_ADL_S_ID_13, |
| 197 | PCI_DEVICE_ID_INTEL_ADL_S_ID_14, |
| 198 | PCI_DEVICE_ID_INTEL_ADL_S_ID_15, |
| 199 | }; |
| 200 | |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 201 | const uint16_t adl_n_mch_ids[] = { |
| 202 | PCI_DEVICE_ID_INTEL_ADL_N_ID_1, |
| 203 | PCI_DEVICE_ID_INTEL_ADL_N_ID_2, |
Usha P | 8f2df28 | 2022-01-17 20:06:38 +0530 | [diff] [blame^] | 204 | PCI_DEVICE_ID_INTEL_ADL_N_ID_3, |
| 205 | PCI_DEVICE_ID_INTEL_ADL_N_ID_4, |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 206 | }; |
| 207 | |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 208 | const uint16_t mchid = pci_s_read_config16(PCI_DEV(0, PCI_SLOT(SA_DEVFN_ROOT), |
| 209 | PCI_FUNC(SA_DEVFN_ROOT)), |
| 210 | PCI_DEVICE_ID); |
| 211 | |
| 212 | for (size_t i = 0; i < ARRAY_SIZE(adl_p_mch_ids); i++) { |
| 213 | if (adl_p_mch_ids[i] == mchid) |
| 214 | return ADL_P; |
| 215 | } |
| 216 | |
| 217 | for (size_t i = 0; i < ARRAY_SIZE(adl_m_mch_ids); i++) { |
| 218 | if (adl_m_mch_ids[i] == mchid) |
| 219 | return ADL_M; |
| 220 | } |
| 221 | |
| 222 | for (size_t i = 0; i < ARRAY_SIZE(adl_s_mch_ids); i++) { |
| 223 | if (adl_s_mch_ids[i] == mchid) |
| 224 | return ADL_S; |
| 225 | } |
| 226 | |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 227 | for (size_t i = 0; i < ARRAY_SIZE(adl_n_mch_ids); i++) { |
| 228 | if (adl_n_mch_ids[i] == mchid) |
| 229 | return ADL_N; |
| 230 | } |
| 231 | |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 232 | return ADL_UNKNOWN; |
| 233 | } |
Tim Wawrzynczak | e2b8f30 | 2021-07-19 15:35:47 -0600 | [diff] [blame] | 234 | |
| 235 | uint8_t get_supported_lpm_mask(void) |
| 236 | { |
| 237 | enum adl_cpu_type type = get_adl_cpu_type(); |
| 238 | switch (type) { |
| 239 | case ADL_M: /* fallthrough */ |
Usha P | 93f50b3 | 2021-12-02 14:18:10 +0530 | [diff] [blame] | 240 | case ADL_N: |
Tim Wawrzynczak | e2b8f30 | 2021-07-19 15:35:47 -0600 | [diff] [blame] | 241 | case ADL_P: |
| 242 | return LPM_S0i2_0 | LPM_S0i3_0; |
| 243 | case ADL_S: |
| 244 | return LPM_S0i2_0 | LPM_S0i2_1; |
| 245 | default: |
| 246 | printk(BIOS_ERR, "Unknown ADL CPU type: %d\n", type); |
| 247 | return 0; |
| 248 | } |
| 249 | } |