blob: 9bac0dd668e20292e86aa4cb17de9e565ab435d4 [file] [log] [blame]
Angel Ponsf23ae0b2020-04-02 23:48:12 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02002
Arthur Heymansb66ee552018-05-15 16:35:45 +02003#include <assert.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02004#include <console/console.h>
5#include <device/device.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07006#include <acpi/acpi.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +02007#include <cpu/cpu.h>
8#include <cpu/x86/mtrr.h>
9#include <cpu/x86/msr.h>
10#include <cpu/x86/lapic.h>
Arthur Heymansb66ee552018-05-15 16:35:45 +020011#include <cpu/x86/mp.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020012#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 Serbinenko22dcdd92013-06-06 22:10:45 +020017#include "model_2065x.h"
18#include "chip.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030019#include <cpu/intel/smm_reloc.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060020#include <cpu/intel/common/common.h>
Elyes HAOUASdda17fa2019-10-27 13:09:37 +010021#include <smp/node.h>
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020022
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020023int 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 Serbinenko22dcdd92013-06-06 22:10:45 +020036static void configure_thermal_target(void)
37{
38 struct cpu_intel_model_2065x_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +110039 struct device *lapic;
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020040 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 Roth4c3ab732013-07-08 16:23:54 -060048 /* Set TCC activation offset if supported */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020049 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
58static 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 Leahy7b5f12b92017-03-15 17:16:59 -070064 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020065 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 Serbinenko22dcdd92013-06-06 22:10:45 +020072}
73
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020074static 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 Pons95de2312020-02-17 13:08:53 +010093 ((perf_ctl.lo >> 8) & 0xff) * IRONLAKE_BCLK);
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020094}
95
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +020096static 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'Callaghan2c9d2cf2014-10-27 23:29:29 +1100107static void model_2065x_init(struct device *cpu)
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200108{
109 char processor_name[49];
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200110
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200111 /* 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 Rudolphfc57d6c2019-11-12 16:30:14 +0100117 printk(BIOS_INFO, "CPU:lapic=%d, boot_cpu=%d\n", lapicid(),
Lee Leahy9d62e7e2017-03-15 17:40:50 -0700118 boot_cpu());
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200119
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200120 /* Setup Page Attribute Tables (PAT) */
121 // TODO set up PAT
122
Elyes HAOUASd6e96862016-08-21 10:12:15 +0200123 /* Enable the local CPU APICs */
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200124 enable_lapic_tpr();
125 setup_lapic();
126
Matt DeVilliered6fe2f2016-12-14 16:12:43 -0600127 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -0600128 set_vmx_and_lock();
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200129
Michael Niewöhner63032432020-10-11 17:34:54 +0200130 set_aesni_lock();
Michael Niewöhner7f8767d2020-10-18 00:45:38 +0200131
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200132 /* Configure Enhanced SpeedStep and Thermal Sensors */
133 configure_misc();
134
135 /* Thermal throttle activation offset */
136 configure_thermal_target();
137
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200138 /* Set Max Ratio */
139 set_max_ratio();
140
141 /* Enable Turbo */
142 enable_turbo();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200143}
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200144
Arthur Heymansb66ee552018-05-15 16:35:45 +0200145/* MP initialization support. */
146static const void *microcode_patch;
147
148static 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
155static int get_cpu_count(void)
156{
157 msr_t msr;
158 int num_threads;
159 int num_cores;
160
Elyes HAOUASa6a396d2019-05-26 13:25:30 +0200161 msr = rdmsr(MSR_CORE_THREAD_COUNT);
Arthur Heymansb66ee552018-05-15 16:35:45 +0200162 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
170static void get_microcode_info(const void **microcode, int *parallel)
171{
172 microcode_patch = intel_microcode_find();
173 *microcode = microcode_patch;
Patrick Rudolphce51b342021-01-11 09:21:58 +0100174 *parallel = !intel_ht_supported();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200175}
176
177static 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
186static 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älkki0778c862020-06-10 12:44:03 +0300190 global_smi_enable();
Arthur Heymansb66ee552018-05-15 16:35:45 +0200191
192 /* Lock down the SMRAM space. */
193 smm_lock();
194}
195
Arthur Heymansb66ee552018-05-15 16:35:45 +0200196static 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älkkib3267e02019-08-13 16:44:04 +0300207void mp_init_cpus(struct bus *cpu_bus)
Arthur Heymansb66ee552018-05-15 16:35:45 +0200208{
209 if (mp_init_with_smm(cpu_bus, &mp_ops))
210 printk(BIOS_ERR, "MP initialization failure.\n");
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200211}
212
213static struct device_operations cpu_dev_ops = {
214 .init = model_2065x_init,
215};
216
Angel Ponsa8305e72020-02-17 14:24:04 +0100217/* Arrandale / Clarkdale CPU IDs */
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100218static const struct cpu_device_id cpu_table[] = {
Angel Ponsa8305e72020-02-17 14:24:04 +0100219 { 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 Serbinenko22dcdd92013-06-06 22:10:45 +0200224 { 0, 0 },
225};
226
227static const struct cpu_driver driver __cpu_driver = {
228 .ops = &cpu_dev_ops,
229 .id_table = cpu_table,
Vladimir Serbinenko22dcdd92013-06-06 22:10:45 +0200230};