blob: 3d0f0e90ad6441fa397f4d2e01f662b3626904c5 [file] [log] [blame]
Angel Pons16f6aa82020-04-05 15:47:21 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Subrata Banik91e89c52019-11-01 18:30:01 +05302
3/*
4 * This file is created based on Intel Tiger Lake Processor CPU Datasheet
5 * Document number: 575683
6 * Chapter number: 15
7 */
8
Subrata Banik91e89c52019-11-01 18:30:01 +05309#include <device/pci.h>
Subrata Banik91e89c52019-11-01 18:30:01 +053010#include <cpu/x86/mp.h>
11#include <cpu/x86/msr.h>
12#include <cpu/intel/smm_reloc.h>
13#include <cpu/intel/turbo.h>
Michael Niewöhner10ae1cf2020-10-11 14:05:32 +020014#include <cpu/intel/common/common.h>
Subrata Banik91e89c52019-11-01 18:30:01 +053015#include <fsp/api.h>
16#include <intelblocks/cpulib.h>
17#include <intelblocks/mp_init.h>
18#include <intelblocks/msr.h>
Subrata Banik91e89c52019-11-01 18:30:01 +053019#include <soc/cpu.h>
20#include <soc/msr.h>
21#include <soc/pci_devs.h>
Subrata Banik91e89c52019-11-01 18:30:01 +053022#include <soc/soc_chip.h>
Felix Heldd27ef5b2021-10-20 20:18:12 +020023#include <types.h>
Subrata Banik91e89c52019-11-01 18:30:01 +053024
Subrata Banik56ab8e22022-01-07 13:40:19 +000025bool cpu_soc_is_in_untrusted_mode(void)
26{
27 msr_t msr;
28
29 msr = rdmsr(MSR_BIOS_DONE);
30 return !!(msr.lo & ENABLE_IA_UNTRUSTED);
31}
32
Subrata Banik37a55d12022-05-30 18:11:12 +000033void cpu_soc_bios_done(void)
34{
35 msr_t msr;
36
37 msr = rdmsr(MSR_BIOS_DONE);
38 msr.lo |= ENABLE_IA_UNTRUSTED;
39 wrmsr(MSR_BIOS_DONE, msr);
40}
41
Subrata Banik91e89c52019-11-01 18:30:01 +053042static void soc_fsp_load(void)
43{
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +020044 fsps_load();
Subrata Banik91e89c52019-11-01 18:30:01 +053045}
46
Subrata Banik91e89c52019-11-01 18:30:01 +053047static void configure_misc(void)
48{
49 msr_t msr;
50
51 config_t *conf = config_of_soc();
52
53 msr = rdmsr(IA32_MISC_ENABLE);
54 msr.lo |= (1 << 0); /* Fast String enable */
55 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Matt Delco54e98942020-03-09 12:41:09 -070056 wrmsr(IA32_MISC_ENABLE, msr);
57
Subrata Banik91e89c52019-11-01 18:30:01 +053058 /* Set EIST status */
59 cpu_set_eist(conf->eist_enable);
Subrata Banik91e89c52019-11-01 18:30:01 +053060
61 /* Disable Thermal interrupts */
62 msr.lo = 0;
63 msr.hi = 0;
64 wrmsr(IA32_THERM_INTERRUPT, msr);
65
66 /* Enable package critical interrupt only */
67 msr.lo = 1 << 4;
68 msr.hi = 0;
69 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
70
71 /* Enable PROCHOT */
72 msr = rdmsr(MSR_POWER_CTL);
Angel Pons4d794bd2021-10-11 14:00:54 +020073 msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */
Subrata Banik91e89c52019-11-01 18:30:01 +053074 msr.lo |= (1 << 23); /* Lock it */
75 wrmsr(MSR_POWER_CTL, msr);
76}
77
Subrata Banik91e89c52019-11-01 18:30:01 +053078/* All CPUs including BSP will run the following function. */
79void soc_core_init(struct device *cpu)
80{
81 /* Clear out pending MCEs */
82 /* TODO(adurbin): This should only be done on a cold boot. Also, some
83 * of these banks are core vs package scope. For now every CPU clears
84 * every bank. */
85 mca_configure();
86
Subrata Banik91e89c52019-11-01 18:30:01 +053087 enable_lapic_tpr();
Subrata Banik91e89c52019-11-01 18:30:01 +053088
Subrata Banik91e89c52019-11-01 18:30:01 +053089 /* Configure Enhanced SpeedStep and Thermal Sensors */
90 configure_misc();
91
Subrata Banik91e89c52019-11-01 18:30:01 +053092 enable_pm_timer_emulation();
93
94 /* Enable Direct Cache Access */
95 configure_dca_cap();
96
97 /* Set energy policy */
98 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
99
100 /* Enable Turbo */
101 enable_turbo();
102}
103
104static void per_cpu_smm_trigger(void)
105{
106 /* Relocate the SMM handler. */
107 smm_relocate();
108}
109
110static void post_mp_init(void)
111{
112 /* Set Max Ratio */
113 cpu_set_max_ratio();
114
115 /*
Kane Chen3aee3ad2021-05-04 09:53:38 +0800116 * 1. Now that all APs have been relocated as well as the BSP let SMIs
Subrata Banik91e89c52019-11-01 18:30:01 +0530117 * start flowing.
Kane Chen3aee3ad2021-05-04 09:53:38 +0800118 * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT
119 * to avoid shutdown hang due to lack of init on certain IP in FSP-S.
Subrata Banik91e89c52019-11-01 18:30:01 +0530120 */
Kane Chen3aee3ad2021-05-04 09:53:38 +0800121 global_smi_enable_no_pwrbtn();
Subrata Banik91e89c52019-11-01 18:30:01 +0530122}
123
124static const struct mp_ops mp_ops = {
125 /*
126 * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
127 * that are set prior to ramstage.
128 * Real MTRRs programming are being done after resource allocation.
129 */
130 .pre_mp_init = soc_fsp_load,
131 .get_cpu_count = get_cpu_count,
132 .get_smm_info = smm_info,
133 .get_microcode_info = get_microcode_info,
134 .pre_mp_smm_init = smm_initialize,
135 .per_cpu_smm_trigger = per_cpu_smm_trigger,
136 .relocation_handler = smm_relocation_handler,
137 .post_mp_init = post_mp_init,
138};
139
Arthur Heymans829e8e62023-01-30 19:09:34 +0100140void mp_init_cpus(struct bus *cpu_bus)
Subrata Banik91e89c52019-11-01 18:30:01 +0530141{
Felix Held4dd7d112021-10-20 23:31:43 +0200142 /* TODO: Handle mp_init_with_smm failure? */
143 mp_init_with_smm(cpu_bus, &mp_ops);
Sumeet R Pawnikar6caa4762020-06-18 16:50:58 +0530144
145 /* Thermal throttle activation offset */
146 configure_tcc_thermal_target();
Subrata Banik91e89c52019-11-01 18:30:01 +0530147}