[coreboot-gerrit] Change in coreboot[master]: soc/amd/stoneyridge: Convert monotonic timer

Marshall Dawson (Code Review) gerrit at coreboot.org
Tue Jun 13 23:28:10 CEST 2017


Marshall Dawson has uploaded this change for review. ( https://review.coreboot.org/20201


Change subject: soc/amd/stoneyridge: Convert monotonic timer
......................................................................

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 at gmail.com>
---
M src/soc/amd/stoneyridge/Kconfig
M src/soc/amd/stoneyridge/Makefile.inc
A src/soc/amd/stoneyridge/tsc_freq.c
3 files changed, 49 insertions(+), 2 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/01/20201/1

diff --git a/src/soc/amd/stoneyridge/Kconfig b/src/soc/amd/stoneyridge/Kconfig
index 6584fbb..b431642 100644
--- a/src/soc/amd/stoneyridge/Kconfig
+++ b/src/soc/amd/stoneyridge/Kconfig
@@ -34,12 +34,14 @@
 	select IOAPIC
 	select HAVE_USBDEBUG_OPTIONS
 	select HAVE_HARD_RESET
-	select LAPIC_MONOTONIC_TIMER
+	select UDELAY_TSC
+	select HAVE_MONOTONIC_TIMER
+	select TSC_MONOTONIC_TIMER
+	select TSC_CONSTANT_RATE
 	select SPI_FLASH if HAVE_ACPI_RESUME
 	select TSC_SYNC_LFENCE
 	select SOC_AMD_COMMON
 	select SOC_AMD_PI
-	select UDELAY_LAPIC
 
 config UDELAY_LAPIC_FIXED_FSB
 	int
diff --git a/src/soc/amd/stoneyridge/Makefile.inc b/src/soc/amd/stoneyridge/Makefile.inc
index 6496897..5d78635 100644
--- a/src/soc/amd/stoneyridge/Makefile.inc
+++ b/src/soc/amd/stoneyridge/Makefile.inc
@@ -46,6 +46,7 @@
 romstage-y += smbus_spd.c
 romstage-$(CONFIG_STONEYRIDGE_UART) += uart.c
 romstage-y += memmap.c
+romstage-y += tsc_freq.c
 
 ramstage-y += chip.c
 ramstage-$(CONFIG_USBDEBUG) += enable_usbdebug.c
@@ -70,9 +71,11 @@
 ramstage-$(CONFIG_STONEYRIDGE_UART) += uart.c
 ramstage-y += usb.c
 ramstage-y += memmap.c
+ramstage-y += tsc_freq.c
 
 smm-$(CONFIG_HAVE_SMI_HANDLER) += smihandler.c
 smm-$(CONFIG_HAVE_SMI_HANDLER) += smi_util.c
+smm-$(CONFIG_HAVE_SMI_HANDLER) += tsc_freq.c
 
 CPPFLAGS_common += -I$(src)/soc/amd/stoneyridge
 CPPFLAGS_common += -I$(src)/soc/amd/stoneyridge/include
diff --git a/src/soc/amd/stoneyridge/tsc_freq.c b/src/soc/amd/stoneyridge/tsc_freq.c
new file mode 100644
index 0000000..85a8329b
--- /dev/null
+++ b/src/soc/amd/stoneyridge/tsc_freq.c
@@ -0,0 +1,42 @@
+/*
+ * 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)
+{
+	unsigned int boost_states, fid, did;
+	msr_t p0;
+
+	boost_states = (pci_read_config32(DEV_D18F4, CORE_PERF_BOOST_CTRL)
+			>> 2) & 0x7;
+
+	p0 = rdmsr(PSTATE_0_MSR + boost_states);
+	if (!(p0.hi & 0x80000000))
+		die("Unknown error: cannot determine P-state 0\n");
+
+	/* freq = 100MHz * (CpuFid + 10h) / (2^(CpuDid)) */
+	fid = p0.lo & 0x3f;
+	did = (p0.lo > 6) & 0x7;
+
+	return 100 * (fid + 0x10) / (1 << did);
+}

-- 
To view, visit https://review.coreboot.org/20201
To unsubscribe, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I07b05fbc7cdea54a45daac01954284a9fd67e42f
Gerrit-Change-Number: 20201
Gerrit-PatchSet: 1
Gerrit-Owner: Marshall Dawson <marshalldawson3rd at gmail.com>



More information about the coreboot-gerrit mailing list