2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-11-15 01:18:43 +00:00
|
|
|
/*
|
|
|
|
* From Coreboot file of the same name
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 The Chromium Authors.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2014-11-15 01:18:43 +00:00
|
|
|
#include <asm/cpu.h>
|
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/turbo.h>
|
|
|
|
|
2017-01-16 14:04:17 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2017-08-17 08:10:42 +00:00
|
|
|
#ifdef CONFIG_CPU_INTEL_TURBO_NOT_PACKAGE_SCOPED
|
2014-11-15 01:18:43 +00:00
|
|
|
static inline int get_global_turbo_state(void)
|
|
|
|
{
|
|
|
|
return TURBO_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_global_turbo_state(int state)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline int get_global_turbo_state(void)
|
|
|
|
{
|
2017-01-16 14:04:17 +00:00
|
|
|
return gd->arch.turbo_state;
|
2014-11-15 01:18:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_global_turbo_state(int state)
|
|
|
|
{
|
2017-01-16 14:04:17 +00:00
|
|
|
gd->arch.turbo_state = state;
|
2014-11-15 01:18:43 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-12-23 15:11:30 +00:00
|
|
|
/* gcc 7.3 does not wwant to drop strings, so use #ifdef */
|
|
|
|
#ifndef CONFIG_TPL_BUILD
|
2014-11-15 01:18:43 +00:00
|
|
|
static const char *const turbo_state_desc[] = {
|
|
|
|
[TURBO_UNKNOWN] = "unknown",
|
|
|
|
[TURBO_UNAVAILABLE] = "unavailable",
|
|
|
|
[TURBO_DISABLED] = "available but hidden",
|
|
|
|
[TURBO_ENABLED] = "available and visible"
|
|
|
|
};
|
2020-12-23 15:11:30 +00:00
|
|
|
#endif
|
2014-11-15 01:18:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
int turbo_get_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);
|
|
|
|
|
2019-09-25 14:56:39 +00:00
|
|
|
msr = msr_read(MSR_IA32_MISC_ENABLE);
|
|
|
|
turbo_en = !(msr.hi & MISC_DISABLE_TURBO);
|
2014-11-15 01:18:43 +00:00
|
|
|
|
|
|
|
if (!turbo_cap && turbo_en) {
|
|
|
|
/* Unavailable */
|
|
|
|
turbo_state = TURBO_UNAVAILABLE;
|
|
|
|
} else if (!turbo_cap && !turbo_en) {
|
|
|
|
/* Available but disabled */
|
|
|
|
turbo_state = TURBO_DISABLED;
|
|
|
|
} else if (turbo_cap && turbo_en) {
|
|
|
|
/* Available */
|
|
|
|
turbo_state = TURBO_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_global_turbo_state(turbo_state);
|
2020-12-23 15:11:30 +00:00
|
|
|
#ifndef CONFIG_TPL_BUILD
|
2014-11-15 01:18:43 +00:00
|
|
|
debug("Turbo is %s\n", turbo_state_desc[turbo_state]);
|
2020-12-23 15:11:30 +00:00
|
|
|
#endif
|
2014-11-15 01:18:43 +00:00
|
|
|
return turbo_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void turbo_enable(void)
|
|
|
|
{
|
|
|
|
msr_t msr;
|
|
|
|
|
|
|
|
/* Only possible if turbo is available but hidden */
|
|
|
|
if (turbo_get_state() == TURBO_DISABLED) {
|
|
|
|
/* Clear Turbo Disable bit in Misc Enables */
|
2019-09-25 14:56:39 +00:00
|
|
|
msr = msr_read(MSR_IA32_MISC_ENABLE);
|
|
|
|
msr.hi &= ~MISC_DISABLE_TURBO;
|
|
|
|
msr_write(MSR_IA32_MISC_ENABLE, msr);
|
2014-11-15 01:18:43 +00:00
|
|
|
|
|
|
|
/* Update cached turbo state */
|
|
|
|
set_global_turbo_state(TURBO_ENABLED);
|
|
|
|
debug("Turbo has been enabled\n");
|
|
|
|
}
|
|
|
|
}
|