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 |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, |
| 20 | * MA 02110-1301 USA |
| 21 | */ |
| 22 | |
| 23 | #include <console/console.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <string.h> |
| 27 | #include <arch/acpi.h> |
| 28 | #include <cpu/cpu.h> |
| 29 | #include <cpu/x86/mtrr.h> |
| 30 | #include <cpu/x86/msr.h> |
| 31 | #include <cpu/x86/lapic.h> |
| 32 | #include <cpu/intel/microcode.h> |
| 33 | #include <cpu/intel/speedstep.h> |
| 34 | #include <cpu/intel/turbo.h> |
| 35 | #include <cpu/x86/cache.h> |
| 36 | #include <cpu/x86/name.h> |
| 37 | #include <pc80/mc146818rtc.h> |
| 38 | #include <usbdebug.h> |
| 39 | #include "model_206ax.h" |
Duncan Laurie | 5563211 | 2012-07-16 12:19:00 -0700 | [diff] [blame] | 40 | #include "chip.h" |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * List of suported C-states in this processor |
| 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 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 119 | /* Convert time in seconds to POWER_LIMIT_1_TIME MSR value */ |
| 120 | static const u8 power_limit_time_sec_to_msr[] = { |
| 121 | [0] = 0x00, |
| 122 | [1] = 0x0a, |
| 123 | [2] = 0x0b, |
| 124 | [3] = 0x4b, |
| 125 | [4] = 0x0c, |
| 126 | [5] = 0x2c, |
| 127 | [6] = 0x4c, |
| 128 | [7] = 0x6c, |
| 129 | [8] = 0x0d, |
| 130 | [10] = 0x2d, |
| 131 | [12] = 0x4d, |
| 132 | [14] = 0x6d, |
| 133 | [16] = 0x0e, |
| 134 | [20] = 0x2e, |
| 135 | [24] = 0x4e, |
| 136 | [28] = 0x6e, |
| 137 | [32] = 0x0f, |
| 138 | [40] = 0x2f, |
| 139 | [48] = 0x4f, |
| 140 | [56] = 0x6f, |
| 141 | [64] = 0x10, |
| 142 | [80] = 0x30, |
| 143 | [96] = 0x50, |
| 144 | [112] = 0x70, |
| 145 | [128] = 0x11, |
| 146 | }; |
| 147 | |
| 148 | /* Convert POWER_LIMIT_1_TIME MSR value to seconds */ |
| 149 | static const u8 power_limit_time_msr_to_sec[] = { |
| 150 | [0x00] = 0, |
| 151 | [0x0a] = 1, |
| 152 | [0x0b] = 2, |
| 153 | [0x4b] = 3, |
| 154 | [0x0c] = 4, |
| 155 | [0x2c] = 5, |
| 156 | [0x4c] = 6, |
| 157 | [0x6c] = 7, |
| 158 | [0x0d] = 8, |
| 159 | [0x2d] = 10, |
| 160 | [0x4d] = 12, |
| 161 | [0x6d] = 14, |
| 162 | [0x0e] = 16, |
| 163 | [0x2e] = 20, |
| 164 | [0x4e] = 24, |
| 165 | [0x6e] = 28, |
| 166 | [0x0f] = 32, |
| 167 | [0x2f] = 40, |
| 168 | [0x4f] = 48, |
| 169 | [0x6f] = 56, |
| 170 | [0x10] = 64, |
| 171 | [0x30] = 80, |
| 172 | [0x50] = 96, |
| 173 | [0x70] = 112, |
| 174 | [0x11] = 128, |
| 175 | }; |
| 176 | |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 177 | int cpu_config_tdp_levels(void) |
| 178 | { |
| 179 | msr_t platform_info; |
| 180 | |
| 181 | /* Minimum CPU revision */ |
| 182 | if (cpuid_eax(1) < IVB_CONFIG_TDP_MIN_CPUID) |
| 183 | return 0; |
| 184 | |
| 185 | /* Bits 34:33 indicate how many levels supported */ |
| 186 | platform_info = rdmsr(MSR_PLATFORM_INFO); |
| 187 | return (platform_info.hi >> 1) & 3; |
| 188 | } |
| 189 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 190 | /* |
| 191 | * Configure processor power limits if possible |
| 192 | * This must be done AFTER set of BIOS_RESET_CPL |
| 193 | */ |
| 194 | void set_power_limits(u8 power_limit_1_time) |
| 195 | { |
| 196 | msr_t msr = rdmsr(MSR_PLATFORM_INFO); |
| 197 | msr_t limit; |
| 198 | unsigned power_unit; |
| 199 | unsigned tdp, min_power, max_power, max_time; |
| 200 | u8 power_limit_1_val; |
| 201 | |
| 202 | if (power_limit_1_time > ARRAY_SIZE(power_limit_time_sec_to_msr)) |
| 203 | return; |
| 204 | |
| 205 | if (!(msr.lo & PLATFORM_INFO_SET_TDP)) |
| 206 | return; |
| 207 | |
| 208 | /* Get units */ |
| 209 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 210 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 211 | |
| 212 | /* Get power defaults for this SKU */ |
| 213 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 214 | tdp = msr.lo & 0x7fff; |
| 215 | min_power = (msr.lo >> 16) & 0x7fff; |
| 216 | max_power = msr.hi & 0x7fff; |
| 217 | max_time = (msr.hi >> 16) & 0x7f; |
| 218 | |
| 219 | printk(BIOS_DEBUG, "CPU TDP: %u Watts\n", tdp / power_unit); |
| 220 | |
| 221 | if (power_limit_time_msr_to_sec[max_time] > power_limit_1_time) |
| 222 | power_limit_1_time = power_limit_time_msr_to_sec[max_time]; |
| 223 | |
| 224 | if (min_power > 0 && tdp < min_power) |
| 225 | tdp = min_power; |
| 226 | |
| 227 | if (max_power > 0 && tdp > max_power) |
| 228 | tdp = max_power; |
| 229 | |
| 230 | power_limit_1_val = power_limit_time_sec_to_msr[power_limit_1_time]; |
| 231 | |
| 232 | /* Set long term power limit to TDP */ |
| 233 | limit.lo = 0; |
| 234 | limit.lo |= tdp & PKG_POWER_LIMIT_MASK; |
| 235 | limit.lo |= PKG_POWER_LIMIT_EN; |
| 236 | limit.lo |= (power_limit_1_val & PKG_POWER_LIMIT_TIME_MASK) << |
| 237 | PKG_POWER_LIMIT_TIME_SHIFT; |
| 238 | |
| 239 | /* Set short term power limit to 1.25 * TDP */ |
| 240 | limit.hi = 0; |
| 241 | limit.hi |= ((tdp * 125) / 100) & PKG_POWER_LIMIT_MASK; |
| 242 | limit.hi |= PKG_POWER_LIMIT_EN; |
| 243 | /* Power limit 2 time is only programmable on SNB EP/EX */ |
| 244 | |
| 245 | wrmsr(MSR_PKG_POWER_LIMIT, limit); |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 246 | |
| 247 | /* Use nominal TDP values for CPUs with configurable TDP */ |
| 248 | if (cpu_config_tdp_levels()) { |
| 249 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 250 | limit.hi = 0; |
| 251 | limit.lo = msr.lo & 0xff; |
| 252 | wrmsr(MSR_TURBO_ACTIVATION_RATIO, limit); |
| 253 | } |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | static void configure_c_states(void) |
| 257 | { |
| 258 | msr_t msr; |
| 259 | |
| 260 | msr = rdmsr(MSR_PMG_CST_CONFIG_CONTROL); |
| 261 | msr.lo |= (1 << 28); // C1 Auto Undemotion Enable |
| 262 | msr.lo |= (1 << 27); // C3 Auto Undemotion Enable |
| 263 | msr.lo |= (1 << 26); // C1 Auto Demotion Enable |
| 264 | msr.lo |= (1 << 25); // C3 Auto Demotion Enable |
| 265 | msr.lo &= ~(1 << 10); // Disable IO MWAIT redirection |
| 266 | msr.lo |= 7; // No package C-state limit |
| 267 | wrmsr(MSR_PMG_CST_CONFIG_CONTROL, msr); |
| 268 | |
| 269 | msr = rdmsr(MSR_PMG_IO_CAPTURE_BASE); |
| 270 | msr.lo &= ~0x7ffff; |
| 271 | msr.lo |= (PMB0_BASE + 4); // LVL_2 base address |
| 272 | msr.lo |= (2 << 16); // CST Range: C7 is max C-state |
| 273 | wrmsr(MSR_PMG_IO_CAPTURE_BASE, msr); |
| 274 | |
| 275 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 276 | msr.lo &= ~(1 << 0); // Enable P-state HW_ALL coordination |
| 277 | wrmsr(MSR_MISC_PWR_MGMT, msr); |
| 278 | |
| 279 | msr = rdmsr(MSR_POWER_CTL); |
| 280 | msr.lo |= (1 << 18); // Enable Energy Perf Bias MSR 0x1b0 |
| 281 | msr.lo |= (1 << 1); // C1E Enable |
| 282 | msr.lo |= (1 << 0); // Bi-directional PROCHOT# |
| 283 | wrmsr(MSR_POWER_CTL, msr); |
| 284 | |
| 285 | /* C3 Interrupt Response Time Limit */ |
| 286 | msr.hi = 0; |
| 287 | msr.lo = IRTL_VALID | IRTL_1024_NS | 0x50; |
| 288 | wrmsr(MSR_PKGC3_IRTL, msr); |
| 289 | |
| 290 | /* C6 Interrupt Response Time Limit */ |
| 291 | msr.hi = 0; |
| 292 | msr.lo = IRTL_VALID | IRTL_1024_NS | 0x68; |
| 293 | wrmsr(MSR_PKGC6_IRTL, msr); |
| 294 | |
| 295 | /* C7 Interrupt Response Time Limit */ |
| 296 | msr.hi = 0; |
| 297 | msr.lo = IRTL_VALID | IRTL_1024_NS | 0x6D; |
| 298 | wrmsr(MSR_PKGC7_IRTL, msr); |
| 299 | |
| 300 | /* Primary Plane Current Limit */ |
| 301 | msr = rdmsr(MSR_PP0_CURRENT_CONFIG); |
| 302 | msr.lo &= ~0x1fff; |
| 303 | msr.lo |= PP0_CURRENT_LIMIT; |
| 304 | wrmsr(MSR_PP0_CURRENT_CONFIG, msr); |
| 305 | |
| 306 | /* Secondary Plane Current Limit */ |
| 307 | msr = rdmsr(MSR_PP1_CURRENT_CONFIG); |
| 308 | msr.lo &= ~0x1fff; |
Duncan Laurie | 4e4320f | 2012-06-25 09:53:58 -0700 | [diff] [blame] | 309 | if (cpuid_eax(1) >= 0x30600) |
| 310 | msr.lo |= PP1_CURRENT_LIMIT_IVB; |
| 311 | else |
| 312 | msr.lo |= PP1_CURRENT_LIMIT_SNB; |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 313 | wrmsr(MSR_PP1_CURRENT_CONFIG, msr); |
| 314 | } |
| 315 | |
Duncan Laurie | 5563211 | 2012-07-16 12:19:00 -0700 | [diff] [blame] | 316 | static void configure_thermal_target(void) |
| 317 | { |
| 318 | struct cpu_intel_model_206ax_config *conf; |
| 319 | device_t lapic; |
| 320 | msr_t msr; |
| 321 | |
| 322 | /* Find pointer to CPU configuration */ |
| 323 | lapic = dev_find_lapic(SPEEDSTEP_APIC_MAGIC); |
| 324 | if (!lapic || !lapic->chip_info) |
| 325 | return; |
| 326 | conf = lapic->chip_info; |
| 327 | |
| 328 | /* Set TCC activaiton offset if supported */ |
| 329 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 330 | if ((msr.lo & (1 << 30)) && conf->tcc_offset) { |
| 331 | msr = rdmsr(MSR_TEMPERATURE_TARGET); |
| 332 | msr.lo &= ~(0xf << 24); /* Bits 27:24 */ |
| 333 | msr.lo |= (conf->tcc_offset & 0xf) << 24; |
| 334 | wrmsr(MSR_TEMPERATURE_TARGET, msr); |
| 335 | } |
| 336 | } |
| 337 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 338 | static void configure_misc(void) |
| 339 | { |
| 340 | msr_t msr; |
| 341 | |
| 342 | msr = rdmsr(IA32_MISC_ENABLE); |
| 343 | msr.lo |= (1 << 0); /* Fast String enable */ |
| 344 | msr.lo |= (1 << 3); /* TM1/TM2/EMTTM enable */ |
| 345 | msr.lo |= (1 << 16); /* Enhanced SpeedStep Enable */ |
| 346 | wrmsr(IA32_MISC_ENABLE, msr); |
| 347 | |
| 348 | /* Disable Thermal interrupts */ |
| 349 | msr.lo = 0; |
| 350 | msr.hi = 0; |
| 351 | wrmsr(IA32_THERM_INTERRUPT, msr); |
| 352 | |
| 353 | /* Enable package critical interrupt only */ |
| 354 | msr.lo = 1 << 4; |
| 355 | msr.hi = 0; |
| 356 | wrmsr(IA32_PACKAGE_THERM_INTERRUPT, msr); |
| 357 | } |
| 358 | |
| 359 | static void enable_lapic_tpr(void) |
| 360 | { |
| 361 | msr_t msr; |
| 362 | |
| 363 | msr = rdmsr(MSR_PIC_MSG_CONTROL); |
| 364 | msr.lo &= ~(1 << 10); /* Enable APIC TPR updates */ |
| 365 | wrmsr(MSR_PIC_MSG_CONTROL, msr); |
| 366 | } |
| 367 | |
| 368 | static void configure_dca_cap(void) |
| 369 | { |
| 370 | struct cpuid_result cpuid_regs; |
| 371 | msr_t msr; |
| 372 | |
| 373 | /* Check feature flag in CPUID.(EAX=1):ECX[18]==1 */ |
| 374 | cpuid_regs = cpuid(1); |
| 375 | if (cpuid_regs.ecx & (1 << 18)) { |
| 376 | msr = rdmsr(IA32_PLATFORM_DCA_CAP); |
| 377 | msr.lo |= 1; |
| 378 | wrmsr(IA32_PLATFORM_DCA_CAP, msr); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | static void set_max_ratio(void) |
| 383 | { |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 384 | msr_t msr, perf_ctl; |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 385 | |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 386 | perf_ctl.hi = 0; |
| 387 | |
| 388 | /* Check for configurable TDP option */ |
| 389 | if (cpu_config_tdp_levels()) { |
| 390 | /* Set to nominal TDP ratio */ |
| 391 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 392 | perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 393 | } else { |
| 394 | /* Platform Info bits 15:8 give max ratio */ |
| 395 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 396 | perf_ctl.lo = msr.lo & 0xff00; |
| 397 | } |
| 398 | wrmsr(IA32_PERF_CTL, perf_ctl); |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 399 | |
| 400 | printk(BIOS_DEBUG, "model_x06ax: frequency set to %d\n", |
Duncan Laurie | 77dbbac | 2012-06-25 09:51:59 -0700 | [diff] [blame] | 401 | ((perf_ctl.lo >> 8) & 0xff) * SANDYBRIDGE_BCLK); |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | static void set_energy_perf_bias(u8 policy) |
| 405 | { |
| 406 | msr_t msr; |
| 407 | |
| 408 | /* Energy Policy is bits 3:0 */ |
| 409 | msr = rdmsr(IA32_ENERGY_PERFORMANCE_BIAS); |
| 410 | msr.lo &= ~0xf; |
| 411 | msr.lo |= policy & 0xf; |
| 412 | wrmsr(IA32_ENERGY_PERFORMANCE_BIAS, msr); |
| 413 | |
| 414 | printk(BIOS_DEBUG, "model_x06ax: energy policy set to %u\n", |
| 415 | policy); |
| 416 | } |
| 417 | |
| 418 | static void configure_mca(void) |
| 419 | { |
| 420 | msr_t msr; |
| 421 | int i; |
| 422 | |
| 423 | msr.lo = msr.hi = 0; |
| 424 | /* This should only be done on a cold boot */ |
| 425 | for (i = 0; i < 7; i++) |
| 426 | wrmsr(IA32_MC0_STATUS + (i * 4), msr); |
| 427 | } |
| 428 | |
| 429 | #if CONFIG_USBDEBUG |
| 430 | static unsigned ehci_debug_addr; |
| 431 | #endif |
| 432 | |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame^] | 433 | /* |
| 434 | * Initialize any extra cores/threads in this package. |
| 435 | */ |
| 436 | static void intel_cores_init(device_t cpu) |
| 437 | { |
| 438 | struct cpuid_result result; |
| 439 | unsigned cores, threads, i; |
| 440 | |
| 441 | result = cpuid_ext(0xb, 0); /* Threads per core */ |
| 442 | threads = result.ebx & 0xff; |
| 443 | |
| 444 | result = cpuid_ext(0xb, 1); /* Cores per package */ |
| 445 | cores = result.ebx & 0xff; |
| 446 | |
| 447 | /* Only initialize extra cores from BSP */ |
| 448 | if (cpu->path.apic.apic_id) |
| 449 | return; |
| 450 | |
| 451 | printk(BIOS_DEBUG, "CPU: %u has %u cores %u threads\n", |
| 452 | cpu->path.apic.apic_id, cores, threads); |
| 453 | |
| 454 | for (i = 1; i < cores; ++i) { |
| 455 | struct device_path cpu_path; |
| 456 | device_t new; |
| 457 | |
| 458 | /* Build the cpu device path */ |
| 459 | cpu_path.type = DEVICE_PATH_APIC; |
| 460 | cpu_path.apic.apic_id = |
| 461 | cpu->path.apic.apic_id + i; |
| 462 | |
| 463 | /* Update APIC ID if no hyperthreading */ |
| 464 | if (threads == 1) |
| 465 | cpu_path.apic.apic_id <<= 1; |
| 466 | |
| 467 | /* Allocate the new cpu device structure */ |
| 468 | new = alloc_dev(cpu->bus, &cpu_path); |
| 469 | if (!new) |
| 470 | continue; |
| 471 | |
| 472 | printk(BIOS_DEBUG, "CPU: %u has core %u\n", |
| 473 | cpu->path.apic.apic_id, |
| 474 | new->path.apic.apic_id); |
| 475 | |
| 476 | /* Start the new cpu */ |
| 477 | if (!start_cpu(new)) { |
| 478 | /* Record the error in cpu? */ |
| 479 | printk(BIOS_ERR, "CPU %u would not start!\n", |
| 480 | new->path.apic.apic_id); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 485 | static void model_206ax_init(device_t cpu) |
| 486 | { |
| 487 | char processor_name[49]; |
| 488 | struct cpuid_result cpuid_regs; |
| 489 | |
| 490 | /* Turn on caching if we haven't already */ |
| 491 | x86_enable_cache(); |
| 492 | |
Vadim Bendebury | 537b4e0 | 2012-06-19 12:56:57 -0700 | [diff] [blame] | 493 | intel_update_microcode_from_cbfs(); |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 494 | |
| 495 | /* Clear out pending MCEs */ |
| 496 | configure_mca(); |
| 497 | |
| 498 | /* Print processor name */ |
| 499 | fill_processor_name(processor_name); |
| 500 | printk(BIOS_INFO, "CPU: %s.\n", processor_name); |
| 501 | |
| 502 | #if CONFIG_USBDEBUG |
| 503 | // Is this caution really needed? |
| 504 | if(!ehci_debug_addr) |
| 505 | ehci_debug_addr = get_ehci_debug(); |
| 506 | set_ehci_debug(0); |
| 507 | #endif |
| 508 | |
| 509 | /* Setup MTRRs based on physical address size */ |
| 510 | cpuid_regs = cpuid(0x80000008); |
| 511 | x86_setup_fixed_mtrrs(); |
| 512 | x86_setup_var_mtrrs(cpuid_regs.eax & 0xff, 2); |
| 513 | x86_mtrr_check(); |
| 514 | |
| 515 | /* Setup Page Attribute Tables (PAT) */ |
| 516 | // TODO set up PAT |
| 517 | |
| 518 | #if CONFIG_USBDEBUG |
| 519 | set_ehci_debug(ehci_debug_addr); |
| 520 | #endif |
| 521 | |
| 522 | /* Enable the local cpu apics */ |
| 523 | enable_lapic_tpr(); |
| 524 | setup_lapic(); |
| 525 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 526 | /* Configure C States */ |
| 527 | configure_c_states(); |
| 528 | |
| 529 | /* Configure Enhanced SpeedStep and Thermal Sensors */ |
| 530 | configure_misc(); |
| 531 | |
Duncan Laurie | 5563211 | 2012-07-16 12:19:00 -0700 | [diff] [blame] | 532 | /* Thermal throttle activation offset */ |
| 533 | configure_thermal_target(); |
| 534 | |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 535 | /* Enable Direct Cache Access */ |
| 536 | configure_dca_cap(); |
| 537 | |
| 538 | /* Set energy policy */ |
| 539 | set_energy_perf_bias(ENERGY_POLICY_NORMAL); |
| 540 | |
| 541 | /* Set Max Ratio */ |
| 542 | set_max_ratio(); |
| 543 | |
| 544 | /* Enable Turbo */ |
| 545 | enable_turbo(); |
Sven Schnelle | 51676b1 | 2012-07-29 19:18:03 +0200 | [diff] [blame^] | 546 | |
| 547 | /* Start up extra cores */ |
| 548 | intel_cores_init(cpu); |
Stefan Reinauer | 5c55463 | 2012-04-04 00:09:50 +0200 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | static struct device_operations cpu_dev_ops = { |
| 552 | .init = model_206ax_init, |
| 553 | }; |
| 554 | |
| 555 | static struct cpu_device_id cpu_table[] = { |
| 556 | { X86_VENDOR_INTEL, 0x206a0 }, /* Intel Sandybridge */ |
| 557 | { X86_VENDOR_INTEL, 0x206a6 }, /* Intel Sandybridge D1 */ |
| 558 | { X86_VENDOR_INTEL, 0x206a7 }, /* Intel Sandybridge D2/J1 */ |
| 559 | { X86_VENDOR_INTEL, 0x306a2 }, /* Intel IvyBridge */ |
| 560 | { X86_VENDOR_INTEL, 0x306a4 }, /* Intel IvyBridge */ |
| 561 | { X86_VENDOR_INTEL, 0x306a5 }, /* Intel IvyBridge */ |
| 562 | { X86_VENDOR_INTEL, 0x306a6 }, /* Intel IvyBridge */ |
| 563 | { X86_VENDOR_INTEL, 0x306a8 }, /* Intel IvyBridge */ |
| 564 | { X86_VENDOR_INTEL, 0x306a9 }, /* Intel IvyBridge */ |
| 565 | { 0, 0 }, |
| 566 | }; |
| 567 | |
| 568 | static const struct cpu_driver driver __cpu_driver = { |
| 569 | .ops = &cpu_dev_ops, |
| 570 | .id_table = cpu_table, |
| 571 | .cstates = cstate_map, |
| 572 | }; |
| 573 | |