1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cpu/x86/msr.h>
4 #include <cpu/x86/tsc.h>
7 static const unsigned int cpu_bus_clk_freq_table
[] = {
19 unsigned int cpu_bus_freq_khz(void)
21 msr_t clk_info
= rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL
);
23 if ((clk_info
.lo
& 0xf) < ARRAY_SIZE(cpu_bus_clk_freq_table
))
24 return cpu_bus_clk_freq_table
[clk_info
.lo
& 0xf];
29 unsigned long tsc_freq_mhz(void)
32 unsigned int bclk_khz
= cpu_bus_freq_khz();
37 platform_info
= rdmsr(MSR_PLATFORM_INFO
);
38 return (bclk_khz
* ((platform_info
.lo
>> 8) & 0xff)) / 1000;
41 void set_max_freq(void)
46 /* Enable Intel SpeedStep */
47 msr
= rdmsr(IA32_MISC_ENABLE
);
49 wrmsr(IA32_MISC_ENABLE
, msr
);
51 /* Enable Burst Mode */
52 msr
= rdmsr(IA32_MISC_ENABLE
);
54 wrmsr(IA32_MISC_ENABLE
, msr
);
56 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of the PERF_CTL */
57 msr
= rdmsr(MSR_IACORE_TURBO_RATIOS
);
58 perf_ctl
.lo
= (msr
.lo
& 0x003f0000) >> 8;
60 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of the PERF_CTL */
61 msr
= rdmsr(MSR_IACORE_TURBO_VIDS
);
62 perf_ctl
.lo
|= (msr
.lo
& 0x007f0000) >> 16;
65 wrmsr(IA32_PERF_CTL
, perf_ctl
);