[PATCH] hw/arm/bcm2838: Route SPI0 interrupt to GIC

Hanyu posted 1 patch 2 weeks ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261109035234.722952-1-hywei787@gmail.com
Maintainers: Peter Maydell <peter.maydell@linaro.org>, "Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
hw/arm/bcm2835_peripherals.c         | 14 +++++++++++---
hw/arm/bcm2838.c                     |  4 ++++
include/hw/arm/bcm2835_peripherals.h |  1 +
include/hw/arm/bcm2838_peripherals.h |  1 +
4 files changed, 17 insertions(+), 3 deletions(-)
[PATCH] hw/arm/bcm2838: Route SPI0 interrupt to GIC
Posted by Hanyu 2 weeks ago
From: Hanyu <hywei737@utexas.edu>

On raspi4b, SPI0's interrupt is connected only to the legacy interrupt
controller. Linux guests whose device trees use the GIC therefore
can't detect an SPI0 interrupt.

This patch adds a two-output IRQ splitter to deliver SPI0's interrupt
to both the legacy controller and GIC SPI 118. This follows commit
fb3e0557a4cb ("hw/arm/bcm2838: Route I2C interrupts to GIC").

Testing

Add these options to the QEMU invocation:

  -device m25p80,bus=spi,drive=flash0 \
  -blockdev node-name=flash0,driver=file,filename=flash.bin

Before the change, probing fails and /proc/mtd contains no devices:

  spi-nor spi0.0: SPI transfer timed out
  spi_master spi0: failed to transfer one message from queue
  spi-nor: probe of spi0.0 failed with error -2

After the change, the flash is detected:

  spi-nor spi0.0: m25p80 (1024 Kbytes)
  # cat /proc/mtd
  dev:    size   erasesize  name
  mtd0: 00100000 00010000 "spi0.0"

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3013
Signed-off-by: Hanyu <hywei737@utexas.edu>
---
 hw/arm/bcm2835_peripherals.c         | 14 +++++++++++---
 hw/arm/bcm2838.c                     |  4 ++++
 include/hw/arm/bcm2835_peripherals.h |  1 +
 include/hw/arm/bcm2838_peripherals.h |  1 +
 4 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
index 558c180df9..be40c6b92a 100644
--- a/hw/arm/bcm2835_peripherals.c
+++ b/hw/arm/bcm2835_peripherals.c
@@ -166,6 +166,8 @@ static void raspi_peripherals_base_init(Object *obj)
     /* SPI */
     object_initialize_child(obj, "bcm2835-spi0", &s->spi[0],
                             TYPE_BCM2835_SPI);
+    object_initialize_child(obj, "spi-irq-splitter",
+                            &s->spi_irq_splitter, TYPE_SPLIT_IRQ);
 
     /* I2C */
     object_initialize_child(obj, "bcm2835-i2c0", &s->i2c[0],
@@ -480,10 +482,16 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)
 
     memory_region_add_subregion(&s->peri_mr, SPI0_OFFSET,
                 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->spi[0]), 0));
+    qdev_prop_set_uint32(DEVICE(&s->spi_irq_splitter), "num-lines", 2);
+    if (!qdev_realize(DEVICE(&s->spi_irq_splitter), NULL, errp)) {
+        return;
+    }
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->spi[0]), 0,
-                       qdev_get_gpio_in_named(DEVICE(&s->ic),
-                                              BCM2835_IC_GPU_IRQ,
-                                              INTERRUPT_SPI));
+                       qdev_get_gpio_in(DEVICE(&s->spi_irq_splitter), 0));
+    qdev_connect_gpio_out(DEVICE(&s->spi_irq_splitter), 0,
+                          qdev_get_gpio_in_named(DEVICE(&s->ic),
+                                                 BCM2835_IC_GPU_IRQ,
+                                                 INTERRUPT_SPI));
 
     /* I2C */
     for (n = 0; n < 3; n++) {
diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c
index 650b1fe8f4..1bde9e68af 100644
--- a/hw/arm/bcm2838.c
+++ b/hw/arm/bcm2838.c
@@ -188,6 +188,10 @@ static void bcm2838_realize(DeviceState *dev, Error **errp)
     qdev_connect_gpio_out(DEVICE(&ps_base->orgated_i2c_irq_splitter), 1,
                           qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_I2C));
 
+    /* Connect the SPI interrupt to the interrupt controller */
+    qdev_connect_gpio_out(DEVICE(&ps_base->spi_irq_splitter), 1,
+                          qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_SPI));
+
     /* Connect VC mailbox to the interrupt controller */
     sysbus_connect_irq(SYS_BUS_DEVICE(&ps_base->mboxes), 0,
                        qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_MBOX));
diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h
index 4f356f4643..cd66a734e7 100644
--- a/include/hw/arm/bcm2835_peripherals.h
+++ b/include/hw/arm/bcm2835_peripherals.h
@@ -71,6 +71,7 @@ struct BCMSocPeripheralBaseState {
     BCM2835SDHostState sdhost;
     UnimplementedDeviceState i2s;
     BCM2835SPIState spi[1];
+    SplitIRQ spi_irq_splitter;
     BCM2835I2CState i2c[3];
     OrIRQState orgated_i2c_irq;
     SplitIRQ orgated_i2c_irq_splitter;
diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h
index 60bfacdce4..f9279daa4d 100644
--- a/include/hw/arm/bcm2838_peripherals.h
+++ b/include/hw/arm/bcm2838_peripherals.h
@@ -27,6 +27,7 @@
 #define GIC_SPI_INTERRUPT_DMA_9_10     88
 #define GIC_SPI_INTERRUPT_AUX_UART1    93
 #define GIC_SPI_INTERRUPT_I2C          117
+#define GIC_SPI_INTERRUPT_SPI          118
 #define GIC_SPI_INTERRUPT_SDHOST       120
 #define GIC_SPI_INTERRUPT_UART0        121
 #define GIC_SPI_INTERRUPT_RNG200       125
-- 
2.43.0
Re: [PATCH] hw/arm/bcm2838: Route SPI0 interrupt to GIC
Posted by Peter Maydell 1 week, 3 days ago
On Mon, 9 Nov 2026 at 03:52, Hanyu <hywei787@gmail.com> wrote:
>
> From: Hanyu <hywei737@utexas.edu>
>
> On raspi4b, SPI0's interrupt is connected only to the legacy interrupt
> controller. Linux guests whose device trees use the GIC therefore
> can't detect an SPI0 interrupt.
>
> This patch adds a two-output IRQ splitter to deliver SPI0's interrupt
> to both the legacy controller and GIC SPI 118. This follows commit
> fb3e0557a4cb ("hw/arm/bcm2838: Route I2C interrupts to GIC").
>
> Testing
>
> Add these options to the QEMU invocation:
>
>   -device m25p80,bus=spi,drive=flash0 \
>   -blockdev node-name=flash0,driver=file,filename=flash.bin
>
> Before the change, probing fails and /proc/mtd contains no devices:
>
>   spi-nor spi0.0: SPI transfer timed out
>   spi_master spi0: failed to transfer one message from queue
>   spi-nor: probe of spi0.0 failed with error -2
>
> After the change, the flash is detected:
>
>   spi-nor spi0.0: m25p80 (1024 Kbytes)
>   # cat /proc/mtd
>   dev:    size   erasesize  name
>   mtd0: 00100000 00010000 "spi0.0"
>
> Resolves: https://gitlab.com/qemu-project/qemu/-/issues/3013
> Signed-off-by: Hanyu <hywei737@utexas.edu>

Thanks for fixing this; the patch looks good to me.



Applied to target-arm.next, thanks.

-- PMM