diff options
author | John Zhao <john.zhao@intel.com> | 2019-07-08 11:52:35 -0700 |
---|---|---|
committer | Martin Roth <martinroth@google.com> | 2019-07-21 19:01:13 +0000 |
commit | a9ee8fcbb0c3a79776492eb8811fef1b3fe9b404 (patch) | |
tree | 32c115e9cde1bf7db8e3ce27057789c577e385e5 /src/cpu/intel | |
parent | a78146c2b9bae51b1dab4067b30c4801e719dee7 (diff) |
src/cpu/intel: Add sanity check for cpu turbo mode capability
It is proper to check cpu turbo mode capability after it is selected
to be enabled. If processor exhibits the presence of hardware support for
turbo, turbo global state will be updated with TURBO_ENABLE. Otherwise,
TURBO_UNAVAILABLE is applied to turbo global state.
TEST=Validated turbo state on GLK and WHL devices.
Change-Id: Ib1bc37fb339b4a0bb6a7cdc6cd4391575b22b55a
Signed-off-by: John Zhao <john.zhao@intel.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34145
Reviewed-by: Furquan Shaikh <furquan@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/cpu/intel')
-rw-r--r-- | src/cpu/intel/turbo/turbo.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/src/cpu/intel/turbo/turbo.c b/src/cpu/intel/turbo/turbo.c index 12cbfc0b81..ae97f9a8cf 100644 --- a/src/cpu/intel/turbo/turbo.c +++ b/src/cpu/intel/turbo/turbo.c @@ -50,21 +50,15 @@ static const char *const turbo_state_desc[] = { }; /* - * Determine the current state of Turbo and cache it for later. - * Turbo is a package level config so it does not need to be - * enabled on every core. + * Try to update the global Turbo state. */ -int get_turbo_state(void) +static int update_turbo_state(void) { struct cpuid_result cpuid_regs; int turbo_en, turbo_cap; msr_t msr; int turbo_state = get_global_turbo_state(); - /* Return cached state if available */ - if (turbo_state != TURBO_UNKNOWN) - return turbo_state; - cpuid_regs = cpuid(CPUID_LEAF_PM); turbo_cap = !!(cpuid_regs.eax & PM_CAP_TURBO_MODE); @@ -84,6 +78,22 @@ int get_turbo_state(void) set_global_turbo_state(turbo_state); printk(BIOS_INFO, "Turbo is %s\n", turbo_state_desc[turbo_state]); + + return turbo_state; +} + +/* + * Determine the current state of Turbo and cache it for later. Turbo is package + * level config so it does not need to be enabled on every core. + */ +int get_turbo_state(void) +{ + int turbo_state = get_global_turbo_state(); + + /* Return cached state if available */ + if (turbo_state == TURBO_UNKNOWN) + turbo_state = update_turbo_state(); + return turbo_state; } @@ -102,8 +112,7 @@ void enable_turbo(void) wrmsr(IA32_MISC_ENABLE, msr); /* Update cached turbo state */ - set_global_turbo_state(TURBO_ENABLED); - printk(BIOS_INFO, "Turbo has been enabled\n"); + update_turbo_state(); } } @@ -114,12 +123,14 @@ void disable_turbo(void) { msr_t msr; - /* Set Turbo Disable bit in Misc Enables */ - msr = rdmsr(IA32_MISC_ENABLE); - msr.hi |= H_MISC_DISABLE_TURBO; - wrmsr(IA32_MISC_ENABLE, msr); + /* Only possible if turbo is available and visible */ + if (get_turbo_state() == TURBO_ENABLED) { + /* Set Turbo Disable bit in Misc Enables */ + msr = rdmsr(IA32_MISC_ENABLE); + msr.hi |= H_MISC_DISABLE_TURBO; + wrmsr(IA32_MISC_ENABLE, msr); - /* Update cached turbo state */ - set_global_turbo_state(TURBO_UNAVAILABLE); - printk(BIOS_INFO, "Turbo has been disabled\n"); + /* Update cached turbo state */ + update_turbo_state(); + } } |