blob: 66fde22d990c0afb6336969f43fd5a869dd74575 [file] [log] [blame]
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -05001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050014 */
15
16#include <stdint.h>
17#include <cpu/x86/msr.h>
18#include <cpu/x86/tsc.h>
Julius Werner18ea2d32014-10-07 16:42:17 -070019#include <soc/msr.h>
Aaron Durbinbb3ee832013-10-07 17:12:20 -050020
Duncan Laurie6aa9f1f2013-11-07 12:47:35 -080021unsigned bus_freq_khz(void)
22{
23 msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL);
24 switch (clk_info.lo & 0x3) {
25 case 0:
26 return 83333;
27 case 1:
28 return 100000;
29 case 2:
30 return 133333;
31 case 3:
32 return 116666;
33 default:
34 return 0;
35 }
36}
37
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050038unsigned long tsc_freq_mhz(void)
39{
40 msr_t platform_info;
Duncan Laurie6aa9f1f2013-11-07 12:47:35 -080041 unsigned bclk_khz = bus_freq_khz();
42
43 if (!bclk_khz)
44 return 0;
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050045
46 platform_info = rdmsr(MSR_PLATFORM_INFO);
Aaron Durbin9d9d7f02013-10-11 00:44:06 -050047 return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000;
Aaron Durbin9a7d7bc2013-09-07 00:41:48 -050048}
Aaron Durbinbb3ee832013-10-07 17:12:20 -050049
Aaron Durbin7837be62013-10-21 22:32:00 -050050#if !defined(__SMM__)
51#if !defined(__PRE_RAM__)
Julius Werner18ea2d32014-10-07 16:42:17 -070052#include <soc/ramstage.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050053#else
Julius Werner18ea2d32014-10-07 16:42:17 -070054#include <soc/romstage.h>
Aaron Durbin7837be62013-10-21 22:32:00 -050055#endif
56
Aaron Durbinbb3ee832013-10-07 17:12:20 -050057void set_max_freq(void)
58{
59 msr_t perf_ctl;
60 msr_t msr;
61
62 /* Enable speed step. */
63 msr = rdmsr(MSR_IA32_MISC_ENABLES);
64 msr.lo |= (1 << 16);
65 wrmsr(MSR_IA32_MISC_ENABLES, msr);
66
Martin Roth99a3bba2014-12-07 14:57:26 -070067 /* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of
Aaron Durbinbb3ee832013-10-07 17:12:20 -050068 * the PERF_CTL. */
69 msr = rdmsr(MSR_IACORE_RATIOS);
70 perf_ctl.lo = (msr.lo & 0x3f0000) >> 8;
Martin Roth99a3bba2014-12-07 14:57:26 -070071 /* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of
Aaron Durbinbb3ee832013-10-07 17:12:20 -050072 * the PERF_CTL. */
73 msr = rdmsr(MSR_IACORE_VIDS);
74 perf_ctl.lo |= (msr.lo & 0x7f0000) >> 16;
75 perf_ctl.hi = 0;
76
77 wrmsr(MSR_IA32_PERF_CTL, perf_ctl);
78}
Aaron Durbin7837be62013-10-21 22:32:00 -050079
80#endif /* __SMM__ */