@@ -179,7 +179,7 @@ static void arm_timer_reset_hold(ArmTimer *s)
s->control = TIMER_CTRL_IE;
}
-static ArmTimer *arm_timer_new(uint32_t freq)
+static ArmTimer *arm_timer_new(uint32_t freq, qemu_irq irq_out)
{
ArmTimer *s;
@@ -187,6 +187,7 @@ static ArmTimer *arm_timer_new(uint32_t freq)
s->freq = freq;
arm_timer_reset_hold(s);
+ s->irq = irq_out;
s->timer = ptimer_init(arm_timer_tick, s, PTIMER_POLICY_LEGACY);
vmstate_register(NULL, VMSTATE_INSTANCE_ID_ANY, &vmstate_arm_timer, s);
return s;
@@ -209,6 +210,7 @@ struct SP804Timer {
uint32_t freq[2];
int level[2];
qemu_irq irq;
+ qemu_irq irq_in[2];
};
static const uint8_t sp804_ids[] = {
@@ -311,8 +313,8 @@ static void sp804_realize(DeviceState *dev, Error **errp)
SP804Timer *s = SP804_TIMER(dev);
for (unsigned i = 0; i < ARRAY_SIZE(s->timer); i++) {
- s->timer[i] = arm_timer_new(s->freq[i]);
- s->timer[i]->irq = qemu_allocate_irq(sp804_set_irq, s, i);
+ s->irq_in[i] = qemu_allocate_irq(sp804_set_irq, s, i);
+ s->timer[i] = arm_timer_new(s->freq[i], s->irq_in[i]);
}
}
@@ -341,6 +343,7 @@ struct IntegratorPIT {
MemoryRegion iomem;
ArmTimer *timer[3];
+ qemu_irq irq_in[3];
};
static uint64_t icp_pit_read(void *opaque, hwaddr offset,
@@ -392,8 +395,8 @@ static void icp_pit_init(Object *obj)
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
for (unsigned i = 0; i < ARRAY_SIZE(s->timer); i++) {
- s->timer[i] = arm_timer_new(tmr_freq[i]);
- sysbus_init_irq(dev, &s->timer[i]->irq);
+ s->timer[i] = arm_timer_new(tmr_freq[i], s->irq_in[i]);
+ sysbus_init_irq(dev, &s->irq_in[i]);
}
memory_region_init_io(&s->iomem, obj, &icp_pit_ops, s,
Both SP804Timer/IntegratorPIT peek at ArmTimer internal state. This is fine so far but we want to convert ArmTimer to QOM where peeking at QOM state internal should be avoided. ArmTimer's IRQ is just a pointer, so we can pass/set it via argument, avoiding accessing ArmTimer internal state except from the arm_timer_*() methods. Once ArmTimer get QOM'ified (in a few commits), it will inherit the SysBus API. This IRQ will then become a SysBus IRQ within this ArmTimer object. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/timer/arm_timer.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)