From 32186ec30002874db64d52ca745048834a153ae7 Mon Sep 17 00:00:00 2001 From: Patrick Wildt Date: Tue, 7 Feb 2017 21:51:04 +0000 Subject: The default frequency we chose for the generic timer does not always ring true. Instead, unless overwritten by the device tree, we should ask the generic timer for its frequency. This fixes time on my AMD Seattle and should improve time management on QEMU as well. --- sys/arch/arm64/dev/agtimer.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'sys/arch/arm64/dev') diff --git a/sys/arch/arm64/dev/agtimer.c b/sys/arch/arm64/dev/agtimer.c index 451f439715f..bbcb37ee038 100644 --- a/sys/arch/arm64/dev/agtimer.c +++ b/sys/arch/arm64/dev/agtimer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: agtimer.c,v 1.3 2017/01/23 10:15:53 kettenis Exp $ */ +/* $OpenBSD: agtimer.c,v 1.4 2017/02/07 21:51:03 patrick Exp $ */ /* * Copyright (c) 2011 Dale Rahn * Copyright (c) 2013 Patrick Wildt @@ -100,6 +100,16 @@ agtimer_readcnt64(void) return (val); } +static inline uint64_t +agtimer_get_freq(void) +{ + uint64_t val; + + __asm volatile("MRS %x0, CNTFRQ_EL0" : "=r" (val)); + + return (val); +} + static inline int agtimer_get_ctrl(void) { @@ -149,6 +159,8 @@ agtimer_attach(struct device *parent, struct device *self, void *aux) sc->sc_node = faa->fa_node; + if (agtimer_get_freq() != 0) + agtimer_frequency = agtimer_get_freq(); agtimer_frequency = OF_getpropint(sc->sc_node, "clock-frequency", agtimer_frequency); sc->sc_ticks_per_second = agtimer_frequency; -- cgit v1.2.3