blob: 37571758cb0a63da6792d6db8c272e8978f99419 [file] [log] [blame]
Angel Pons32abdd62020-04-05 15:47:03 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05302
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05303#include <device/pci.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05304#include <cpu/x86/mp.h>
5#include <cpu/x86/msr.h>
Kyösti Mälkkifaf20d32019-08-14 05:41:41 +03006#include <cpu/intel/smm_reloc.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05307#include <cpu/intel/turbo.h>
Michael Niewöhner10ae1cf2020-10-11 14:05:32 +02008#include <cpu/intel/common/common.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +05309#include <fsp/api.h>
10#include <intelblocks/cpulib.h>
11#include <intelblocks/mp_init.h>
Aamir Bohra34508cd2018-04-19 18:03:46 +053012#include <intelblocks/msr.h>
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053013#include <soc/cpu.h>
14#include <soc/msr.h>
15#include <soc/pci_devs.h>
Subrata Banikdf29d232019-07-05 16:00:38 +053016#include <soc/soc_chip.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020017#include <types.h>
Elyes HAOUASc3385072019-03-21 15:38:06 +010018
Subrata Banik56ab8e22022-01-07 13:40:19 +000019bool cpu_soc_is_in_untrusted_mode(void)
20{
21 msr_t msr;
22
23 msr = rdmsr(MSR_BIOS_DONE);
24 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
25}
26
Subrata Banik37a55d12022-05-30 18:11:12 +000027void cpu_soc_bios_done(void)
28{
29 msr_t msr;
30
31 msr = rdmsr(MSR_BIOS_DONE);
32 msr.lo |= ENABLE_IA_UNTRUSTED;
33 wrmsr(MSR_BIOS_DONE, msr);
34}
35
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053036static void soc_fsp_load(void)
37{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020038 fsps_load();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053039}
40
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053041static void configure_misc(void)
42{
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053043 msr_t msr;
44
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030045 config_t *conf = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +030046
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053047 msr = rdmsr(IA32_MISC_ENABLE);
48 msr.lo |= (1 << 0); /* Fast String enable */
49 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Matt Delco54e98942020-03-09 12:41:09 -070050 wrmsr(IA32_MISC_ENABLE, msr);
51
Subrata Banik6d569162019-04-10 12:19:27 +053052 /* Set EIST status */
53 cpu_set_eist(conf->eist_enable);
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053054
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 */
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053068 msr.lo |= (1 << 23); /* Lock it */
69 wrmsr(MSR_POWER_CTL, msr);
70}
71
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053072static void configure_c_states(void)
73{
74 msr_t msr;
75
76 /* C-state Interrupt Response Latency Control 1 - package C6/C7 short */
77 msr.hi = 0;
78 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_1_LIMIT;
79 wrmsr(MSR_C_STATE_LATENCY_CONTROL_1, msr);
80
81 /* C-state Interrupt Response Latency Control 2 - package C6/C7 long */
82 msr.hi = 0;
83 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_2_LIMIT;
84 wrmsr(MSR_C_STATE_LATENCY_CONTROL_2, msr);
85
86 /* C-state Interrupt Response Latency Control 3 - package C8 */
87 msr.hi = 0;
88 msr.lo = IRTL_VALID | IRTL_32768_NS |
89 C_STATE_LATENCY_CONTROL_3_LIMIT;
90 wrmsr(MSR_C_STATE_LATENCY_CONTROL_3, msr);
91
92 /* C-state Interrupt Response Latency Control 4 - package C9 */
93 msr.hi = 0;
94 msr.lo = IRTL_VALID | IRTL_32768_NS |
95 C_STATE_LATENCY_CONTROL_4_LIMIT;
96 wrmsr(MSR_C_STATE_LATENCY_CONTROL_4, msr);
97
98 /* C-state Interrupt Response Latency Control 5 - package C10 */
99 msr.hi = 0;
100 msr.lo = IRTL_VALID | IRTL_32768_NS |
101 C_STATE_LATENCY_CONTROL_5_LIMIT;
102 wrmsr(MSR_C_STATE_LATENCY_CONTROL_5, msr);
103}
104
105/* All CPUs including BSP will run the following function. */
106void soc_core_init(struct device *cpu)
107{
108 /* Clear out pending MCEs */
109 /* TODO(adurbin): This should only be done on a cold boot. Also, some
110 * of these banks are core vs package scope. For now every CPU clears
111 * every bank. */
Subrata Banikf91344c2019-05-06 19:23:26 +0530112 mca_configure();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530113
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530114 enable_lapic_tpr();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530115
116 /* Configure c-state interrupt response time */
117 configure_c_states();
118
119 /* Configure Enhanced SpeedStep and Thermal Sensors */
120 configure_misc();
121
Aamir Bohra34508cd2018-04-19 18:03:46 +0530122 enable_pm_timer_emulation();
123
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530124 /* Enable Direct Cache Access */
125 configure_dca_cap();
126
127 /* Set energy policy */
128 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
129
130 /* Enable Turbo */
131 enable_turbo();
132}
133
134static void per_cpu_smm_trigger(void)
135{
136 /* Relocate the SMM handler. */
137 smm_relocate();
138}
139
140static void post_mp_init(void)
141{
142 /* Set Max Ratio */
143 cpu_set_max_ratio();
144
145 /*
146 * Now that all APs have been relocated as well as the BSP let SMIs
147 * start flowing.
148 */
Kyösti Mälkki040c5312020-05-31 20:03:11 +0300149 global_smi_enable();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530150}
151
152static 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
168void soc_init_cpus(struct bus *cpu_bus)
169{
Felix Held4dd7d112021-10-20 23:31:43 +0200170 /* TODO: Handle mp_init_with_smm failure? */
171 mp_init_with_smm(cpu_bus, &mp_ops);
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530172}