[PATCH] hw/ide/macio.c: switch from using qemu_allocate_irq() to qdev input GPIOs

Mark Cave-Ayland posted 1 patch 6 months ago
There is a newer version of this series
hw/ide/macio.c                | 10 ++++++----
include/hw/misc/macio/macio.h |  5 +++++
2 files changed, 11 insertions(+), 4 deletions(-)
[PATCH] hw/ide/macio.c: switch from using qemu_allocate_irq() to qdev input GPIOs
Posted by Mark Cave-Ayland 6 months ago
This prevents the IRQs from being leaked when the macio IDE device is used.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/ide/macio.c                | 10 ++++++----
 include/hw/misc/macio/macio.h |  5 +++++
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/hw/ide/macio.c b/hw/ide/macio.c
index aca90d04f0..e84bf2c9f6 100644
--- a/hw/ide/macio.c
+++ b/hw/ide/macio.c
@@ -420,7 +420,8 @@ static void macio_ide_realizefn(DeviceState *dev, Error **errp)
 {
     MACIOIDEState *s = MACIO_IDE(dev);
 
-    ide_bus_init_output_irq(&s->bus, s->ide_irq);
+    ide_bus_init_output_irq(&s->bus,
+                            qdev_get_gpio_in(dev, MACIO_IDE_PMAC_IDE_IRQ));
 
     /* Register DMA callbacks */
     s->dma.ops = &dbdma_ops;
@@ -456,8 +457,8 @@ static void macio_ide_initfn(Object *obj)
     sysbus_init_mmio(d, &s->mem);
     sysbus_init_irq(d, &s->real_ide_irq);
     sysbus_init_irq(d, &s->real_dma_irq);
-    s->dma_irq = qemu_allocate_irq(pmac_ide_irq, s, 0);
-    s->ide_irq = qemu_allocate_irq(pmac_ide_irq, s, 1);
+
+    qdev_init_gpio_in(DEVICE(obj), pmac_ide_irq, MACIO_IDE_PMAC_NIRQS);
 
     object_property_add_link(obj, "dbdma", TYPE_MAC_DBDMA,
                              (Object **) &s->dbdma,
@@ -508,7 +509,8 @@ void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
 
 void macio_ide_register_dma(MACIOIDEState *s)
 {
-    DBDMA_register_channel(s->dbdma, s->channel, s->dma_irq,
+    DBDMA_register_channel(s->dbdma, s->channel,
+                           qdev_get_gpio_in(DEVICE(s), MACIO_IDE_PMAC_DMA_IRQ),
                            pmac_ide_transfer, pmac_ide_flush, s);
 }
 
diff --git a/include/hw/misc/macio/macio.h b/include/hw/misc/macio/macio.h
index 2b54da6b31..869b66055b 100644
--- a/include/hw/misc/macio/macio.h
+++ b/include/hw/misc/macio/macio.h
@@ -92,6 +92,11 @@ struct MACIOIDEState {
     uint32_t irq_reg;
 };
 
+#define MACIO_IDE_PMAC_NIRQS 2
+
+#define MACIO_IDE_PMAC_DMA_IRQ 0
+#define MACIO_IDE_PMAC_IDE_IRQ 1
+
 void macio_ide_init_drives(MACIOIDEState *ide, DriveInfo **hd_table);
 void macio_ide_register_dma(MACIOIDEState *ide);
 
-- 
2.39.2
Re: [PATCH] hw/ide/macio.c: switch from using qemu_allocate_irq() to qdev input GPIOs
Posted by Peter Maydell 6 months ago
On Fri, 28 Jun 2024 at 11:55, Mark Cave-Ayland
<mark.cave-ayland@ilande.co.uk> wrote:
>
> This prevents the IRQs from being leaked when the macio IDE device is used.
>
> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
> ---
>  hw/ide/macio.c                | 10 ++++++----
>  include/hw/misc/macio/macio.h |  5 +++++
>  2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
> index aca90d04f0..e84bf2c9f6 100644
> --- a/hw/ide/macio.c
> +++ b/hw/ide/macio.c
> @@ -420,7 +420,8 @@ static void macio_ide_realizefn(DeviceState *dev, Error **errp)
>  {
>      MACIOIDEState *s = MACIO_IDE(dev);
>
> -    ide_bus_init_output_irq(&s->bus, s->ide_irq);
> +    ide_bus_init_output_irq(&s->bus,
> +                            qdev_get_gpio_in(dev, MACIO_IDE_PMAC_IDE_IRQ));
>
>      /* Register DMA callbacks */
>      s->dma.ops = &dbdma_ops;
> @@ -456,8 +457,8 @@ static void macio_ide_initfn(Object *obj)
>      sysbus_init_mmio(d, &s->mem);
>      sysbus_init_irq(d, &s->real_ide_irq);
>      sysbus_init_irq(d, &s->real_dma_irq);
> -    s->dma_irq = qemu_allocate_irq(pmac_ide_irq, s, 0);
> -    s->ide_irq = qemu_allocate_irq(pmac_ide_irq, s, 1);
> +
> +    qdev_init_gpio_in(DEVICE(obj), pmac_ide_irq, MACIO_IDE_PMAC_NIRQS);
>
>      object_property_add_link(obj, "dbdma", TYPE_MAC_DBDMA,
>                               (Object **) &s->dbdma,
> @@ -508,7 +509,8 @@ void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
>
>  void macio_ide_register_dma(MACIOIDEState *s)
>  {
> -    DBDMA_register_channel(s->dbdma, s->channel, s->dma_irq,
> +    DBDMA_register_channel(s->dbdma, s->channel,
> +                           qdev_get_gpio_in(DEVICE(s), MACIO_IDE_PMAC_DMA_IRQ),
>                             pmac_ide_transfer, pmac_ide_flush, s);
>  }
>
> diff --git a/include/hw/misc/macio/macio.h b/include/hw/misc/macio/macio.h
> index 2b54da6b31..869b66055b 100644
> --- a/include/hw/misc/macio/macio.h
> +++ b/include/hw/misc/macio/macio.h
> @@ -92,6 +92,11 @@ struct MACIOIDEState {
>      uint32_t irq_reg;
>  };
>
> +#define MACIO_IDE_PMAC_NIRQS 2
> +
> +#define MACIO_IDE_PMAC_DMA_IRQ 0
> +#define MACIO_IDE_PMAC_IDE_IRQ 1
> +
>  void macio_ide_init_drives(MACIOIDEState *ide, DriveInfo **hd_table);
>  void macio_ide_register_dma(MACIOIDEState *ide);

Can we also now delete the dma_irq and ide_irq fields from the
MACIOIDEState struct?

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM
Re: [PATCH] hw/ide/macio.c: switch from using qemu_allocate_irq() to qdev input GPIOs
Posted by Mark Cave-Ayland 6 months ago
On 28/06/2024 16:28, Peter Maydell wrote:

> On Fri, 28 Jun 2024 at 11:55, Mark Cave-Ayland
> <mark.cave-ayland@ilande.co.uk> wrote:
>>
>> This prevents the IRQs from being leaked when the macio IDE device is used.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
>> ---
>>   hw/ide/macio.c                | 10 ++++++----
>>   include/hw/misc/macio/macio.h |  5 +++++
>>   2 files changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/hw/ide/macio.c b/hw/ide/macio.c
>> index aca90d04f0..e84bf2c9f6 100644
>> --- a/hw/ide/macio.c
>> +++ b/hw/ide/macio.c
>> @@ -420,7 +420,8 @@ static void macio_ide_realizefn(DeviceState *dev, Error **errp)
>>   {
>>       MACIOIDEState *s = MACIO_IDE(dev);
>>
>> -    ide_bus_init_output_irq(&s->bus, s->ide_irq);
>> +    ide_bus_init_output_irq(&s->bus,
>> +                            qdev_get_gpio_in(dev, MACIO_IDE_PMAC_IDE_IRQ));
>>
>>       /* Register DMA callbacks */
>>       s->dma.ops = &dbdma_ops;
>> @@ -456,8 +457,8 @@ static void macio_ide_initfn(Object *obj)
>>       sysbus_init_mmio(d, &s->mem);
>>       sysbus_init_irq(d, &s->real_ide_irq);
>>       sysbus_init_irq(d, &s->real_dma_irq);
>> -    s->dma_irq = qemu_allocate_irq(pmac_ide_irq, s, 0);
>> -    s->ide_irq = qemu_allocate_irq(pmac_ide_irq, s, 1);
>> +
>> +    qdev_init_gpio_in(DEVICE(obj), pmac_ide_irq, MACIO_IDE_PMAC_NIRQS);
>>
>>       object_property_add_link(obj, "dbdma", TYPE_MAC_DBDMA,
>>                                (Object **) &s->dbdma,
>> @@ -508,7 +509,8 @@ void macio_ide_init_drives(MACIOIDEState *s, DriveInfo **hd_table)
>>
>>   void macio_ide_register_dma(MACIOIDEState *s)
>>   {
>> -    DBDMA_register_channel(s->dbdma, s->channel, s->dma_irq,
>> +    DBDMA_register_channel(s->dbdma, s->channel,
>> +                           qdev_get_gpio_in(DEVICE(s), MACIO_IDE_PMAC_DMA_IRQ),
>>                              pmac_ide_transfer, pmac_ide_flush, s);
>>   }
>>
>> diff --git a/include/hw/misc/macio/macio.h b/include/hw/misc/macio/macio.h
>> index 2b54da6b31..869b66055b 100644
>> --- a/include/hw/misc/macio/macio.h
>> +++ b/include/hw/misc/macio/macio.h
>> @@ -92,6 +92,11 @@ struct MACIOIDEState {
>>       uint32_t irq_reg;
>>   };
>>
>> +#define MACIO_IDE_PMAC_NIRQS 2
>> +
>> +#define MACIO_IDE_PMAC_DMA_IRQ 0
>> +#define MACIO_IDE_PMAC_IDE_IRQ 1
>> +
>>   void macio_ide_init_drives(MACIOIDEState *ide, DriveInfo **hd_table);
>>   void macio_ide_register_dma(MACIOIDEState *ide);
> 
> Can we also now delete the dma_irq and ide_irq fields from the
> MACIOIDEState struct?
> 
> Otherwise
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

Ooops, yes. I'll update and send a v2 including your Reviewed-by tag.


ATB,

Mark.