| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <device/device.h> |
| 5 |
#include <device/pci.h> |
| 6 |
#include <cpu/x86/mtrr.h> |
| 7 |
#include <cpu/x86/msr.h> |
| 8 |
#include <cpu/x86/mp.h> |
| 9 |
#include <cpu/intel/common/common.h> |
| 10 |
#include <cpu/intel/microcode.h> |
| 11 |
#include <cpu/intel/speedstep.h> |
| 12 |
#include <cpu/intel/turbo.h> |
| 13 |
#include <cpu/x86/name.h> |
| 14 |
#include <cpu/intel/smm_reloc.h> |
| 15 |
#include <intelblocks/cpulib.h> |
| 16 |
#include <intelblocks/fast_spi.h> |
| 17 |
#include <intelblocks/mp_init.h> |
| 18 |
#include <intelblocks/sgx.h> |
| 19 |
#include <soc/cpu.h> |
| 20 |
#include <soc/msr.h> |
| 21 |
#include <soc/pci_devs.h> |
| 22 |
#include <soc/ramstage.h> |
| 23 |
#include <soc/systemagent.h> |
| 24 |
#include <static.h> |
| 25 |
#include <types.h> |
| 26 |
|
| 27 |
#include "chip.h" |
| 28 |
|
| 29 |
bool cpu_soc_is_in_untrusted_mode(void) |
| 30 |
{ |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
if (!CONFIG(MAINBOARD_SUPPORTS_COFFEELAKE_CPU)) |
| 36 |
return false; |
| 37 |
|
| 38 |
|
| 39 |
msr_t msr = rdmsr(MSR_BIOS_DONE); |
| 40 |
return !!(msr.lo & ENABLE_IA_UNTRUSTED); |
| 41 |
} |
| 42 |
|
| 43 |
void cpu_soc_bios_done(void) |
| 44 |
{ |
| 45 |
if (!CONFIG(MAINBOARD_SUPPORTS_COFFEELAKE_CPU)) |
| 46 |
return; |
| 47 |
|
| 48 |
msr_t msr; |
| 49 |
|
| 50 |
msr = rdmsr(MSR_BIOS_DONE); |
| 51 |
msr.lo |= ENABLE_IA_UNTRUSTED; |
| 52 |
wrmsr(MSR_BIOS_DONE, msr); |
| 53 |
} |
| 54 |
|
| 55 |
static void configure_misc(void) |
| 56 |
{ |
| 57 |
config_t *conf = config_of_soc(); |
| 58 |
msr_t msr; |
| 59 |
|
| 60 |
msr = rdmsr(IA32_MISC_ENABLE); |
| 61 |
msr.lo |= (1 << 0); |
| 62 |
msr.lo |= (1 << 3); |
| 63 |
wrmsr(IA32_MISC_ENABLE, msr); |
| 64 |
|
| 65 |
|
| 66 |
cpu_set_eist(conf->eist_enable); |
| 67 |
|
| 68 |
|
| 69 |
msr.lo = 0; |
| 70 |
msr.hi = 0; |
| 71 |
wrmsr(IA32_THERM_INTERRUPT, msr); |
| 72 |
|
| 73 |
|
| 74 |
msr.lo = 1 << 4; |
| 75 |
msr.hi = 0; |
| 76 |
wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr); |
| 77 |
|
| 78 |
msr = rdmsr(MSR_POWER_CTL); |
| 79 |
msr.lo |= (1 << 0); |
| 80 |
msr.lo |= (1 << 18); |
| 81 |
msr.lo &= ~POWER_CTL_C1E_MASK; |
| 82 |
msr.lo |= (1 << 23); |
| 83 |
wrmsr(MSR_POWER_CTL, msr); |
| 84 |
} |
| 85 |
|
| 86 |
static void configure_c_states(void) |
| 87 |
{ |
| 88 |
msr_t msr; |
| 89 |
|
| 90 |
|
| 91 |
msr.hi = 0; |
| 92 |
msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_0_LIMIT; |
| 93 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_0, msr); |
| 94 |
|
| 95 |
|
| 96 |
msr.hi = 0; |
| 97 |
msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_1_LIMIT; |
| 98 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_1, msr); |
| 99 |
|
| 100 |
|
| 101 |
msr.hi = 0; |
| 102 |
msr.lo = IRTL_VALID | IRTL_1024_NS | C_STATE_LATENCY_CONTROL_2_LIMIT; |
| 103 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_2, msr); |
| 104 |
|
| 105 |
|
| 106 |
msr.hi = 0; |
| 107 |
msr.lo = IRTL_VALID | IRTL_1024_NS | |
| 108 |
C_STATE_LATENCY_CONTROL_3_LIMIT; |
| 109 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_3, msr); |
| 110 |
|
| 111 |
|
| 112 |
msr.hi = 0; |
| 113 |
msr.lo = IRTL_VALID | IRTL_1024_NS | |
| 114 |
C_STATE_LATENCY_CONTROL_4_LIMIT; |
| 115 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_4, msr); |
| 116 |
|
| 117 |
|
| 118 |
msr.hi = 0; |
| 119 |
msr.lo = IRTL_VALID | IRTL_1024_NS | |
| 120 |
C_STATE_LATENCY_CONTROL_5_LIMIT; |
| 121 |
wrmsr(MSR_C_STATE_LATENCY_CONTROL_5, msr); |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
void soc_core_init(struct device *cpu) |
| 126 |
{ |
| 127 |
|
| 128 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE)) |
| 129 |
prmrr_core_configure(); |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
mca_configure(); |
| 136 |
|
| 137 |
enable_lapic_tpr(); |
| 138 |
|
| 139 |
|
| 140 |
configure_c_states(); |
| 141 |
|
| 142 |
|
| 143 |
configure_misc(); |
| 144 |
|
| 145 |
set_aesni_lock(); |
| 146 |
|
| 147 |
|
| 148 |
enable_pm_timer_emulation(); |
| 149 |
|
| 150 |
|
| 151 |
configure_dca_cap(); |
| 152 |
|
| 153 |
|
| 154 |
set_energy_perf_bias(ENERGY_POLICY_NORMAL); |
| 155 |
|
| 156 |
|
| 157 |
enable_turbo(); |
| 158 |
} |
| 159 |
|
| 160 |
static void per_cpu_smm_trigger(void) |
| 161 |
{ |
| 162 |
|
| 163 |
smm_relocate(); |
| 164 |
} |
| 165 |
|
| 166 |
void smm_lock(void) |
| 167 |
{ |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
printk(BIOS_DEBUG, "Locking SMM.\n"); |
| 175 |
pci_io_write_config8(SA_DEVFN_ROOT, SMRAM, D_LCK | G_SMRAME | C_BASE_SEG); |
| 176 |
} |
| 177 |
|
| 178 |
static void vmx_configure(void *unused) |
| 179 |
{ |
| 180 |
set_feature_ctrl_vmx(); |
| 181 |
} |
| 182 |
|
| 183 |
static void fc_lock_configure(void *unused) |
| 184 |
{ |
| 185 |
set_feature_ctrl_lock(); |
| 186 |
} |
| 187 |
|
| 188 |
static void post_mp_init(void) |
| 189 |
{ |
| 190 |
bool failure = false; |
| 191 |
|
| 192 |
|
| 193 |
cpu_set_max_ratio(); |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
global_smi_enable_no_pwrbtn(); |
| 200 |
|
| 201 |
|
| 202 |
smm_lock(); |
| 203 |
|
| 204 |
if (mp_run_on_all_cpus(vmx_configure, NULL) != CB_SUCCESS) |
| 205 |
failure = true; |
| 206 |
|
| 207 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE)) |
| 208 |
if (mp_run_on_all_cpus(sgx_configure, NULL) != CB_SUCCESS) |
| 209 |
failure = true; |
| 210 |
|
| 211 |
if (mp_run_on_all_cpus(fc_lock_configure, NULL) != CB_SUCCESS) |
| 212 |
failure = true; |
| 213 |
|
| 214 |
if (failure) |
| 215 |
printk(BIOS_CRIT, "CRITICAL ERROR: MP post init failed\n"); |
| 216 |
} |
| 217 |
|
| 218 |
static void soc_fsp_load(void) |
| 219 |
{ |
| 220 |
fsps_load(); |
| 221 |
} |
| 222 |
|
| 223 |
static const struct mp_ops mp_ops = { |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
.pre_mp_init = soc_fsp_load, |
| 230 |
.get_cpu_count = get_cpu_count, |
| 231 |
.get_smm_info = smm_info, |
| 232 |
.get_microcode_info = get_microcode_info, |
| 233 |
.pre_mp_smm_init = smm_initialize, |
| 234 |
.per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 235 |
.relocation_handler = smm_relocation_handler, |
| 236 |
.post_mp_init = post_mp_init, |
| 237 |
}; |
| 238 |
|
| 239 |
void mp_init_cpus(struct bus *cpu_bus) |
| 240 |
{ |
| 241 |
|
| 242 |
mp_init_with_smm(cpu_bus, &mp_ops); |
| 243 |
|
| 244 |
|
| 245 |
configure_tcc_thermal_target(); |
| 246 |
} |
| 247 |
|
| 248 |
int soc_skip_ucode_update(u32 current_patch_id, u32 new_patch_id) |
| 249 |
{ |
| 250 |
msr_t msr1; |
| 251 |
msr_t msr2; |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
msr1 = rdmsr(MTRR_CAP_MSR); |
| 263 |
msr2 = rdmsr(MSR_PRMRR_PHYS_BASE); |
| 264 |
if (msr2.lo && (current_patch_id == new_patch_id - 1)) |
| 265 |
return 0; |
| 266 |
else |
| 267 |
return (msr1.lo & MTRR_CAP_PRMRR) && |
| 268 |
(current_patch_id == new_patch_id - 1); |
| 269 |
} |