blob: 3e0dae191ad3c809375377ed17a9fb3010b66f94 [file] [log] [blame]
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07003#include <cpu/intel/smm_reloc.h>
4#include <cpu/intel/turbo.h>
Michael Niewöhner10ae1cf2020-10-11 14:05:32 +02005#include <cpu/intel/common/common.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -07006#include <cpu/x86/mp.h>
7#include <cpu/x86/msr.h>
8#include <device/pci.h>
9#include <fsp/api.h>
10#include <intelblocks/cpulib.h>
11#include <intelblocks/mp_init.h>
12#include <intelblocks/msr.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070013#include <soc/cpu.h>
14#include <soc/msr.h>
15#include <soc/pci_devs.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070016#include <soc/soc_chip.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020017#include <types.h>
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070018
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
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070027static void soc_fsp_load(void)
28{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020029 fsps_load();
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070030}
31
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070032static void configure_misc(void)
33{
34 msr_t msr;
35
36 config_t *conf = config_of_soc();
37
38 msr = rdmsr(IA32_MISC_ENABLE);
39 msr.lo |= (1 << 0); /* Fast String enable */
40 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
41 wrmsr(IA32_MISC_ENABLE, msr);
42
43 /* Set EIST status */
44 cpu_set_eist(conf->eist_enable);
45
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 */
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070059 msr.lo |= (1 << 23); /* Lock it */
60 wrmsr(MSR_POWER_CTL, msr);
61}
62
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070063/* All CPUs including BSP will run the following function. */
64void soc_core_init(struct device *cpu)
65{
66 /* Clear out pending MCEs */
67 /* TODO(adurbin): This should only be done on a cold boot. Also, some
68 * of these banks are core vs package scope. For now every CPU clears
69 * every bank. */
70 mca_configure();
71
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070072 enable_lapic_tpr();
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070073
74 /* Configure Enhanced SpeedStep and Thermal Sensors */
75 configure_misc();
76
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -070077 enable_pm_timer_emulation();
78
79 /* Enable Direct Cache Access */
80 configure_dca_cap();
81
82 /* Set energy policy */
83 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
84
85 /* Enable Turbo */
86 enable_turbo();
87}
88
89static void per_cpu_smm_trigger(void)
90{
91 /* Relocate the SMM handler. */
92 smm_relocate();
93}
94
95static void post_mp_init(void)
96{
97 /* Set Max Ratio */
98 cpu_set_max_ratio();
99
100 /*
101 * Now that all APs have been relocated as well as the BSP let SMIs
102 * start flowing.
103 */
104 global_smi_enable();
105}
106
107static const struct mp_ops mp_ops = {
108 /*
109 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
110 * that are set prior to ramstage.
111 * Real MTRRs programming are being done after resource allocation.
112 */
113 .pre_mp_init = soc_fsp_load,
114 .get_cpu_count = get_cpu_count,
115 .get_smm_info = smm_info,
116 .get_microcode_info = get_microcode_info,
117 .pre_mp_smm_init = smm_initialize,
118 .per_cpu_smm_trigger = per_cpu_smm_trigger,
119 .relocation_handler = smm_relocation_handler,
120 .post_mp_init = post_mp_init,
121};
122
123void soc_init_cpus(struct bus *cpu_bus)
124{
Felix Held4dd7d112021-10-20 23:31:43 +0200125 /* TODO: Handle mp_init_with_smm failure? */
126 mp_init_with_smm(cpu_bus, &mp_ops);
Tan, Lean Sheng05dfe312020-08-25 20:40:17 -0700127
128 /* Thermal throttle activation offset */
129 configure_tcc_thermal_target();
130}