From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBqV2-0007ZR-AC for qemu-devel@nongnu.org; Sun, 05 Jul 2015 16:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZBqUy-0003xe-Qj for qemu-devel@nongnu.org; Sun, 05 Jul 2015 16:26:52 -0400 Received: from mail-pd0-x230.google.com ([2607:f8b0:400e:c02::230]:36034) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZBqUy-0003xO-Js for qemu-devel@nongnu.org; Sun, 05 Jul 2015 16:26:48 -0400 Received: by pddu5 with SMTP id u5so5730940pdd.3 for ; Sun, 05 Jul 2015 13:26:47 -0700 (PDT) From: Peter Crosthwaite Date: Sun, 5 Jul 2015 13:26:39 -0700 Message-Id: <1436128000-16262-2-git-send-email-crosthwaite.peter@gmail.com> In-Reply-To: <1436128000-16262-1-git-send-email-crosthwaite.peter@gmail.com> References: <1436128000-16262-1-git-send-email-crosthwaite.peter@gmail.com> Subject: [Qemu-devel] [RFC v1 1/2] timer: arm_mp: Factor out timer value calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, digetx@gmail.com, Peter Crosthwaite Factor out the code that calculates the runtime value of the timer. Updates tb->count to the calculated value. Prepares support for pausing the timer where the timer disable event should sync the counter to its current value. Signed-off-by: Peter Crosthwaite --- hw/timer/arm_mptimer.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c index 8b93b3c..04dfb63 100644 --- a/hw/timer/arm_mptimer.c +++ b/hw/timer/arm_mptimer.c @@ -72,25 +72,32 @@ static void timerblock_tick(void *opaque) timerblock_update_irq(tb); } +static void timerblock_sync(TimerBlock *tb) +{ + int64_t val; + + if (((tb->control & 1) == 0) || (tb->count == 0)) { + return; + } + /* Slow and ugly, but hopefully won't happen too often. */ + val = tb->tick - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + val /= timerblock_scale(tb); + if (val < 0) { + val = 0; + } + tb->count = val; +} + static uint64_t timerblock_read(void *opaque, hwaddr addr, unsigned size) { TimerBlock *tb = (TimerBlock *)opaque; - int64_t val; switch (addr) { case 0: /* Load */ return tb->load; case 4: /* Counter. */ - if (((tb->control & 1) == 0) || (tb->count == 0)) { - return 0; - } - /* Slow and ugly, but hopefully won't happen too often. */ - val = tb->tick - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); - val /= timerblock_scale(tb); - if (val < 0) { - val = 0; - } - return val; + timerblock_sync(tb); + return tb->count; case 8: /* Control. */ return tb->control; case 12: /* Interrupt status. */ -- 1.9.1