Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3153
-gerrit
commit 24b6abaff5d42024a563a3c238525370c64a3083
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Mon Apr 29 16:57:10 2013 -0500
haswell: 24MHz monotonic time implementation
Haswell ULT devices have a 24MHz package-level counter. Use
this counter to provide a timer_monotonic_get() implementation.
Change-Id: Ic79843fcbfbbb6462ee5ebd12b39502307750dbb
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/cpu/intel/haswell/Kconfig | 7 ++++
src/cpu/intel/haswell/Makefile.inc | 1 +
src/cpu/intel/haswell/monotonic_timer.c | 62 +++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/src/cpu/intel/haswell/Kconfig b/src/cpu/intel/haswell/Kconfig
index 5f27d4c..13861f9 100644
--- a/src/cpu/intel/haswell/Kconfig
+++ b/src/cpu/intel/haswell/Kconfig
@@ -54,4 +54,11 @@ config RESET_ON_INVALID_RAMSTAGE_CACHE
the system will reset otherwise the ramstage will be reloaded from
cbfs.
+config MONOTONIC_TIMER_MSR
+ def_bool n
+ depends on INTEL_LYNXPOINT_LP
+ select HAVE_MONOTONIC_TIMER
+ help
+ Provide a monotonic timer using the 24MHz MSR counter.
+
endif
diff --git a/src/cpu/intel/haswell/Makefile.inc b/src/cpu/intel/haswell/Makefile.inc
index a19a8c5..90ffd66 100644
--- a/src/cpu/intel/haswell/Makefile.inc
+++ b/src/cpu/intel/haswell/Makefile.inc
@@ -5,6 +5,7 @@ romstage-y += romstage.c
ramstage-$(CONFIG_GENERATE_ACPI_TABLES) += acpi.c
ramstage-$(CONFIG_HAVE_SMI_HANDLER) += smmrelocate.c
+ramstage-$(CONFIG_MONOTONIC_TIMER_MSR) += monotonic_timer.c
cpu_microcode-$(CONFIG_CPU_MICROCODE_CBFS_GENERATE) += microcode_blob.c
diff --git a/src/cpu/intel/haswell/monotonic_timer.c b/src/cpu/intel/haswell/monotonic_timer.c
new file mode 100644
index 0000000..c51bcbd
--- /dev/null
+++ b/src/cpu/intel/haswell/monotonic_timer.c
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2013 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; 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdint.h>
+#include <cpu/x86/msr.h>
+#include <timer.h>
+
+#define MSR_COUNTER_24_MHz 0x637
+static struct monotonic_counter {
+ int initialized;
+ struct mono_time time;
+ uint32_t last_value;
+} mono_counter;
+
+static inline uint32_t read_counter_msr(void)
+{
+ /* Even though the MSR is 64-bit it is assumed that the hardware
+ * is polled frequently enough to only use the lower 32-bits. */
+ msr_t counter_msr;
+
+ counter_msr = rdmsr(MSR_COUNTER_24_MHz);
+
+ return counter_msr.lo;
+}
+
+void timer_monotonic_get(struct mono_time *mt)
+{
+ uint32_t current_tick;
+ uint32_t usecs_elapsed;
+
+ if (!mono_counter.initialized) {
+ mono_counter.last_value = read_counter_msr();
+ mono_counter.initialized = 1;
+ }
+
+ current_tick = read_counter_msr();
+ usecs_elapsed = (current_tick - mono_counter.last_value) / 24;
+
+ /* Update current time and tick values only if a full tick occurred. */
+ if (usecs_elapsed) {
+ mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
+ mono_counter.last_value = current_tick;
+ }
+
+ /* Save result. */
+ *mt = mono_counter.time;
+}
Ronald G. Minnich (rminnich(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3157
-gerrit
commit 14f905dbef8910bd48d5598d85ab4f9de9e6d710
Author: Ronald G. Minnich <rminnich(a)gmail.com>
Date: Tue Apr 30 08:38:16 2013 -0700
Define a config variable for 64 bit address capability
For the most part, we don't need 64 bit addressing. In the future,
it will be more important, but it's useful to have an indicator
that a CPU can even run in that mode.
Change-Id: I59e4061e07c16c5def7d9950749a55083612f6af
Signed-off-by: Ronald G. Minnich <rminnich(a)gmail.com>
---
src/cpu/Kconfig | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/cpu/Kconfig b/src/cpu/Kconfig
index ed7d6ab..5d348a3 100644
--- a/src/cpu/Kconfig
+++ b/src/cpu/Kconfig
@@ -1,6 +1,17 @@
# Warning: This file is included whether or not the if is here.
# The if controls how the evaluation occurs.
# (See also src/Kconfig)
+
+config HAVE_64BIT
+ bool
+ default n
+ help
+ Many of the CPUs in our tree can support 64-bit addresses.
+ Currently, we don't use this capability on any of them.
+ This variable indicates whether it is even possible,
+ for a given CPU, to run in 64 bit mode. For the subset of
+ CPUs which can support 64 bit mode it can be overridden.
+
if ARCH_ARMV7
source src/cpu/armltd/Kconfig
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3152
-gerrit
commit fca7d309eb2ae71f52c7e0808c4ae6a4a7b060df
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Mon Apr 29 22:31:51 2013 -0500
coreboot: introduce monotonic timer API
The notion of a monotonic timer is introduced. Along with it
are helper functions and other types for comparing times. This
is just the framework where it is the responsibility of the
chipset/board to provide the implementation of timer_monotonic_get().
The reason structs are used instead of native types is to allow
for future changes to the data structure without chaning all the
call sites.
Change-Id: Ie56b9ab9dedb0da69dea86ef87ca744004eb1ae3
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/Kconfig | 5 ++
src/include/timer.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 145 insertions(+)
diff --git a/src/Kconfig b/src/Kconfig
index c3cc6bf..a49643e 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -313,6 +313,11 @@ config HAVE_INIT_TIMER
default n if UDELAY_IO
default y
+config HAVE_MONOTONIC_TIMER
+ def_bool n
+ help
+ The board/chipset provides a monotonic timer.
+
config HIGH_SCRATCH_MEMORY_SIZE
hex
default 0x0
diff --git a/src/include/timer.h b/src/include/timer.h
new file mode 100644
index 0000000..2b112dd
--- /dev/null
+++ b/src/include/timer.h
@@ -0,0 +1,140 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2013 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; 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef TIMER_H
+#define TIMER_H
+
+#define USECS_PER_SEC 1000000
+#define MSECS_PER_SEC 1000
+#define USECS_PER_MSEC (USECS_PER_SEC / MSECS_PER_SEC)
+
+/* The time structures are defined to be a representation of the time since
+ * coreboot started executing one of its stages. The reason for using structures
+ * is to allow for changes in the future. The structures' details are exposed
+ * so that the compiler can allocate space on the stack and use in other
+ * structures. In other words, accessing any field within this structure
+ * outside of the core timer code is not supported. */
+
+struct mono_time {
+ long microseconds;
+};
+
+struct rela_time {
+ long microseconds;
+};
+
+/* Obtain the current monotonic time. The assumption is that the time counts
+ * up from the value 0 with value 0 being the point when the timer was
+ * initialized. Additionally, the timer is assumed to only be valid for the
+ * duration of the boot.
+ *
+ * Note that any implementations of timer_monotonic_get()
+ * need to ensure its timesource does not roll over within 10 secs. The reason
+ * is that the time between calls to timer_monotonic_get() may be on order
+ * of 10 seconds. */
+void timer_monotonic_get(struct mono_time *mt);
+
+/* Add microseconds to an absoute time. */
+static inline void mono_time_add_usecs(struct mono_time *mt, long us)
+{
+ mt->microseconds += us;
+}
+
+/* Add milliseconds to an absoute time. */
+static inline void mono_time_add_msecs(struct mono_time *mt, long ms)
+{
+ mono_time_add_usecs(mt, ms * USECS_PER_MSEC);
+}
+
+static inline void mono_time_add_rela_time(struct mono_time *mt,
+ const struct rela_time *t)
+{
+ mono_time_add_usecs(mt, t->microseconds);
+}
+
+/* Compare two absoluted times: Return -1, 0, or 1 if t1 is <, =, or > t2,
+ * respectively. */
+static inline int mono_time_cmp(const struct mono_time *t1,
+ const struct mono_time *t2)
+{
+ if (t1->microseconds == t2->microseconds)
+ return 0;
+
+ if (t1->microseconds < t2->microseconds)
+ return -1;
+
+ return 1;
+}
+
+static inline int rela_time_cmp(const struct rela_time *t1,
+ const struct rela_time *t2)
+{
+ if (t1->microseconds == t2->microseconds)
+ return 0;
+
+ if (t1->microseconds < t2->microseconds)
+ return -1;
+
+ return 1;
+}
+
+/* Iniitalize a rela_time structure. */
+static inline struct rela_time rela_time_init_usecs(long us)
+{
+ struct rela_time t;
+ t.microseconds = us;
+ return t;
+}
+
+/* Return time difference between t1 and t2. i.e. t2 - t1. */
+static struct rela_time mono_time_diff(const struct mono_time *t1,
+ const struct mono_time *t2)
+{
+ return rela_time_init_usecs(t2->microseconds - t1->microseconds);
+}
+
+/* Return true if t1 after t2 */
+static inline int mono_time_after(const struct mono_time *t1,
+ const struct mono_time *t2)
+{
+ return mono_time_cmp(t1, t2) > 0;
+}
+
+/* Return true if t1 before t2. */
+static inline int mono_time_before(const struct mono_time *t1,
+ const struct mono_time *t2)
+{
+ return mono_time_cmp(t1, t2) < 0;
+}
+
+/* Return the difference between now and t. */
+static inline struct rela_time current_time_from(const struct mono_time *t)
+{
+ struct mono_time now;
+
+ timer_monotonic_get(&now);
+ return mono_time_diff(t, &now);
+
+}
+
+static inline long rela_time_in_microseconds(const struct rela_time *rt)
+{
+ return rt->microseconds;
+}
+
+#endif /* TIMER_H */
Aaron Durbin (adurbin(a)google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3153
-gerrit
commit d86f98c72eb174167c3ca072b37a45e9e4355d1c
Author: Aaron Durbin <adurbin(a)chromium.org>
Date: Mon Apr 29 16:57:10 2013 -0500
haswell: 24MHz monotonic time implementation
Haswell ULT devices have a 24MHz package-level counter. Use
this counter to provide a time_monotonic_get() implementation.
Change-Id: Ic79843fcbfbbb6462ee5ebd12b39502307750dbb
Signed-off-by: Aaron Durbin <adurbin(a)chromium.org>
---
src/cpu/intel/haswell/Kconfig | 7 ++++
src/cpu/intel/haswell/Makefile.inc | 1 +
src/cpu/intel/haswell/monotonic_timer.c | 62 +++++++++++++++++++++++++++++++++
3 files changed, 70 insertions(+)
diff --git a/src/cpu/intel/haswell/Kconfig b/src/cpu/intel/haswell/Kconfig
index 5f27d4c..13861f9 100644
--- a/src/cpu/intel/haswell/Kconfig
+++ b/src/cpu/intel/haswell/Kconfig
@@ -54,4 +54,11 @@ config RESET_ON_INVALID_RAMSTAGE_CACHE
the system will reset otherwise the ramstage will be reloaded from
cbfs.
+config MONOTONIC_TIMER_MSR
+ def_bool n
+ depends on INTEL_LYNXPOINT_LP
+ select HAVE_MONOTONIC_TIMER
+ help
+ Provide a monotonic timer using the 24MHz MSR counter.
+
endif
diff --git a/src/cpu/intel/haswell/Makefile.inc b/src/cpu/intel/haswell/Makefile.inc
index a19a8c5..90ffd66 100644
--- a/src/cpu/intel/haswell/Makefile.inc
+++ b/src/cpu/intel/haswell/Makefile.inc
@@ -5,6 +5,7 @@ romstage-y += romstage.c
ramstage-$(CONFIG_GENERATE_ACPI_TABLES) += acpi.c
ramstage-$(CONFIG_HAVE_SMI_HANDLER) += smmrelocate.c
+ramstage-$(CONFIG_MONOTONIC_TIMER_MSR) += monotonic_timer.c
cpu_microcode-$(CONFIG_CPU_MICROCODE_CBFS_GENERATE) += microcode_blob.c
diff --git a/src/cpu/intel/haswell/monotonic_timer.c b/src/cpu/intel/haswell/monotonic_timer.c
new file mode 100644
index 0000000..c51bcbd
--- /dev/null
+++ b/src/cpu/intel/haswell/monotonic_timer.c
@@ -0,0 +1,62 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2013 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; 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <stdint.h>
+#include <cpu/x86/msr.h>
+#include <timer.h>
+
+#define MSR_COUNTER_24_MHz 0x637
+static struct monotonic_counter {
+ int initialized;
+ struct mono_time time;
+ uint32_t last_value;
+} mono_counter;
+
+static inline uint32_t read_counter_msr(void)
+{
+ /* Even though the MSR is 64-bit it is assumed that the hardware
+ * is polled frequently enough to only use the lower 32-bits. */
+ msr_t counter_msr;
+
+ counter_msr = rdmsr(MSR_COUNTER_24_MHz);
+
+ return counter_msr.lo;
+}
+
+void timer_monotonic_get(struct mono_time *mt)
+{
+ uint32_t current_tick;
+ uint32_t usecs_elapsed;
+
+ if (!mono_counter.initialized) {
+ mono_counter.last_value = read_counter_msr();
+ mono_counter.initialized = 1;
+ }
+
+ current_tick = read_counter_msr();
+ usecs_elapsed = (current_tick - mono_counter.last_value) / 24;
+
+ /* Update current time and tick values only if a full tick occurred. */
+ if (usecs_elapsed) {
+ mono_time_add_usecs(&mono_counter.time, usecs_elapsed);
+ mono_counter.last_value = current_tick;
+ }
+
+ /* Save result. */
+ *mt = mono_counter.time;
+}