mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-29 22:43:10 +00:00
401d1c4f5d
Move this out of the common header and include it only where needed. In a number of cases this requires adding "struct udevice;" to avoid adding another large header or in other cases replacing / adding missing header files that had been pulled in, very indirectly. Finally, we have a few cases where we did not need to include <asm/global_data.h> at all, so remove that include. Signed-off-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
104 lines
2.3 KiB
C
104 lines
2.3 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* From Coreboot file of the same name
|
|
*
|
|
* Copyright (C) 2011 The Chromium Authors.
|
|
*/
|
|
|
|
#include <common.h>
|
|
#include <log.h>
|
|
#include <asm/cpu.h>
|
|
#include <asm/global_data.h>
|
|
#include <asm/msr.h>
|
|
#include <asm/processor.h>
|
|
#include <asm/turbo.h>
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
#ifdef CONFIG_CPU_INTEL_TURBO_NOT_PACKAGE_SCOPED
|
|
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)
|
|
{
|
|
return gd->arch.turbo_state;
|
|
}
|
|
|
|
static inline void set_global_turbo_state(int state)
|
|
{
|
|
gd->arch.turbo_state = state;
|
|
}
|
|
#endif
|
|
|
|
/* gcc 7.3 does not wwant to drop strings, so use #ifdef */
|
|
#ifndef CONFIG_TPL_BUILD
|
|
static const char *const turbo_state_desc[] = {
|
|
[TURBO_UNKNOWN] = "unknown",
|
|
[TURBO_UNAVAILABLE] = "unavailable",
|
|
[TURBO_DISABLED] = "available but hidden",
|
|
[TURBO_ENABLED] = "available and visible"
|
|
};
|
|
#endif
|
|
|
|
/*
|
|
* 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);
|
|
|
|
msr = msr_read(MSR_IA32_MISC_ENABLE);
|
|
turbo_en = !(msr.hi & MISC_DISABLE_TURBO);
|
|
|
|
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);
|
|
#ifndef CONFIG_TPL_BUILD
|
|
debug("Turbo is %s\n", turbo_state_desc[turbo_state]);
|
|
#endif
|
|
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 */
|
|
msr = msr_read(MSR_IA32_MISC_ENABLE);
|
|
msr.hi &= ~MISC_DISABLE_TURBO;
|
|
msr_write(MSR_IA32_MISC_ENABLE, msr);
|
|
|
|
/* Update cached turbo state */
|
|
set_global_turbo_state(TURBO_ENABLED);
|
|
debug("Turbo has been enabled\n");
|
|
}
|
|
}
|