diff mbox series

[7/7] hw: Simplify using sysbus_init_irqs() [manual]

Message ID 20230531223341.34827-8-philmd@linaro.org
State New
Headers show
Series hw/sysbus: Add sysbus_init_irqs and reduce SYSBUS_DEVICE_GPIO_IRQ scope | expand

Commit Message

Philippe Mathieu-Daudé May 31, 2023, 10:33 p.m. UTC
Audit the sysbus_init_irq() calls and manually convert
to sysbus_init_irqs() when a loop is involved.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/intc/loongarch_extioi.c | 3 +--
 hw/intc/omap_intc.c        | 3 +--
 hw/pci-host/gpex.c         | 2 +-
 hw/timer/renesas_tmr.c     | 9 +++------
 4 files changed, 6 insertions(+), 11 deletions(-)

Comments

Richard Henderson June 1, 2023, 3:13 a.m. UTC | #1
On 5/31/23 15:33, Philippe Mathieu-Daudé wrote:
> Audit the sysbus_init_irq() calls and manually convert
> to sysbus_init_irqs() when a loop is involved.
> 
> Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org>
> ---
>   hw/intc/loongarch_extioi.c | 3 +--
>   hw/intc/omap_intc.c        | 3 +--
>   hw/pci-host/gpex.c         | 2 +-
>   hw/timer/renesas_tmr.c     | 9 +++------
>   4 files changed, 6 insertions(+), 11 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~
Markus Armbruster June 1, 2023, 5:59 a.m. UTC | #2
Philippe Mathieu-Daudé <philmd@linaro.org> writes:

> Audit the sysbus_init_irq() calls and manually convert
> to sysbus_init_irqs() when a loop is involved.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/intc/loongarch_extioi.c | 3 +--
>  hw/intc/omap_intc.c        | 3 +--
>  hw/pci-host/gpex.c         | 2 +-
>  hw/timer/renesas_tmr.c     | 9 +++------
>  4 files changed, 6 insertions(+), 11 deletions(-)
>
> diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
> index db941de20e..c579636215 100644
> --- a/hw/intc/loongarch_extioi.c
> +++ b/hw/intc/loongarch_extioi.c
> @@ -275,8 +275,7 @@ static void loongarch_extioi_instance_init(Object *obj)
>      LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
>      int cpu, pin;
>  
> -    sysbus_init_irqs(SYS_BUS_DEVICE(dev), s->irq, EXTIOI_IRQS);
> -
> +    sysbus_init_irqs(dev, s->irq, EXTIOI_IRQS);

Commit message claims "when a loop is involved".  No loop here.  That
work was actually done in the previous patch:

  diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
  index 0e7a3e32f3..db941de20e 100644
  --- a/hw/intc/loongarch_extioi.c
  +++ b/hw/intc/loongarch_extioi.c
  @@ -273,11 +273,9 @@ static void loongarch_extioi_instance_init(Object *obj)
   {
       SysBusDevice *dev = SYS_BUS_DEVICE(obj);
       LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
  -    int i, cpu, pin;
  +    int cpu, pin;

  -    for (i = 0; i < EXTIOI_IRQS; i++) {
  -        sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]);
  -    }
  +    sysbus_init_irqs(SYS_BUS_DEVICE(dev), s->irq, EXTIOI_IRQS);

       qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS);

In this patch, you merely delete a superfluous type conversion that is
present even before your series.

There are more of them in this function.  Please delete them all, and in
a separate patch.

Actually, there are more elsewhere.  Coccinelle script

    @@
    typedef SysBusDevice;
    SysBusDevice *dev;
    @@
    -    SYS_BUS_DEVICE(dev)
    +    dev

finds some in hw/arm/xlnx-versal.c and hw/rx/rx62n.c, too.

Would be nice to do this for every QOM type, but I don't know how
without duplicating the semantic patch for each of them.  There are
almost 150 uses os OBJECT_DECLARE_TYPE()...

You might want to address this in a separate series, to not delay this
one.

