From 6079bf3f90c1c7ef70bc07fa44b17d05298184c4 Mon Sep 17 00:00:00 2001 From: Andrew Baumann Date: Thu, 31 Dec 2015 11:38:28 -0800 Subject: [PATCH] bcm2835_st: misc cleanup and bugfixes * avoid possible (but maybe not actual) races/corner cases in update() * only call set_irq for interrupts that change * define region size appropriately --- hw/timer/bcm2835_st.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/hw/timer/bcm2835_st.c b/hw/timer/bcm2835_st.c index 0fe55c7d08..0b6348bebd 100644 --- a/hw/timer/bcm2835_st.c +++ b/hw/timer/bcm2835_st.c @@ -11,19 +11,26 @@ static void bcm2835_st_update(BCM2835StState *s) { int64_t now = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL); uint32_t clo = (uint32_t)now; - uint32_t delta = -1; + uint32_t delta; + bool set = false; int i; /* Calculate new "next" value and reschedule */ for (i = 0; i < 4; i++) { if (!(s->match & (1 << i))) { - if (s->compare[i] - clo < delta) { + if (!set || s->compare[i] - clo < delta) { + set = true; s->next = s->compare[i]; delta = s->next - clo; } } } - timer_mod(s->timer, now + delta); + + if (set) { + timer_mod(s->timer, now + delta); + } else { + timer_del(s->timer); + } } static void bcm2835_st_tick(void *opaque) @@ -47,7 +54,7 @@ static uint64_t bcm2835_st_read(void *opaque, hwaddr offset, { BCM2835StState *s = (BCM2835StState *)opaque; uint32_t res = 0; - int64_t now = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL); + uint64_t now = qemu_clock_get_us(QEMU_CLOCK_VIRTUAL); assert(size == 4); @@ -98,7 +105,7 @@ static void bcm2835_st_write(void *opaque, hwaddr offset, case 0x00: s->match &= ~value & 0x0f; for (i = 0; i < 4; i++) { - if (!(s->match & (1 << i))) { + if (value & (1 << i)) { qemu_set_irq(s->irq[i], 0); } } @@ -151,7 +158,7 @@ static void bcm2835_st_init(Object *obj) } memory_region_init_io(&s->iomem, obj, &bcm2835_st_ops, s, - TYPE_BCM2835_ST, 0x1000); + TYPE_BCM2835_ST, 0x20); sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->iomem); } -- 2.11.4.GIT