blob: 773940850defbc2380c91c122509de924a6e95f7 [file] [log] [blame]
Stefan Reinauer5c554632012-04-04 00:09:50 +02001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer5c554632012-04-04 00:09:50 +02004 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; version 2 of
7 * the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Stefan Reinauer5c554632012-04-04 00:09:50 +020013 */
14
15#include <console/console.h>
16#include <device/device.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020017#include <arch/acpi.h>
Subrata Banik53b08c32018-12-10 14:11:35 +053018#include <arch/cpu.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020019#include <cpu/cpu.h>
20#include <cpu/x86/mtrr.h>
21#include <cpu/x86/msr.h>
22#include <cpu/x86/lapic.h>
Arthur Heymansedbf5d92018-01-25 20:03:42 +010023#include <cpu/x86/mp.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020024#include <cpu/intel/microcode.h>
25#include <cpu/intel/speedstep.h>
26#include <cpu/intel/turbo.h>
27#include <cpu/x86/cache.h>
28#include <cpu/x86/name.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020029#include "model_206ax.h"
Duncan Laurie55632112012-07-16 12:19:00 -070030#include "chip.h"
Kyösti Mälkkif091f4d2019-08-14 03:49:21 +030031#include <cpu/intel/smm_reloc.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060032#include <cpu/intel/common/common.h>
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +020033
Stefan Reinauer5c554632012-04-04 00:09:50 +020034/*
Martin Roth4c3ab732013-07-08 16:23:54 -060035 * List of supported C-states in this processor
Stefan Reinauer5c554632012-04-04 00:09:50 +020036 *
37 * Latencies are typical worst-case package exit time in uS
38 * taken from the SandyBridge BIOS specification.
39 */
40static acpi_cstate_t cstate_map[] = {
41 { /* 0: C0 */
Lee Leahy9d62e7e2017-03-15 17:40:50 -070042 }, { /* 1: C1 */
Stefan Reinauer5c554632012-04-04 00:09:50 +020043 .latency = 1,
44 .power = 1000,
45 .resource = {
46 .addrl = 0x00, /* MWAIT State 0 */
47 .space_id = ACPI_ADDRESS_SPACE_FIXED,
48 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
49 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010050 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +020051 }
52 },
53 { /* 2: C1E */
54 .latency = 1,
55 .power = 1000,
56 .resource = {
57 .addrl = 0x01, /* MWAIT State 0 Sub-state 1 */
58 .space_id = ACPI_ADDRESS_SPACE_FIXED,
59 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
60 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010061 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +020062 }
63 },
64 { /* 3: C3 */
65 .latency = 63,
66 .power = 500,
67 .resource = {
68 .addrl = 0x10, /* MWAIT State 1 */
69 .space_id = ACPI_ADDRESS_SPACE_FIXED,
70 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
71 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010072 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +020073 }
74 },
75 { /* 4: C6 */
76 .latency = 87,
77 .power = 350,
78 .resource = {
79 .addrl = 0x20, /* MWAIT State 2 */
80 .space_id = ACPI_ADDRESS_SPACE_FIXED,
81 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
82 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010083 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +020084 }
85 },
86 { /* 5: C7 */
87 .latency = 90,
88 .power = 200,
89 .resource = {
90 .addrl = 0x30, /* MWAIT State 3 */
91 .space_id = ACPI_ADDRESS_SPACE_FIXED,
92 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
93 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +010094 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +020095 }
96 },
97 { /* 6: C7S */
98 .latency = 90,
99 .power = 200,
100 .resource = {
101 .addrl = 0x31, /* MWAIT State 3 Sub-state 1 */
102 .space_id = ACPI_ADDRESS_SPACE_FIXED,
103 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
104 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
Elyes HAOUAS8ee161d2019-03-03 12:49:56 +0100105 .access_size = ACPI_FFIXEDHW_FLAG_HW_COORD,
Stefan Reinauer5c554632012-04-04 00:09:50 +0200106 }
107 },
108 { 0 }
109};
110
Stefan Reinauer5c554632012-04-04 00:09:50 +0200111/* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */
112static const u8 power_limit_time_sec_to_msr[] = {
113 [0] = 0x00,
114 [1] = 0x0a,
115 [2] = 0x0b,
116 [3] = 0x4b,
117 [4] = 0x0c,
118 [5] = 0x2c,
119 [6] = 0x4c,
120 [7] = 0x6c,
121 [8] = 0x0d,
122 [10] = 0x2d,
123 [12] = 0x4d,
124 [14] = 0x6d,
125 [16] = 0x0e,
126 [20] = 0x2e,
127 [24] = 0x4e,
128 [28] = 0x6e,
129 [32] = 0x0f,
130 [40] = 0x2f,
131 [48] = 0x4f,
132 [56] = 0x6f,
133 [64] = 0x10,
134 [80] = 0x30,
135 [96] = 0x50,
136 [112] = 0x70,
137 [128] = 0x11,
138};
139
140/* Convert POWER_LIMIT_1_TIME MSR value to seconds */
141static const u8 power_limit_time_msr_to_sec[] = {
142 [0x00] = 0,
143 [0x0a] = 1,
144 [0x0b] = 2,
145 [0x4b] = 3,
146 [0x0c] = 4,
147 [0x2c] = 5,
148 [0x4c] = 6,
149 [0x6c] = 7,
150 [0x0d] = 8,
151 [0x2d] = 10,
152 [0x4d] = 12,
153 [0x6d] = 14,
154 [0x0e] = 16,
155 [0x2e] = 20,
156 [0x4e] = 24,
157 [0x6e] = 28,
158 [0x0f] = 32,
159 [0x2f] = 40,
160 [0x4f] = 48,
161 [0x6f] = 56,
162 [0x10] = 64,
163 [0x30] = 80,
164 [0x50] = 96,
165 [0x70] = 112,
166 [0x11] = 128,
167};
168
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700169int cpu_config_tdp_levels(void)
170{
171 msr_t platform_info;
172
173 /* Minimum CPU revision */
174 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
175 return 0;
176
177 /* Bits 34:33 indicate how many levels supported */
178 platform_info = rdmsr(MSR_PLATFORM_INFO);
179 return (platform_info.hi >> 1) & 3;
180}
181
Stefan Reinauer5c554632012-04-04 00:09:50 +0200182/*
183 * Configure processor power limits if possible
184 * This must be done AFTER set of BIOS_RESET_CPL
185 */
186void set_power_limits(u8 power_limit_1_time)
187{
188 msr_t msr = rdmsr(MSR_PLATFORM_INFO);
189 msr_t limit;
Lee Leahy73a28942017-03-15 17:52:06 -0700190 unsigned int power_unit;
191 unsigned int tdp, min_power, max_power, max_time;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200192 u8 power_limit_1_val;
193
Edward O'Callaghan5cfef132014-08-03 20:00:47 +1000194 if (power_limit_1_time >= ARRAY_SIZE(power_limit_time_sec_to_msr))
Stefan Reinauer5c554632012-04-04 00:09:50 +0200195 return;
196
197 if (!(msr.lo & PLATFORM_INFO_SET_TDP))
198 return;
199
200 /* Get units */
201 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
202 power_unit = 2 << ((msr.lo & 0xf) - 1);
203
204 /* Get power defaults for this SKU */
205 msr = rdmsr(MSR_PKG_POWER_SKU);
206 tdp = msr.lo & 0x7fff;
207 min_power = (msr.lo >> 16) & 0x7fff;
208 max_power = msr.hi & 0x7fff;
209 max_time = (msr.hi >> 16) & 0x7f;
210
211 printk(BIOS_DEBUG, "CPU TDP: %u Watts\n", tdp / power_unit);
212
213 if (power_limit_time_msr_to_sec[max_time] > power_limit_1_time)
214 power_limit_1_time = power_limit_time_msr_to_sec[max_time];
215
216 if (min_power > 0 && tdp < min_power)
217 tdp = min_power;
218
219 if (max_power > 0 && tdp > max_power)
220 tdp = max_power;
221
222 power_limit_1_val = power_limit_time_sec_to_msr[power_limit_1_time];
223
224 /* Set long term power limit to TDP */
225 limit.lo = 0;
226 limit.lo |= tdp & PKG_POWER_LIMIT_MASK;
227 limit.lo |= PKG_POWER_LIMIT_EN;
228 limit.lo |= (power_limit_1_val & PKG_POWER_LIMIT_TIME_MASK) <<
229 PKG_POWER_LIMIT_TIME_SHIFT;
230
231 /* Set short term power limit to 1.25 * TDP */
232 limit.hi = 0;
233 limit.hi |= ((tdp * 125) / 100) & PKG_POWER_LIMIT_MASK;
234 limit.hi |= PKG_POWER_LIMIT_EN;
235 /* Power limit 2 time is only programmable on SNB EP/EX */
236
237 wrmsr(MSR_PKG_POWER_LIMIT, limit);
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700238
239 /* Use nominal TDP values for CPUs with configurable TDP */
240 if (cpu_config_tdp_levels()) {
241 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
242 limit.hi = 0;
243 limit.lo = msr.lo & 0xff;
244 wrmsr(MSR_TURBO_ACTIVATION_RATIO, limit);
245 }
Stefan Reinauer5c554632012-04-04 00:09:50 +0200246}
247
248static void configure_c_states(void)
249{
250 msr_t msr;
251
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200252 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200253 msr.lo |= (1 << 28); // C1 Auto Undemotion Enable
254 msr.lo |= (1 << 27); // C3 Auto Undemotion Enable
255 msr.lo |= (1 << 26); // C1 Auto Demotion Enable
256 msr.lo |= (1 << 25); // C3 Auto Demotion Enable
257 msr.lo &= ~(1 << 10); // Disable IO MWAIT redirection
258 msr.lo |= 7; // No package C-state limit
Patrick Rudolph573481b2020-03-02 14:21:32 +0100259
260 msr.lo |= (1 << 15); // Lock C-State MSR
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200261 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200262
Patrick Georgi644e83b2013-02-09 15:35:30 +0100263 msr = rdmsr(MSR_PMG_IO_CAPTURE_ADDR);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200264 msr.lo &= ~0x7ffff;
265 msr.lo |= (PMB0_BASE + 4); // LVL_2 base address
266 msr.lo |= (2 << 16); // CST Range: C7 is max C-state
Patrick Georgi644e83b2013-02-09 15:35:30 +0100267 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200268
269 msr = rdmsr(MSR_MISC_PWR_MGMT);
270 msr.lo &= ~(1 << 0); // Enable P-state HW_ALL coordination
271 wrmsr(MSR_MISC_PWR_MGMT, msr);
272
273 msr = rdmsr(MSR_POWER_CTL);
274 msr.lo |= (1 << 18); // Enable Energy Perf Bias MSR 0x1b0
275 msr.lo |= (1 << 1); // C1E Enable
276 msr.lo |= (1 << 0); // Bi-directional PROCHOT#
277 wrmsr(MSR_POWER_CTL, msr);
278
279 /* C3 Interrupt Response Time Limit */
280 msr.hi = 0;
281 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x50;
282 wrmsr(MSR_PKGC3_IRTL, msr);
283
284 /* C6 Interrupt Response Time Limit */
285 msr.hi = 0;
286 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x68;
287 wrmsr(MSR_PKGC6_IRTL, msr);
288
289 /* C7 Interrupt Response Time Limit */
290 msr.hi = 0;
291 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x6D;
292 wrmsr(MSR_PKGC7_IRTL, msr);
293
294 /* Primary Plane Current Limit */
295 msr = rdmsr(MSR_PP0_CURRENT_CONFIG);
296 msr.lo &= ~0x1fff;
297 msr.lo |= PP0_CURRENT_LIMIT;
298 wrmsr(MSR_PP0_CURRENT_CONFIG, msr);
299
300 /* Secondary Plane Current Limit */
301 msr = rdmsr(MSR_PP1_CURRENT_CONFIG);
302 msr.lo &= ~0x1fff;
Duncan Laurie4e4320f2012-06-25 09:53:58 -0700303 if (cpuid_eax(1) >= 0x30600)
304 msr.lo |= PP1_CURRENT_LIMIT_IVB;
305 else
306 msr.lo |= PP1_CURRENT_LIMIT_SNB;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200307 wrmsr(MSR_PP1_CURRENT_CONFIG, msr);
308}
309
Duncan Laurie55632112012-07-16 12:19:00 -0700310static void configure_thermal_target(void)
311{
312 struct cpu_intel_model_206ax_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100313 struct device *lapic;
Duncan Laurie55632112012-07-16 12:19:00 -0700314 msr_t msr;
315
316 /* Find pointer to CPU configuration */
317 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
318 if (!lapic || !lapic->chip_info)
319 return;
320 conf = lapic->chip_info;
321
Martin Roth4c3ab732013-07-08 16:23:54 -0600322 /* Set TCC activation offset if supported */
Duncan Laurie55632112012-07-16 12:19:00 -0700323 msr = rdmsr(MSR_PLATFORM_INFO);
324 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
325 msr = rdmsr(MSR_TEMPERATURE_TARGET);
326 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
327 msr.lo |= (conf->tcc_offset & 0xf) << 24;
328 wrmsr(MSR_TEMPERATURE_TARGET, msr);
329 }
330}
331
Stefan Reinauer5c554632012-04-04 00:09:50 +0200332static void configure_misc(void)
333{
334 msr_t msr;
335
336 msr = rdmsr(IA32_MISC_ENABLE);
337 msr.lo |= (1 << 0); /* Fast String enable */
Lee Leahy7b5f12b92017-03-15 17:16:59 -0700338 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200339 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
340 wrmsr(IA32_MISC_ENABLE, msr);
341
342 /* Disable Thermal interrupts */
343 msr.lo = 0;
344 msr.hi = 0;
345 wrmsr(IA32_THERM_INTERRUPT, msr);
346
347 /* Enable package critical interrupt only */
348 msr.lo = 1 << 4;
349 msr.hi = 0;
350 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
351}
352
353static void enable_lapic_tpr(void)
354{
355 msr_t msr;
356
357 msr = rdmsr(MSR_PIC_MSG_CONTROL);
358 msr.lo &= ~(1 << 10); /* Enable APIC TPR updates */
359 wrmsr(MSR_PIC_MSG_CONTROL, msr);
360}
361
362static void configure_dca_cap(void)
363{
Subrata Banik53b08c32018-12-10 14:11:35 +0530364 uint32_t feature_flag;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200365 msr_t msr;
366
367 /* Check feature flag in CPUID.(EAX=1):ECX[18]==1 */
Subrata Banik53b08c32018-12-10 14:11:35 +0530368 feature_flag = cpu_get_feature_flags_ecx();
369 if (feature_flag & CPUID_DCA) {
Stefan Reinauer5c554632012-04-04 00:09:50 +0200370 msr = rdmsr(IA32_PLATFORM_DCA_CAP);
371 msr.lo |= 1;
372 wrmsr(IA32_PLATFORM_DCA_CAP, msr);
373 }
374}
375
376static void set_max_ratio(void)
377{
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700378 msr_t msr, perf_ctl;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200379
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700380 perf_ctl.hi = 0;
381
382 /* Check for configurable TDP option */
383 if (cpu_config_tdp_levels()) {
384 /* Set to nominal TDP ratio */
385 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
386 perf_ctl.lo = (msr.lo & 0xff) << 8;
387 } else {
388 /* Platform Info bits 15:8 give max ratio */
389 msr = rdmsr(MSR_PLATFORM_INFO);
390 perf_ctl.lo = msr.lo & 0xff00;
391 }
392 wrmsr(IA32_PERF_CTL, perf_ctl);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200393
394 printk(BIOS_DEBUG, "model_x06ax: frequency set to %d\n",
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700395 ((perf_ctl.lo >> 8) & 0xff) * SANDYBRIDGE_BCLK);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200396}
397
398static void set_energy_perf_bias(u8 policy)
399{
400 msr_t msr;
401
402 /* Energy Policy is bits 3:0 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200403 msr = rdmsr(IA32_ENERGY_PERF_BIAS);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200404 msr.lo &= ~0xf;
405 msr.lo |= policy & 0xf;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200406 wrmsr(IA32_ENERGY_PERF_BIAS, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200407
408 printk(BIOS_DEBUG, "model_x06ax: energy policy set to %u\n",
409 policy);
410}
411
412static void configure_mca(void)
413{
414 msr_t msr;
415 int i;
Dan Elkoubydfaff4d2018-09-03 18:34:07 +0300416 int num_banks;
417
418 msr = rdmsr(IA32_MCG_CAP);
419 num_banks = msr.lo & 0xff;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200420
421 msr.lo = msr.hi = 0;
422 /* This should only be done on a cold boot */
Dan Elkoubydfaff4d2018-09-03 18:34:07 +0300423 for (i = 0; i < num_banks; i++)
Stefan Reinauer5c554632012-04-04 00:09:50 +0200424 wrmsr(IA32_MC0_STATUS + (i * 4), msr);
425}
426
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200427static void model_206ax_report(void)
428{
429 static const char *const mode[] = {"NOT ", ""};
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200430 char processor_name[49];
431 int vt, txt, aes;
Subrata Banik53b08c32018-12-10 14:11:35 +0530432 uint32_t cpu_id, cpu_feature_flag;
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200433
434 /* Print processor name */
435 fill_processor_name(processor_name);
436 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
437
438 /* Print platform ID */
439 printk(BIOS_INFO, "CPU: platform id %x\n", get_platform_id());
440
441 /* CPUID and features */
Subrata Banik53b08c32018-12-10 14:11:35 +0530442 cpu_id = cpu_get_cpuid();
443 printk(BIOS_INFO, "CPU: cpuid(1) 0x%x\n", cpu_id);
444
445 cpu_feature_flag = cpu_get_feature_flags_ecx();
446 aes = (cpu_feature_flag & CPUID_AES) ? 1 : 0;
447 txt = (cpu_feature_flag & CPUID_SMX) ? 1 : 0;
448 vt = (cpu_feature_flag & CPUID_VMX) ? 1 : 0;
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200449 printk(BIOS_INFO, "CPU: AES %ssupported\n", mode[aes]);
450 printk(BIOS_INFO, "CPU: TXT %ssupported\n", mode[txt]);
451 printk(BIOS_INFO, "CPU: VT %ssupported\n", mode[vt]);
452}
453
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100454static void model_206ax_init(struct device *cpu)
Stefan Reinauer5c554632012-04-04 00:09:50 +0200455{
Stefan Reinauer5c554632012-04-04 00:09:50 +0200456
457 /* Turn on caching if we haven't already */
458 x86_enable_cache();
459
Stefan Reinauer5c554632012-04-04 00:09:50 +0200460 /* Clear out pending MCEs */
461 configure_mca();
462
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200463 /* Print infos */
464 model_206ax_report();
Patrick Rudolph74203de2017-11-20 11:57:01 +0100465
Stefan Reinauer5c554632012-04-04 00:09:50 +0200466 /* Setup Page Attribute Tables (PAT) */
467 // TODO set up PAT
468
Elyes HAOUASd6e96862016-08-21 10:12:15 +0200469 /* Enable the local CPU APICs */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200470 enable_lapic_tpr();
471 setup_lapic();
472
Matt DeVilliered6fe2f2016-12-14 16:12:43 -0600473 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -0600474 set_vmx_and_lock();
Marc Jones5986eda2012-10-25 09:37:19 -0600475
Stefan Reinauer5c554632012-04-04 00:09:50 +0200476 /* Configure C States */
477 configure_c_states();
478
479 /* Configure Enhanced SpeedStep and Thermal Sensors */
480 configure_misc();
481
Duncan Laurie55632112012-07-16 12:19:00 -0700482 /* Thermal throttle activation offset */
483 configure_thermal_target();
484
Stefan Reinauer5c554632012-04-04 00:09:50 +0200485 /* Enable Direct Cache Access */
486 configure_dca_cap();
487
488 /* Set energy policy */
489 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
490
491 /* Set Max Ratio */
492 set_max_ratio();
493
494 /* Enable Turbo */
495 enable_turbo();
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100496}
Sven Schnelle51676b12012-07-29 19:18:03 +0200497
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100498/* MP initialization support. */
499static const void *microcode_patch;
500
501static void pre_mp_init(void)
502{
503 /* Setup MTRRs based on physical address size. */
504 x86_setup_mtrrs_with_detect();
505 x86_mtrr_check();
506}
507
508static int get_cpu_count(void)
509{
510 msr_t msr;
511 int num_threads;
512 int num_cores;
513
Elyes HAOUASa6a396d2019-05-26 13:25:30 +0200514 msr = rdmsr(MSR_CORE_THREAD_COUNT);
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100515 num_threads = (msr.lo >> 0) & 0xffff;
516 num_cores = (msr.lo >> 16) & 0xffff;
517 printk(BIOS_DEBUG, "CPU has %u cores, %u threads enabled.\n",
518 num_cores, num_threads);
519
520 return num_threads;
521}
522
523static void get_microcode_info(const void **microcode, int *parallel)
524{
525 microcode_patch = intel_microcode_find();
526 *microcode = microcode_patch;
527 *parallel = 1;
528}
529
530static void per_cpu_smm_trigger(void)
531{
532 /* Relocate the SMM handler. */
533 smm_relocate();
534
535 /* After SMM relocation a 2nd microcode load is required. */
536 intel_microcode_load_unlocked(microcode_patch);
537}
538
539static void post_mp_init(void)
540{
541 /* Now that all APs have been relocated as well as the BSP let SMIs
542 * start flowing. */
Kyösti Mälkkifaf20d32019-08-14 05:41:41 +0300543 smm_southbridge_enable_smi();
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100544
545 /* Lock down the SMRAM space. */
546 smm_lock();
547}
548
549
550static const struct mp_ops mp_ops = {
551 .pre_mp_init = pre_mp_init,
552 .get_cpu_count = get_cpu_count,
553 .get_smm_info = smm_info,
554 .get_microcode_info = get_microcode_info,
555 .pre_mp_smm_init = smm_initialize,
556 .per_cpu_smm_trigger = per_cpu_smm_trigger,
557 .relocation_handler = smm_relocation_handler,
558 .post_mp_init = post_mp_init,
559};
560
Kyösti Mälkkib3267e02019-08-13 16:44:04 +0300561void mp_init_cpus(struct bus *cpu_bus)
Arthur Heymansedbf5d92018-01-25 20:03:42 +0100562{
563 if (mp_init_with_smm(cpu_bus, &mp_ops))
564 printk(BIOS_ERR, "MP initialization failure.\n");
Stefan Reinauer5c554632012-04-04 00:09:50 +0200565}
566
567static struct device_operations cpu_dev_ops = {
568 .init = model_206ax_init,
569};
570
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100571static const struct cpu_device_id cpu_table[] = {
Stefan Reinauer5c554632012-04-04 00:09:50 +0200572 { X86_VENDOR_INTEL, 0x206a0 }, /* Intel Sandybridge */
573 { X86_VENDOR_INTEL, 0x206a6 }, /* Intel Sandybridge D1 */
574 { X86_VENDOR_INTEL, 0x206a7 }, /* Intel Sandybridge D2/J1 */
Stefan Reinauer08067ba2012-10-15 13:47:04 -0700575 { X86_VENDOR_INTEL, 0x306a0 }, /* Intel IvyBridge */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200576 { X86_VENDOR_INTEL, 0x306a2 }, /* Intel IvyBridge */
577 { X86_VENDOR_INTEL, 0x306a4 }, /* Intel IvyBridge */
578 { X86_VENDOR_INTEL, 0x306a5 }, /* Intel IvyBridge */
579 { X86_VENDOR_INTEL, 0x306a6 }, /* Intel IvyBridge */
580 { X86_VENDOR_INTEL, 0x306a8 }, /* Intel IvyBridge */
581 { X86_VENDOR_INTEL, 0x306a9 }, /* Intel IvyBridge */
582 { 0, 0 },
583};
584
585static const struct cpu_driver driver __cpu_driver = {
586 .ops = &cpu_dev_ops,
587 .id_table = cpu_table,
588 .cstates = cstate_map,
589};