aboutsummaryrefslogtreecommitdiff
path: root/hw/timer
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2019-07-01 17:26:17 +0100
committerPeter Maydell <peter.maydell@linaro.org>2019-07-01 17:28:59 +0100
commit696942b8bc6562a2b23c6ed8ae32ecdeb9bf4b60 (patch)
tree103d9f9d0aa4f1fc20caf52e2cbf8d35c87fb72b /hw/timer
parent58044b5cf5f30eb298709696ddbafdf547c1291c (diff)
aspeed/timer: Fix match calculations
If the match value exceeds reload then we don't want to include it in calculations for the next event. Signed-off-by: Andrew Jeffery <andrew@aj.id.au> Signed-off-by: Cédric Le Goater <clg@kaod.org> Message-id: 20190618165311.27066-10-clg@kaod.org Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/timer')
-rw-r--r--hw/timer/aspeed_timer.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
index 8d6266b0fd..745eb8608b 100644
--- a/hw/timer/aspeed_timer.c
+++ b/hw/timer/aspeed_timer.c
@@ -107,6 +107,11 @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
return t->start + delta_ns;
}
+static inline uint32_t calculate_match(struct AspeedTimer *t, int i)
+{
+ return t->match[i] < t->reload ? t->match[i] : 0;
+}
+
static uint64_t calculate_next(struct AspeedTimer *t)
{
uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -118,12 +123,12 @@ static uint64_t calculate_next(struct AspeedTimer *t)
* the timer counts down to zero.
*/
- next = calculate_time(t, MAX(t->match[0], t->match[1]));
+ next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1)));
if (now < next) {
return next;
}
- next = calculate_time(t, MIN(t->match[0], t->match[1]));
+ next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1)));
if (now < next) {
return next;
}
@@ -141,8 +146,10 @@ static uint64_t calculate_next(struct AspeedTimer *t)
qemu_set_irq(t->irq, t->level);
}
+ next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
- return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
+
+ return calculate_time(t, next);
}
static void aspeed_timer_mod(AspeedTimer *t)