| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi.h> |
| 4 |
#include <assert.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include "chip.h" |
| 7 |
#include <cpu/cpu.h> |
| 8 |
#include <cpu/x86/mp.h> |
| 9 |
#include <cpu/intel/microcode.h> |
| 10 |
#include <cpu/intel/turbo.h> |
| 11 |
#include <cpu/intel/common/common.h> |
| 12 |
#include <cpu/x86/msr.h> |
| 13 |
#include <cpu/x86/mtrr.h> |
| 14 |
#include <cpu/x86/smm.h> |
| 15 |
#include <cpu/intel/em64t100_save_state.h> |
| 16 |
#include <cpu/intel/smm_reloc.h> |
| 17 |
#include <device/device.h> |
| 18 |
#include <device/pci.h> |
| 19 |
#include <fsp/api.h> |
| 20 |
#include <intelblocks/cpulib.h> |
| 21 |
#include <intelblocks/fast_spi.h> |
| 22 |
#include <intelblocks/mp_init.h> |
| 23 |
#include <intelblocks/msr.h> |
| 24 |
#include <intelblocks/sgx.h> |
| 25 |
#include <reg_script.h> |
| 26 |
#include <soc/cpu.h> |
| 27 |
#include <soc/iomap.h> |
| 28 |
#include <soc/pci_devs.h> |
| 29 |
#include <soc/pm.h> |
| 30 |
#include <types.h> |
| 31 |
|
| 32 |
static const struct reg_script core_msr_script[] = { |
| 33 |
#if !CONFIG(SOC_INTEL_GEMINILAKE) |
| 34 |
|
| 35 |
REG_MSR_WRITE(MSR_PKG_CST_CONFIG_CONTROL, |
| 36 |
(PKG_C_STATE_LIMIT_C2_MASK | CORE_C_STATE_LIMIT_C10_MASK |
| 37 |
| IO_MWAIT_REDIRECT_MASK | CST_CFG_LOCK_MASK)), |
| 38 |
|
| 39 |
REG_MSR_WRITE(MSR_PMG_IO_CAPTURE_BASE, |
| 40 |
(ACPI_PMIO_CST_REG | (PMG_IO_BASE_CST_RNG_BLK_SIZE << 16))), |
| 41 |
|
| 42 |
REG_MSR_RMW(IA32_MISC_ENABLE, ~MONITOR_MWAIT_DIS_MASK, 0), |
| 43 |
#endif |
| 44 |
|
| 45 |
REG_MSR_RMW(MSR_POWER_CTL, ~POWER_CTL_C1E_MASK, 0), |
| 46 |
REG_SCRIPT_END |
| 47 |
}; |
| 48 |
|
| 49 |
bool cpu_soc_is_in_untrusted_mode(void) |
| 50 |
{ |
| 51 |
msr_t msr; |
| 52 |
|
| 53 |
msr = rdmsr(MSR_POWER_MISC); |
| 54 |
return !!(msr.lo & ENABLE_IA_UNTRUSTED); |
| 55 |
} |
| 56 |
|
| 57 |
void cpu_soc_bios_done(void) |
| 58 |
{ |
| 59 |
msr_t msr; |
| 60 |
|
| 61 |
msr = rdmsr(MSR_POWER_MISC); |
| 62 |
msr.lo |= ENABLE_IA_UNTRUSTED; |
| 63 |
wrmsr(MSR_POWER_MISC, msr); |
| 64 |
} |
| 65 |
|
| 66 |
void soc_core_init(struct device *cpu) |
| 67 |
{ |
| 68 |
|
| 69 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE)) |
| 70 |
prmrr_core_configure(); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE) || acpi_get_sleep_type() == ACPI_S5) |
| 76 |
mca_configure(); |
| 77 |
|
| 78 |
|
| 79 |
reg_script_run(core_msr_script); |
| 80 |
|
| 81 |
set_aesni_lock(); |
| 82 |
|
| 83 |
|
| 84 |
set_vmx_and_lock(); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
enable_pm_timer_emulation(); |
| 92 |
|
| 93 |
|
| 94 |
if (CONFIG(SOC_INTEL_DISABLE_POWER_LIMITS)) { |
| 95 |
cpu_set_p_state_to_max_non_turbo_ratio(); |
| 96 |
|
| 97 |
cpu_set_eist(false); |
| 98 |
} else if (CONFIG(SOC_INTEL_SET_MIN_CLOCK_RATIO)) { |
| 99 |
cpu_set_p_state_to_min_clock_ratio(); |
| 100 |
|
| 101 |
cpu_set_eist(false); |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
#if !CONFIG(SOC_INTEL_COMMON_BLOCK_CPU_MPINIT) |
| 106 |
static void soc_init_core(struct device *cpu) |
| 107 |
{ |
| 108 |
soc_core_init(cpu); |
| 109 |
} |
| 110 |
|
| 111 |
static struct device_operations cpu_dev_ops = { |
| 112 |
.init = soc_init_core, |
| 113 |
}; |
| 114 |
|
| 115 |
static const struct cpu_device_id cpu_table[] = { |
| 116 |
{ X86_VENDOR_INTEL, CPUID_APOLLOLAKE_A0, CPUID_EXACT_MATCH_MASK }, |
| 117 |
{ X86_VENDOR_INTEL, CPUID_APOLLOLAKE_B0, CPUID_EXACT_MATCH_MASK }, |
| 118 |
{ X86_VENDOR_INTEL, CPUID_APOLLOLAKE_E0, CPUID_EXACT_MATCH_MASK }, |
| 119 |
{ X86_VENDOR_INTEL, CPUID_GLK_A0, CPUID_EXACT_MATCH_MASK }, |
| 120 |
{ X86_VENDOR_INTEL, CPUID_GLK_B0, CPUID_EXACT_MATCH_MASK }, |
| 121 |
{ X86_VENDOR_INTEL, CPUID_GLK_R0, CPUID_EXACT_MATCH_MASK }, |
| 122 |
CPU_TABLE_END |
| 123 |
}; |
| 124 |
|
| 125 |
static const struct cpu_driver driver __cpu_driver = { |
| 126 |
.ops = &cpu_dev_ops, |
| 127 |
.id_table = cpu_table, |
| 128 |
}; |
| 129 |
#endif |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
struct smm_relocation_attrs { |
| 135 |
uint32_t smbase; |
| 136 |
uint32_t smrr_base; |
| 137 |
uint32_t smrr_mask; |
| 138 |
}; |
| 139 |
|
| 140 |
static struct smm_relocation_attrs relo_attrs; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
static void pre_mp_init(void) |
| 160 |
{ |
| 161 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_CPU_MPINIT)) { |
| 162 |
fsps_load(); |
| 163 |
return; |
| 164 |
} |
| 165 |
x86_setup_mtrrs_with_detect(); |
| 166 |
x86_mtrr_check(); |
| 167 |
} |
| 168 |
|
| 169 |
#if !CONFIG(SOC_INTEL_COMMON_BLOCK_CPU_MPINIT) |
| 170 |
static void read_cpu_topology(unsigned int *num_phys, unsigned int *num_virt) |
| 171 |
{ |
| 172 |
msr_t msr; |
| 173 |
msr = rdmsr(MSR_CORE_THREAD_COUNT); |
| 174 |
*num_virt = (msr.lo >> 0) & 0xffff; |
| 175 |
*num_phys = (msr.lo >> 16) & 0xffff; |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
int get_cpu_count(void) |
| 180 |
{ |
| 181 |
unsigned int num_virt_cores, num_phys_cores; |
| 182 |
|
| 183 |
read_cpu_topology(&num_phys_cores, &num_virt_cores); |
| 184 |
|
| 185 |
printk(BIOS_DEBUG, "Detected %u core, %u thread CPU.\n", |
| 186 |
num_phys_cores, num_virt_cores); |
| 187 |
|
| 188 |
return num_virt_cores; |
| 189 |
} |
| 190 |
|
| 191 |
void get_microcode_info(const void **microcode, int *parallel) |
| 192 |
{ |
| 193 |
*microcode = intel_microcode_find(); |
| 194 |
*parallel = 1; |
| 195 |
|
| 196 |
|
| 197 |
intel_microcode_load_unlocked(*microcode); |
| 198 |
} |
| 199 |
#endif |
| 200 |
|
| 201 |
static void get_smm_info(uintptr_t *perm_smbase, size_t *perm_smsize, |
| 202 |
size_t *smm_save_state_size) |
| 203 |
{ |
| 204 |
uintptr_t smm_base; |
| 205 |
size_t smm_size; |
| 206 |
uintptr_t handler_base; |
| 207 |
size_t handler_size; |
| 208 |
|
| 209 |
|
| 210 |
const uint32_t rmask = ~((1 << 12) - 1); |
| 211 |
|
| 212 |
|
| 213 |
smm_region(&smm_base, &smm_size); |
| 214 |
smm_subregion(SMM_SUBREGION_HANDLER, &handler_base, &handler_size); |
| 215 |
|
| 216 |
relo_attrs.smbase = smm_base; |
| 217 |
relo_attrs.smrr_base = relo_attrs.smbase | MTRR_TYPE_WRBACK; |
| 218 |
relo_attrs.smrr_mask = ~(smm_size - 1) & rmask; |
| 219 |
relo_attrs.smrr_mask |= MTRR_PHYS_MASK_VALID; |
| 220 |
|
| 221 |
*perm_smbase = handler_base; |
| 222 |
*perm_smsize = handler_size; |
| 223 |
*smm_save_state_size = sizeof(em64t100_smm_state_save_area_t); |
| 224 |
} |
| 225 |
|
| 226 |
static void relocation_handler(int cpu, uintptr_t curr_smbase, |
| 227 |
uintptr_t staggered_smbase) |
| 228 |
{ |
| 229 |
msr_t smrr; |
| 230 |
em64t100_smm_state_save_area_t *smm_state; |
| 231 |
|
| 232 |
smrr.lo = relo_attrs.smrr_base; |
| 233 |
smrr.hi = 0; |
| 234 |
wrmsr(IA32_SMRR_PHYS_BASE, smrr); |
| 235 |
smrr.lo = relo_attrs.smrr_mask; |
| 236 |
smrr.hi = 0; |
| 237 |
wrmsr(IA32_SMRR_PHYS_MASK, smrr); |
| 238 |
smm_state = (void *)(SMM_EM64T100_SAVE_STATE_OFFSET + curr_smbase); |
| 239 |
smm_state->smbase = staggered_smbase; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
static void post_mp_init(void) |
| 250 |
{ |
| 251 |
global_smi_enable(); |
| 252 |
|
| 253 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_SGX_ENABLE)) |
| 254 |
mp_run_on_all_cpus(sgx_configure, NULL); |
| 255 |
} |
| 256 |
|
| 257 |
static const struct mp_ops mp_ops = { |
| 258 |
.pre_mp_init = pre_mp_init, |
| 259 |
.get_cpu_count = get_cpu_count, |
| 260 |
.get_smm_info = get_smm_info, |
| 261 |
.get_microcode_info = get_microcode_info, |
| 262 |
.pre_mp_smm_init = smm_southbridge_clear_state, |
| 263 |
.relocation_handler = relocation_handler, |
| 264 |
.post_mp_init = post_mp_init, |
| 265 |
}; |
| 266 |
|
| 267 |
void mp_init_cpus(struct bus *cpu_bus) |
| 268 |
{ |
| 269 |
|
| 270 |
|
| 271 |
mp_init_with_smm(cpu_bus, &mp_ops); |
| 272 |
|
| 273 |
|
| 274 |
if (CONFIG(SOC_INTEL_COMMON_BLOCK_CPU_MPINIT)) |
| 275 |
return; |
| 276 |
|
| 277 |
|
| 278 |
if (CONFIG(BOOT_DEVICE_MEMORY_MAPPED) && |
| 279 |
CONFIG(BOOT_DEVICE_SPI_FLASH)) |
| 280 |
fast_spi_cache_bios_region(); |
| 281 |
} |
| 282 |
|
| 283 |
#if CONFIG(SOC_INTEL_GEMINILAKE) |
| 284 |
int soc_skip_ucode_update(u32 current_patch_id, u32 new_patch_id) |
| 285 |
{ |
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
const msr_t mtrr_cap = rdmsr(MTRR_CAP_MSR); |
| 296 |
if (mtrr_cap.lo & MTRR_CAP_PRMRR) { |
| 297 |
const msr_t prmrr_phys_base = rdmsr(MSR_PRMRR_PHYS_BASE); |
| 298 |
if (prmrr_phys_base.raw) { |
| 299 |
return 0; |
| 300 |
} |
| 301 |
} |
| 302 |
return current_patch_id == new_patch_id - 1; |
| 303 |
} |
| 304 |
#endif |