[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 11/15] hw/timer/arm_timer: Iterate on timers using for() loop sta
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH 11/15] hw/timer/arm_timer: Iterate on timers using for() loop statement |
Date: |
Wed, 31 May 2023 22:35:55 +0200 |
The same pattern is used for each timer, 2 or 3 times. To avoid
too much code churn in the next commits, iterate on the number
of timers using a for() loop statement.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/timer/arm_timer.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/hw/timer/arm_timer.c b/hw/timer/arm_timer.c
index 4d31f917f6..19789ad2c4 100644
--- a/hw/timer/arm_timer.c
+++ b/hw/timer/arm_timer.c
@@ -308,10 +308,10 @@ static void sp804_realize(DeviceState *dev, Error **errp)
{
SP804State *s = SP804(dev);
- s->timer[0] = arm_timer_new(s->freq[0]);
- s->timer[1] = arm_timer_new(s->freq[1]);
- s->timer[0]->irq = qemu_allocate_irq(sp804_set_irq, s, 0);
- s->timer[1]->irq = qemu_allocate_irq(sp804_set_irq, s, 1);
+ 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);
+ }
}
static void sp804_unrealize(DeviceState *dev)
@@ -390,18 +390,19 @@ static const MemoryRegionOps icp_pit_ops = {
static void icp_pit_init(Object *obj)
{
+ static const uint32_t tmr_freq[] = {
+ /* Timer 0 runs at the system clock speed (40MHz). */
+ 40000000,
+ /* The other two timers run at 1MHz. */
+ 1000000, 1000000
+ };
IntegratorPitState *s = INTEGRATOR_PIT(obj);
SysBusDevice *dev = SYS_BUS_DEVICE(obj);
- /* Timer 0 runs at the system clock speed (40MHz). */
- s->timer[0] = arm_timer_new(40000000);
- /* The other two timers run at 1MHz. */
- s->timer[1] = arm_timer_new(1000000);
- s->timer[2] = arm_timer_new(1000000);
-
- sysbus_init_irq(dev, &s->timer[0]->irq);
- sysbus_init_irq(dev, &s->timer[1]->irq);
- sysbus_init_irq(dev, &s->timer[2]->irq);
+ 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);
+ }
memory_region_init_io(&s->iomem, obj, &icp_pit_ops, s,
"icp_pit", 0x1000);
--
2.38.1
- [PATCH 01/15] hw/timer/arm_timer: Declare QOM types using DEFINE_TYPES() macro, (continued)
- [PATCH 01/15] hw/timer/arm_timer: Declare QOM types using DEFINE_TYPES() macro, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 02/15] hw/timer/arm_timer: Move SP804 code around, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 03/15] hw/timer/arm_timer: Add missing sp804_unrealize() handler, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 04/15] hw/timer/arm_timer: Remove pointless cast from void *, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 05/15] hw/timer/arm_timer: CamelCase rename icp_pit_state -> IntegratorPitState, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 06/15] hw/timer/arm_timer: CamelCase rename arm_timer_state -> ArmTimerState, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 07/15] hw/timer/arm_timer: Extract arm_timer_reset(), Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 08/15] hw/timer/arm_timer: Rename arm_timer_init() -> arm_timer_new(), Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 09/15] hw/timer/arm_timer: Convert ArmTimerState::freq to uint32_t type, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 10/15] hw/timer/arm_timer: Use array of frequency in SP804State, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 11/15] hw/timer/arm_timer: Iterate on timers using for() loop statement,
Philippe Mathieu-Daudé <=
- [PATCH 12/15] hw/timer/arm_timer: Pass timer output IRQ as parameter to arm_timer_new, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 13/15] hw/timer/arm_timer: Fix misuse of SysBus IRQ in IcpPitState, Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 14/15] hw/timer/arm_timer: Extract icp_pit_realize() from icp_pit_init(), Philippe Mathieu-Daudé, 2023/05/31
- [PATCH 15/15] hw/timer/arm_timer: QOM'ify ARM_TIMER, Philippe Mathieu-Daudé, 2023/05/31