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 static 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;
71 
72  /* C-state Interrupt Response Latency Control 2 - package C6/C7 long */
73  msr.hi = 0;
76 
77  /* C-state Interrupt Response Latency Control 3 - package C8 */
78  msr.hi = 0;
79  msr.lo = IRTL_VALID | IRTL_32768_NS |
82 
83  /* C-state Interrupt Response Latency Control 4 - package C9 */
84  msr.hi = 0;
85  msr.lo = IRTL_VALID | IRTL_32768_NS |
88 
89  /* C-state Interrupt Response Latency Control 5 - package C10 */
90  msr.hi = 0;
91  msr.lo = IRTL_VALID | IRTL_32768_NS |
94 }
95 
96 /* All CPUs including BSP will run the following function. */
97 void 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. */
103  mca_configure();
104 
106 
107  /* Configure c-state interrupt response time */
109 
110  /* Configure Enhanced SpeedStep and Thermal Sensors */
111  configure_misc();
112 
114 
115  /* Enable Direct Cache Access */
117 
118  /* Set energy policy */
120 
121  /* Enable Turbo */
122  enable_turbo();
123 }
124 
125 static void per_cpu_smm_trigger(void)
126 {
127  /* Relocate the SMM handler. */
128  smm_relocate();
129 }
130 
131 static void post_mp_init(void)
132 {
133  /* Set Max Ratio */
135 
136  /*
137  * Now that all APs have been relocated as well as the BSP let SMIs
138  * start flowing.
139  */
141 }
142 
143 static 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  */
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 
159 void soc_init_cpus(struct bus *cpu_bus)
160 {
161  /* TODO: Handle mp_init_with_smm failure? */
162  mp_init_with_smm(cpu_bus, &mp_ops);
163 }
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_C_STATE_LATENCY_CONTROL_1
Definition: haswell.h:64
#define IRTL_32768_NS
Definition: haswell.h:73
#define C_STATE_LATENCY_CONTROL_4_LIMIT
Definition: haswell.h:114
#define MSR_POWER_CTL
Definition: haswell.h:56
#define C_STATE_LATENCY_CONTROL_2_LIMIT
Definition: haswell.h:112
#define C_STATE_LATENCY_CONTROL_3_LIMIT
Definition: haswell.h:113
#define IRTL_VALID
Definition: haswell.h:69
#define C_STATE_LATENCY_CONTROL_1_LIMIT
Definition: haswell.h:111
#define MSR_C_STATE_LATENCY_CONTROL_5
Definition: haswell.h:68
#define C_STATE_LATENCY_CONTROL_5_LIMIT
Definition: haswell.h:115
#define MSR_C_STATE_LATENCY_CONTROL_2
Definition: haswell.h:65
#define MSR_C_STATE_LATENCY_CONTROL_3
Definition: haswell.h:66
#define MSR_C_STATE_LATENCY_CONTROL_4
Definition: haswell.h:67
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 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(void)
Set the EOS bit and enable SMI generation from southbridge.
Definition: smi_util.c:60
#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_c_states(void)
Definition: cpu.c:63
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:125
static void post_mp_init(void)
Definition: cpu.c:131
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