blob: 13992d46d19506ce9b2eb49787db1645233fe979 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy77ff0b12015-05-05 15:07:29 -07004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Lee Leahy77ff0b12015-05-05 15:07:29 -070013 */
14
Lee Leahy77ff0b12015-05-05 15:07:29 -070015#include <cpu/x86/msr.h>
16#include <cpu/x86/tsc.h>
17#include <soc/msr.h>
Lee Leahy32471722015-04-20 15:20:28 -070018#include <stdint.h>
19
Subrata Banik45a221d2015-08-05 17:01:55 +053020static const unsigned int cpu_bus_clk_freq_table[] = {
21 83333,
22 100000,
23 133333,
24 116666,
25 80000,
26 93333,
27 90000,
28 88900,
29 87500
30};
31
32unsigned int cpu_bus_freq_khz(void)
33{
34 msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL);
Angel Ponsaee7ab22020-03-19 00:31:58 +010035
36 if ((clk_info.lo & 0xf) < (sizeof(cpu_bus_clk_freq_table) / sizeof(unsigned int)))
37 return cpu_bus_clk_freq_table[clk_info.lo & 0xf];
38
Subrata Banik45a221d2015-08-05 17:01:55 +053039 return 0;
40}
41
Lee Leahy32471722015-04-20 15:20:28 -070042unsigned long tsc_freq_mhz(void)
43{
Subrata Banik45a221d2015-08-05 17:01:55 +053044 msr_t platform_info;
45 unsigned int bclk_khz = cpu_bus_freq_khz();
Lee Leahy32471722015-04-20 15:20:28 -070046
Subrata Banik45a221d2015-08-05 17:01:55 +053047 if (!bclk_khz)
48 return 0;
49
50 platform_info = rdmsr(MSR_PLATFORM_INFO);
51 return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000;
Lee Leahy32471722015-04-20 15:20:28 -070052}
53
Lee Leahy77ff0b12015-05-05 15:07:29 -070054void set_max_freq(void)
55{
56 msr_t perf_ctl;
57 msr_t msr;
58
Angel Ponsaee7ab22020-03-19 00:31:58 +010059 /* Enable Intel SpeedStep */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020060 msr = rdmsr(IA32_MISC_ENABLE);
Lee Leahy77ff0b12015-05-05 15:07:29 -070061 msr.lo |= (1 << 16);
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020062 wrmsr(IA32_MISC_ENABLE, msr);
Lee Leahy77ff0b12015-05-05 15:07:29 -070063
Hannah Williamsb0eb5942015-08-23 17:24:43 -070064 /* Enable Burst Mode */
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020065 msr = rdmsr(IA32_MISC_ENABLE);
Hannah Williamsb0eb5942015-08-23 17:24:43 -070066 msr.hi = 0;
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020067 wrmsr(IA32_MISC_ENABLE, msr);
Hannah Williamsb0eb5942015-08-23 17:24:43 -070068
Angel Ponsaee7ab22020-03-19 00:31:58 +010069 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of the PERF_CTL */
Hannah Williamsb0eb5942015-08-23 17:24:43 -070070 msr = rdmsr(MSR_IACORE_TURBO_RATIOS);
Angel Ponsaee7ab22020-03-19 00:31:58 +010071 perf_ctl.lo = (msr.lo & 0x003f0000) >> 8;
Lee Leahy32471722015-04-20 15:20:28 -070072
Angel Ponsaee7ab22020-03-19 00:31:58 +010073 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of the PERF_CTL */
Hannah Williamsb0eb5942015-08-23 17:24:43 -070074 msr = rdmsr(MSR_IACORE_TURBO_VIDS);
Angel Ponsaee7ab22020-03-19 00:31:58 +010075 perf_ctl.lo |= (msr.lo & 0x007f0000) >> 16;
Lee Leahy77ff0b12015-05-05 15:07:29 -070076 perf_ctl.hi = 0;
77
Elyes HAOUAS419bfbc2018-10-01 08:47:51 +020078 wrmsr(IA32_PERF_CTL, perf_ctl);
Lee Leahy77ff0b12015-05-05 15:07:29 -070079}