hw/arm/bcm2838: Route SPI0 interrupt to GIC
Subsystems (2)
PATCH 1/1 hw/arm/bcm2838: Route SPI0 interrupt to GIC
From: Hanyu <[email protected]>
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
--- 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(-)
hw/arm/bcm2835_peripherals.c +11 -3
@@ -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++) {
hw/arm/bcm2838.c +4 -0
@@ -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 ));
include/hw/arm/bcm2835_peripherals.h +1 -0
@@ -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;
include/hw/arm/bcm2838_peripherals.h +1 -0
@@ -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
Signature · 1 line
2.43.0
Peter Maydell
AppliedQuoted 26 lines · Hanyu
From: Hanyu <[email protected]>
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.binBefore the change, probing fails and
/proc/mtdcontains no devices:spi-nor spi0.0: SPI transfer timed out
spi_masterspi0: failed to transfer one message from queue
spi-nor: probe of spi0.0 failed with error -2After the change, the flash is detected:
Quoted 7 lines
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 <[email protected]>
Thanks for fixing this; the patch looks good to me.
Applied to target-arm.next, thanks.
-- PMM