>      qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS);
>  
>      for (cpu = 0; cpu < EXTIOI_CPUS; cpu++) {
> diff --git a/hw/intc/omap_intc.c b/hw/intc/omap_intc.c
> index 647bf324a8..f324b640e3 100644
> --- a/hw/intc/omap_intc.c
> +++ b/hw/intc/omap_intc.c
> @@ -627,8 +627,7 @@ static void omap2_intc_init(Object *obj)
>  
>      s->level_only = 1;
>      s->nbanks = 3;
> -    sysbus_init_irq(sbd, &s->parent_intr[0]);
> -    sysbus_init_irq(sbd, &s->parent_intr[1]);
> +    sysbus_init_irqs(sbd, s->parent_intr, ARRAY_SIZE(s->parent_intr));

Unrolled loop.  s->parent_intr[] indeed has 2 elements.  Okay.

>      qdev_init_gpio_in(dev, omap_set_intr_noedge, s->nbanks * 32);
>      memory_region_init_io(&s->mmio, obj, &omap2_inth_mem_ops, s,
>                            "omap2-intc", 0x1000);

[...]
Philippe Mathieu-Daudé June 1, 2023, 8:58 a.m. UTC | #3
On 1/6/23 07:59, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@linaro.org> writes:
> 
>> Audit the sysbus_init_irq() calls and manually convert
>> to sysbus_init_irqs() when a loop is involved.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   hw/intc/loongarch_extioi.c | 3 +--
>>   hw/intc/omap_intc.c        | 3 +--
>>   hw/pci-host/gpex.c         | 2 +-
>>   hw/timer/renesas_tmr.c     | 9 +++------
>>   4 files changed, 6 insertions(+), 11 deletions(-)
>>
>> diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
>> index db941de20e..c579636215 100644
>> --- a/hw/intc/loongarch_extioi.c
>> +++ b/hw/intc/loongarch_extioi.c
>> @@ -275,8 +275,7 @@ static void loongarch_extioi_instance_init(Object *obj)
>>       LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
>>       int cpu, pin;
>>   
>> -    sysbus_init_irqs(SYS_BUS_DEVICE(dev), s->irq, EXTIOI_IRQS);
>> -
>> +    sysbus_init_irqs(dev, s->irq, EXTIOI_IRQS);
> 
> Commit message claims "when a loop is involved".  No loop here.  That
> work was actually done in the previous patch:
> 
>    diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
>    index 0e7a3e32f3..db941de20e 100644
>    --- a/hw/intc/loongarch_extioi.c
>    +++ b/hw/intc/loongarch_extioi.c
>    @@ -273,11 +273,9 @@ static void loongarch_extioi_instance_init(Object *obj)
>     {
>         SysBusDevice *dev = SYS_BUS_DEVICE(obj);
>         LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
>    -    int i, cpu, pin;
>    +    int cpu, pin;
> 
>    -    for (i = 0; i < EXTIOI_IRQS; i++) {
>    -        sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq[i]);
>    -    }
>    +    sysbus_init_irqs(SYS_BUS_DEVICE(dev), s->irq, EXTIOI_IRQS);
> 
>         qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS);
> 
> In this patch, you merely delete a superfluous type conversion that is
> present even before your series.

Right. I guess I did that automatically "why are we casting the same
type?" without even noticing.

> There are more of them in this function.  Please delete them all, and in
> a separate patch.

OK.

> Actually, there are more elsewhere.  Coccinelle script
> 
>      @@
>      typedef SysBusDevice;
>      SysBusDevice *dev;
>      @@
>      -    SYS_BUS_DEVICE(dev)
>      +    dev
> 
> finds some in hw/arm/xlnx-versal.c and hw/rx/rx62n.c, too.
> 
> Would be nice to do this for every QOM type, but I don't know how
> without duplicating the semantic patch for each of them.  There are
> almost 150 uses os OBJECT_DECLARE_TYPE()...

Checking all QOM macros, I counted 1076 types...
diff mbox series

Patch

