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