David Hendricks (dhendrix@chromium.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/3175
-gerrit
commit 1625f612052c714620f1e244bc80ca9298128193 Author: David Hendricks dhendrix@chromium.org Date: Thu May 2 13:23:08 2013 -0700
exynos5250: monotonic timer implementation (using MCT)
This implements the new monotonic timer API using the global multi-core timer (MCT).
Change-Id: Id56249ff5d3e0f85808f5754954c83c0bc75f1c1 Signed-off-by: David Hendricks dhendrix@chromium.org --- src/cpu/samsung/exynos5250/Makefile.inc | 1 + src/cpu/samsung/exynos5250/clk.h | 2 + src/cpu/samsung/exynos5250/mct.c | 5 +-- src/cpu/samsung/exynos5250/monotonic_timer.c | 58 ++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 3 deletions(-)
diff --git a/src/cpu/samsung/exynos5250/Makefile.inc b/src/cpu/samsung/exynos5250/Makefile.inc index 403c198..73fc292 100644 --- a/src/cpu/samsung/exynos5250/Makefile.inc +++ b/src/cpu/samsung/exynos5250/Makefile.inc @@ -30,6 +30,7 @@ ramstage-$(CONFIG_CONSOLE_SERIAL_UART) += uart.c ramstage-y += cpu.c ramstage-y += exynos5250-tmu.c ramstage-y += mct.c +ramstage-y += monotonic_timer.c
#ramstage-$(CONFIG_SATA_AHCI) += sata.c
diff --git a/src/cpu/samsung/exynos5250/clk.h b/src/cpu/samsung/exynos5250/clk.h index 4785894..1894c00 100644 --- a/src/cpu/samsung/exynos5250/clk.h +++ b/src/cpu/samsung/exynos5250/clk.h @@ -585,4 +585,6 @@ int clock_get_mem_selection(enum ddr_mode *mem_type, unsigned *frequency_mhz, unsigned *arm_freq, enum mem_manuf *mem_manuf);
+uint64_t mct_raw_value(void); + #endif diff --git a/src/cpu/samsung/exynos5250/mct.c b/src/cpu/samsung/exynos5250/mct.c index ddabbf7..4216643 100644 --- a/src/cpu/samsung/exynos5250/mct.c +++ b/src/cpu/samsung/exynos5250/mct.c @@ -88,7 +88,7 @@ static int enabled = 0; static struct mct_regs *const mct = (struct mct_regs *)MCT_ADDRESS;
-static uint64_t timer_raw_value(void) +uint64_t mct_raw_value(void) { if (!enabled) { writel(readl(&mct->g_tcon) | (0x1 << 8), &mct->g_tcon); @@ -109,9 +109,8 @@ void timer_start(void)
u32 timer_us(void) { - uint64_t raw = timer_raw_value(); + uint64_t raw = mct_raw_value(); static uint32_t ticks_per_microsecond = MCT_HZ/1000000; uint32_t usec = raw / ticks_per_microsecond; return usec; } - diff --git a/src/cpu/samsung/exynos5250/monotonic_timer.c b/src/cpu/samsung/exynos5250/monotonic_timer.c new file mode 100644 index 0000000..f0444ce --- /dev/null +++ b/src/cpu/samsung/exynos5250/monotonic_timer.c @@ -0,0 +1,58 @@ +/* + * 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 <delay.h> +#include <timer.h> +#include <time.h> /* TODO: deprecate in favor of monotonic timer stuff */ + +#include "clk.h" + +static struct monotonic_counter { + int initialized; + struct mono_time time; + uint64_t last_value; +} mono_counter; + +static uint32_t clocks_per_usec = MCT_HZ/1000000; + +void timer_monotonic_get(struct mono_time *mt) +{ + uint64_t current_tick; + uint64_t usecs_elapsed; + + if (!mono_counter.initialized) { + init_timer(); + mono_counter.last_value = mct_raw_value(); + mono_counter.initialized = 1; + } + + current_tick = mct_raw_value(); + usecs_elapsed = (current_tick - mono_counter.last_value) / + clocks_per_usec; + + /* 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; +}