2013-09-07 07:41:48 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <cpu/x86/msr.h>
|
|
|
|
#include <cpu/x86/tsc.h>
|
2014-10-08 01:42:17 +02:00
|
|
|
#include <soc/msr.h>
|
2013-10-08 00:12:20 +02:00
|
|
|
|
2013-11-07 21:47:35 +01:00
|
|
|
unsigned bus_freq_khz(void)
|
2013-09-07 07:41:48 +02:00
|
|
|
{
|
2013-11-07 21:47:35 +01:00
|
|
|
msr_t clk_info = rdmsr(MSR_BSEL_CR_OVERCLOCK_CONTROL);
|
2013-10-11 07:44:06 +02:00
|
|
|
switch (clk_info.lo & 0x3) {
|
|
|
|
case 0:
|
2013-11-07 21:47:35 +01:00
|
|
|
return 83333;
|
2013-10-11 07:44:06 +02:00
|
|
|
case 1:
|
2013-11-07 21:47:35 +01:00
|
|
|
return 100000;
|
2013-10-11 07:44:06 +02:00
|
|
|
case 2:
|
2013-11-07 21:47:35 +01:00
|
|
|
return 133333;
|
2013-10-11 07:44:06 +02:00
|
|
|
case 3:
|
2013-11-07 21:47:35 +01:00
|
|
|
return 116666;
|
|
|
|
default:
|
|
|
|
return 0;
|
2013-10-11 07:44:06 +02:00
|
|
|
}
|
2013-11-07 21:47:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long tsc_freq_mhz(void)
|
|
|
|
{
|
|
|
|
msr_t platform_info;
|
|
|
|
unsigned bclk_khz = bus_freq_khz();
|
|
|
|
|
|
|
|
if (!bclk_khz)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
platform_info = rdmsr(MSR_PLATFORM_INFO);
|
2013-10-11 07:44:06 +02:00
|
|
|
return (bclk_khz * ((platform_info.lo >> 8) & 0xff)) / 1000;
|
2013-09-07 07:41:48 +02:00
|
|
|
}
|
2013-10-08 00:12:20 +02:00
|
|
|
|
2013-10-22 05:32:00 +02:00
|
|
|
#if !defined(__SMM__)
|
|
|
|
#if !defined(__PRE_RAM__)
|
2014-10-08 01:42:17 +02:00
|
|
|
#include <soc/ramstage.h>
|
2013-10-22 05:32:00 +02:00
|
|
|
#else
|
2014-10-08 01:42:17 +02:00
|
|
|
#include <soc/romstage.h>
|
2013-10-22 05:32:00 +02:00
|
|
|
#endif
|
|
|
|
|
2013-10-08 00:12:20 +02:00
|
|
|
void set_max_freq(void)
|
|
|
|
{
|
|
|
|
msr_t perf_ctl;
|
|
|
|
msr_t msr;
|
|
|
|
|
|
|
|
/* Enable speed step. */
|
|
|
|
msr = rdmsr(MSR_IA32_MISC_ENABLES);
|
|
|
|
msr.lo |= (1 << 16);
|
|
|
|
wrmsr(MSR_IA32_MISC_ENABLES, msr);
|
|
|
|
|
2014-12-07 22:57:26 +01:00
|
|
|
/* Set guaranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of
|
2013-10-08 00:12:20 +02:00
|
|
|
* the PERF_CTL. */
|
|
|
|
msr = rdmsr(MSR_IACORE_RATIOS);
|
|
|
|
perf_ctl.lo = (msr.lo & 0x3f0000) >> 8;
|
2014-12-07 22:57:26 +01:00
|
|
|
/* Set guaranteed vid [21:16] from IACORE_VIDS to bits [7:0] of
|
2013-10-08 00:12:20 +02:00
|
|
|
* the PERF_CTL. */
|
|
|
|
msr = rdmsr(MSR_IACORE_VIDS);
|
|
|
|
perf_ctl.lo |= (msr.lo & 0x7f0000) >> 16;
|
|
|
|
perf_ctl.hi = 0;
|
|
|
|
|
|
|
|
wrmsr(MSR_IA32_PERF_CTL, perf_ctl);
|
|
|
|
}
|
2013-10-22 05:32:00 +02:00
|
|
|
|
|
|
|
#endif /* __SMM__ */
|