1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cpu/x86/msr.h>
4 #include <cpu/x86/tsc.h>
7 unsigned int bus_freq_khz(void)
9 msr_t clk_info
= rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL
);
10 switch (clk_info
.lo
& 0x3) {
24 unsigned long tsc_freq_mhz(void)
27 unsigned int bclk_khz
= bus_freq_khz();
32 platform_info
= rdmsr(MSR_PLATFORM_INFO
);
33 return (bclk_khz
* ((platform_info
.lo
>> 8) & 0xff)) / 1000;
36 void set_max_freq(void)
41 /* Enable speed step. */
42 msr
= rdmsr(IA32_MISC_ENABLE
);
44 wrmsr(IA32_MISC_ENABLE
, msr
);
46 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of
48 msr
= rdmsr(MSR_IACORE_RATIOS
);
49 perf_ctl
.lo
= (msr
.lo
& 0x3f0000) >> 8;
50 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of
52 msr
= rdmsr(MSR_IACORE_VIDS
);
53 perf_ctl
.lo
|= (msr
.lo
& 0x7f0000) >> 16;
56 wrmsr(IA32_PERF_CTL
, perf_ctl
);