blob: ae2332e42cad8a50f1bbd4c4832adb12b08da38e [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>
22#include <cpu/cpu.h>
23#include <cpu/x86/mtrr.h>
24#include <cpu/x86/msr.h>
25#include <cpu/x86/lapic.h>
26#include <cpu/intel/microcode.h>
27#include <cpu/intel/speedstep.h>
28#include <cpu/intel/turbo.h>
29#include <cpu/x86/cache.h>
30#include <cpu/x86/name.h>
31#include <pc80/mc146818rtc.h>
Stefan Reinauer5c554632012-04-04 00:09:50 +020032#include "model_206ax.h"
Duncan Laurie55632112012-07-16 12:19:00 -070033#include "chip.h"
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +020034#include <cpu/intel/smm/gen1/smi.h>
35
Stefan Reinauer5c554632012-04-04 00:09:50 +020036/*
Martin Roth4c3ab732013-07-08 16:23:54 -060037 * List of supported C-states in this processor
Stefan Reinauer5c554632012-04-04 00:09:50 +020038 *
39 * Latencies are typical worst-case package exit time in uS
40 * taken from the SandyBridge BIOS specification.
41 */
42static acpi_cstate_t cstate_map[] = {
43 { /* 0: C0 */
44 },{ /* 1: C1 */
45 .latency = 1,
46 .power = 1000,
47 .resource = {
48 .addrl = 0x00, /* MWAIT State 0 */
49 .space_id = ACPI_ADDRESS_SPACE_FIXED,
50 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
51 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
52 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
53 }
54 },
55 { /* 2: C1E */
56 .latency = 1,
57 .power = 1000,
58 .resource = {
59 .addrl = 0x01, /* MWAIT State 0 Sub-state 1 */
60 .space_id = ACPI_ADDRESS_SPACE_FIXED,
61 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
62 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
63 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
64 }
65 },
66 { /* 3: C3 */
67 .latency = 63,
68 .power = 500,
69 .resource = {
70 .addrl = 0x10, /* MWAIT State 1 */
71 .space_id = ACPI_ADDRESS_SPACE_FIXED,
72 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
73 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
74 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
75 }
76 },
77 { /* 4: C6 */
78 .latency = 87,
79 .power = 350,
80 .resource = {
81 .addrl = 0x20, /* MWAIT State 2 */
82 .space_id = ACPI_ADDRESS_SPACE_FIXED,
83 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
84 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
85 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
86 }
87 },
88 { /* 5: C7 */
89 .latency = 90,
90 .power = 200,
91 .resource = {
92 .addrl = 0x30, /* MWAIT State 3 */
93 .space_id = ACPI_ADDRESS_SPACE_FIXED,
94 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
95 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
96 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
97 }
98 },
99 { /* 6: C7S */
100 .latency = 90,
101 .power = 200,
102 .resource = {
103 .addrl = 0x31, /* MWAIT State 3 Sub-state 1 */
104 .space_id = ACPI_ADDRESS_SPACE_FIXED,
105 .bit_width = ACPI_FFIXEDHW_VENDOR_INTEL,
106 .bit_offset = ACPI_FFIXEDHW_CLASS_MWAIT,
107 .resv = ACPI_FFIXEDHW_FLAG_HW_COORD,
108 }
109 },
110 { 0 }
111};
112
Marc Jones5986eda2012-10-25 09:37:19 -0600113static void enable_vmx(void)
114{
115 struct cpuid_result regs;
116 msr_t msr;
117 int enable = CONFIG_ENABLE_VMX;
118
Marc Jonesf5a11aa2012-10-25 14:01:37 -0600119 regs = cpuid(1);
120 /* Check that the VMX is supported before reading or writing the MSR. */
121 if (!((regs.ecx & CPUID_VMX) || (regs.ecx & CPUID_SMX)))
122 return;
123
Marc Jones5986eda2012-10-25 09:37:19 -0600124 msr = rdmsr(IA32_FEATURE_CONTROL);
125
126 if (msr.lo & (1 << 0)) {
Marc Jonesf5a11aa2012-10-25 14:01:37 -0600127 printk(BIOS_ERR, "VMX is locked, so %s will do nothing\n", __func__);
Marc Jones5986eda2012-10-25 09:37:19 -0600128 /* VMX locked. If we set it again we get an illegal
129 * instruction
130 */
131 return;
132 }
133
Marc Jonesf5a11aa2012-10-25 14:01:37 -0600134 /* The IA32_FEATURE_CONTROL MSR may initialize with random values.
135 * It must be cleared regardless of VMX config setting.
136 */
137 msr.hi = msr.lo = 0;
Marc Jones5986eda2012-10-25 09:37:19 -0600138
Marc Jonesf5a11aa2012-10-25 14:01:37 -0600139 printk(BIOS_DEBUG, "%s VMX\n", enable ? "Enabling" : "Disabling");
140
Mike Frysinger223af0d2013-02-08 17:45:27 -0500141 /* Even though the Intel manual says you must set the lock bit in addition
142 * to the VMX bit in order for VMX to work, it is incorrect. Thus we leave
143 * it unlocked for the OS to manage things itself. This is good for a few
144 * reasons:
145 * - No need to reflash the bios just to toggle the lock bit.
146 * - The VMX bits really really should match each other across cores, so
147 * hard locking it on one while another has the opposite setting can
148 * easily lead to crashes as code using VMX migrates between them.
149 * - Vendors that want to "upsell" from a bios that disables+locks to
150 * one that doesn't is sleazy.
151 * By leaving this to the OS (e.g. Linux), people can do exactly what they
152 * want on the fly, and do it correctly (e.g. across multiple cores).
153 */
Marc Jonesf5a11aa2012-10-25 14:01:37 -0600154 if (enable) {
Mike Frysinger223af0d2013-02-08 17:45:27 -0500155 msr.lo |= (1 << 2);
156 if (regs.ecx & CPUID_SMX)
157 msr.lo |= (1 << 1);
Marc Jones5986eda2012-10-25 09:37:19 -0600158 }
159
160 wrmsr(IA32_FEATURE_CONTROL, msr);
161}
162
Stefan Reinauer5c554632012-04-04 00:09:50 +0200163/* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */
164static const u8 power_limit_time_sec_to_msr[] = {
165 [0] = 0x00,
166 [1] = 0x0a,
167 [2] = 0x0b,
168 [3] = 0x4b,
169 [4] = 0x0c,
170 [5] = 0x2c,
171 [6] = 0x4c,
172 [7] = 0x6c,
173 [8] = 0x0d,
174 [10] = 0x2d,
175 [12] = 0x4d,
176 [14] = 0x6d,
177 [16] = 0x0e,
178 [20] = 0x2e,
179 [24] = 0x4e,
180 [28] = 0x6e,
181 [32] = 0x0f,
182 [40] = 0x2f,
183 [48] = 0x4f,
184 [56] = 0x6f,
185 [64] = 0x10,
186 [80] = 0x30,
187 [96] = 0x50,
188 [112] = 0x70,
189 [128] = 0x11,
190};
191
192/* Convert POWER_LIMIT_1_TIME MSR value to seconds */
193static const u8 power_limit_time_msr_to_sec[] = {
194 [0x00] = 0,
195 [0x0a] = 1,
196 [0x0b] = 2,
197 [0x4b] = 3,
198 [0x0c] = 4,
199 [0x2c] = 5,
200 [0x4c] = 6,
201 [0x6c] = 7,
202 [0x0d] = 8,
203 [0x2d] = 10,
204 [0x4d] = 12,
205 [0x6d] = 14,
206 [0x0e] = 16,
207 [0x2e] = 20,
208 [0x4e] = 24,
209 [0x6e] = 28,
210 [0x0f] = 32,
211 [0x2f] = 40,
212 [0x4f] = 48,
213 [0x6f] = 56,
214 [0x10] = 64,
215 [0x30] = 80,
216 [0x50] = 96,
217 [0x70] = 112,
218 [0x11] = 128,
219};
220
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700221int cpu_config_tdp_levels(void)
222{
223 msr_t platform_info;
224
225 /* Minimum CPU revision */
226 if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID)
227 return 0;
228
229 /* Bits 34:33 indicate how many levels supported */
230 platform_info = rdmsr(MSR_PLATFORM_INFO);
231 return (platform_info.hi >> 1) & 3;
232}
233
Stefan Reinauer5c554632012-04-04 00:09:50 +0200234/*
235 * Configure processor power limits if possible
236 * This must be done AFTER set of BIOS_RESET_CPL
237 */
238void set_power_limits(u8 power_limit_1_time)
239{
240 msr_t msr = rdmsr(MSR_PLATFORM_INFO);
241 msr_t limit;
242 unsigned power_unit;
243 unsigned tdp, min_power, max_power, max_time;
244 u8 power_limit_1_val;
245
Edward O'Callaghan5cfef132014-08-03 20:00:47 +1000246 if (power_limit_1_time >= ARRAY_SIZE(power_limit_time_sec_to_msr))
Stefan Reinauer5c554632012-04-04 00:09:50 +0200247 return;
248
249 if (!(msr.lo & PLATFORM_INFO_SET_TDP))
250 return;
251
252 /* Get units */
253 msr = rdmsr(MSR_PKG_POWER_SKU_UNIT);
254 power_unit = 2 << ((msr.lo & 0xf) - 1);
255
256 /* Get power defaults for this SKU */
257 msr = rdmsr(MSR_PKG_POWER_SKU);
258 tdp = msr.lo & 0x7fff;
259 min_power = (msr.lo >> 16) & 0x7fff;
260 max_power = msr.hi & 0x7fff;
261 max_time = (msr.hi >> 16) & 0x7f;
262
263 printk(BIOS_DEBUG, "CPU TDP: %u Watts\n", tdp / power_unit);
264
265 if (power_limit_time_msr_to_sec[max_time] > power_limit_1_time)
266 power_limit_1_time = power_limit_time_msr_to_sec[max_time];
267
268 if (min_power > 0 && tdp < min_power)
269 tdp = min_power;
270
271 if (max_power > 0 && tdp > max_power)
272 tdp = max_power;
273
274 power_limit_1_val = power_limit_time_sec_to_msr[power_limit_1_time];
275
276 /* Set long term power limit to TDP */
277 limit.lo = 0;
278 limit.lo |= tdp & PKG_POWER_LIMIT_MASK;
279 limit.lo |= PKG_POWER_LIMIT_EN;
280 limit.lo |= (power_limit_1_val & PKG_POWER_LIMIT_TIME_MASK) <<
281 PKG_POWER_LIMIT_TIME_SHIFT;
282
283 /* Set short term power limit to 1.25 * TDP */
284 limit.hi = 0;
285 limit.hi |= ((tdp * 125) / 100) & PKG_POWER_LIMIT_MASK;
286 limit.hi |= PKG_POWER_LIMIT_EN;
287 /* Power limit 2 time is only programmable on SNB EP/EX */
288
289 wrmsr(MSR_PKG_POWER_LIMIT, limit);
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700290
291 /* Use nominal TDP values for CPUs with configurable TDP */
292 if (cpu_config_tdp_levels()) {
293 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
294 limit.hi = 0;
295 limit.lo = msr.lo & 0xff;
296 wrmsr(MSR_TURBO_ACTIVATION_RATIO, limit);
297 }
Stefan Reinauer5c554632012-04-04 00:09:50 +0200298}
299
300static void configure_c_states(void)
301{
302 msr_t msr;
303
304 msr = rdmsr(MSR_PMG_CST_CONFIG_CONTROL);
305 msr.lo |= (1 << 28); // C1 Auto Undemotion Enable
306 msr.lo |= (1 << 27); // C3 Auto Undemotion Enable
307 msr.lo |= (1 << 26); // C1 Auto Demotion Enable
308 msr.lo |= (1 << 25); // C3 Auto Demotion Enable
309 msr.lo &= ~(1 << 10); // Disable IO MWAIT redirection
310 msr.lo |= 7; // No package C-state limit
311 wrmsr(MSR_PMG_CST_CONFIG_CONTROL, msr);
312
Patrick Georgi644e83b2013-02-09 15:35:30 +0100313 msr = rdmsr(MSR_PMG_IO_CAPTURE_ADDR);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200314 msr.lo &= ~0x7ffff;
315 msr.lo |= (PMB0_BASE + 4); // LVL_2 base address
316 msr.lo |= (2 << 16); // CST Range: C7 is max C-state
Patrick Georgi644e83b2013-02-09 15:35:30 +0100317 wrmsr(MSR_PMG_IO_CAPTURE_ADDR, msr);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200318
319 msr = rdmsr(MSR_MISC_PWR_MGMT);
320 msr.lo &= ~(1 << 0); // Enable P-state HW_ALL coordination
321 wrmsr(MSR_MISC_PWR_MGMT, msr);
322
323 msr = rdmsr(MSR_POWER_CTL);
324 msr.lo |= (1 << 18); // Enable Energy Perf Bias MSR 0x1b0
325 msr.lo |= (1 << 1); // C1E Enable
326 msr.lo |= (1 << 0); // Bi-directional PROCHOT#
327 wrmsr(MSR_POWER_CTL, msr);
328
329 /* C3 Interrupt Response Time Limit */
330 msr.hi = 0;
331 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x50;
332 wrmsr(MSR_PKGC3_IRTL, msr);
333
334 /* C6 Interrupt Response Time Limit */
335 msr.hi = 0;
336 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x68;
337 wrmsr(MSR_PKGC6_IRTL, msr);
338
339 /* C7 Interrupt Response Time Limit */
340 msr.hi = 0;
341 msr.lo = IRTL_VALID | IRTL_1024_NS | 0x6D;
342 wrmsr(MSR_PKGC7_IRTL, msr);
343
344 /* Primary Plane Current Limit */
345 msr = rdmsr(MSR_PP0_CURRENT_CONFIG);
346 msr.lo &= ~0x1fff;
347 msr.lo |= PP0_CURRENT_LIMIT;
348 wrmsr(MSR_PP0_CURRENT_CONFIG, msr);
349
350 /* Secondary Plane Current Limit */
351 msr = rdmsr(MSR_PP1_CURRENT_CONFIG);
352 msr.lo &= ~0x1fff;
Duncan Laurie4e4320f2012-06-25 09:53:58 -0700353 if (cpuid_eax(1) >= 0x30600)
354 msr.lo |= PP1_CURRENT_LIMIT_IVB;
355 else
356 msr.lo |= PP1_CURRENT_LIMIT_SNB;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200357 wrmsr(MSR_PP1_CURRENT_CONFIG, msr);
358}
359
Duncan Laurie55632112012-07-16 12:19:00 -0700360static void configure_thermal_target(void)
361{
362 struct cpu_intel_model_206ax_config *conf;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100363 struct device *lapic;
Duncan Laurie55632112012-07-16 12:19:00 -0700364 msr_t msr;
365
366 /* Find pointer to CPU configuration */
367 lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC);
368 if (!lapic || !lapic->chip_info)
369 return;
370 conf = lapic->chip_info;
371
Martin Roth4c3ab732013-07-08 16:23:54 -0600372 /* Set TCC activation offset if supported */
Duncan Laurie55632112012-07-16 12:19:00 -0700373 msr = rdmsr(MSR_PLATFORM_INFO);
374 if ((msr.lo & (1 << 30)) && conf->tcc_offset) {
375 msr = rdmsr(MSR_TEMPERATURE_TARGET);
376 msr.lo &= ~(0xf << 24); /* Bits 27:24 */
377 msr.lo |= (conf->tcc_offset & 0xf) << 24;
378 wrmsr(MSR_TEMPERATURE_TARGET, msr);
379 }
380}
381
Stefan Reinauer5c554632012-04-04 00:09:50 +0200382static void configure_misc(void)
383{
384 msr_t msr;
385
386 msr = rdmsr(IA32_MISC_ENABLE);
387 msr.lo |= (1 << 0); /* Fast String enable */
388 msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */
389 msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */
390 wrmsr(IA32_MISC_ENABLE, msr);
391
392 /* Disable Thermal interrupts */
393 msr.lo = 0;
394 msr.hi = 0;
395 wrmsr(IA32_THERM_INTERRUPT, msr);
396
397 /* Enable package critical interrupt only */
398 msr.lo = 1 << 4;
399 msr.hi = 0;
400 wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr);
401}
402
403static void enable_lapic_tpr(void)
404{
405 msr_t msr;
406
407 msr = rdmsr(MSR_PIC_MSG_CONTROL);
408 msr.lo &= ~(1 << 10); /* Enable APIC TPR updates */
409 wrmsr(MSR_PIC_MSG_CONTROL, msr);
410}
411
412static void configure_dca_cap(void)
413{
414 struct cpuid_result cpuid_regs;
415 msr_t msr;
416
417 /* Check feature flag in CPUID.(EAX=1):ECX[18]==1 */
418 cpuid_regs = cpuid(1);
419 if (cpuid_regs.ecx & (1 << 18)) {
420 msr = rdmsr(IA32_PLATFORM_DCA_CAP);
421 msr.lo |= 1;
422 wrmsr(IA32_PLATFORM_DCA_CAP, msr);
423 }
424}
425
426static void set_max_ratio(void)
427{
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700428 msr_t msr, perf_ctl;
Stefan Reinauer5c554632012-04-04 00:09:50 +0200429
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700430 perf_ctl.hi = 0;
431
432 /* Check for configurable TDP option */
433 if (cpu_config_tdp_levels()) {
434 /* Set to nominal TDP ratio */
435 msr = rdmsr(MSR_CONFIG_TDP_NOMINAL);
436 perf_ctl.lo = (msr.lo & 0xff) << 8;
437 } else {
438 /* Platform Info bits 15:8 give max ratio */
439 msr = rdmsr(MSR_PLATFORM_INFO);
440 perf_ctl.lo = msr.lo & 0xff00;
441 }
442 wrmsr(IA32_PERF_CTL, perf_ctl);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200443
444 printk(BIOS_DEBUG, "model_x06ax: frequency set to %d\n",
Duncan Laurie77dbbac2012-06-25 09:51:59 -0700445 ((perf_ctl.lo >> 8) & 0xff) * SANDYBRIDGE_BCLK);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200446}
447
448static void set_energy_perf_bias(u8 policy)
449{
450 msr_t msr;
451
452 /* Energy Policy is bits 3:0 */
453 msr = rdmsr(IA32_ENERGY_PERFORMANCE_BIAS);
454 msr.lo &= ~0xf;
455 msr.lo |= policy & 0xf;
456 wrmsr(IA32_ENERGY_PERFORMANCE_BIAS, msr);
457
458 printk(BIOS_DEBUG, "model_x06ax: energy policy set to %u\n",
459 policy);
460}
461
462static void configure_mca(void)
463{
464 msr_t msr;
465 int i;
466
467 msr.lo = msr.hi = 0;
468 /* This should only be done on a cold boot */
469 for (i = 0; i < 7; i++)
470 wrmsr(IA32_MC0_STATUS + (i * 4), msr);
471}
472
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200473int cpu_get_apic_id_map(int *apic_id_map)
474{
Vladimir Serbinenkoefc01f02015-06-08 20:06:48 +0200475 struct cpuid_result result;
476 unsigned threads_per_package, threads_per_core, i, shift = 0;
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200477
Vladimir Serbinenkoefc01f02015-06-08 20:06:48 +0200478 /* Logical processors (threads) per core */
479 result = cpuid_ext(0xb, 0);
480 threads_per_core = result.ebx & 0xffff;
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200481
Vladimir Serbinenkoefc01f02015-06-08 20:06:48 +0200482 /* Logical processors (threads) per package */
483 result = cpuid_ext(0xb, 1);
484 threads_per_package = result.ebx & 0xffff;
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200485
Vladimir Serbinenkoefc01f02015-06-08 20:06:48 +0200486 if (threads_per_core == 1)
487 shift++;
488
489 for (i = 0; i < threads_per_package && i < CONFIG_MAX_CPUS; i++)
490 apic_id_map[i] = i << shift;
491
492 return threads_per_package;
Vladimir Serbinenkoc16e9dfa2015-05-29 16:18:01 +0200493}
494
Sven Schnelle51676b12012-07-29 19:18:03 +0200495/*
496 * Initialize any extra cores/threads in this package.
497 */
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100498static void intel_cores_init(struct device *cpu)
Sven Schnelle51676b12012-07-29 19:18:03 +0200499{
500 struct cpuid_result result;
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700501 unsigned threads_per_package, threads_per_core, i;
Sven Schnelle51676b12012-07-29 19:18:03 +0200502
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700503 /* Logical processors (threads) per core */
504 result = cpuid_ext(0xb, 0);
505 threads_per_core = result.ebx & 0xffff;
Sven Schnelle51676b12012-07-29 19:18:03 +0200506
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700507 /* Logical processors (threads) per package */
508 result = cpuid_ext(0xb, 1);
509 threads_per_package = result.ebx & 0xffff;
Sven Schnelle51676b12012-07-29 19:18:03 +0200510
511 /* Only initialize extra cores from BSP */
512 if (cpu->path.apic.apic_id)
513 return;
514
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700515 printk(BIOS_DEBUG, "CPU: %u has %u cores, %u threads per core\n",
516 cpu->path.apic.apic_id, threads_per_package/threads_per_core,
517 threads_per_core);
Sven Schnelle51676b12012-07-29 19:18:03 +0200518
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700519 for (i = 1; i < threads_per_package; ++i) {
Sven Schnelle51676b12012-07-29 19:18:03 +0200520 struct device_path cpu_path;
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100521 struct device *new;
Sven Schnelle51676b12012-07-29 19:18:03 +0200522
523 /* Build the cpu device path */
524 cpu_path.type = DEVICE_PATH_APIC;
525 cpu_path.apic.apic_id =
526 cpu->path.apic.apic_id + i;
527
528 /* Update APIC ID if no hyperthreading */
Stefan Reinauerbb9dff52012-10-15 13:45:11 -0700529 if (threads_per_core == 1)
Sven Schnelle51676b12012-07-29 19:18:03 +0200530 cpu_path.apic.apic_id <<= 1;
531
532 /* Allocate the new cpu device structure */
533 new = alloc_dev(cpu->bus, &cpu_path);
534 if (!new)
535 continue;
536
537 printk(BIOS_DEBUG, "CPU: %u has core %u\n",
538 cpu->path.apic.apic_id,
539 new->path.apic.apic_id);
540
Stefan Reinauer455f4b42012-11-12 15:17:24 -0800541#if CONFIG_SMP && CONFIG_MAX_CPUS > 1
Sven Schnelle51676b12012-07-29 19:18:03 +0200542 /* Start the new cpu */
543 if (!start_cpu(new)) {
544 /* Record the error in cpu? */
545 printk(BIOS_ERR, "CPU %u would not start!\n",
546 new->path.apic.apic_id);
547 }
Stefan Reinauer455f4b42012-11-12 15:17:24 -0800548#endif
Sven Schnelle51676b12012-07-29 19:18:03 +0200549 }
550}
551
Edward O'Callaghan2c9d2cf2014-10-27 23:29:29 +1100552static void model_206ax_init(struct device *cpu)
Stefan Reinauer5c554632012-04-04 00:09:50 +0200553{
554 char processor_name[49];
555 struct cpuid_result cpuid_regs;
556
557 /* Turn on caching if we haven't already */
558 x86_enable_cache();
559
Vadim Bendebury537b4e02012-06-19 12:56:57 -0700560 intel_update_microcode_from_cbfs();
Stefan Reinauer5c554632012-04-04 00:09:50 +0200561
562 /* Clear out pending MCEs */
563 configure_mca();
564
565 /* Print processor name */
566 fill_processor_name(processor_name);
567 printk(BIOS_INFO, "CPU: %s.\n", processor_name);
568
Stefan Reinauer5c554632012-04-04 00:09:50 +0200569 /* Setup MTRRs based on physical address size */
570 cpuid_regs = cpuid(0x80000008);
571 x86_setup_fixed_mtrrs();
572 x86_setup_var_mtrrs(cpuid_regs.eax & 0xff, 2);
573 x86_mtrr_check();
574
575 /* Setup Page Attribute Tables (PAT) */
576 // TODO set up PAT
577
Stefan Reinauer5c554632012-04-04 00:09:50 +0200578 /* Enable the local cpu apics */
579 enable_lapic_tpr();
580 setup_lapic();
581
Marc Jones5986eda2012-10-25 09:37:19 -0600582 /* Enable virtualization if enabled in CMOS */
583 enable_vmx();
584
Stefan Reinauer5c554632012-04-04 00:09:50 +0200585 /* Configure C States */
586 configure_c_states();
587
588 /* Configure Enhanced SpeedStep and Thermal Sensors */
589 configure_misc();
590
Duncan Laurie55632112012-07-16 12:19:00 -0700591 /* Thermal throttle activation offset */
592 configure_thermal_target();
593
Stefan Reinauer5c554632012-04-04 00:09:50 +0200594 /* Enable Direct Cache Access */
595 configure_dca_cap();
596
597 /* Set energy policy */
598 set_energy_perf_bias(ENERGY_POLICY_NORMAL);
599
600 /* Set Max Ratio */
601 set_max_ratio();
602
603 /* Enable Turbo */
604 enable_turbo();
Sven Schnelle51676b12012-07-29 19:18:03 +0200605
606 /* Start up extra cores */
607 intel_cores_init(cpu);
Stefan Reinauer5c554632012-04-04 00:09:50 +0200608}
609
610static struct device_operations cpu_dev_ops = {
611 .init = model_206ax_init,
612};
613
614static struct cpu_device_id cpu_table[] = {
615 { X86_VENDOR_INTEL, 0x206a0 }, /* Intel Sandybridge */
616 { X86_VENDOR_INTEL, 0x206a6 }, /* Intel Sandybridge D1 */
617 { X86_VENDOR_INTEL, 0x206a7 }, /* Intel Sandybridge D2/J1 */
Stefan Reinauer08067ba2012-10-15 13:47:04 -0700618 { X86_VENDOR_INTEL, 0x306a0 }, /* Intel IvyBridge */
Stefan Reinauer5c554632012-04-04 00:09:50 +0200619 { X86_VENDOR_INTEL, 0x306a2 }, /* Intel IvyBridge */
620 { X86_VENDOR_INTEL, 0x306a4 }, /* Intel IvyBridge */
621 { X86_VENDOR_INTEL, 0x306a5 }, /* Intel IvyBridge */
622 { X86_VENDOR_INTEL, 0x306a6 }, /* Intel IvyBridge */
623 { X86_VENDOR_INTEL, 0x306a8 }, /* Intel IvyBridge */
624 { X86_VENDOR_INTEL, 0x306a9 }, /* Intel IvyBridge */
625 { 0, 0 },
626};
627
628static const struct cpu_driver driver __cpu_driver = {
629 .ops = &cpu_dev_ops,
630 .id_table = cpu_table,
631 .cstates = cstate_map,
632};