Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google Inc. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame^] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | * |
| 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 Georgi | 25509ee | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 21 | #include <cpu/x86/msr.h> |
| 22 | #include <cpu/x86/tsc.h> |
| 23 | #include <soc/msr.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame^] | 24 | #include <console/console.h> |
| 25 | #if ENV_RAMSTAGE |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 26 | #include <soc/ramstage.h> |
| 27 | #else |
| 28 | #include <soc/romstage.h> |
| 29 | #endif |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame^] | 30 | #include <stdint.h> |
| 31 | |
| 32 | unsigned 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 Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 41 | |
| 42 | void 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 Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame^] | 52 | /* |
| 53 | * Set guranteed ratio [21:16] from IACORE_RATIOS to bits [15:8] of |
| 54 | * the PERF_CTL. |
| 55 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 56 | msr = rdmsr(MSR_IACORE_RATIOS); |
| 57 | perf_ctl.lo = (msr.lo & 0x3f0000) >> 8; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame^] | 58 | |
| 59 | /* |
| 60 | * Set guranteed vid [21:16] from IACORE_VIDS to bits [7:0] of |
| 61 | * the PERF_CTL. |
| 62 | */ |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 63 | 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__ */ |