Commit a7de87e9f4 for qemu.org

commit a7de87e9f46584147019fe94595b1c22c7e53cfe
Author: Jayesh Agarwal <agarwaljayesh03@gmail.com>
Date:   Tue Nov 24 10:23:09 2026 +0000

    hw/arm/bcm2838: Route system timer interrupts to GIC

    The system timer interrupts are only routed to the legacy interrupt
    controller and not to the GIC, so a guest using the GIC (software that
    relies on the system timer interrupts through the GIC, such as bare
    metal programs or hobby kernels) never receives them.

    A qemu_irq connection follows one output, one input. So also wiring the
    timer to the GIC would replace its connection to the legacy controller.

    Add a splitter per system-timer interrupt line so that each interrupt
    reaches both the legacy controller (output 0 of the splitters) and the
    GIC (output 1 of the splitters). The timer channel n goes to GIC SPI
    64+n, so channels 0-3 go to SPIs 64-67.

    Testing:
    The raspi4b machine started in the qtest mode:
            qemu-system-aarch64 -M raspi4b -display none -accel qtest -qtest stdio

    Ran following commands:
            irq_intercept_in /machine/soc/peripherals
            readl 0xfe003004
            writel 0xfe00300c 1000
            writel 0xfe003010 2000
            writel 0xfe003014 3000
            writel 0xfe003018 4000
            clock_step 5000000
            readl 0xfe003000

    Before the fix:
        clock_step 5000000
        OK 5000000
        readl 0xfe003000
        OK 0x000000000000000f
    The alarm fires correctly (status flag outputs 0xf), but no IRQ raise
    64-67 reaches the GIC.

    After the fix:
        clock_step 5000000
        IRQ raise 64
        IRQ raise 65
        IRQ raise 66
        IRQ raise 67
        OK 5000000
        readl 0xfe003000
        OK 0x000000000000000f
    The alarm fires, and all the four channels reached GIC lines 64-67.

    Reported-by: Sourojeet Adhikari <s23adhik@csclub.uwaterloo.ca>
    Signed-off-by: Jayesh Agarwal <agarwaljayesh03@gmail.com>
    Message-id: 20261117193205.8236-1-agarwaljayesh03@gmail.com
    Suggested-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Jayesh Agarwal <agarwaljayesh03@gmail.com>
    Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>

diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c
index be40c6b92a..5ab2bac4b1 100644
--- a/hw/arm/bcm2835_peripherals.c
+++ b/hw/arm/bcm2835_peripherals.c
@@ -95,6 +95,14 @@ static void raspi_peripherals_base_init(Object *obj)
     /* SYS Timer */
     object_initialize_child(obj, "systimer", &s->systmr,
                             TYPE_BCM2835_SYSTIMER);
+    /*
+     * One splitter per system-timer interrupt line so that each interrupt
+     * reaches both the legacy controller and the GIC.
+     */
+    for (int n = 0; n < BCM2835_SYSTIMER_COUNT; n++) {
+        object_initialize_child(obj, "systmr-irq-splitter[*]",
+                                &s->systmr_irq_splitter[n], TYPE_SPLIT_IRQ);
+    }

     /* UART0 */
     object_initialize_child(obj, "uart0", &s->uart0, TYPE_PL011);
@@ -304,18 +312,19 @@ void bcm_soc_peripherals_common_realize(DeviceState *dev, Error **errp)
     }
     memory_region_add_subregion(&s->peri_mr, ST_OFFSET,
                 sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systmr), 0));
-    sysbus_connect_irq(SYS_BUS_DEVICE(&s->systmr), 0,
-        qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
-                               INTERRUPT_TIMER0));
-    sysbus_connect_irq(SYS_BUS_DEVICE(&s->systmr), 1,
-        qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
-                               INTERRUPT_TIMER1));
-    sysbus_connect_irq(SYS_BUS_DEVICE(&s->systmr), 2,
-        qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
-                               INTERRUPT_TIMER2));
-    sysbus_connect_irq(SYS_BUS_DEVICE(&s->systmr), 3,
-        qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ,
-                               INTERRUPT_TIMER3));
+    for (n = 0; n < BCM2835_SYSTIMER_COUNT; n++) {
+        qdev_prop_set_uint32(DEVICE(&s->systmr_irq_splitter[n]),
+                "num-lines", 2);
+        if (!qdev_realize(DEVICE(&s->systmr_irq_splitter[n]), NULL, errp)) {
+            return;
+        }
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->systmr), n,
+                qdev_get_gpio_in(DEVICE(&s->systmr_irq_splitter[n]), 0));
+        qdev_connect_gpio_out(DEVICE(&s->systmr_irq_splitter[n]), 0,
+                qdev_get_gpio_in_named(DEVICE(&s->ic),
+                    BCM2835_IC_GPU_IRQ,
+                    INTERRUPT_TIMER0 + n));
+    }

     /* UART0 */
     qdev_prop_set_chr(DEVICE(&s->uart0), "chardev", serial_hd(0));
diff --git a/hw/arm/bcm2838.c b/hw/arm/bcm2838.c
index 1bde9e68af..a88d750f76 100644
--- a/hw/arm/bcm2838.c
+++ b/hw/arm/bcm2838.c
@@ -192,6 +192,13 @@ static void bcm2838_realize(DeviceState *dev, Error **errp)
     qdev_connect_gpio_out(DEVICE(&ps_base->spi_irq_splitter), 1,
                           qdev_get_gpio_in(gicdev, GIC_SPI_INTERRUPT_SPI));

+    /* Connect the system timer interrupts to the interrupt controller */
+    for (int n = 0; n < BCM2835_SYSTIMER_COUNT; n++) {
+        int int_n = GIC_SPI_INTERRUPT_SYS_TIMER0 + n;
+        qdev_connect_gpio_out(DEVICE(&ps_base->systmr_irq_splitter[n]), 1,
+                              qdev_get_gpio_in(gicdev, int_n));
+    }
+
     /* 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 cd66a734e7..b262bdccb7 100644
--- a/include/hw/arm/bcm2835_peripherals.h
+++ b/include/hw/arm/bcm2835_peripherals.h
@@ -54,6 +54,7 @@ struct BCMSocPeripheralBaseState {
     qemu_irq irq, fiq;

     BCM2835SystemTimerState systmr;
+    SplitIRQ systmr_irq_splitter[BCM2835_SYSTIMER_COUNT];
     BCM2835MphiState mphi;
     UnimplementedDeviceState txp;
     UnimplementedDeviceState armtmr;
diff --git a/include/hw/arm/bcm2838_peripherals.h b/include/hw/arm/bcm2838_peripherals.h
index f9279daa4d..bb18842201 100644
--- a/include/hw/arm/bcm2838_peripherals.h
+++ b/include/hw/arm/bcm2838_peripherals.h
@@ -20,6 +20,10 @@
 /* SPI */
 #define GIC_SPI_INTERRUPT_MBOX         33
 #define GIC_SPI_INTERRUPT_MPHI         40
+#define GIC_SPI_INTERRUPT_SYS_TIMER0   64
+#define GIC_SPI_INTERRUPT_SYS_TIMER1   65
+#define GIC_SPI_INTERRUPT_SYS_TIMER2   66
+#define GIC_SPI_INTERRUPT_SYS_TIMER3   67
 #define GIC_SPI_INTERRUPT_DWC2         73
 #define GIC_SPI_INTERRUPT_DMA_0        80
 #define GIC_SPI_INTERRUPT_DMA_6        86