Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/34170 )
Change subject: libpayload/x86: Try to discover invariant TSC rate
......................................................................
libpayload/x86: Try to discover invariant TSC rate
We can skip the PIT-based TSC calibration if we can derive the invariant
TSC rate from CPUID/MSR data. This is necessary if the PIT is disabled,
which is the default, for instance, on Coffee Lake CPUs.
This implementation should cover all Intel Core i processors at least.
For older processors, we fall back to the PIT calibration.
Change-Id: Ic6607ee2a8b41c2be9dc1bb4f1e23e652bb33889
Signed-off-by: Nico Huber <nico.huber(a)secunet.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/34170
Tested-by: build bot (Jenkins) <no-reply(a)coreboot.org>
Reviewed-by: Angel Pons <th3fanbus(a)gmail.com>
Reviewed-by: Michael Niewöhner <foss(a)mniewoehner.de>
---
M payloads/libpayload/arch/x86/timer.c
1 file changed, 116 insertions(+), 3 deletions(-)
Approvals:
build bot (Jenkins): Verified
Angel Pons: Looks good to me, approved
Michael Niewöhner: Looks good to me, but someone else must approve
diff --git a/payloads/libpayload/arch/x86/timer.c b/payloads/libpayload/arch/x86/timer.c
index 1ff2cd6..6dcfd5b 100644
--- a/payloads/libpayload/arch/x86/timer.c
+++ b/payloads/libpayload/arch/x86/timer.c
@@ -33,6 +33,10 @@
#include <libpayload.h>
#include <arch/rdtsc.h>
+#include <arch/cpuid.h>
+#include <arch/msr.h>
+
+#define MSR_PLATFORM_INFO 0xce
/**
* @ingroup arch
@@ -41,11 +45,11 @@
uint32_t cpu_khz;
/**
- * Calculate the speed of the processor for use in delays.
+ * @brief Measure the speed of the processor for use in delays
*
* @return The CPU speed in kHz.
*/
-unsigned int get_cpu_speed(void)
+static unsigned int calibrate_pit(void)
{
unsigned long long start, end;
const uint32_t clock_rate = 1193182; // 1.193182 MHz
@@ -71,7 +75,116 @@
* clock_rate / (interval * 1000). Multiply that by the number of
* measured clocks to get the kHz value.
*/
- cpu_khz = (end - start) * clock_rate / (1000 * interval);
+ return (end - start) * clock_rate / (1000 * interval);
+}
+
+/**
+ * @brief Calculates the core clock frequency via CPUID 0x15
+ *
+ * Newer Intel CPUs report their core clock in CPUID leaf 0x15. Early models
+ * supporting this leaf didn't provide the nominal crystal frequency in ecx,
+ * hence we use hard coded values for them.
+ */
+static int get_cpu_khz_xtal(void)
+{
+ uint32_t ecx, edx, num, denom;
+ uint64_t nominal;
+
+ if (cpuid_max() < 0x15)
+ return -1;
+ cpuid(0x15, denom, num, ecx, edx);
+
+ if (denom == 0 || num == 0)
+ return -1;
+
+ if (ecx != 0) {
+ nominal = ecx;
+ } else {
+ if (cpuid_family() != 6)
+ return -1;
+
+ switch (cpuid_model()) {
+ case SKYLAKE_U_Y:
+ case SKYLAKE_S_H:
+ case KABYLAKE_U_Y:
+ case KABYLAKE_S_H:
+ nominal = 24000000;
+ break;
+ case APOLLOLAKE:
+ nominal = 19200000;
+ break;
+ default:
+ return -1;
+ }
+ }
+
+ return nominal * num / denom / 1000;
+}
+
+/**
+ * @brief Returns three times the bus clock in kHz
+ *
+ * The result of calculations with the returned value shall be divided by 3.
+ * This helps to avoid rounding errors.
+ */
+static int get_bus_khz_x3(void)
+{
+ if (cpuid_family() != 6)
+ return -1;
+
+ switch (cpuid_model()) {
+ case NEHALEM:
+ return 400 * 1000; /* 133 MHz */
+ case SANDYBRIDGE:
+ case IVYBRIDGE:
+ case HASWELL:
+ case HASWELL_U:
+ case HASWELL_GT3E:
+ case BROADWELL:
+ case BROADWELL_U:
+ return 300 * 1000; /* 100 MHz */
+ default:
+ return -1;
+ }
+}
+
+/**
+ * @brief Returns the calculated CPU frequency
+ *
+ * Over the years, multiple ways to discover the CPU frequency have been
+ * exposed through CPUID and MSRs. Try the most recent and accurate first
+ * (crystal information in CPUID leaf 0x15) and then fall back to older
+ * methods.
+ *
+ * This should cover all Intel Core i processors at least. For older
+ * processors we fall back to the PIT calibration.
+ */
+static int get_cpu_khz_fast(void)
+{
+ /* Try core crystal clock frequency first (supposed to be more accurate). */
+ const int cpu_khz_xtal = get_cpu_khz_xtal();
+ if (cpu_khz_xtal > 0)
+ return cpu_khz_xtal;
+
+ /* Try `bus clock * speedstep multiplier`. */
+ const int bus_x3 = get_bus_khz_x3();
+ if (bus_x3 <= 0)
+ return -1;
+ /*
+ * Systems with an invariant TSC report the multiplier (maximum
+ * non-turbo ratio) in MSR_PLATFORM_INFO[15:8].
+ */
+ const unsigned int mult = _rdmsr(MSR_PLATFORM_INFO) >> 8 & 0xff;
+ return bus_x3 * mult / 3;
+}
+
+unsigned int get_cpu_speed(void)
+{
+ const int cpu_khz_fast = get_cpu_khz_fast();
+ if (cpu_khz_fast > 0)
+ cpu_khz = (unsigned int)cpu_khz_fast;
+ else
+ cpu_khz = calibrate_pit();
return cpu_khz;
}
--
To view, visit https://review.coreboot.org/c/coreboot/+/34170
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Ic6607ee2a8b41c2be9dc1bb4f1e23e652bb33889
Gerrit-Change-Number: 34170
Gerrit-PatchSet: 8
Gerrit-Owner: Nico Huber <nico.h(a)gmx.de>
Gerrit-Reviewer: Felix Singer <felixsinger(a)posteo.net>
Gerrit-Reviewer: Aaron Durbin <adurbin(a)chromium.org>
Gerrit-Reviewer: Angel Pons <th3fanbus(a)gmail.com>
Gerrit-Reviewer: Arthur Heymans <arthur(a)aheymans.xyz>
Gerrit-Reviewer: Julius Werner <jwerner(a)chromium.org>
Gerrit-Reviewer: Michael Niewöhner <foss(a)mniewoehner.de>
Gerrit-Reviewer: Patrick Georgi <pgeorgi(a)google.com>
Gerrit-Reviewer: Thomas Heijligen <src(a)posteo.de>
Gerrit-Reviewer: Tim Wawrzynczak <twawrzynczak(a)chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply(a)coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter(a)users.sourceforge.net>
Gerrit-MessageType: merged
David Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/47007 )
Change subject: volteer: Create voema variant
......................................................................
volteer: Create voema variant
Create the voema variant of the volteer reference board by copying
the template files to a new directory named for the variant.
(Auto-Generated by create_coreboot_variant.sh version 4.2.0).
BUG=b:171755775
BRANCH=None
TEST=util/abuild/abuild -p none -t google/volteer -x -a
make sure the build includes GOOGLE_VOEMA
Signed-off-by: David Wu <david_wu(a)quanta.corp-partner.google.com>
Change-Id: I4e1872d1ebff6fefdfb232f1ff82fce95a1ec643
---
M src/mainboard/google/volteer/Kconfig
M src/mainboard/google/volteer/Kconfig.name
A src/mainboard/google/volteer/variants/voema/include/variant/ec.h
A src/mainboard/google/volteer/variants/voema/include/variant/gpio.h
A src/mainboard/google/volteer/variants/voema/memory/Makefile.inc
A src/mainboard/google/volteer/variants/voema/memory/dram_id.generated.txt
A src/mainboard/google/volteer/variants/voema/memory/mem_parts_used.txt
A src/mainboard/google/volteer/variants/voema/overridetree.cb
8 files changed, 45 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/07/47007/1
diff --git a/src/mainboard/google/volteer/Kconfig b/src/mainboard/google/volteer/Kconfig
index 69f58b5..8fd119e 100644
--- a/src/mainboard/google/volteer/Kconfig
+++ b/src/mainboard/google/volteer/Kconfig
@@ -94,6 +94,7 @@
default "Voxel" if BOARD_GOOGLE_VOXEL
default "Boldar" if BOARD_GOOGLE_BOLDAR
default "Elemi" if BOARD_GOOGLE_ELEMI
+ default "Voema" if BOARD_GOOGLE_VOEMA
config MAX_CPUS
int
@@ -132,6 +133,7 @@
default "voxel" if BOARD_GOOGLE_VOXEL
default "boldar" if BOARD_GOOGLE_BOLDAR
default "elemi" if BOARD_GOOGLE_ELEMI
+ default "voema" if BOARD_GOOGLE_VOEMA
config VARIANT_HAS_MIPI_CAMERA
bool
diff --git a/src/mainboard/google/volteer/Kconfig.name b/src/mainboard/google/volteer/Kconfig.name
index f59d82b..9e48a2f 100644
--- a/src/mainboard/google/volteer/Kconfig.name
+++ b/src/mainboard/google/volteer/Kconfig.name
@@ -71,3 +71,7 @@
config BOARD_GOOGLE_ELEMI
bool "-> Elemi"
select BOARD_GOOGLE_BASEBOARD_VOLTEER
+
+config BOARD_GOOGLE_VOEMA
+ bool "-> Voema"
+ select BOARD_GOOGLE_BASEBOARD_VOLTEER
diff --git a/src/mainboard/google/volteer/variants/voema/include/variant/ec.h b/src/mainboard/google/volteer/variants/voema/include/variant/ec.h
new file mode 100644
index 0000000..7a2a6ff
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/include/variant/ec.h
@@ -0,0 +1,8 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef __VARIANT_EC_H__
+#define __VARIANT_EC_H__
+
+#include <baseboard/ec.h>
+
+#endif
diff --git a/src/mainboard/google/volteer/variants/voema/include/variant/gpio.h b/src/mainboard/google/volteer/variants/voema/include/variant/gpio.h
new file mode 100644
index 0000000..b5fa8c5
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/include/variant/gpio.h
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+#ifndef VARIANT_GPIO_H
+#define VARIANT_GPIO_H
+
+#include <baseboard/gpio.h>
+
+/* Memory configuration board straps */
+/* Copied from baseboard and may need to change for the new variant. */
+#define GPIO_MEM_CONFIG_0 GPP_C12
+#define GPIO_MEM_CONFIG_1 GPP_C15
+#define GPIO_MEM_CONFIG_2 GPP_C14
+#define GPIO_MEM_CONFIG_3 GPP_D15
+
+#endif
diff --git a/src/mainboard/google/volteer/variants/voema/memory/Makefile.inc b/src/mainboard/google/volteer/variants/voema/memory/Makefile.inc
new file mode 100644
index 0000000..b0ca222
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/memory/Makefile.inc
@@ -0,0 +1,5 @@
+## SPDX-License-Identifier: GPL-2.0-or-later
+## This is an auto-generated file. Do not edit!!
+## Add memory parts in mem_parts_used.txt and run spd_tools to regenerate.
+
+SPD_SOURCES = placeholder.spd.hex
diff --git a/src/mainboard/google/volteer/variants/voema/memory/dram_id.generated.txt b/src/mainboard/google/volteer/variants/voema/memory/dram_id.generated.txt
new file mode 100644
index 0000000..fa24790
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/memory/dram_id.generated.txt
@@ -0,0 +1 @@
+DRAM Part Name ID to assign
diff --git a/src/mainboard/google/volteer/variants/voema/memory/mem_parts_used.txt b/src/mainboard/google/volteer/variants/voema/memory/mem_parts_used.txt
new file mode 100644
index 0000000..f51b3af
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/memory/mem_parts_used.txt
@@ -0,0 +1,4 @@
+# This is a CSV file containing a list of memory parts used by this variant.
+# Generate an updated Makefile.inc and dram_id.generated.txt by running the
+# gen_part_id tool from util/spd_tools/ddr4 or util/spd_tools/lp4x
+# See util/spd_tools/{ddr4,lp4x}/README.md for more details and instructions.
diff --git a/src/mainboard/google/volteer/variants/voema/overridetree.cb b/src/mainboard/google/volteer/variants/voema/overridetree.cb
new file mode 100644
index 0000000..32204c5
--- /dev/null
+++ b/src/mainboard/google/volteer/variants/voema/overridetree.cb
@@ -0,0 +1,6 @@
+chip soc/intel/tigerlake
+
+ device domain 0 on
+ end
+
+end
--
To view, visit https://review.coreboot.org/c/coreboot/+/47007
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I4e1872d1ebff6fefdfb232f1ff82fce95a1ec643
Gerrit-Change-Number: 47007
Gerrit-PatchSet: 1
Gerrit-Owner: David Wu <david_wu(a)quanta.corp-partner.google.com>
Gerrit-MessageType: newchange