Angel Pons | f23ae0b | 2020-04-02 23:48:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 2 | |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 3 | #include <assert.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 4 | #include <console/console.h> |
| 5 | #include <device/device.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 6 | #include <acpi/acpi.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 7 | #include <cpu/cpu.h> |
| 8 | #include <cpu/x86/mtrr.h> |
| 9 | #include <cpu/x86/msr.h> |
| 10 | #include <cpu/x86/lapic.h> |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 11 | #include <cpu/x86/mp.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 12 | #include <cpu/intel/microcode.h> |
| 13 | #include <cpu/intel/speedstep.h> |
| 14 | #include <cpu/intel/turbo.h> |
| 15 | #include <cpu/x86/cache.h> |
| 16 | #include <cpu/x86/name.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 17 | #include "model_2065x.h" |
| 18 | #include "chip.h" |
Kyösti Mälkki | f091f4d | 2019-08-14 03:49:21 +0300 | [diff] [blame] | 19 | #include <cpu/intel/smm_reloc.h> |
Matt DeVillier | ed6fe2f | 2016-12-14 16:12:43 -0600 | [diff] [blame] | 20 | #include <cpu/intel/common/common.h> |
Elyes HAOUAS | dda17fa | 2019-10-27 13:09:37 +0100 | [diff] [blame] | 21 | #include <smp/node.h> |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 22 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 23 | int cpu_config_tdp_levels(void) |
| 24 | { |
| 25 | msr_t platform_info; |
| 26 | |
| 27 | /* Minimum CPU revision */ |
| 28 | if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID) |
| 29 | return 0; |
| 30 | |
| 31 | /* Bits 34:33 indicate how many levels supported */ |
| 32 | platform_info = rdmsr(MSR_PLATFORM_INFO); |
| 33 | return (platform_info.hi >> 1) & 3; |
| 34 | } |
| 35 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 36 | static void configure_thermal_target(void) |
| 37 | { |
| 38 | struct cpu_intel_model_2065x_config *conf; |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 39 | struct device *lapic; |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 40 | msr_t msr; |
| 41 | |
| 42 | /* Find pointer to CPU configuration */ |
| 43 | lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC); |
| 44 | if (!lapic || !lapic->chip_info) |
| 45 | return; |
| 46 | conf = lapic->chip_info; |
| 47 | |
Martin Roth | 4c3ab73 | 2013-07-08 16:23:54 -0600 | [diff] [blame] | 48 | /* Set TCC activation offset if supported */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 49 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 50 | if ((msr.lo & (1 << 30)) && conf->tcc_offset) { |
| 51 | msr = rdmsr(MSR_TEMPERATURE_TARGET); |
| 52 | msr.lo &= ~(0xf << 24); /* Bits 27:24 */ |
| 53 | msr.lo |= (conf->tcc_offset & 0xf) << 24; |
| 54 | wrmsr(MSR_TEMPERATURE_TARGET, msr); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | static void configure_misc(void) |
| 59 | { |
| 60 | msr_t msr; |
| 61 | |
| 62 | msr = rdmsr(IA32_MISC_ENABLE); |
| 63 | msr.lo |= (1 << 0); /* Fast String enable */ |
Lee Leahy | 7b5f12b9 | 2017-03-15 17:16:59 -0700 | [diff] [blame] | 64 | msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 65 | msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */ |
| 66 | wrmsr(IA32_MISC_ENABLE, msr); |
| 67 | |
| 68 | /* Disable Thermal interrupts */ |
| 69 | msr.lo = 0; |
| 70 | msr.hi = 0; |
| 71 | wrmsr(IA32_THERM_INTERRUPT, msr); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 74 | static void set_max_ratio(void) |
| 75 | { |
| 76 | msr_t msr, perf_ctl; |
| 77 | |
| 78 | perf_ctl.hi = 0; |
| 79 | |
| 80 | /* Check for configurable TDP option */ |
| 81 | if (cpu_config_tdp_levels()) { |
| 82 | /* Set to nominal TDP ratio */ |
| 83 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 84 | perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 85 | } else { |
| 86 | /* Platform Info bits 15:8 give max ratio */ |
| 87 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 88 | perf_ctl.lo = msr.lo & 0xff00; |
| 89 | } |
| 90 | wrmsr(IA32_PERF_CTL, perf_ctl); |
| 91 | |
| 92 | printk(BIOS_DEBUG, "model_x06ax: frequency set to %d\n", |
Angel Pons | 95de231 | 2020-02-17 13:08:53 +0100 | [diff] [blame] | 93 | ((perf_ctl.lo >> 8) & 0xff) * IRONLAKE_BCLK); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 96 | static void configure_mca(void) |
| 97 | { |
| 98 | msr_t msr; |
| 99 | int i; |
| 100 | |
| 101 | msr.lo = msr.hi = 0; |
| 102 | /* This should only be done on a cold boot */ |
| 103 | for (i = 0; i < 7; i++) |
| 104 | wrmsr(IA32_MC0_STATUS + (i * 4), msr); |
| 105 | } |
| 106 | |
Edward O'Callaghan | 2c9d2cf | 2014-10-27 23:29:29 +1100 | [diff] [blame] | 107 | static void model_2065x_init(struct device *cpu) |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 108 | { |
| 109 | char processor_name[49]; |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 110 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 111 | /* Clear out pending MCEs */ |
| 112 | configure_mca(); |
| 113 | |
| 114 | /* Print processor name */ |
| 115 | fill_processor_name(processor_name); |
| 116 | printk(BIOS_INFO, "CPU: %s.\n", processor_name); |
Patrick Rudolph | fc57d6c | 2019-11-12 16:30:14 +0100 | [diff] [blame] | 117 | printk(BIOS_INFO, "CPU:lapic=%d, boot_cpu=%d\n", lapicid(), |
Lee Leahy | 9d62e7e | 2017-03-15 17:40:50 -0700 | [diff] [blame] | 118 | boot_cpu()); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 119 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 120 | /* Setup Page Attribute Tables (PAT) */ |
| 121 | // TODO set up PAT |
| 122 | |
Elyes HAOUAS | d6e9686 | 2016-08-21 10:12:15 +0200 | [diff] [blame] | 123 | /* Enable the local CPU APICs */ |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 124 | enable_lapic_tpr(); |
| 125 | setup_lapic(); |
| 126 | |
Matt DeVillier | ed6fe2f | 2016-12-14 16:12:43 -0600 | [diff] [blame] | 127 | /* Set virtualization based on Kconfig option */ |
Matt DeVillier | f9aed65 | 2018-12-15 15:57:33 -0600 | [diff] [blame] | 128 | set_vmx_and_lock(); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 129 | |
Michael Niewöhner | 6303243 | 2020-10-11 17:34:54 +0200 | [diff] [blame] | 130 | set_aesni_lock(); |
Michael Niewöhner | 7f8767d | 2020-10-18 00:45:38 +0200 | [diff] [blame] | 131 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 132 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 133 | configure_misc(); |
| 134 | |
| 135 | /* Thermal throttle activation offset */ |
| 136 | configure_thermal_target(); |
| 137 | |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 138 | /* Set Max Ratio */ |
| 139 | set_max_ratio(); |
| 140 | |
| 141 | /* Enable Turbo */ |
| 142 | enable_turbo(); |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 143 | } |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 144 | |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 145 | /* MP initialization support. */ |
| 146 | static const void *microcode_patch; |
| 147 | |
| 148 | static void pre_mp_init(void) |
| 149 | { |
| 150 | /* Setup MTRRs based on physical address size. */ |
| 151 | x86_setup_mtrrs_with_detect(); |
| 152 | x86_mtrr_check(); |
| 153 | } |
| 154 | |
| 155 | static int get_cpu_count(void) |
| 156 | { |
| 157 | msr_t msr; |
| 158 | int num_threads; |
| 159 | int num_cores; |
| 160 | |
Elyes HAOUAS | a6a396d | 2019-05-26 13:25:30 +0200 | [diff] [blame] | 161 | msr = rdmsr(MSR_CORE_THREAD_COUNT); |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 162 | num_threads = (msr.lo >> 0) & 0xffff; |
| 163 | num_cores = (msr.lo >> 16) & 0xffff; |
| 164 | printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n", |
| 165 | num_cores, num_threads); |
| 166 | |
| 167 | return num_threads; |
| 168 | } |
| 169 | |
| 170 | static void get_microcode_info(const void **microcode, int *parallel) |
| 171 | { |
| 172 | microcode_patch = intel_microcode_find(); |
| 173 | *microcode = microcode_patch; |
Patrick Rudolph | ce51b34 | 2021-01-11 09:21:58 +0100 | [diff] [blame] | 174 | *parallel = !intel_ht_supported(); |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | static void per_cpu_smm_trigger(void) |
| 178 | { |
| 179 | /* Relocate the SMM handler. */ |
| 180 | smm_relocate(); |
| 181 | |
| 182 | /* After SMM relocation a 2nd microcode load is required. */ |
| 183 | intel_microcode_load_unlocked(microcode_patch); |
| 184 | } |
| 185 | |
| 186 | static void post_mp_init(void) |
| 187 | { |
| 188 | /* Now that all APs have been relocated as well as the BSP let SMIs |
| 189 | * start flowing. */ |
Kyösti Mälkki | 0778c86 | 2020-06-10 12:44:03 +0300 | [diff] [blame] | 190 | global_smi_enable(); |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 191 | |
| 192 | /* Lock down the SMRAM space. */ |
| 193 | smm_lock(); |
| 194 | } |
| 195 | |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 196 | static const struct mp_ops mp_ops = { |
| 197 | .pre_mp_init = pre_mp_init, |
| 198 | .get_cpu_count = get_cpu_count, |
| 199 | .get_smm_info = smm_info, |
| 200 | .get_microcode_info = get_microcode_info, |
| 201 | .pre_mp_smm_init = smm_initialize, |
| 202 | .per_cpu_smm_trigger = per_cpu_smm_trigger, |
| 203 | .relocation_handler = smm_relocation_handler, |
| 204 | .post_mp_init = post_mp_init, |
| 205 | }; |
| 206 | |
Kyösti Mälkki | b3267e0 | 2019-08-13 16:44:04 +0300 | [diff] [blame] | 207 | void mp_init_cpus(struct bus *cpu_bus) |
Arthur Heymans | b66ee55 | 2018-05-15 16:35:45 +0200 | [diff] [blame] | 208 | { |
| 209 | if (mp_init_with_smm(cpu_bus, &mp_ops)) |
| 210 | printk(BIOS_ERR, "MP initialization failure.\n"); |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | static struct device_operations cpu_dev_ops = { |
| 214 | .init = model_2065x_init, |
| 215 | }; |
| 216 | |
Angel Pons | a8305e7 | 2020-02-17 14:24:04 +0100 | [diff] [blame] | 217 | /* Arrandale / Clarkdale CPU IDs */ |
Jonathan Neuschäfer | 8f06ce3 | 2017-11-20 01:56:44 +0100 | [diff] [blame] | 218 | static const struct cpu_device_id cpu_table[] = { |
Angel Pons | a8305e7 | 2020-02-17 14:24:04 +0100 | [diff] [blame] | 219 | { X86_VENDOR_INTEL, 0x20650 }, |
| 220 | { X86_VENDOR_INTEL, 0x20651 }, |
| 221 | { X86_VENDOR_INTEL, 0x20652 }, |
| 222 | { X86_VENDOR_INTEL, 0x20654 }, |
| 223 | { X86_VENDOR_INTEL, 0x20655 }, |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 224 | { 0, 0 }, |
| 225 | }; |
| 226 | |
| 227 | static const struct cpu_driver driver __cpu_driver = { |
| 228 | .ops = &cpu_dev_ops, |
| 229 | .id_table = cpu_table, |
Vladimir Serbinenko | 22dcdd9 | 2013-06-06 22:10:45 +0200 | [diff] [blame] | 230 | }; |