Wonkyu Kim has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/74389 )
Change subject: src/arch/x86 Add CPU frequency APIs ......................................................................
src/arch/x86 Add CPU frequency APIs
Signed-off-by: Wonkyu Kim wonkyu.kim@intel.com Change-Id: I8eb4397b4a8d4058af1b5c67716ee625261c4e2a --- M src/arch/x86/cpu_common.c M src/arch/x86/include/arch/cpu.h 2 files changed, 52 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/89/74389/1
diff --git a/src/arch/x86/cpu_common.c b/src/arch/x86/cpu_common.c index e674afa..58eb57b 100644 --- a/src/arch/x86/cpu_common.c +++ b/src/arch/x86/cpu_common.c @@ -2,6 +2,8 @@
#include <cpu/cpu.h> #include <types.h> +#include <cpu/x86/msr.h> +#include <intelblocks/msr.h>
#if ENV_X86_32 /* Standard macro to see if a specific flag is changeable */ @@ -212,3 +214,38 @@
return true; } + +uint32_t cpu_get_current_freq(void) +{ + msr_t msr; + uint32_t ratio, freq; + msr = rdmsr(IA32_PERF_CTL); + ratio = (msr.lo >> 8) & 0xff; + freq = ratio * CONFIG_CPU_BCLK_MHZ; + return freq; +} + +uint32_t cpu_get_max_turbo_freq(void) +{ + msr_t msr; + uint32_t ratio, freq; + msr = rdmsr(MSR_TURBO_RATIO_LIMIT); + ratio = msr.lo & 0xff; + freq = ratio * CONFIG_CPU_BCLK_MHZ; + return freq; +} + +uint32_t cpu_get_max_non_turbo_freq(void) +{ + msr_t msr; + uint32_t ratio, freq; + msr = rdmsr(MSR_PLATFORM_INFO); + ratio = (msr.lo >> 8) & 0xff; + freq = ratio * CONFIG_CPU_BCLK_MHZ; + return freq; +} + +uint32_t cpu_get_base_freq(void) +{ + return cpuid_eax(0x16); +} diff --git a/src/arch/x86/include/arch/cpu.h b/src/arch/x86/include/arch/cpu.h index b8c990e..3819f44 100644 --- a/src/arch/x86/include/arch/cpu.h +++ b/src/arch/x86/include/arch/cpu.h @@ -313,4 +313,9 @@ */ bool fill_cpu_cache_info(uint8_t level, struct cpu_cache_info *info);
+uint32_t cpu_get_current_freq(void); +uint32_t cpu_get_max_turbo_freq(void); +uint32_t cpu_get_max_non_turbo_freq(void); +uint32_t cpu_get_base_freq(void); + #endif /* ARCH_CPU_H */