blob: 92ffe8704389b7c8d98c1b868237d53206ea89fe [file] [log] [blame]
Subrata Banik2871e0e2020-09-27 11:30:58 +05301/* 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 Banik2871e0e2020-09-27 11:30:58 +05309#include <console/console.h>
10#include <device/pci.h>
Tim Wawrzynczak6cf79d92021-07-30 10:37:55 -060011#include <device/pci_ids.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053012#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öhner10ae1cf2020-10-11 14:05:32 +020017#include <cpu/intel/common/common.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053018#include <fsp/api.h>
19#include <intelblocks/cpulib.h>
20#include <intelblocks/mp_init.h>
21#include <intelblocks/msr.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053022#include <soc/cpu.h>
23#include <soc/msr.h>
24#include <soc/pci_devs.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053025#include <soc/soc_chip.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020026#include <types.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053027
Subrata Banik56ab8e22022-01-07 13:40:19 +000028bool cpu_soc_is_in_untrusted_mode(void)
29{
30 msr_t msr;
31
32 msr = rdmsr(MSR_BIOS_DONE);
33 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
34}
35
Subrata Banik2871e0e2020-09-27 11:30:58 +053036static void soc_fsp_load(void)
37{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020038 fsps_load();
Subrata Banik2871e0e2020-09-27 11:30:58 +053039}
40
Subrata Banik2871e0e2020-09-27 11:30:58 +053041static void configure_misc(void)
42{
43 msr_t msr;
44
Tim Wawrzynczakb0d3a012021-12-02 16:19:29 -070045 const config_t *conf = config_of_soc();
Subrata Banik2871e0e2020-09-27 11:30:58 +053046
47 msr = rdmsr(IA32_MISC_ENABLE);
48 msr.lo |= (1 << 0); /* Fast String enable */
49 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
50 wrmsr(IA32_MISC_ENABLE, msr);
51
52 /* Set EIST status */
53 cpu_set_eist(conf->eist_enable);
54
55 /* Disable Thermal interrupts */
56 msr.lo = 0;
57 msr.hi = 0;
58 wrmsr(IA32_THERM_INTERRUPT, msr);
59
60 /* Enable package critical interrupt only */
61 msr.lo = 1 << 4;
62 msr.hi = 0;
63 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
64
65 /* Enable PROCHOT */
66 msr = rdmsr(MSR_POWER_CTL);
Angel Pons4d794bd2021-10-11 14:00:54 +020067 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */
Subrata Banik2871e0e2020-09-27 11:30:58 +053068 msr.lo |= (1 << 23); /* Lock it */
69 wrmsr(MSR_POWER_CTL, msr);
70}
71
Subrata Banik2871e0e2020-09-27 11:30:58 +053072/* All CPUs including BSP will run the following function. */
73void soc_core_init(struct device *cpu)
74{
75 /* Clear out pending MCEs */
76 /* TODO(adurbin): This should only be done on a cold boot. Also, some
77 * of these banks are core vs package scope. For now every CPU clears
78 * every bank. */
79 mca_configure();
80
81 /* Enable the local CPU apics */
82 enable_lapic_tpr();
83 setup_lapic();
84
85 /* Configure Enhanced SpeedStep and Thermal Sensors */
86 configure_misc();
87
Subrata Banik2871e0e2020-09-27 11:30:58 +053088 enable_pm_timer_emulation();
89
90 /* Enable Direct Cache Access */
91 configure_dca_cap();
92
93 /* Set energy policy */
94 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
95
96 /* Enable Turbo */
97 enable_turbo();
98}
99
100static void per_cpu_smm_trigger(void)
101{
102 /* Relocate the SMM handler. */
103 smm_relocate();
104}
105
106static void post_mp_init(void)
107{
108 /* Set Max Ratio */
109 cpu_set_max_ratio();
110
111 /*
Kane Chen3aee3ad2021-05-04 09:53:38 +0800112 * 1. Now that all APs have been relocated as well as the BSP let SMIs
Subrata Banik2871e0e2020-09-27 11:30:58 +0530113 * start flowing.
Kane Chen3aee3ad2021-05-04 09:53:38 +0800114 * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT
115 * to avoid shutdown hang due to lack of init on certain IP in FSP-S.
Subrata Banik2871e0e2020-09-27 11:30:58 +0530116 */
Kane Chen3aee3ad2021-05-04 09:53:38 +0800117 global_smi_enable_no_pwrbtn();
Subrata Banik2871e0e2020-09-27 11:30:58 +0530118}
119
120static const struct mp_ops mp_ops = {
121 /*
122 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
123 * that are set prior to ramstage.
124 * Real MTRRs programming are being done after resource allocation.
125 */
126 .pre_mp_init = soc_fsp_load,
127 .get_cpu_count = get_cpu_count,
128 .get_smm_info = smm_info,
129 .get_microcode_info = get_microcode_info,
130 .pre_mp_smm_init = smm_initialize,
131 .per_cpu_smm_trigger = per_cpu_smm_trigger,
132 .relocation_handler = smm_relocation_handler,
133 .post_mp_init = post_mp_init,
134};
135
136void soc_init_cpus(struct bus *cpu_bus)
137{
Felix Held4dd7d112021-10-20 23:31:43 +0200138 /* TODO: Handle mp_init_with_smm failure? */
139 mp_init_with_smm(cpu_bus, &mp_ops);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530140
141 /* Thermal throttle activation offset */
142 configure_tcc_thermal_target();
143}
Tim Wawrzynczak6cf79d92021-07-30 10:37:55 -0600144
145enum adl_cpu_type get_adl_cpu_type(void)
146{
147 const uint16_t adl_m_mch_ids[] = {
148 PCI_DEVICE_ID_INTEL_ADL_M_ID_1,
149 PCI_DEVICE_ID_INTEL_ADL_M_ID_2,
150 };
151 const uint16_t adl_p_mch_ids[] = {
152 PCI_DEVICE_ID_INTEL_ADL_P_ID_1,
153 PCI_DEVICE_ID_INTEL_ADL_P_ID_3,
154 PCI_DEVICE_ID_INTEL_ADL_P_ID_4,
155 PCI_DEVICE_ID_INTEL_ADL_P_ID_5,
156 PCI_DEVICE_ID_INTEL_ADL_P_ID_6,
157 PCI_DEVICE_ID_INTEL_ADL_P_ID_7,
158 PCI_DEVICE_ID_INTEL_ADL_P_ID_8,
159 PCI_DEVICE_ID_INTEL_ADL_P_ID_9,
Kane Chen415eadb2022-01-17 10:03:29 +0800160 PCI_DEVICE_ID_INTEL_ADL_P_ID_10
Tim Wawrzynczak6cf79d92021-07-30 10:37:55 -0600161 };
162 const uint16_t adl_s_mch_ids[] = {
163 PCI_DEVICE_ID_INTEL_ADL_S_ID_1,
164 PCI_DEVICE_ID_INTEL_ADL_S_ID_2,
165 PCI_DEVICE_ID_INTEL_ADL_S_ID_3,
166 PCI_DEVICE_ID_INTEL_ADL_S_ID_4,
167 PCI_DEVICE_ID_INTEL_ADL_S_ID_5,
168 PCI_DEVICE_ID_INTEL_ADL_S_ID_6,
169 PCI_DEVICE_ID_INTEL_ADL_S_ID_7,
170 PCI_DEVICE_ID_INTEL_ADL_S_ID_8,
171 PCI_DEVICE_ID_INTEL_ADL_S_ID_9,
172 PCI_DEVICE_ID_INTEL_ADL_S_ID_10,
173 PCI_DEVICE_ID_INTEL_ADL_S_ID_11,
174 PCI_DEVICE_ID_INTEL_ADL_S_ID_12,
175 PCI_DEVICE_ID_INTEL_ADL_S_ID_13,
176 PCI_DEVICE_ID_INTEL_ADL_S_ID_14,
177 PCI_DEVICE_ID_INTEL_ADL_S_ID_15,
178 };
179
Usha P93f50b32021-12-02 14:18:10 +0530180 const uint16_t adl_n_mch_ids[] = {
181 PCI_DEVICE_ID_INTEL_ADL_N_ID_1,
182 PCI_DEVICE_ID_INTEL_ADL_N_ID_2,
183 };
184
Tim Wawrzynczak6cf79d92021-07-30 10:37:55 -0600185 const uint16_t mchid = pci_s_read_config16(PCI_DEV(0, PCI_SLOT(SA_DEVFN_ROOT),
186 PCI_FUNC(SA_DEVFN_ROOT)),
187 PCI_DEVICE_ID);
188
189 for (size_t i = 0; i < ARRAY_SIZE(adl_p_mch_ids); i++) {
190 if (adl_p_mch_ids[i] == mchid)
191 return ADL_P;
192 }
193
194 for (size_t i = 0; i < ARRAY_SIZE(adl_m_mch_ids); i++) {
195 if (adl_m_mch_ids[i] == mchid)
196 return ADL_M;
197 }
198
199 for (size_t i = 0; i < ARRAY_SIZE(adl_s_mch_ids); i++) {
200 if (adl_s_mch_ids[i] == mchid)
201 return ADL_S;
202 }
203
Usha P93f50b32021-12-02 14:18:10 +0530204 for (size_t i = 0; i < ARRAY_SIZE(adl_n_mch_ids); i++) {
205 if (adl_n_mch_ids[i] == mchid)
206 return ADL_N;
207 }
208
Tim Wawrzynczak6cf79d92021-07-30 10:37:55 -0600209 return ADL_UNKNOWN;
210}
Tim Wawrzynczake2b8f302021-07-19 15:35:47 -0600211
212uint8_t get_supported_lpm_mask(void)
213{
214 enum adl_cpu_type type = get_adl_cpu_type();
215 switch (type) {
216 case ADL_M: /* fallthrough */
Usha P93f50b32021-12-02 14:18:10 +0530217 case ADL_N:
Tim Wawrzynczake2b8f302021-07-19 15:35:47 -0600218 case ADL_P:
219 return LPM_S0i2_0 | LPM_S0i3_0;
220 case ADL_S:
221 return LPM_S0i2_0 | LPM_S0i2_1;
222 default:
223 printk(BIOS_ERR, "Unknown ADL CPU type: %d\n", type);
224 return 0;
225 }
226}