blob: f503fcd051aa9071818eed88ea5dc22b9e8b26e9 [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
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053027static void soc_fsp_load(void)
28{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020029 fsps_load();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053030}
31
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053032static void configure_misc(void)
33{
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053034 msr_t msr;
35
Kyösti Mälkkid5f645c2019-09-28 00:20:27 +030036 config_t *conf = config_of_soc();
Kyösti Mälkki28dc7dc2019-07-12 13:10:19 +030037
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053038 msr = rdmsr(IA32_MISC_ENABLE);
39 msr.lo |= (1 << 0); /* Fast String enable */
40 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Matt Delco54e98942020-03-09 12:41:09 -070041 wrmsr(IA32_MISC_ENABLE, msr);
42
Subrata Banik6d569162019-04-10 12:19:27 +053043 /* Set EIST status */
44 cpu_set_eist(conf->eist_enable);
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053045
46 /* Disable Thermal interrupts */
47 msr.lo = 0;
48 msr.hi = 0;
49 wrmsr(IA32_THERM_INTERRUPT, msr);
50
51 /* Enable package critical interrupt only */
52 msr.lo = 1 << 4;
53 msr.hi = 0;
54 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
55
56 /* Enable PROCHOT */
57 msr = rdmsr(MSR_POWER_CTL);
Angel Pons4d794bd2021-10-11 14:00:54 +020058 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053059 msr.lo |= (1 << 23); /* Lock it */
60 wrmsr(MSR_POWER_CTL, msr);
61}
62
Aamir Bohra3ee54bb2018-10-17 11:55:01 +053063static void configure_c_states(void)
64{
65 msr_t msr;
66
67 /* C-state Interrupt Response Latency Control 1 - package C6/C7 short */
68 msr.hi = 0;
69 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_1_LIMIT;
70 wrmsr(MSR_C_STATE_LATENCY_CONTROL_1, msr);
71
72 /* C-state Interrupt Response Latency Control 2 - package C6/C7 long */
73 msr.hi = 0;
74 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_2_LIMIT;
75 wrmsr(MSR_C_STATE_LATENCY_CONTROL_2, msr);
76
77 /* C-state Interrupt Response Latency Control 3 - package C8 */
78 msr.hi = 0;
79 msr.lo = IRTL_VALID | IRTL_32768_NS |
80 C_STATE_LATENCY_CONTROL_3_LIMIT;
81 wrmsr(MSR_C_STATE_LATENCY_CONTROL_3, msr);
82
83 /* C-state Interrupt Response Latency Control 4 - package C9 */
84 msr.hi = 0;
85 msr.lo = IRTL_VALID | IRTL_32768_NS |
86 C_STATE_LATENCY_CONTROL_4_LIMIT;
87 wrmsr(MSR_C_STATE_LATENCY_CONTROL_4, msr);
88
89 /* C-state Interrupt Response Latency Control 5 - package C10 */
90 msr.hi = 0;
91 msr.lo = IRTL_VALID | IRTL_32768_NS |
92 C_STATE_LATENCY_CONTROL_5_LIMIT;
93 wrmsr(MSR_C_STATE_LATENCY_CONTROL_5, msr);
94}
95
96/* All CPUs including BSP will run the following function. */
97void soc_core_init(struct device *cpu)
98{
99 /* Clear out pending MCEs */
100 /* TODO(adurbin): This should only be done on a cold boot. Also, some
101 * of these banks are core vs package scope. For now every CPU clears
102 * every bank. */
Subrata Banikf91344c2019-05-06 19:23:26 +0530103 mca_configure();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530104
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530105 enable_lapic_tpr();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530106
107 /* Configure c-state interrupt response time */
108 configure_c_states();
109
110 /* Configure Enhanced SpeedStep and Thermal Sensors */
111 configure_misc();
112
Aamir Bohra34508cd2018-04-19 18:03:46 +0530113 enable_pm_timer_emulation();
114
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530115 /* Enable Direct Cache Access */
116 configure_dca_cap();
117
118 /* Set energy policy */
119 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
120
121 /* Enable Turbo */
122 enable_turbo();
123}
124
125static void per_cpu_smm_trigger(void)
126{
127 /* Relocate the SMM handler. */
128 smm_relocate();
129}
130
131static void post_mp_init(void)
132{
133 /* Set Max Ratio */
134 cpu_set_max_ratio();
135
136 /*
137 * Now that all APs have been relocated as well as the BSP let SMIs
138 * start flowing.
139 */
Kyösti Mälkki040c5312020-05-31 20:03:11 +0300140 global_smi_enable();
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530141}
142
143static const struct mp_ops mp_ops = {
144 /*
145 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
146 * that are set prior to ramstage.
147 * Real MTRRs programming are being done after resource allocation.
148 */
149 .pre_mp_init = soc_fsp_load,
150 .get_cpu_count = get_cpu_count,
151 .get_smm_info = smm_info,
152 .get_microcode_info = get_microcode_info,
153 .pre_mp_smm_init = smm_initialize,
154 .per_cpu_smm_trigger = per_cpu_smm_trigger,
155 .relocation_handler = smm_relocation_handler,
156 .post_mp_init = post_mp_init,
157};
158
159void soc_init_cpus(struct bus *cpu_bus)
160{
Felix Held4dd7d112021-10-20 23:31:43 +0200161 /* TODO: Handle mp_init_with_smm failure? */
162 mp_init_with_smm(cpu_bus, &mp_ops);
Aamir Bohra3ee54bb2018-10-17 11:55:01 +0530163}