| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpigen.h> |
| 4 |
#include <assert.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <console/debug.h> |
| 7 |
#include <cpu/cpu.h> |
| 8 |
#include <cpu/intel/common/common.h> |
| 9 |
#include <cpu/intel/em64t101_save_state.h> |
| 10 |
#include <cpu/intel/microcode.h> |
| 11 |
#include <cpu/intel/smm_reloc.h> |
| 12 |
#include <cpu/intel/turbo.h> |
| 13 |
#include <cpu/x86/mp.h> |
| 14 |
#include <cpu/x86/mtrr.h> |
| 15 |
#include <intelblocks/cpulib.h> |
| 16 |
#include <intelblocks/mp_init.h> |
| 17 |
#include <intelpch/lockdown.h> |
| 18 |
#include <soc/msr.h> |
| 19 |
#include <soc/pci_devs.h> |
| 20 |
#include <soc/pm.h> |
| 21 |
#include <soc/smmrelocate.h> |
| 22 |
#include <soc/soc_util.h> |
| 23 |
#include <soc/util.h> |
| 24 |
#include <types.h> |
| 25 |
|
| 26 |
#include "chip.h" |
| 27 |
|
| 28 |
static const void *microcode_patch; |
| 29 |
|
| 30 |
static const config_t *chip_config = NULL; |
| 31 |
|
| 32 |
bool cpu_soc_is_in_untrusted_mode(void) |
| 33 |
{ |
| 34 |
|
| 35 |
return false; |
| 36 |
} |
| 37 |
|
| 38 |
void cpu_soc_bios_done(void) |
| 39 |
{ |
| 40 |
|
| 41 |
} |
| 42 |
|
| 43 |
static void xeon_configure_mca(void) |
| 44 |
{ |
| 45 |
msr_t msr; |
| 46 |
struct cpuid_result cpuid_regs; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
cpuid_regs = cpuid(1); |
| 53 |
if ((cpuid_regs.edx & (1 << 7 | 1 << 14)) != (1 << 7 | 1 << 14)) |
| 54 |
return; |
| 55 |
|
| 56 |
msr = rdmsr(IA32_MCG_CAP); |
| 57 |
if (msr.lo & IA32_MCG_CAP_CTL_P_MASK) { |
| 58 |
|
| 59 |
msr.lo = msr.hi = 0xffffffff; |
| 60 |
wrmsr(IA32_MCG_CTL, msr); |
| 61 |
} |
| 62 |
|
| 63 |
mca_configure(); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
void get_microcode_info(const void **microcode, int *parallel) |
| 72 |
{ |
| 73 |
*microcode = intel_microcode_find(); |
| 74 |
*parallel = 0; |
| 75 |
} |
| 76 |
|
| 77 |
static void each_cpu_init(struct device *cpu) |
| 78 |
{ |
| 79 |
msr_t msr; |
| 80 |
|
| 81 |
printk(BIOS_SPEW, "%s: cpu: %lu, apic_id: 0x%x, package_id: 0x%x\n", |
| 82 |
__func__, cpu_index(), cpu->path.apic.apic_id, |
| 83 |
cpu->path.apic.package_id); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 91 |
if (!(msr.lo & LOCK_MISC_PWR_MGMT_MSR)) { |
| 92 |
msr.lo = (HWP_ENUM_ENABLE | HWP_EPP_ENUM_ENABLE | LOCK_MISC_PWR_MGMT_MSR | |
| 93 |
LOCK_THERM_INT); |
| 94 |
wrmsr(MSR_MISC_PWR_MGMT, msr); |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
msr = rdmsr(IA32_MISC_ENABLE); |
| 99 |
msr.lo |= FAST_STRINGS_ENABLE_BIT; |
| 100 |
wrmsr(IA32_MISC_ENABLE, msr); |
| 101 |
|
| 102 |
enable_turbo(); |
| 103 |
|
| 104 |
|
| 105 |
if (get_turbo_state() == TURBO_ENABLED) { |
| 106 |
msr = rdmsr(IA32_MISC_ENABLE); |
| 107 |
msr.lo |= SPEED_STEP_ENABLE_BIT; |
| 108 |
wrmsr(IA32_MISC_ENABLE, msr); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
xeon_configure_mca(); |
| 113 |
|
| 114 |
|
| 115 |
set_vmx_and_lock(); |
| 116 |
set_aesni_lock(); |
| 117 |
|
| 118 |
msr = rdmsr(MSR_TURBO_ACTIVATION_RATIO); |
| 119 |
msr.lo |= BIT31; |
| 120 |
wrmsr(MSR_TURBO_ACTIVATION_RATIO, msr); |
| 121 |
} |
| 122 |
|
| 123 |
static struct device_operations cpu_dev_ops = { |
| 124 |
.init = each_cpu_init, |
| 125 |
}; |
| 126 |
|
| 127 |
static const struct cpu_device_id cpu_table[] = { |
| 128 |
{X86_VENDOR_INTEL, CPUID_COOPERLAKE_SP_A0, CPUID_EXACT_MATCH_MASK }, |
| 129 |
{X86_VENDOR_INTEL, CPUID_COOPERLAKE_SP_A1, CPUID_EXACT_MATCH_MASK }, |
| 130 |
CPU_TABLE_END |
| 131 |
}; |
| 132 |
|
| 133 |
static const struct cpu_driver driver __cpu_driver = { |
| 134 |
.ops = &cpu_dev_ops, |
| 135 |
.id_table = cpu_table, |
| 136 |
}; |
| 137 |
|
| 138 |
static void set_max_turbo_freq(void) |
| 139 |
{ |
| 140 |
msr_t msr, perf_ctl; |
| 141 |
|
| 142 |
FUNC_ENTER(); |
| 143 |
perf_ctl.hi = 0; |
| 144 |
|
| 145 |
|
| 146 |
if (get_turbo_state() == TURBO_ENABLED) { |
| 147 |
msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 148 |
perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 149 |
} else if (cpu_config_tdp_levels()) { |
| 150 |
|
| 151 |
msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 152 |
perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 153 |
} else { |
| 154 |
|
| 155 |
msr = rdmsr(MSR_PLATFORM_INFO); |
| 156 |
perf_ctl.lo = msr.lo & 0xff00; |
| 157 |
} |
| 158 |
wrmsr(IA32_PERF_CTL, perf_ctl); |
| 159 |
|
| 160 |
printk(BIOS_DEBUG, "cpu: frequency set to %d\n", |
| 161 |
((perf_ctl.lo >> 8) & 0xff) * CONFIG_CPU_BCLK_MHZ); |
| 162 |
FUNC_EXIT(); |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
static void pre_mp_init(void) |
| 169 |
{ |
| 170 |
x86_setup_mtrrs_with_detect(); |
| 171 |
x86_mtrr_check(); |
| 172 |
} |
| 173 |
|
| 174 |
static void post_mp_init(void) |
| 175 |
{ |
| 176 |
|
| 177 |
set_max_turbo_freq(); |
| 178 |
|
| 179 |
if (CONFIG(HAVE_SMI_HANDLER)) { |
| 180 |
global_smi_enable(); |
| 181 |
if (get_lockdown_config() == CHIPSET_LOCKDOWN_COREBOOT) |
| 182 |
pmc_lock_smi(); |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
static const struct mp_ops mp_ops = { |
| 187 |
.pre_mp_init = pre_mp_init, |
| 188 |
.get_cpu_count = get_platform_thread_count, |
| 189 |
.get_smm_info = get_smm_info, |
| 190 |
.pre_mp_smm_init = smm_southbridge_clear_state, |
| 191 |
.relocation_handler = smm_relocation_handler, |
| 192 |
.get_microcode_info = get_microcode_info, |
| 193 |
.post_mp_init = post_mp_init, |
| 194 |
}; |
| 195 |
|
| 196 |
void mp_init_cpus(struct bus *bus) |
| 197 |
{ |
| 198 |
microcode_patch = intel_microcode_find(); |
| 199 |
|
| 200 |
if (!microcode_patch) |
| 201 |
printk(BIOS_ERR, "microcode not found in CBFS!\n"); |
| 202 |
|
| 203 |
intel_microcode_load_unlocked(microcode_patch); |
| 204 |
|
| 205 |
|
| 206 |
mp_init_with_smm(bus, &mp_ops); |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
chip_config = bus->dev->chip_info; |
| 213 |
} |