diff --git a/hw/intc/loongarch_extioi.c b/hw/intc/loongarch_extioi.c
index db941de20e..c579636215 100644
--- a/hw/intc/loongarch_extioi.c
+++ b/hw/intc/loongarch_extioi.c
@@ -275,8 +275,7 @@  static void loongarch_extioi_instance_init(Object *obj)
     LoongArchExtIOI *s = LOONGARCH_EXTIOI(obj);
     int cpu, pin;
 
-    sysbus_init_irqs(SYS_BUS_DEVICE(dev), s->irq, EXTIOI_IRQS);
-
+    sysbus_init_irqs(dev, s->irq, EXTIOI_IRQS);
     qdev_init_gpio_in(DEVICE(obj), extioi_setirq, EXTIOI_IRQS);
 
     for (cpu = 0; cpu < EXTIOI_CPUS; cpu++) {
diff --git a/hw/intc/omap_intc.c b/hw/intc/omap_intc.c
index 647bf324a8..f324b640e3 100644
--- a/hw/intc/omap_intc.c
+++ b/hw/intc/omap_intc.c
@@ -627,8 +627,7 @@  static void omap2_intc_init(Object *obj)
 
     s->level_only = 1;
     s->nbanks = 3;
-    sysbus_init_irq(sbd, &s->parent_intr[0]);
-    sysbus_init_irq(sbd, &s->parent_intr[1]);
+    sysbus_init_irqs(sbd, s->parent_intr, ARRAY_SIZE(s->parent_intr));
     qdev_init_gpio_in(dev, omap_set_intr_noedge, s->nbanks * 32);
     memory_region_init_io(&s->mmio, obj, &omap2_inth_mem_ops, s,
                           "omap2-intc", 0x1000);
diff --git a/hw/pci-host/gpex.c b/hw/pci-host/gpex.c
index a6752fac5e..7b46e3e36e 100644
--- a/hw/pci-host/gpex.c
+++ b/hw/pci-host/gpex.c
@@ -128,8 +128,8 @@  static void gpex_host_realize(DeviceState *dev, Error **errp)
         sysbus_init_mmio(sbd, &s->io_ioport);
     }
 
+    sysbus_init_irqs(sbd, s->irq, GPEX_NUM_IRQS);
     for (i = 0; i < GPEX_NUM_IRQS; i++) {
-        sysbus_init_irq(sbd, &s->irq[i]);
         s->irq_num[i] = -1;
     }
 
diff --git a/hw/timer/renesas_tmr.c b/hw/timer/renesas_tmr.c
index c15f654738..dd2929d6e7 100644
--- a/hw/timer/renesas_tmr.c
+++ b/hw/timer/renesas_tmr.c
@@ -428,17 +428,14 @@  static void rtmr_init(Object *obj)
 {
     SysBusDevice *d = SYS_BUS_DEVICE(obj);
     RTMRState *tmr = RTMR(obj);
-    int i;
 
     memory_region_init_io(&tmr->memory, OBJECT(tmr), &tmr_ops,
                           tmr, "renesas-tmr", 0x10);
     sysbus_init_mmio(d, &tmr->memory);
 
-    for (i = 0; i < ARRAY_SIZE(tmr->ovi); i++) {
-        sysbus_init_irq(d, &tmr->cmia[i]);
-        sysbus_init_irq(d, &tmr->cmib[i]);
-        sysbus_init_irq(d, &tmr->ovi[i]);
-    }
+    sysbus_init_irqs(d, tmr->cmia, ARRAY_SIZE(tmr->cmia));
+    sysbus_init_irqs(d, tmr->cmib, ARRAY_SIZE(tmr->cmib));
+    sysbus_init_irqs(d, tmr->ovi, ARRAY_SIZE(tmr->ovi));
     timer_init_ns(&tmr->timer[0], QEMU_CLOCK_VIRTUAL, timer_event0, tmr);
     timer_init_ns(&tmr->timer[1], QEMU_CLOCK_VIRTUAL, timer_event1, tmr);
 }