Martin Roth has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/34145 )
Change subject: src/cpu/intel: Add sanity check for cpu turbo mode capability ......................................................................
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 --- M src/cpu/intel/turbo/turbo.c 1 file changed, 28 insertions(+), 17 deletions(-)
Approvals: build bot (Jenkins): Verified Furquan Shaikh: Looks good to me, approved
diff --git a/src/cpu/intel/turbo/turbo.c b/src/cpu/intel/turbo/turbo.c index 12cbfc0..ae97f9a 100644 --- a/src/cpu/intel/turbo/turbo.c +++ b/src/cpu/intel/turbo/turbo.c @@ -50,21 +50,15 @@ };
/* - * 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 @@
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 @@ 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 @@ { 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(); + } }