aboutsummaryrefslogtreecommitdiff
path: root/src/soc/amd/stoneyridge/tsc_freq.c
diff options
context:
space:
mode:
authorMarshall Dawson <marshalldawson3rd@gmail.com>2017-06-16 10:10:17 -0600
committerMartin Roth <martinroth@google.com>2017-06-29 14:49:55 +0000
commit786bd5d29371745bb731e92be0e73e261baf125e (patch)
tree2f3418f49c8aecc306ba9c13f8cc80f15a8c49c2 /src/soc/amd/stoneyridge/tsc_freq.c
parentd16022bdd470a8aedbb0ba5c5c2646a040ff1a9a (diff)
soc/amd/stoneyridge: Convert monotonic timer
Use the TSC for the Stoney Ridge monotonic timer. Modern AMD CPUs have invariant timestamp counters. This patch brings the feature more in line with other devices and allows the use of typical monotonic timer functions. BUG=chrome-os-partner:62578062 Change-Id: I07b05fbc7cdea54a45daac01954284a9fd67e42f Signed-off-by: Marshall Dawson <marshalldawson3rd@gmail.com> Reviewed-on: https://review.coreboot.org/20201 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Martin Roth <martinroth@google.com>
Diffstat (limited to 'src/soc/amd/stoneyridge/tsc_freq.c')
-rw-r--r--src/soc/amd/stoneyridge/tsc_freq.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/soc/amd/stoneyridge/tsc_freq.c b/src/soc/amd/stoneyridge/tsc_freq.c
new file mode 100644
index 0000000000..1f48306afe
--- /dev/null
+++ b/src/soc/amd/stoneyridge/tsc_freq.c
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015 Intel Corp.
+ * Copyright (C) 2017 Advanced Micro Devices
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 <arch/io.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/tsc.h>
+#include <cpu/amd/amdfam15.h>
+#include <console/console.h>
+#include <soc/pci_devs.h>
+
+unsigned long tsc_freq_mhz(void)
+{
+ msr_t msr;
+ uint8_t cpufid;
+ uint8_t cpudid;
+ uint8_t boost_states;
+
+ /*
+ * See the Family 15h Models 70h-7Fh BKDG (PID 55072) definition for
+ * MSR0000_0010. The TSC increments at the P0 frequency. According
+ * to the "Software P-state Numbering" section, P0 is the highest
+ * non-boosted state. freq = 100MHz * (CpuFid + 10h) / (2^(CpuDid)).
+ */
+ boost_states = (pci_read_config32(DEV_D18F4, CORE_PERF_BOOST_CTRL)
+ >> 2) & 0x7;
+
+ msr = rdmsr(PSTATE_0_MSR + boost_states);
+ if (!(msr.hi & 0x80000000))
+ die("Unknown error: cannot determine P-state 0\n");
+
+ cpufid = (msr.lo & 0x3f);
+ cpudid = (msr.lo & 0x1c0) >> 6;
+
+ return (100 * (cpufid + 0x10)) / (0x01 << cpudid);
+}