coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
cpu.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <device/pci.h>
4 #include <cpu/x86/mp.h>
5 #include <cpu/x86/msr.h>
6 #include <cpu/intel/smm_reloc.h>
7 #include <cpu/intel/turbo.h>
9 #include <fsp/api.h>
10 #include <intelblocks/cpulib.h>
11 #include <intelblocks/mp_init.h>
12 #include <intelblocks/msr.h>
13 #include <soc/cpu.h>
14 #include <soc/msr.h>
15 #include <soc/pci_devs.h>
16 #include <soc/soc_chip.h>
17 #include <types.h>
18 
20 {
21  msr_t msr;
22 
23  msr = rdmsr(MSR_BIOS_DONE);
24  return !!(msr.lo & ENABLE_IA_UNTRUSTED);
25 }
26 
27 static void soc_fsp_load(void)
28 {
29  fsps_load();
30 }
31 
32 static 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;
50 
51  /* Enable package critical interrupt only */
52  msr.lo = 1 << 4;
53  msr.hi = 0;
55 
56  /* Enable PROCHOT */
57  msr = rdmsr(MSR_POWER_CTL);
58  msr.lo |= (1 << 0); /* Enable Bi-directional PROCHOT as an input */
59  msr.lo |= (1 << 23); /* Lock it */
60  wrmsr(MSR_POWER_CTL, msr);
61 }
62 
63 /* All CPUs including BSP will run the following function. */
64 void 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 
73 
74  /* Configure Enhanced SpeedStep and Thermal Sensors */
76 
78 
79  /* Enable Direct Cache Access */
81 
82  /* Set energy policy */
84 
85  /* Enable Turbo */
86  enable_turbo();
87 }
88 
89 static void per_cpu_smm_trigger(void)
90 {
91  /* Relocate the SMM handler. */
92  smm_relocate();
93 }
94 
95 static void post_mp_init(void)
96 {
97  /* Set Max Ratio */
99 
100  /*
101  * 1. Now that all APs have been relocated as well as the BSP let SMIs
102  * start flowing.
103  * 2. Skip enabling power button SMI and enable it after BS_CHIPS_INIT
104  * to avoid shutdown hang due to lack of init on certain IP in FSP-S.
105  */
107 }
108 
109 static const struct mp_ops mp_ops = {
110  /*
111  * Skip Pre MP init MTRR programming as MTRRs are mirrored from BSP,
112  * that are set prior to ramstage.
113  * Real MTRRs programming are being done after resource allocation.
114  */
116  .get_cpu_count = get_cpu_count,
117  .get_smm_info = smm_info,
118  .get_microcode_info = get_microcode_info,
119  .pre_mp_smm_init = smm_initialize,
120  .per_cpu_smm_trigger = per_cpu_smm_trigger,
121  .relocation_handler = smm_relocation_handler,
122  .post_mp_init = post_mp_init,
123 };
124 
125 void soc_init_cpus(struct bus *cpu_bus)
126 {
127  /* TODO: Handle mp_init_with_smm failure? */
128  mp_init_with_smm(cpu_bus, &mp_ops);
129 
130  /* Thermal throttle activation offset */
132 }
void configure_dca_cap(void)
Definition: common_init.c:172
void set_energy_perf_bias(u8 policy)
Definition: common_init.c:178
void enable_lapic_tpr(void)
Definition: common_init.c:167
#define MSR_POWER_CTL
Definition: haswell.h:56
void smm_relocate(void)
Definition: smmrelocate.c:247
void smm_relocation_handler(int cpu, uintptr_t curr_smbase, uintptr_t staggered_smbase)
Definition: smmrelocate.c:90
void smm_initialize(void)
Definition: smmrelocate.c:227
void smm_info(uintptr_t *perm_smbase, size_t *perm_smsize, size_t *smm_save_state_size)
Definition: smmrelocate.c:213
enum cb_err mp_init_with_smm(struct bus *cpu_bus, const struct mp_ops *mp_ops)
Definition: mp_init.c:1145
void mca_configure(void)
Definition: cpulib.c:376
void cpu_set_eist(bool eist_status)
Definition: cpulib.c:250
void cpu_set_max_ratio(void)
Definition: cpulib.c:45
void configure_tcc_thermal_target(void)
Definition: cpulib.c:317
void fsps_load(void)
Definition: silicon_init.c:204
static __always_inline msr_t rdmsr(unsigned int index)
Definition: msr.h:146
#define IA32_MISC_ENABLE
Definition: msr.h:45
#define IA32_PACKAGE_THERM_INTERRUPT
Definition: msr.h:53
#define ENERGY_POLICY_NORMAL
Definition: msr.h:50
static __always_inline void wrmsr(unsigned int index, msr_t msr)
Definition: msr.h:157
#define IA32_THERM_INTERRUPT
Definition: msr.h:44
void global_smi_enable_no_pwrbtn(void)
Definition: smm.c:69
#define config_of_soc()
Definition: device.h:394
void enable_pm_timer_emulation(void)
int get_cpu_count(void)
Definition: cpu.c:10
void soc_init_cpus(struct bus *cpu_bus)
Definition: cpu.c:183
bool cpu_soc_is_in_untrusted_mode(void)
Definition: cpu.c:33
void soc_core_init(struct device *cpu)
Definition: cpu.c:104
#define MSR_BIOS_DONE
Definition: msr.h:8
#define ENABLE_IA_UNTRUSTED
Definition: msr.h:9
void get_microcode_info(const void **microcode, int *parallel)
Definition: cpu.c:180
static void configure_misc(void)
Definition: cpu.c:32
static void soc_fsp_load(void)
Definition: cpu.c:27
static void per_cpu_smm_trigger(void)
Definition: cpu.c:89
static void post_mp_init(void)
Definition: cpu.c:95
Definition: device.h:76
Definition: device.h:107
Definition: mp.h:20
void(* pre_mp_init)(void)
Definition: mp.h:27
unsigned int hi
Definition: msr.h:112
unsigned int lo
Definition: msr.h:111
void enable_turbo(void)
Definition: turbo.c:89