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>
This commit is contained in:
John Zhao 2019-07-08 11:52:35 -07:00 committed by Martin Roth
parent a78146c2b9
commit a9ee8fcbb0
1 changed files with 28 additions and 17 deletions

View File

@ -50,21 +50,15 @@ static const char *const turbo_state_desc[] = {
}; };
/* /*
* Determine the current state of Turbo and cache it for later. * Try to update the global Turbo state.
* Turbo is a package level config so it does not need to be
* enabled on every core.
*/ */
int get_turbo_state(void) static int update_turbo_state(void)
{ {
struct cpuid_result cpuid_regs; struct cpuid_result cpuid_regs;
int turbo_en, turbo_cap; int turbo_en, turbo_cap;
msr_t msr; msr_t msr;
int turbo_state = get_global_turbo_state(); 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); cpuid_regs = cpuid(CPUID_LEAF_PM);
turbo_cap = !!(cpuid_regs.eax & PM_CAP_TURBO_MODE); turbo_cap = !!(cpuid_regs.eax & PM_CAP_TURBO_MODE);
@ -84,6 +78,22 @@ int get_turbo_state(void)
set_global_turbo_state(turbo_state); set_global_turbo_state(turbo_state);
printk(BIOS_INFO, "Turbo is %s\n", turbo_state_desc[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; return turbo_state;
} }
@ -102,8 +112,7 @@ void enable_turbo(void)
wrmsr(IA32_MISC_ENABLE, msr); wrmsr(IA32_MISC_ENABLE, msr);
/* Update cached turbo state */ /* Update cached turbo state */
set_global_turbo_state(TURBO_ENABLED); update_turbo_state();
printk(BIOS_INFO, "Turbo has been enabled\n");
} }
} }
@ -114,12 +123,14 @@ void disable_turbo(void)
{ {
msr_t msr; msr_t msr;
/* Set Turbo Disable bit in Misc Enables */ /* Only possible if turbo is available and visible */
msr = rdmsr(IA32_MISC_ENABLE); if (get_turbo_state() == TURBO_ENABLED) {
msr.hi |= H_MISC_DISABLE_TURBO; /* Set Turbo Disable bit in Misc Enables */
wrmsr(IA32_MISC_ENABLE, msr); msr = rdmsr(IA32_MISC_ENABLE);
msr.hi |= H_MISC_DISABLE_TURBO;
wrmsr(IA32_MISC_ENABLE, msr);
/* Update cached turbo state */ /* Update cached turbo state */
set_global_turbo_state(TURBO_UNAVAILABLE); update_turbo_state();
printk(BIOS_INFO, "Turbo has been disabled\n"); }
} }