blob: e7a1c13f519134d9c553a8b5723f339a70723d15 [file] [log] [blame]
Lee Leahy77ff0b12015-05-05 15:07:29 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2013 Google Inc.
Lee Leahy32471722015-04-20 15:20:28 -07005 * Copyright (C) 2015 Intel Corp.
Lee Leahy77ff0b12015-05-05 15:07:29 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Patrick Georgi25509ee2015-03-26 15:17:45 +010018 * Foundation, Inc.
Lee Leahy77ff0b12015-05-05 15:07:29 -070019 */
20
Lee Leahy77ff0b12015-05-05 15:07:29 -070021#include <cpu/x86/msr.h>
22#include <cpu/x86/tsc.h>
23#include <soc/msr.h>
Lee Leahy32471722015-04-20 15:20:28 -070024#include <console/console.h>
25#if ENV_RAMSTAGE
Lee Leahy77ff0b12015-05-05 15:07:29 -070026#include <soc/ramstage.h>
27#else
28#include <soc/romstage.h>
29#endif
Lee Leahy32471722015-04-20 15:20:28 -070030#include <stdint.h>
31
32unsigned long tsc_freq_mhz(void)
33{
34 msr_t ia_core_ratios;
35
36 ia_core_ratios = rdmsr(MSR_IACORE_RATIOS);
37 return (BUS_FREQ_KHZ * ((ia_core_ratios.lo >> 16) & 0x3f)) / 1000;
38}
39
40#if !defined(__SMM__)
Lee Leahy77ff0b12015-05-05 15:07:29 -070041
42void set_max_freq(void)
43{
44 msr_t perf_ctl;
45 msr_t msr;
46
47 /* Enable speed step. */
48 msr = rdmsr(MSR_IA32_MISC_ENABLES);
49 msr.lo |= (1 << 16);
50 wrmsr(MSR_IA32_MISC_ENABLES, msr);
51
Lee Leahy32471722015-04-20 15:20:28 -070052 /*
53 * Set guranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of
54 * the PERF_CTL.
55 */
Lee Leahy77ff0b12015-05-05 15:07:29 -070056 msr = rdmsr(MSR_IACORE_RATIOS);
57 perf_ctl.lo = (msr.lo & 0x3f0000) >> 8;
Lee Leahy32471722015-04-20 15:20:28 -070058
59 /*
60 * Set guranteed vid [21:16] from IACORE_VIDS to bits [7:0] of
61 * the PERF_CTL.
62 */
Lee Leahy77ff0b12015-05-05 15:07:29 -070063 msr = rdmsr(MSR_IACORE_VIDS);
64 perf_ctl.lo |= (msr.lo & 0x7f0000) >> 16;
65 perf_ctl.hi = 0;
66
67 wrmsr(MSR_IA32_PERF_CTL, perf_ctl);
68}
69
70#endif /* __SMM__ */