blob: 8b845c004c7ceabc7bd84150570f74dfae0d34c2 [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Pratik Prajapati01eda282017-08-17 21:09:45 -07002
3#include <console/console.h>
4#include <device/pci.h>
Pratik Prajapati01eda282017-08-17 21:09:45 -07005#include <cpu/x86/lapic.h>
6#include <cpu/x86/mp.h>
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +02007#include <cpu/x86/msr.h>
Kyösti Mälkkifaf20d32019-08-14 05:41:41 +03008#include <cpu/intel/smm_reloc.h>
Pratik Prajapati01eda282017-08-17 21:09:45 -07009#include <cpu/intel/turbo.h>
10#include <intelblocks/cpulib.h>
11#include <intelblocks/mp_init.h>
Pratik Prajapati01eda282017-08-17 21:09:45 -070012#include <soc/cpu.h>
13#include <soc/msr.h>
14#include <soc/pci_devs.h>
Sumeet Pawnikarc896e92e2019-01-08 19:52:54 +053015#include <soc/systemagent.h>
Ronak Kanabar69a95652019-02-19 20:10:23 +053016#include <cpu/x86/mtrr.h>
17#include <cpu/intel/microcode.h>
Ronak Kanabara432f382019-03-16 21:26:43 +053018#include <cpu/intel/common/common.h>
Sumeet Pawnikarc896e92e2019-01-08 19:52:54 +053019
Elyes HAOUASc3385072019-03-21 15:38:06 +010020#include "chip.h"
21
Pratik Prajapati01eda282017-08-17 21:09:45 -070022static void soc_fsp_load(void)
23{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020024 fsps_load();
Pratik Prajapati01eda282017-08-17 21:09:45 -070025}
26
Pratik Prajapati01eda282017-08-17 21:09:45 -070027static void configure_misc(void)
28{
Pratik Prajapati01eda282017-08-17 21:09:45 -070029 msr_t msr;
30
Angel Ponsbda02b02020-09-28 01:10:40 +020031 config_t *conf = config_of_soc();
32
Pratik Prajapati01eda282017-08-17 21:09:45 -070033 msr = rdmsr(IA32_MISC_ENABLE);
34 msr.lo |= (1 << 0); /* Fast String enable */
35 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Matt Delco54e98942020-03-09 12:41:09 -070036 wrmsr(IA32_MISC_ENABLE, msr);
37
Subrata Banik6d569162019-04-10 12:19:27 +053038 /* Set EIST status */
39 cpu_set_eist(conf->eist_enable);
Pratik Prajapati01eda282017-08-17 21:09:45 -070040
41 /* Disable Thermal interrupts */
42 msr.lo = 0;
43 msr.hi = 0;
44 wrmsr(IA32_THERM_INTERRUPT, msr);
45
46 /* Enable package critical interrupt only */
47 msr.lo = 1 << 4;
48 msr.hi = 0;
49 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
50
51 /* Enable PROCHOT */
52 msr = rdmsr(MSR_POWER_CTL);
53 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input*/
54 msr.lo |= (1 << 23); /* Lock it */
55 wrmsr(MSR_POWER_CTL, msr);
56}
57
Pratik Prajapati01eda282017-08-17 21:09:45 -070058static void configure_c_states(void)
59{
60 msr_t msr;
61
Pratik Prajapati01eda282017-08-17 21:09:45 -070062 /* C-state Interrupt Response Latency Control 1 - package C6/C7 short */
63 msr.hi = 0;
Vaibhav Shankar66dbb0c2018-01-11 10:27:50 -080064 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_1_LIMIT;
Pratik Prajapati01eda282017-08-17 21:09:45 -070065 wrmsr(MSR_C_STATE_LATENCY_CONTROL_1, msr);
66
67 /* C-state Interrupt Response Latency Control 2 - package C6/C7 long */
68 msr.hi = 0;
Vaibhav Shankar66dbb0c2018-01-11 10:27:50 -080069 msr.lo = IRTL_VALID | IRTL_32768_NS | C_STATE_LATENCY_CONTROL_2_LIMIT;
Pratik Prajapati01eda282017-08-17 21:09:45 -070070 wrmsr(MSR_C_STATE_LATENCY_CONTROL_2, msr);
71
72 /* C-state Interrupt Response Latency Control 3 - package C8 */
73 msr.hi = 0;
Vaibhav Shankar66dbb0c2018-01-11 10:27:50 -080074 msr.lo = IRTL_VALID | IRTL_32768_NS |
Pratik Prajapati01eda282017-08-17 21:09:45 -070075 C_STATE_LATENCY_CONTROL_3_LIMIT;
76 wrmsr(MSR_C_STATE_LATENCY_CONTROL_3, msr);
77
78 /* C-state Interrupt Response Latency Control 4 - package C9 */
79 msr.hi = 0;
Vaibhav Shankar66dbb0c2018-01-11 10:27:50 -080080 msr.lo = IRTL_VALID | IRTL_32768_NS |
Pratik Prajapati01eda282017-08-17 21:09:45 -070081 C_STATE_LATENCY_CONTROL_4_LIMIT;
82 wrmsr(MSR_C_STATE_LATENCY_CONTROL_4, msr);
83
84 /* C-state Interrupt Response Latency Control 5 - package C10 */
85 msr.hi = 0;
Vaibhav Shankar66dbb0c2018-01-11 10:27:50 -080086 msr.lo = IRTL_VALID | IRTL_32768_NS |
Pratik Prajapati01eda282017-08-17 21:09:45 -070087 C_STATE_LATENCY_CONTROL_5_LIMIT;
88 wrmsr(MSR_C_STATE_LATENCY_CONTROL_5, msr);
89}
90
91/* All CPUs including BSP will run the following function. */
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +020092void soc_core_init(struct device *cpu)
Pratik Prajapati01eda282017-08-17 21:09:45 -070093{
94 /* Clear out pending MCEs */
Pratik Prajapati2ad1ddb2017-08-28 12:28:24 -070095 /* TODO(adurbin): This should only be done on a cold boot. Also, some
96 * of these banks are core vs package scope. For now every CPU clears
97 * every bank. */
Subrata Banikf91344c2019-05-06 19:23:26 +053098 mca_configure();
Pratik Prajapati01eda282017-08-17 21:09:45 -070099
100 /* Enable the local CPU apics */
101 enable_lapic_tpr();
102 setup_lapic();
103
104 /* Configure c-state interrupt response time */
105 configure_c_states();
106
107 /* Configure Enhanced SpeedStep and Thermal Sensors */
108 configure_misc();
109
Michael Niewöhner5611cfd2020-10-11 13:04:02 +0200110 set_aesni_lock();
111
Lijian Zhao0f5d7b92018-10-05 10:31:11 -0700112 enable_pm_timer_emulation();
113
Pratik Prajapati01eda282017-08-17 21:09:45 -0700114 /* Enable Direct Cache Access */
115 configure_dca_cap();
116
117 /* Set energy policy */
118 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
119
120 /* Enable Turbo */
121 enable_turbo();
Ronak Kanabara432f382019-03-16 21:26:43 +0530122
123 /* Enable Vmx */
124 set_vmx_and_lock();
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700125}
Pratik Prajapati01eda282017-08-17 21:09:45 -0700126
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700127static void per_cpu_smm_trigger(void)
128{
129 /* Relocate the SMM handler. */
130 smm_relocate();
Pratik Prajapati01eda282017-08-17 21:09:45 -0700131}
132
Pratik Prajapati01eda282017-08-17 21:09:45 -0700133static void post_mp_init(void)
134{
135 /* Set Max Ratio */
136 cpu_set_max_ratio();
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700137
138 /*
139 * Now that all APs have been relocated as well as the BSP let SMIs
140 * start flowing.
141 */
Kyösti Mälkki040c5312020-05-31 20:03:11 +0300142 global_smi_enable_no_pwrbtn();
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700143
144 /* Lock down the SMRAM space. */
145 smm_lock();
Pratik Prajapati01eda282017-08-17 21:09:45 -0700146}
147
148static const struct mp_ops mp_ops = {
149 /*
150 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
151 * that are set prior to ramstage.
152 * Real MTRRs programming are being done after resource allocation.
153 */
154 .pre_mp_init = soc_fsp_load,
155 .get_cpu_count = get_cpu_count,
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700156 .get_smm_info = smm_info,
Pratik Prajapati01eda282017-08-17 21:09:45 -0700157 .get_microcode_info = get_microcode_info,
Lijian Zhaof0eb9992017-09-14 14:51:12 -0700158 .pre_mp_smm_init = smm_initialize,
159 .per_cpu_smm_trigger = per_cpu_smm_trigger,
160 .relocation_handler = smm_relocation_handler,
Pratik Prajapati01eda282017-08-17 21:09:45 -0700161 .post_mp_init = post_mp_init,
162};
163
164void soc_init_cpus(struct bus *cpu_bus)
165{
166 if (mp_init_with_smm(cpu_bus, &mp_ops))
167 printk(BIOS_ERR, "MP initialization failure.\n");
John Su31269642019-01-10 14:53:26 +0800168
169 /* Thermal throttle activation offset */
Sumeet R Pawnikar360684b2020-06-18 15:56:11 +0530170 configure_tcc_thermal_target();
Pratik Prajapati01eda282017-08-17 21:09:45 -0700171}
Ronak Kanabar69a95652019-02-19 20:10:23 +0530172
173int soc_skip_ucode_update(u32 current_patch_id, u32 new_patch_id)
174{
175 msr_t msr1;
176 msr_t msr2;
177
178 /*
Ronak Kanabar69a95652019-02-19 20:10:23 +0530179 * If PRMRR/SGX is supported the FIT microcode load will set the msr
180 * 0x08b with the Patch revision id one less than the id in the
181 * microcode binary. The PRMRR support is indicated in the MSR
182 * MTRRCAP[12]. If SGX is not enabled, check and avoid reloading the
183 * same microcode during CPU initialization. If SGX is enabled, as
184 * part of SGX BIOS initialization steps, the same microcode needs to
185 * be reloaded after the core PRMRR MSRs are programmed.
186 */
187 msr1 = rdmsr(MTRR_CAP_MSR);
188 msr2 = rdmsr(MSR_PRMRR_PHYS_BASE);
189 if (msr2.lo && (current_patch_id == new_patch_id - 1))
190 return 0;
191
Kyösti Mälkkieadd2512020-06-11 09:52:45 +0300192 return (msr1.lo & MTRR_CAP_PRMRR) &&
Ronak Kanabar69a95652019-02-19 20:10:23 +0530193 (current_patch_id == new_patch_id - 1);
194}