Angel Pons | ba38f37 | 2020-04-05 15:46:45 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 3 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 4 | #include <cpu/x86/msr.h> |
| 5 | #include <cpu/x86/tsc.h> |
| 6 | #include <soc/msr.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 9 | static const unsigned int cpu_bus_clk_freq_table[] = { |
| 10 | 83333, |
| 11 | 100000, |
| 12 | 133333, |
| 13 | 116666, |
| 14 | 80000, |
| 15 | 93333, |
| 16 | 90000, |
| 17 | 88900, |
| 18 | 87500 |
| 19 | }; |
| 20 | |
| 21 | unsigned int cpu_bus_freq_khz(void) |
| 22 | { |
| 23 | msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 24 | |
| 25 | if ((clk_info.lo & 0xf) < (sizeof(cpu_bus_clk_freq_table) / sizeof(unsigned int))) |
| 26 | return cpu_bus_clk_freq_table[clk_info.lo & 0xf]; |
| 27 | |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 28 | return 0; |
| 29 | } |
| 30 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 31 | unsigned long tsc_freq_mhz(void) |
| 32 | { |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 33 | msr_t platform_info; |
| 34 | unsigned int bclk_khz = cpu_bus_freq_khz(); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 35 | |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 36 | if (!bclk_khz) |
| 37 | return 0; |
| 38 | |
| 39 | platform_info = rdmsr(MSR_PLATFORM_INFO); |
| 40 | return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 41 | } |
| 42 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 43 | void set_max_freq(void) |
| 44 | { |
| 45 | msr_t perf_ctl; |
| 46 | msr_t msr; |
| 47 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 48 | /* Enable Intel SpeedStep */ |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 49 | msr = rdmsr(IA32_MISC_ENABLE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 50 | msr.lo |= (1 << 16); |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 51 | wrmsr(IA32_MISC_ENABLE, msr); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 52 | |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 53 | /* Enable Burst Mode */ |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 54 | msr = rdmsr(IA32_MISC_ENABLE); |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 55 | msr.hi = 0; |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 56 | wrmsr(IA32_MISC_ENABLE, msr); |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 57 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 58 | /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of the PERF_CTL */ |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 59 | msr = rdmsr(MSR_IACORE_TURBO_RATIOS); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 60 | perf_ctl.lo = (msr.lo & 0x003f0000) >> 8; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 61 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 62 | /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of the PERF_CTL */ |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 63 | msr = rdmsr(MSR_IACORE_TURBO_VIDS); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame] | 64 | perf_ctl.lo |= (msr.lo & 0x007f0000) >> 16; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 65 | perf_ctl.hi = 0; |
| 66 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 67 | wrmsr(IA32_PERF_CTL, perf_ctl); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 68 | } |