Skip to contentSkip to conversation

hw/ppc: sam460ex.c: store all GPIO lines in mal_irqs[]

PATCH In review Daniel Henrique Barboza 3 participants 3 messages Aug 3, 2022 – Aug 4, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/ppc: sam460ex.c: store all GPIO lines in mal_irqs[]

We're not storing all GPIO lines we're retrieving with qdev_get_gpio_in() in mal_irqs[]. We're storing just the last one in the first index:

    for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
        mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
    }
    ppc4xx_mal_init(env, 4, 16, mal_irqs);

mal_irqs is used in ppc4xx_mal_init() to assign the IRQs to MAL:

    for (i = 0; i < 4; i++) {
        mal->irqs[i] = irqs[i];
    }

Since only irqs[0] has been initialized, mal->irqs[1,2,3] are being zeroed.

This doesn´t seem to trigger any apparent issues at this moment, but Cedric's QOMification of the MAL device [1] is executing a sysbus_connect_irq() that will fail if we do not store all GPIO lines properly.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg00497.html

Cc Peter Maydell <[email protected]>
Cc BALATON Zoltan <[email protected]>
Fixes 706e944206d7 ("hw/ppc/sam460ex: Drop use of ppcuic_init()")
---
 hw/ppc/sam460ex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/sam460ex.c +1 -1
index 7e8da657c2..0357ee077f 100644
@@ -384,7 +384,7 @@ static void sam460ex_init(MachineState *machine)
 
     /* MAL */
     for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
-        mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
+        mal_irqs[i] = qdev_get_gpio_in(uic[2], 3 + i);
     }
     ppc4xx_mal_init(env, 4, 16, mal_irqs);
 
Signature · 1 line
2.36.1
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Daniel Henrique Barboza

We're not storing all GPIO lines we're retrieving with qdev_get_gpio_in() in mal_irqs[]. We're storing just the last one in the first index:

   for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
       mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
   }
   ppc4xx_mal_init(env, 4, 16, mal_irqs);

Indeed, this used to be ppc4xx_mal_init(env, 4, 16, &uic[2][3]); before 706e944206d7 and this typo slipped thorugh unnoticed, likely because the MAL is only there for the firmware to be happy. I think it would be used by the EMAC Ethernet port or maybe SATA which are not emulated so probably nothing really uses the MAL.

Quoted 39 lines

mal_irqs is used in ppc4xx_mal_init() to assign the IRQs to MAL:

   for (i = 0; i < 4; i++) {
       mal->irqs[i] = irqs[i];
   }

Since only irqs[0] has been initialized, mal->irqs[1,2,3] are being zeroed.

This doesn´t seem to trigger any apparent issues at this moment, but Cedric's QOMification of the MAL device [1] is executing a sysbus_connect_irq() that will fail if we do not store all GPIO lines properly.

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg00497.html

Cc Peter Maydell <[email protected]>
Cc BALATON Zoltan <[email protected]>
Fixes 706e944206d7 ("hw/ppc/sam460ex: Drop use of ppcuic_init()")

---
hw/ppc/sam460ex.c | 2 +-

1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/sam460ex.c +1 -1
index 7e8da657c2..0357ee077f 100644
@@ -384,7 +384,7 @@ static void sam460ex_init(MachineState *machine)
 
    /* MAL */
    for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
-        mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
+        mal_irqs[i] = qdev_get_gpio_in(uic[2], 3 + i);
    }
    ppc4xx_mal_init(env, 4, 16, mal_irqs);
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Daniel Henrique Barboza
Quoted 23 lines · Daniel Henrique Barboza

We're not storing all GPIO lines we're retrieving with qdev_get_gpio_in() in mal_irqs[]. We're storing just the last one in the first index:

     for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
         mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
     }
     ppc4xx_mal_init(env, 4, 16, mal_irqs);

mal_irqs is used in ppc4xx_mal_init() to assign the IRQs to MAL:

     for (i = 0; i < 4; i++) {
         mal->irqs[i] = irqs[i];
     }

Since only irqs[0] has been initialized, mal->irqs[1,2,3] are being zeroed.

This doesn´t seem to trigger any apparent issues at this moment, but Cedric's QOMification of the MAL device [1] is executing a sysbus_connect_irq() that will fail if we do not store all GPIO lines properly.

Quoted 6 lines

[1] https://lists.gnu.org/archive/html/qemu-devel/2022-08/msg00497.html

Cc Peter Maydell <[email protected]>
Cc BALATON Zoltan <[email protected]>
Fixes 706e944206d7 ("hw/ppc/sam460ex: Drop use of ppcuic_init()")

Yes, I found the same issue when fixing ppc4xx_mal_init().

Thanks,

C.

Quoted 17 lines
---
  hw/ppc/sam460ex.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/ppc/sam460ex.c +1 -1
index 7e8da657c2..0357ee077f 100644
@@ -384,7 +384,7 @@ static void sam460ex_init(MachineState *machine)
 
      /* MAL */
      for (i = 0; i < ARRAY_SIZE(mal_irqs); i++) {
-        mal_irqs[0] = qdev_get_gpio_in(uic[2], 3 + i);
+        mal_irqs[i] = qdev_get_gpio_in(uic[2], 3 + i);
      }
      ppc4xx_mal_init(env, 4, 16, mal_irqs);