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>
This commit is contained in:
parent
58044b5cf5
commit
696942b8bc
|
@ -107,6 +107,11 @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
|
||||||
return t->start + delta_ns;
|
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)
|
static uint64_t calculate_next(struct AspeedTimer *t)
|
||||||
{
|
{
|
||||||
uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
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.
|
* 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) {
|
if (now < next) {
|
||||||
return 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) {
|
if (now < next) {
|
||||||
return next;
|
return next;
|
||||||
}
|
}
|
||||||
|
@ -141,8 +146,10 @@ static uint64_t calculate_next(struct AspeedTimer *t)
|
||||||
qemu_set_irq(t->irq, t->level);
|
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);
|
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)
|
static void aspeed_timer_mod(AspeedTimer *t)
|
||||||
|
|
Loading…
Reference in a new issue