blob: 5c10dd58d04a84a390f435622ab9ba24317ad101 [file] [log] [blame]
Angel Ponsba38f372020-04-05 15:46:45 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy77ff0b12015-05-05 15:07:29 -07002
Lee Leahy77ff0b12015-05-05 15:07:29 -07003#include <cpu/x86/msr.h>
4#include <cpu/x86/tsc.h>
5#include <soc/msr.h>
Lee Leahy32471722015-04-20 15:20:28 -07006
Subrata Banik45a221d2015-08-05 17:01:55 +05307static const unsigned int cpu_bus_clk_freq_table[] = {
8 83333,
9 100000,
10 133333,
11 116666,
12 80000,
13 93333,
14 90000,
15 88900,
16 87500
17};
18
19unsigned int cpu_bus_freq_khz(void)
20{
21 msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL);
Angel Ponsaee7ab22020-03-19 00:31:58 +010022
Patrick Georgi6b688f52021-02-12 13:49:11 +010023 if ((clk_info.lo & 0xf) < ARRAY_SIZE(cpu_bus_clk_freq_table))
Angel Ponsaee7ab22020-03-19 00:31:58 +010024 return cpu_bus_clk_freq_table[clk_info.lo & 0xf];
25
Subrata Banik45a221d2015-08-05 17:01:55 +053026 return 0;
27}
28
Lee Leahy32471722015-04-20 15:20:28 -070029unsigned long tsc_freq_mhz(void)
30{
Subrata Banik45a221d2015-08-05 17:01:55 +053031 msr_t platform_info;
32 unsigned int bclk_khz = cpu_bus_freq_khz();
Lee Leahy32471722015-04-20 15:20:28 -070033
Subrata Banik45a221d2015-08-05 17:01:55 +053034 if (!bclk_khz)
35 return 0;
36
37 platform_info = rdmsr(MSR_PLATFORM_INFO);
38 return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000;
Lee Leahy32471722015-04-20 15:20:28 -070039}
40
Lee Leahy77ff0b12015-05-05 15:07:29 -070041void set_max_freq(void)
42{
43 msr_t perf_ctl;
44 msr_t msr;
45
Angel Ponsaee7ab22020-03-19 00:31:58 +010046 /* Enable Intel SpeedStep */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020047 msr = rdmsr(IA32_MISC_ENABLE);
Lee Leahy77ff0b12015-05-05 15:07:29 -070048 msr.lo |= (1 << 16);
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020049 wrmsr(IA32_MISC_ENABLE, msr);
Lee Leahy77ff0b12015-05-05 15:07:29 -070050
Hannah Williamsb0eb5942015-08-23 17:24:43 -070051 /* Enable Burst Mode */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020052 msr = rdmsr(IA32_MISC_ENABLE);
Hannah Williamsb0eb5942015-08-23 17:24:43 -070053 msr.hi = 0;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020054 wrmsr(IA32_MISC_ENABLE, msr);
Hannah Williamsb0eb5942015-08-23 17:24:43 -070055
Angel Ponsaee7ab22020-03-19 00:31:58 +010056 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of the PERF_CTL */
Hannah Williamsb0eb5942015-08-23 17:24:43 -070057 msr = rdmsr(MSR_IACORE_TURBO_RATIOS);
Angel Ponsaee7ab22020-03-19 00:31:58 +010058 perf_ctl.lo = (msr.lo & 0x003f0000) >> 8;
Lee Leahy32471722015-04-20 15:20:28 -070059
Angel Ponsaee7ab22020-03-19 00:31:58 +010060 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of the PERF_CTL */
Hannah Williamsb0eb5942015-08-23 17:24:43 -070061 msr = rdmsr(MSR_IACORE_TURBO_VIDS);
Angel Ponsaee7ab22020-03-19 00:31:58 +010062 perf_ctl.lo |= (msr.lo & 0x007f0000) >> 16;
Lee Leahy77ff0b12015-05-05 15:07:29 -070063 perf_ctl.hi = 0;
64
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020065 wrmsr(IA32_PERF_CTL, perf_ctl);
Lee Leahy77ff0b12015-05-05 15:07:29 -070066}