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