qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 13/17] timer/aspeed: fix timer enablement when a reload is not set
Date: Tue, 13 Jun 2017 15:07:02 +0100	[thread overview]
Message-ID: <1497362826-21125-14-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1497362826-21125-1-git-send-email-peter.maydell@linaro.org>

From: Cédric Le Goater <clg@kaod.org>

When a timer is enabled before a reload value is set, the controller
waits for a reload value to be set before starting decrementing. This
fix tries to cover that case by changing the timer expiry only when
a reload value is valid.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
Reviewed-by: Andrew Jeffery <andrew@aj.id.au>
Message-id: 1496739312-32304-1-git-send-email-clg@kaod.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 hw/timer/aspeed_timer.c | 37 +++++++++++++++++++++++++++++--------
 1 file changed, 29 insertions(+), 8 deletions(-)

diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
index 9b70ee0..50acbf5 100644
--- a/hw/timer/aspeed_timer.c
+++ b/hw/timer/aspeed_timer.c
@@ -130,15 +130,26 @@ static uint64_t calculate_next(struct AspeedTimer *t)
             next = seq[1];
         } else if (now < seq[2]) {
             next = seq[2];
-        } else {
+        } else if (t->reload) {
             reload_ns = muldiv64(t->reload, NANOSECONDS_PER_SECOND, rate);
             t->start = now - ((now - t->start) % reload_ns);
+        } else {
+            /* no reload value, return 0 */
+            break;
         }
     }
 
     return next;
 }
 
+static void aspeed_timer_mod(AspeedTimer *t)
+{
+    uint64_t next = calculate_next(t);
+    if (next) {
+        timer_mod(&t->timer, next);
+    }
+}
+
 static void aspeed_timer_expire(void *opaque)
 {
     AspeedTimer *t = opaque;
@@ -164,7 +175,7 @@ static void aspeed_timer_expire(void *opaque)
         qemu_set_irq(t->irq, t->level);
     }
 
-    timer_mod(&t->timer, calculate_next(t));
+    aspeed_timer_mod(t);
 }
 
 static uint64_t aspeed_timer_get_value(AspeedTimer *t, int reg)
@@ -227,10 +238,23 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
                                    uint32_t value)
 {
     AspeedTimer *t;
+    uint32_t old_reload;
 
     trace_aspeed_timer_set_value(timer, reg, value);
     t = &s->timers[timer];
     switch (reg) {
+    case TIMER_REG_RELOAD:
+        old_reload = t->reload;
+        t->reload = value;
+
+        /* If the reload value was not previously set, or zero, and
+         * the current value is valid, try to start the timer if it is
+         * enabled.
+         */
+        if (old_reload || !t->reload) {
+            break;
+        }
+
     case TIMER_REG_STATUS:
         if (timer_enabled(t)) {
             uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -238,17 +262,14 @@ static void aspeed_timer_set_value(AspeedTimerCtrlState *s, int timer, int reg,
             uint32_t rate = calculate_rate(t);
 
             t->start += muldiv64(delta, NANOSECONDS_PER_SECOND, rate);
-            timer_mod(&t->timer, calculate_next(t));
+            aspeed_timer_mod(t);
         }
         break;
-    case TIMER_REG_RELOAD:
-        t->reload = value;
-        break;
     case TIMER_REG_MATCH_FIRST:
     case TIMER_REG_MATCH_SECOND:
         t->match[reg - 2] = value;
         if (timer_enabled(t)) {
-            timer_mod(&t->timer, calculate_next(t));
+            aspeed_timer_mod(t);
         }
         break;
     default:
@@ -268,7 +289,7 @@ static void aspeed_timer_ctrl_enable(AspeedTimer *t, bool enable)
     trace_aspeed_timer_ctrl_enable(t->id, enable);
     if (enable) {
         t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
-        timer_mod(&t->timer, calculate_next(t));
+        aspeed_timer_mod(t);
     } else {
         timer_del(&t->timer);
     }
-- 
2.7.4

  parent reply	other threads:[~2017-06-13 14:07 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-13 14:06 [Qemu-devel] [PULL 00/17] target-arm queue Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 01/17] hw/intc/exynos4210_gic: Use more meaningful name for local variable Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 02/17] hw/timer/exynos4210_mct: Fix checkpatch style errors Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 03/17] hw/timer/exynos4210_mct: Cleanup indentation and empty new lines Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 04/17] hw/timer/exynos4210_mct: Remove unused defines Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 05/17] hw/arm/exynos: Move DRAM initialization next boards Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 06/17] hw/arm/exynos: Declare local variables in some order Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 07/17] hw/arm/exynos: Use type define instead of hard-coded a9mpcore_priv string Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 08/17] hw/intc/exynos4210_gic: Constify array of combiner interrupts Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 09/17] hw/misc/exynos4210_pmu: Add support for system poweroff Peter Maydell
2017-06-13 14:06 ` [Qemu-devel] [PULL 10/17] timer.h: Provide better monotonic time Peter Maydell
2017-06-13 14:07 ` [Qemu-devel] [PULL 11/17] hw/misc: add a TMP42{1, 2, 3} device model Peter Maydell
2017-06-13 14:07 ` [Qemu-devel] [PULL 12/17] aspeed: add a temp sensor device on I2C bus 3 Peter Maydell
2017-06-13 14:07 ` Peter Maydell [this message]
2017-06-13 14:07 ` [Qemu-devel] [PULL 14/17] kvm-all: Pass an error object to kvm_device_access Peter Maydell
2017-06-13 14:07 ` [Qemu-devel] [PULL 15/17] hw/intc/arm_gicv3_its: Implement state save/restore Peter Maydell
2017-06-13 14:07 ` [Qemu-devel] [PULL 16/17] hw/intc/arm_gicv3_kvm: Implement pending table save Peter Maydell
2017-06-13 14:07 ` [Qemu-devel] [PULL 17/17] hw/intc/arm_gicv3_its: Allow save/restore Peter Maydell
2017-06-13 14:51 ` [Qemu-devel] [PULL 00/17] target-arm queue no-reply
2017-06-13 17:17 ` Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1497362826-21125-14-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).