2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
22 #include <console/console.h>
23 #include <cpu/intel/turbo.h>
24 #include <cpu/x86/msr.h>
27 static int turbo_state = TURBO_UNKNOWN;
29 static const char *turbo_state_desc[] = {
30 [TURBO_UNKNOWN] = "unknown",
31 [TURBO_UNAVAILABLE] = "unavailable",
32 [TURBO_DISABLED] = "available but hidden",
33 [TURBO_ENABLED] = "available and visible"
37 * Determine the current state of Turbo and cache it for later.
38 * Turbo is a package level config so it does not need to be
39 * enabled on every core.
41 int get_turbo_state(void)
43 struct cpuid_result cpuid_regs;
44 int turbo_en, turbo_cap;
47 /* Return cached state if available */
48 if (turbo_state != TURBO_UNKNOWN)
51 cpuid_regs = cpuid(CPUID_LEAF_PM);
52 turbo_cap = !!(cpuid_regs.eax & PM_CAP_TURBO_MODE);
54 msr = rdmsr(MSR_IA32_MISC_ENABLES);
55 turbo_en = !(msr.hi & H_MISC_DISABLE_TURBO);
57 if (!turbo_cap && turbo_en) {
59 turbo_state = TURBO_UNAVAILABLE;
60 } else if (!turbo_cap && !turbo_en) {
61 /* Available but disabled */
62 turbo_state = TURBO_DISABLED;
63 } else if (turbo_cap && turbo_en) {
65 turbo_state = TURBO_ENABLED;
68 printk(BIOS_INFO, "Turbo is %s\n", turbo_state_desc[turbo_state]);
73 * Try to enable Turbo mode.
75 void enable_turbo(void)
79 /* Only possible if turbo is available but hidden */
80 if (get_turbo_state() == TURBO_DISABLED) {
81 /* Clear Turbo Disable bit in Misc Enables */
82 msr = rdmsr(MSR_IA32_MISC_ENABLES);
83 msr.hi &= ~H_MISC_DISABLE_TURBO;
84 wrmsr(MSR_IA32_MISC_ENABLES, msr);
86 /* Update cached turbo state */
87 turbo_state = TURBO_ENABLED;
88 printk(BIOS_INFO, "Turbo has been enabled\n");