summaryrefslogtreecommitdiff
path: root/src/soc/amd/stoneyridge/monotonic_timer.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2018-01-23 10:53:05 -0700
committerMartin Roth <martinroth@google.com>2018-01-24 16:27:03 +0000
commit24079323d4d83db4ce0ff0646309bd644b53aa76 (patch)
tree9f77bd4d4bb399ad895016c24bdb78e90b6e2383 /src/soc/amd/stoneyridge/monotonic_timer.c
parent137484dee70b378ee557de4e6bbe59716e4791f0 (diff)
downloadcoreboot-24079323d4d83db4ce0ff0646309bd644b53aa76.tar.xz
soc/amd/stoneyridge: provide alternate monotonic timer
The TSC has been observed to be ticking at a non-constant rate in early boot. The root cause is still not known, but this misbehavior necessitates an alternative monotonic timer source. Use the perf TSC which ticks at 100 MHz. This also means the timestamp table is not accurate as well. Root cause of TSC rate instability needs to be resolved in order to fix that. BUG=b:72170796 Change-Id: Ie052169868a9d9f25f8cc0ce8dd8251b560e671f Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/23397 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Justin TerAvest <teravest@chromium.org>
Diffstat (limited to 'src/soc/amd/stoneyridge/monotonic_timer.c')
-rw-r--r--src/soc/amd/stoneyridge/monotonic_timer.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/soc/amd/stoneyridge/monotonic_timer.c b/src/soc/amd/stoneyridge/monotonic_timer.c
new file mode 100644
index 0000000000..170a640233
--- /dev/null
+++ b/src/soc/amd/stoneyridge/monotonic_timer.c
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2018 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; either 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 <cpu/x86/msr.h>
+#include <timer.h>
+
+#define CU_PTSC_MSR 0xc0010280
+#define PTSC_FREQ_MHZ 100
+
+void timer_monotonic_get(struct mono_time *mt)
+{
+ unsigned long long val;
+ msr_t msr;
+
+ msr = rdmsr(CU_PTSC_MSR);
+
+ val = ((unsigned long long)msr.hi << 32) | msr.lo;
+
+ mono_time_set_usecs(mt, val / PTSC_FREQ_MHZ);
+}