blob: 58aabdb1981922877d626bb5b6909375a4eef7c7 [file] [log] [blame]
Stefan Reinauer5c554632012-04-04 00:09:50 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Stefan Reinauer5c554632012-04-04 00:09:50 +020016 */
17
18#include <console/console.h>
19#include <device/device.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020020#include <string.h>
21#include <arch/acpi.h>
Subrata Banik53b08c32018-12-10 14:11:35 +053022#include <arch/cpu.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020023#include <cpu/cpu.h>
24#include <cpu/x86/mtrr.h>
25#include <cpu/x86/msr.h>
26#include <cpu/x86/lapic.h>
27#include <cpu/intel/microcode.h>
28#include <cpu/intel/speedstep.h>
29#include <cpu/intel/turbo.h>
30#include <cpu/x86/cache.h>
31#include <cpu/x86/name.h>
32#include <pc80/mc146818rtc.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020033#include "model_206ax.h"
Duncan Laurie55632112012-07-16 12:19:00 -070034#include "chip.h"
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +020035#include <cpu/intel/smm/gen1/smi.h>
Matt DeVilliered6fe2f2016-12-14 16:12:43 -060036#include <cpu/intel/common/common.h>
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +020037
Stefan Reinauer5c554632012-04-04 00:09:50 +020038/*
Martin Roth4c3ab732013-07-08 16:23:54 -060039 * List of supported C-states in this processor
Stefan Reinauer5c554632012-04-04 00:09:50 +020040 *
41 * Latencies are typical worst-case package exit time in uS
42 * taken from the SandyBridge BIOS specification.
43 */
44static acpi_cstate_t cstate_map[] = {
45 { /* 0: C0 */
Lee Leahy9d62e7e2017-03-15 17:40:50 -070046 }, { /* 1: C1 */
Stefan Reinauer5c554632012-04-04 00:09:50 +020047 .latency = 1,
48 .power = 1000,
49 .resource = {
50 .addrl = 0x00, /* MWAIT State 0 */
51 .space_id = ACPI_ADDRESS_SPACE_FIXED,
52 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
53 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
54 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
55 }
56 },
57 { /* 2: C1E */
58 .latency = 1,
59 .power = 1000,
60 .resource = {
61 .addrl = 0x01, /* MWAIT State 0 Sub-state 1 */
62 .space_id = ACPI_ADDRESS_SPACE_FIXED,
63 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
64 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
65 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
66 }
67 },
68 { /* 3: C3 */
69 .latency = 63,
70 .power = 500,
71 .resource = {
72 .addrl = 0x10, /* MWAIT State 1 */
73 .space_id = ACPI_ADDRESS_SPACE_FIXED,
74 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
75 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
76 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
77 }
78 },
79 { /* 4: C6 */
80 .latency = 87,
81 .power = 350,
82 .resource = {
83 .addrl = 0x20, /* MWAIT State 2 */
84 .space_id = ACPI_ADDRESS_SPACE_FIXED,
85 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
86 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
87 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
88 }
89 },
90 { /* 5: C7 */
91 .latency = 90,
92 .power = 200,
93 .resource = {
94 .addrl = 0x30, /* MWAIT State 3 */
95 .space_id = ACPI_ADDRESS_SPACE_FIXED,
96 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
97 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
98 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
99 }
100 },
101 { /* 6: C7S */
102 .latency = 90,
103 .power = 200,
104 .resource = {
105 .addrl = 0x31, /* MWAIT State 3 Sub-state 1 */
106 .space_id = ACPI_ADDRESS_SPACE_FIXED,
107 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
108 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
109 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
110 }
111 },
112 { 0 }
113};
114
Stefan Reinauer5c554632012-04-04 00:09:50 +0200115/* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */
116static const u8 power_limit_time_sec_to_msr[] = {
117 [0] = 0x00,
118 [1] = 0x0a,
119 [2] = 0x0b,
120 [3] = 0x4b,
121 [4] = 0x0c,
122 [5] = 0x2c,
123 [6] = 0x4c,
124 [7] = 0x6c,
125 [8] = 0x0d,
126 [10] = 0x2d,
127 [12] = 0x4d,
128 [14] = 0x6d,
129 [16] = 0x0e,
130 [20] = 0x2e,
131 [24] = 0x4e,
132 [28] = 0x6e,
133 [32] = 0x0f,
134 [40] = 0x2f,
135 [48] = 0x4f,
136 [56] = 0x6f,
137 [64] = 0x10,
138 [80] = 0x30,
139 [96] = 0x50,
140 [112] = 0x70,
141 [128] = 0x11,
142};
143
144/* Convert POWER_LIMIT_1_TIME MSR value to seconds */
145static const u8 power_limit_time_msr_to_sec[] = {
146 [0x00] = 0,
147 [0x0a] = 1,
148 [0x0b] = 2,
149 [0x4b] = 3,
150 [0x0c] = 4,
151 [0x2c] = 5,
152 [0x4c] = 6,
153 [0x6c] = 7,
154 [0x0d] = 8,
155 [0x2d] = 10,
156 [0x4d] = 12,
157 [0x6d] = 14,
158 [0x0e] = 16,
159 [0x2e] = 20,
160 [0x4e] = 24,
161 [0x6e] = 28,
162 [0x0f] = 32,
163 [0x2f] = 40,
164 [0x4f] = 48,
165 [0x6f] = 56,
166 [0x10] = 64,
167 [0x30] = 80,
168 [0x50] = 96,
169 [0x70] = 112,
170 [0x11] = 128,
171};
172
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700173int cpu_config_tdp_levels(void)
174{
175 msr_t platform_info;
176
177 /* Minimum CPU revision */
178 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
179 return 0;
180
181 /* Bits 34:33 indicate how many levels supported */
182 platform_info = rdmsr(MSR_PLATFORM_INFO);
183 return (platform_info.hi >> 1) & 3;
184}
185
Stefan Reinauer5c554632012-04-04 00:09:50 +0200186/*
187 * Configure processor power limits if possible
188 * This must be done AFTER set of BIOS_RESET_CPL
189 */
190void set_power_limits(u8 power_limit_1_time)
191{
192 msr_t msr = rdmsr(MSR_PLATFORM_INFO);
193 msr_t limit;
Lee Leahy73a28942017-03-15 17:52:06 -0700194 unsigned int power_unit;
195 unsigned int tdp, min_power, max_power, max_time;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200196 u8 power_limit_1_val;
197
Edward O'Callaghan5cfef132014-08-03 20:00:47 +1000198 if (power_limit_1_time >= ARRAY_SIZE(power_limit_time_sec_to_msr))
Stefan Reinauer5c554632012-04-04 00:09:50 +0200199 return;
200
201 if (!(msr.lo & PLATFORM_INFO_SET_TDP))
202 return;
203
204 /* Get units */
205 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
206 power_unit = 2 << ((msr.lo & 0xf) - 1);
207
208 /* Get power defaults for this SKU */
209 msr = rdmsr(MSR_PKG_POWER_SKU);
210 tdp = msr.lo & 0x7fff;
211 min_power = (msr.lo >> 16) & 0x7fff;
212 max_power = msr.hi & 0x7fff;
213 max_time = (msr.hi >> 16) & 0x7f;
214
215 printk(BIOS_DEBUG, "CPU TDP: %u Watts\n", tdp / power_unit);
216
217 if (power_limit_time_msr_to_sec[max_time] > power_limit_1_time)
218 power_limit_1_time = power_limit_time_msr_to_sec[max_time];
219
220 if (min_power > 0 && tdp < min_power)
221 tdp = min_power;
222
223 if (max_power > 0 && tdp > max_power)
224 tdp = max_power;
225
226 power_limit_1_val = power_limit_time_sec_to_msr[power_limit_1_time];
227
228 /* Set long term power limit to TDP */
229 limit.lo = 0;
230 limit.lo |= tdp & PKG_POWER_LIMIT_MASK;
231 limit.lo |= PKG_POWER_LIMIT_EN;
232 limit.lo |= (power_limit_1_val & PKG_POWER_LIMIT_TIME_MASK) <<
233 PKG_POWER_LIMIT_TIME_SHIFT;
234
235 /* Set short term power limit to 1.25 * TDP */
236 limit.hi = 0;
237 limit.hi |= ((tdp * 125) / 100) & PKG_POWER_LIMIT_MASK;
238 limit.hi |= PKG_POWER_LIMIT_EN;
239 /* Power limit 2 time is only programmable on SNB EP/EX */
240
241 wrmsr(MSR_PKG_POWER_LIMIT, limit);
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700242
243 /* Use nominal TDP values for CPUs with configurable TDP */
244 if (cpu_config_tdp_levels()) {
245 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
246 limit.hi = 0;
247 limit.lo = msr.lo & 0xff;
248 wrmsr(MSR_TURBO_ACTIVATION_RATIO, limit);
249 }
Stefan Reinauer5c554632012-04-04 00:09:50 +0200250}
251
252static void configure_c_states(void)
253{
254 msr_t msr;
255
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200256 msr = rdmsr(MSR_PKG_CST_CONFIG_CONTROL);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200257 msr.lo |= (1 << 28); // C1 Auto Undemotion Enable
258 msr.lo |= (1 << 27); // C3 Auto Undemotion Enable
259 msr.lo |= (1 << 26); // C1 Auto Demotion Enable
260 msr.lo |= (1 << 25); // C3 Auto Demotion Enable
261 msr.lo &= ~(1 << 10); // Disable IO MWAIT redirection
262 msr.lo |= 7; // No package C-state limit
Elyes HAOUAS4e6b7902018-10-02 08:44:47 +0200263 wrmsr(MSR_PKG_CST_CONFIG_CONTROL, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200264
Patrick Georgi644e83b2013-02-09 15:35:30 +0100265 msr = rdmsr(MSR_PMG_IO_CAPTURE_ADDR);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200266 msr.lo &= ~0x7ffff;
267 msr.lo |= (PMB0_BASE + 4); // LVL_2 base address
268 msr.lo |= (2 << 16); // CST Range: C7 is max C-state
Patrick Georgi644e83b2013-02-09 15:35:30 +0100269 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200270
271 msr = rdmsr(MSR_MISC_PWR_MGMT);
272 msr.lo &= ~(1 << 0); // Enable P-state HW_ALL coordination
273 wrmsr(MSR_MISC_PWR_MGMT, msr);
274
275 msr = rdmsr(MSR_POWER_CTL);
276 msr.lo |= (1 << 18); // Enable Energy Perf Bias MSR 0x1b0
277 msr.lo |= (1 << 1); // C1E Enable
278 msr.lo |= (1 << 0); // Bi-directional PROCHOT#
279 wrmsr(MSR_POWER_CTL, msr);
280
281 /* C3 Interrupt Response Time Limit */
282 msr.hi = 0;
283 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x50;
284 wrmsr(MSR_PKGC3_IRTL, msr);
285
286 /* C6 Interrupt Response Time Limit */
287 msr.hi = 0;
288 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x68;
289 wrmsr(MSR_PKGC6_IRTL, msr);
290
291 /* C7 Interrupt Response Time Limit */
292 msr.hi = 0;
293 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x6D;
294 wrmsr(MSR_PKGC7_IRTL, msr);
295
296 /* Primary Plane Current Limit */
297 msr = rdmsr(MSR_PP0_CURRENT_CONFIG);
298 msr.lo &= ~0x1fff;
299 msr.lo |= PP0_CURRENT_LIMIT;
300 wrmsr(MSR_PP0_CURRENT_CONFIG, msr);
301
302 /* Secondary Plane Current Limit */
303 msr = rdmsr(MSR_PP1_CURRENT_CONFIG);
304 msr.lo &= ~0x1fff;
Duncan Laurie4e4320f2012-06-25 09:53:58 -0700305 if (cpuid_eax(1) >= 0x30600)
306 msr.lo |= PP1_CURRENT_LIMIT_IVB;
307 else
308 msr.lo |= PP1_CURRENT_LIMIT_SNB;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200309 wrmsr(MSR_PP1_CURRENT_CONFIG, msr);
310}
311
Duncan Laurie55632112012-07-16 12:19:00 -0700312static void configure_thermal_target(void)
313{
314 struct cpu_intel_model_206ax_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100315 struct device *lapic;
Duncan Laurie55632112012-07-16 12:19:00 -0700316 msr_t msr;
317
318 /* Find pointer to CPU configuration */
319 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
320 if (!lapic || !lapic->chip_info)
321 return;
322 conf = lapic->chip_info;
323
Martin Roth4c3ab732013-07-08 16:23:54 -0600324 /* Set TCC activation offset if supported */
Duncan Laurie55632112012-07-16 12:19:00 -0700325 msr = rdmsr(MSR_PLATFORM_INFO);
326 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
327 msr = rdmsr(MSR_TEMPERATURE_TARGET);
328 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
329 msr.lo |= (conf->tcc_offset & 0xf) << 24;
330 wrmsr(MSR_TEMPERATURE_TARGET, msr);
331 }
332}
333
Stefan Reinauer5c554632012-04-04 00:09:50 +0200334static void configure_misc(void)
335{
336 msr_t msr;
337
338 msr = rdmsr(IA32_MISC_ENABLE);
339 msr.lo |= (1 << 0); /* Fast String enable */
Lee Leahy7b5f12b92017-03-15 17:16:59 -0700340 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200341 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
342 wrmsr(IA32_MISC_ENABLE, msr);
343
344 /* Disable Thermal interrupts */
345 msr.lo = 0;
346 msr.hi = 0;
347 wrmsr(IA32_THERM_INTERRUPT, msr);
348
349 /* Enable package critical interrupt only */
350 msr.lo = 1 << 4;
351 msr.hi = 0;
352 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
353}
354
355static void enable_lapic_tpr(void)
356{
357 msr_t msr;
358
359 msr = rdmsr(MSR_PIC_MSG_CONTROL);
360 msr.lo &= ~(1 << 10); /* Enable APIC TPR updates */
361 wrmsr(MSR_PIC_MSG_CONTROL, msr);
362}
363
364static void configure_dca_cap(void)
365{
Subrata Banik53b08c32018-12-10 14:11:35 +0530366 uint32_t feature_flag;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200367 msr_t msr;
368
369 /* Check feature flag in CPUID.(EAX=1):ECX[18]==1 */
Subrata Banik53b08c32018-12-10 14:11:35 +0530370 feature_flag = cpu_get_feature_flags_ecx();
371 if (feature_flag & CPUID_DCA) {
Stefan Reinauer5c554632012-04-04 00:09:50 +0200372 msr = rdmsr(IA32_PLATFORM_DCA_CAP);
373 msr.lo |= 1;
374 wrmsr(IA32_PLATFORM_DCA_CAP, msr);
375 }
376}
377
378static void set_max_ratio(void)
379{
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700380 msr_t msr, perf_ctl;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200381
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700382 perf_ctl.hi = 0;
383
384 /* Check for configurable TDP option */
385 if (cpu_config_tdp_levels()) {
386 /* Set to nominal TDP ratio */
387 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
388 perf_ctl.lo = (msr.lo & 0xff) << 8;
389 } else {
390 /* Platform Info bits 15:8 give max ratio */
391 msr = rdmsr(MSR_PLATFORM_INFO);
392 perf_ctl.lo = msr.lo & 0xff00;
393 }
394 wrmsr(IA32_PERF_CTL, perf_ctl);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200395
396 printk(BIOS_DEBUG, "model_x06ax: frequency set to %d\n",
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700397 ((perf_ctl.lo >> 8) & 0xff) * SANDYBRIDGE_BCLK);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200398}
399
400static void set_energy_perf_bias(u8 policy)
401{
402 msr_t msr;
403
404 /* Energy Policy is bits 3:0 */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200405 msr = rdmsr(IA32_ENERGY_PERF_BIAS);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200406 msr.lo &= ~0xf;
407 msr.lo |= policy & 0xf;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +0200408 wrmsr(IA32_ENERGY_PERF_BIAS, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200409
410 printk(BIOS_DEBUG, "model_x06ax: energy policy set to %u\n",
411 policy);
412}
413
414static void configure_mca(void)
415{
416 msr_t msr;
417 int i;
Dan Elkoubydfaff4d2018-09-03 18:34:07 +0300418 int num_banks;
419
420 msr = rdmsr(IA32_MCG_CAP);
421 num_banks = msr.lo & 0xff;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200422
423 msr.lo = msr.hi = 0;
424 /* This should only be done on a cold boot */
Dan Elkoubydfaff4d2018-09-03 18:34:07 +0300425 for (i = 0; i < num_banks; i++)
Stefan Reinauer5c554632012-04-04 00:09:50 +0200426 wrmsr(IA32_MC0_STATUS + (i * 4), msr);
427}
428
Arthur Heymans68f68882018-04-11 13:03:34 +0200429int cpu_get_apic_id_map(int *apic_id_map)
430{
431 struct cpuid_result result;
432 unsigned int threads_per_package, threads_per_core, i, shift = 0;
433
434 /* Logical processors (threads) per core */
435 result = cpuid_ext(0xb, 0);
436 threads_per_core = result.ebx & 0xffff;
437
438 /* Logical processors (threads) per package */
439 result = cpuid_ext(0xb, 1);
440 threads_per_package = result.ebx & 0xffff;
441
442 if (threads_per_core == 1)
443 shift++;
444
445 for (i = 0; i < threads_per_package && i < CONFIG_MAX_CPUS; i++)
446 apic_id_map[i] = i << shift;
447
448 return threads_per_package;
449}
450
451/*
452 * Initialize any extra cores/threads in this package.
453 */
454static void intel_cores_init(struct device *cpu)
455{
456 struct cpuid_result result;
457 unsigned int threads_per_package, threads_per_core, i;
458
459 /* Logical processors (threads) per core */
460 result = cpuid_ext(0xb, 0);
461 threads_per_core = result.ebx & 0xffff;
462
463 /* Logical processors (threads) per package */
464 result = cpuid_ext(0xb, 1);
465 threads_per_package = result.ebx & 0xffff;
466
467 /* Only initialize extra cores from BSP */
468 if (cpu->path.apic.apic_id)
469 return;
470
471 printk(BIOS_DEBUG, "CPU: %u has %u cores, %u threads per core\n",
472 cpu->path.apic.apic_id, threads_per_package/threads_per_core,
473 threads_per_core);
474
475 for (i = 1; i < threads_per_package; ++i) {
476 struct device_path cpu_path;
477 struct device *new;
478
479 /* Build the CPU device path */
480 cpu_path.type = DEVICE_PATH_APIC;
481 cpu_path.apic.apic_id =
482 cpu->path.apic.apic_id + i;
483
484 /* Update APIC ID if no hyperthreading */
485 if (threads_per_core == 1)
486 cpu_path.apic.apic_id <<= 1;
487
488 /* Allocate the new CPU device structure */
489 new = alloc_dev(cpu->bus, &cpu_path);
490 if (!new)
491 continue;
492
493 printk(BIOS_DEBUG, "CPU: %u has core %u\n",
494 cpu->path.apic.apic_id,
495 new->path.apic.apic_id);
496
497 /* Start the new CPU */
498 if (is_smp_boot() && !start_cpu(new)) {
499 /* Record the error in cpu? */
500 printk(BIOS_ERR, "CPU %u would not start!\n",
501 new->path.apic.apic_id);
502 }
503 }
504}
505
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200506static void model_206ax_report(void)
507{
508 static const char *const mode[] = {"NOT ", ""};
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200509 char processor_name[49];
510 int vt, txt, aes;
Subrata Banik53b08c32018-12-10 14:11:35 +0530511 uint32_t cpu_id, cpu_feature_flag;
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200512
513 /* Print processor name */
514 fill_processor_name(processor_name);
515 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
516
517 /* Print platform ID */
518 printk(BIOS_INFO, "CPU: platform id %x\n", get_platform_id());
519
520 /* CPUID and features */
Subrata Banik53b08c32018-12-10 14:11:35 +0530521 cpu_id = cpu_get_cpuid();
522 printk(BIOS_INFO, "CPU: cpuid(1) 0x%x\n", cpu_id);
523
524 cpu_feature_flag = cpu_get_feature_flags_ecx();
525 aes = (cpu_feature_flag & CPUID_AES) ? 1 : 0;
526 txt = (cpu_feature_flag & CPUID_SMX) ? 1 : 0;
527 vt = (cpu_feature_flag & CPUID_VMX) ? 1 : 0;
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200528 printk(BIOS_INFO, "CPU: AES %ssupported\n", mode[aes]);
529 printk(BIOS_INFO, "CPU: TXT %ssupported\n", mode[txt]);
530 printk(BIOS_INFO, "CPU: VT %ssupported\n", mode[vt]);
531}
532
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100533static void model_206ax_init(struct device *cpu)
Stefan Reinauer5c554632012-04-04 00:09:50 +0200534{
Stefan Reinauer5c554632012-04-04 00:09:50 +0200535
536 /* Turn on caching if we haven't already */
537 x86_enable_cache();
538
Arthur Heymans68f68882018-04-11 13:03:34 +0200539 intel_update_microcode_from_cbfs();
540
Stefan Reinauer5c554632012-04-04 00:09:50 +0200541 /* Clear out pending MCEs */
542 configure_mca();
543
Patrick Rudolph9e1b9b52018-07-27 17:25:05 +0200544 /* Print infos */
545 model_206ax_report();
Patrick Rudolph74203de2017-11-20 11:57:01 +0100546
Arthur Heymans68f68882018-04-11 13:03:34 +0200547 /* Setup MTRRs based on physical address size */
548 x86_setup_mtrrs_with_detect();
549 x86_mtrr_check();
550
Stefan Reinauer5c554632012-04-04 00:09:50 +0200551 /* Setup Page Attribute Tables (PAT) */
552 // TODO set up PAT
553
Elyes HAOUASd6e96862016-08-21 10:12:15 +0200554 /* Enable the local CPU APICs */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200555 enable_lapic_tpr();
556 setup_lapic();
557
Matt DeVilliered6fe2f2016-12-14 16:12:43 -0600558 /* Set virtualization based on Kconfig option */
Matt DeVillierf9aed652018-12-15 15:57:33 -0600559 set_vmx_and_lock();
Marc Jones5986eda2012-10-25 09:37:19 -0600560
Stefan Reinauer5c554632012-04-04 00:09:50 +0200561 /* Configure C States */
562 configure_c_states();
563
564 /* Configure Enhanced SpeedStep and Thermal Sensors */
565 configure_misc();
566
Duncan Laurie55632112012-07-16 12:19:00 -0700567 /* Thermal throttle activation offset */
568 configure_thermal_target();
569
Stefan Reinauer5c554632012-04-04 00:09:50 +0200570 /* Enable Direct Cache Access */
571 configure_dca_cap();
572
573 /* Set energy policy */
574 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
575
576 /* Set Max Ratio */
577 set_max_ratio();
578
579 /* Enable Turbo */
580 enable_turbo();
Sven Schnelle51676b12012-07-29 19:18:03 +0200581
Arthur Heymans68f68882018-04-11 13:03:34 +0200582 /* Start up extra cores */
583 intel_cores_init(cpu);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200584}
585
586static struct device_operations cpu_dev_ops = {
587 .init = model_206ax_init,
588};
589
Jonathan Neuschäfer8f06ce32017-11-20 01:56:44 +0100590static const struct cpu_device_id cpu_table[] = {
Stefan Reinauer5c554632012-04-04 00:09:50 +0200591 { X86_VENDOR_INTEL, 0x206a0 }, /* Intel Sandybridge */
592 { X86_VENDOR_INTEL, 0x206a6 }, /* Intel Sandybridge D1 */
593 { X86_VENDOR_INTEL, 0x206a7 }, /* Intel Sandybridge D2/J1 */
Stefan Reinauer08067ba2012-10-15 13:47:04 -0700594 { X86_VENDOR_INTEL, 0x306a0 }, /* Intel IvyBridge */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200595 { X86_VENDOR_INTEL, 0x306a2 }, /* Intel IvyBridge */
596 { X86_VENDOR_INTEL, 0x306a4 }, /* Intel IvyBridge */
597 { X86_VENDOR_INTEL, 0x306a5 }, /* Intel IvyBridge */
598 { X86_VENDOR_INTEL, 0x306a6 }, /* Intel IvyBridge */
599 { X86_VENDOR_INTEL, 0x306a8 }, /* Intel IvyBridge */
600 { X86_VENDOR_INTEL, 0x306a9 }, /* Intel IvyBridge */
601 { 0, 0 },
602};
603
604static const struct cpu_driver driver __cpu_driver = {
605 .ops = &cpu_dev_ops,
606 .id_table = cpu_table,
607 .cstates = cstate_map,
608};