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> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 22 | #include <soc/cpu.h> |
| 23 | #include <soc/msr.h> |
| 24 | #include <soc/pci_devs.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 25 | #include <soc/soc_chip.h> |
Felix Held | d27ef5b | 2021-10-20 20:18:12 +0200 | [diff] [blame] | 26 | #include <types.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 27 | |
| 28 | static void soc_fsp_load(void) |
| 29 | { |
Kyösti Mälkki | cc93c6e | 2021-01-09 22:53:52 +0200 | [diff] [blame] | 30 | fsps_load(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 31 | } |
| 32 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 33 | static void configure_misc(void) |
| 34 | { |
| 35 | msr_t msr; |
| 36 | |
| 37 | config_t *conf = config_of_soc(); |
| 38 | |
| 39 | msr = rdmsr(IA32_MISC_ENABLE); |
| 40 | msr.lo |= (1 << 0); /* Fast String enable */ |
| 41 | msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */ |
| 42 | wrmsr(IA32_MISC_ENABLE, msr); |
| 43 | |
| 44 | /* Set EIST status */ |
| 45 | cpu_set_eist(conf->eist_enable); |
| 46 | |
| 47 | /* Disable Thermal interrupts */ |
| 48 | msr.lo = 0; |
| 49 | msr.hi = 0; |
| 50 | wrmsr(IA32_THERM_INTERRUPT, msr); |
| 51 | |
| 52 | /* Enable package critical interrupt only */ |
| 53 | msr.lo = 1 << 4; |
| 54 | msr.hi = 0; |
| 55 | wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr); |
| 56 | |
| 57 | /* Enable PROCHOT */ |
| 58 | msr = rdmsr(MSR_POWER_CTL); |
Angel Pons | 4d794bd | 2021-10-11 14:00:54 +0200 | [diff] [blame] | 59 | msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */ |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 60 | msr.lo |= (1 << 23); /* Lock it */ |
| 61 | wrmsr(MSR_POWER_CTL, msr); |
| 62 | } |
| 63 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 64 | /* All CPUs including BSP will run the following function. */ |
| 65 | void soc_core_init(struct device *cpu) |
| 66 | { |
| 67 | /* Clear out pending MCEs */ |
| 68 | /* TODO(adurbin): This should only be done on a cold boot. Also, some |
| 69 | * of these banks are core vs package scope. For now every CPU clears |
| 70 | * every bank. */ |
| 71 | mca_configure(); |
| 72 | |
| 73 | /* Enable the local CPU apics */ |
| 74 | enable_lapic_tpr(); |
| 75 | setup_lapic(); |
| 76 | |
| 77 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 78 | configure_misc(); |
| 79 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 80 | enable_pm_timer_emulation(); |
| 81 | |
| 82 | /* Enable Direct Cache Access */ |
| 83 | configure_dca_cap(); |
| 84 | |
| 85 | /* Set energy policy */ |
| 86 | set_energy_perf_bias(ENERGY_POLICY_NORMAL); |
| 87 | |
| 88 | /* Enable Turbo */ |
| 89 | enable_turbo(); |
| 90 | } |
| 91 | |
| 92 | static void per_cpu_smm_trigger(void) |
| 93 | { |
| 94 | /* Relocate the SMM handler. */ |
| 95 | smm_relocate(); |
| 96 | } |
| 97 | |
| 98 | static void post_mp_init(void) |
| 99 | { |
| 100 | /* Set Max Ratio */ |
| 101 | cpu_set_max_ratio(); |
| 102 | |
| 103 | /* |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 104 | * 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] | 105 | * start flowing. |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 106 | * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT |
| 107 | * 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] | 108 | */ |
Kane Chen | 3aee3ad | 2021-05-04 09:53:38 +0800 | [diff] [blame] | 109 | global_smi_enable_no_pwrbtn(); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | static const struct mp_ops mp_ops = { |
| 113 | /* |
| 114 | * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP, |
| 115 | * that are set prior to ramstage. |
| 116 | * Real MTRRs programming are being done after resource allocation. |
| 117 | */ |
| 118 | .pre_mp_init = soc_fsp_load, |
| 119 | .get_cpu_count = get_cpu_count, |
| 120 | .get_smm_info = smm_info, |
| 121 | .get_microcode_info = get_microcode_info, |
| 122 | .pre_mp_smm_init = smm_initialize, |
| 123 | .per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 124 | .relocation_handler = smm_relocation_handler, |
| 125 | .post_mp_init = post_mp_init, |
| 126 | }; |
| 127 | |
| 128 | void soc_init_cpus(struct bus *cpu_bus) |
| 129 | { |
Felix Held | d27ef5b | 2021-10-20 20:18:12 +0200 | [diff] [blame] | 130 | if (mp_init_with_smm(cpu_bus, &mp_ops) != CB_SUCCESS) |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 131 | printk(BIOS_ERR, "MP initialization failure.\n"); |
| 132 | |
| 133 | /* Thermal throttle activation offset */ |
| 134 | configure_tcc_thermal_target(); |
| 135 | } |
Tim Wawrzynczak | 6cf79d9 | 2021-07-30 10:37:55 -0600 | [diff] [blame] | 136 | |
| 137 | enum adl_cpu_type get_adl_cpu_type(void) |
| 138 | { |
| 139 | const uint16_t adl_m_mch_ids[] = { |
| 140 | PCI_DEVICE_ID_INTEL_ADL_M_ID_1, |
| 141 | PCI_DEVICE_ID_INTEL_ADL_M_ID_2, |
| 142 | }; |
| 143 | const uint16_t adl_p_mch_ids[] = { |
| 144 | PCI_DEVICE_ID_INTEL_ADL_P_ID_1, |
| 145 | PCI_DEVICE_ID_INTEL_ADL_P_ID_3, |
| 146 | PCI_DEVICE_ID_INTEL_ADL_P_ID_4, |
| 147 | PCI_DEVICE_ID_INTEL_ADL_P_ID_5, |
| 148 | PCI_DEVICE_ID_INTEL_ADL_P_ID_6, |
| 149 | PCI_DEVICE_ID_INTEL_ADL_P_ID_7, |
| 150 | PCI_DEVICE_ID_INTEL_ADL_P_ID_8, |
| 151 | PCI_DEVICE_ID_INTEL_ADL_P_ID_9, |
| 152 | }; |
| 153 | const uint16_t adl_s_mch_ids[] = { |
| 154 | PCI_DEVICE_ID_INTEL_ADL_S_ID_1, |
| 155 | PCI_DEVICE_ID_INTEL_ADL_S_ID_2, |
| 156 | PCI_DEVICE_ID_INTEL_ADL_S_ID_3, |
| 157 | PCI_DEVICE_ID_INTEL_ADL_S_ID_4, |
| 158 | PCI_DEVICE_ID_INTEL_ADL_S_ID_5, |
| 159 | PCI_DEVICE_ID_INTEL_ADL_S_ID_6, |
| 160 | PCI_DEVICE_ID_INTEL_ADL_S_ID_7, |
| 161 | PCI_DEVICE_ID_INTEL_ADL_S_ID_8, |
| 162 | PCI_DEVICE_ID_INTEL_ADL_S_ID_9, |
| 163 | PCI_DEVICE_ID_INTEL_ADL_S_ID_10, |
| 164 | PCI_DEVICE_ID_INTEL_ADL_S_ID_11, |
| 165 | PCI_DEVICE_ID_INTEL_ADL_S_ID_12, |
| 166 | PCI_DEVICE_ID_INTEL_ADL_S_ID_13, |
| 167 | PCI_DEVICE_ID_INTEL_ADL_S_ID_14, |
| 168 | PCI_DEVICE_ID_INTEL_ADL_S_ID_15, |
| 169 | }; |
| 170 | |
| 171 | const uint16_t mchid = pci_s_read_config16(PCI_DEV(0, PCI_SLOT(SA_DEVFN_ROOT), |
| 172 | PCI_FUNC(SA_DEVFN_ROOT)), |
| 173 | PCI_DEVICE_ID); |
| 174 | |
| 175 | for (size_t i = 0; i < ARRAY_SIZE(adl_p_mch_ids); i++) { |
| 176 | if (adl_p_mch_ids[i] == mchid) |
| 177 | return ADL_P; |
| 178 | } |
| 179 | |
| 180 | for (size_t i = 0; i < ARRAY_SIZE(adl_m_mch_ids); i++) { |
| 181 | if (adl_m_mch_ids[i] == mchid) |
| 182 | return ADL_M; |
| 183 | } |
| 184 | |
| 185 | for (size_t i = 0; i < ARRAY_SIZE(adl_s_mch_ids); i++) { |
| 186 | if (adl_s_mch_ids[i] == mchid) |
| 187 | return ADL_S; |
| 188 | } |
| 189 | |
| 190 | return ADL_UNKNOWN; |
| 191 | } |
Tim Wawrzynczak | e2b8f30 | 2021-07-19 15:35:47 -0600 | [diff] [blame] | 192 | |
| 193 | uint8_t get_supported_lpm_mask(void) |
| 194 | { |
| 195 | enum adl_cpu_type type = get_adl_cpu_type(); |
| 196 | switch (type) { |
| 197 | case ADL_M: /* fallthrough */ |
| 198 | case ADL_P: |
| 199 | return LPM_S0i2_0 | LPM_S0i3_0; |
| 200 | case ADL_S: |
| 201 | return LPM_S0i2_0 | LPM_S0i2_1; |
| 202 | default: |
| 203 | printk(BIOS_ERR, "Unknown ADL CPU type: %d\n", type); |
| 204 | return 0; |
| 205 | } |
| 206 | } |