blob: 42ed5845079c4e8f4c2a09a07406de4017a1ac1b [file] [log] [blame]
Angel Ponsc3f58f62020-04-05 15:46:41 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05002
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05003#include <cpu/x86/msr.h>
4#include <cpu/x86/tsc.h>
Julius Werner18ea2d32014-10-07 16:42:17 -07005#include <soc/msr.h>
Aaron Durbinbb3ee832013-10-07 17:12:20 -05006
Martin Roth57e89092019-10-23 21:45:23 -06007unsigned int bus_freq_khz(void)
Duncan Laurie6aa9f1f2013-11-07 12:47:35 -08008{
9 msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL);
10 switch (clk_info.lo & 0x3) {
11 case 0:
12 return 83333;
13 case 1:
14 return 100000;
15 case 2:
16 return 133333;
17 case 3:
18 return 116666;
19 default:
20 return 0;
21 }
22}
23
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050024unsigned long tsc_freq_mhz(void)
25{
26 msr_t platform_info;
Martin Roth57e89092019-10-23 21:45:23 -060027 unsigned int bclk_khz = bus_freq_khz();
Duncan Laurie6aa9f1f2013-11-07 12:47:35 -080028
29 if (!bclk_khz)
30 return 0;
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050031
32 platform_info = rdmsr(MSR_PLATFORM_INFO);
Aaron Durbin9d9d7f02013-10-11 00:44:06 -050033 return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000;
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050034}
Aaron Durbinbb3ee832013-10-07 17:12:20 -050035
36void set_max_freq(void)
37{
38 msr_t perf_ctl;
39 msr_t msr;
40
41 /* Enable speed step. */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020042 msr = rdmsr(IA32_MISC_ENABLE);
Aaron Durbinbb3ee832013-10-07 17:12:20 -050043 msr.lo |= (1 << 16);
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020044 wrmsr(IA32_MISC_ENABLE, msr);
Aaron Durbinbb3ee832013-10-07 17:12:20 -050045
Martin Roth99a3bba2014-12-07 14:57:26 -070046 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of
Aaron Durbinbb3ee832013-10-07 17:12:20 -050047 * the PERF_CTL. */
48 msr = rdmsr(MSR_IACORE_RATIOS);
49 perf_ctl.lo = (msr.lo & 0x3f0000) >> 8;
Martin Roth99a3bba2014-12-07 14:57:26 -070050 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of
Aaron Durbinbb3ee832013-10-07 17:12:20 -050051 * the PERF_CTL. */
52 msr = rdmsr(MSR_IACORE_VIDS);
53 perf_ctl.lo |= (msr.lo & 0x7f0000) >> 16;
54 perf_ctl.hi = 0;
55
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020056 wrmsr(IA32_PERF_CTL, perf_ctl);
Aaron Durbinbb3ee832013-10-07 17:12:20 -050057}