Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 4 | * |
| 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 15 | #include <cpu/x86/msr.h> |
| 16 | #include <cpu/x86/tsc.h> |
| 17 | #include <soc/msr.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 20 | static 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 | |
| 32 | unsigned int cpu_bus_freq_khz(void) |
| 33 | { |
| 34 | msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 35 | |
| 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 Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 39 | return 0; |
| 40 | } |
| 41 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 42 | unsigned long tsc_freq_mhz(void) |
| 43 | { |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 44 | msr_t platform_info; |
| 45 | unsigned int bclk_khz = cpu_bus_freq_khz(); |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 46 | |
Subrata Banik | 45a221d | 2015-08-05 17:01:55 +0530 | [diff] [blame] | 47 | 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 54 | void set_max_freq(void) |
| 55 | { |
| 56 | msr_t perf_ctl; |
| 57 | msr_t msr; |
| 58 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 59 | /* Enable Intel SpeedStep */ |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 60 | msr = rdmsr(IA32_MISC_ENABLE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 61 | msr.lo |= (1 << 16); |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 62 | wrmsr(IA32_MISC_ENABLE, msr); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 64 | /* Enable Burst Mode */ |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 65 | msr = rdmsr(IA32_MISC_ENABLE); |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 66 | msr.hi = 0; |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 67 | wrmsr(IA32_MISC_ENABLE, msr); |
Hannah Williams | b0eb594 | 2015-08-23 17:24:43 -0700 | [diff] [blame] | 68 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 69 | /* 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] | 70 | msr = rdmsr(MSR_IACORE_TURBO_RATIOS); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 71 | perf_ctl.lo = (msr.lo & 0x003f0000) >> 8; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 72 | |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 73 | /* 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] | 74 | msr = rdmsr(MSR_IACORE_TURBO_VIDS); |
Angel Pons | aee7ab2 | 2020-03-19 00:31:58 +0100 | [diff] [blame^] | 75 | perf_ctl.lo |= (msr.lo & 0x007f0000) >> 16; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 76 | perf_ctl.hi = 0; |
| 77 | |
Elyes HAOUAS | 419bfbc | 2018-10-01 08:47:51 +0200 | [diff] [blame] | 78 | wrmsr(IA32_PERF_CTL, perf_ctl); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 79 | } |