On Mon, 2 Nov 2026 at 10:21, Lorand Marton <[email protected]> wrote:
>
> bcm2835_spi_reset() cleared CS, so neither DONE nor RXR is set
> afterwards, but left the interrupt line as it was: a reset in the
> middle of an interrupt-driven transfer (a guest reboot while
> spi-bcm2835 waits for DONE) kept the line raised into the next boot.
> Update the interrupt from the new register values.
>
> Test that a reset during a transfer with INTD set drops the line.
>
> Fixes: 28004fb74134 ("hw/ssi: Implement BCM2835 SPI Controller")
> Signed-off-by: Lorand Marton <[email protected]>
> ---
>  hw/ssi/bcm2835_spi.c           |  2 ++
>  tests/qtest/bcm2835-spi-test.c | 42 ++++++++++++++++++++++++++++++++++
>  tests/qtest/meson.build        |  3 ++-
>  3 files changed, 46 insertions(+), 1 deletion(-)
>  create mode 100644 tests/qtest/bcm2835-spi-test.c
>
> diff --git a/hw/ssi/bcm2835_spi.c b/hw/ssi/bcm2835_spi.c
> index 01763c458c..4ab47787a4 100644
> --- a/hw/ssi/bcm2835_spi.c
> +++ b/hw/ssi/bcm2835_spi.c
> @@ -246,6 +246,8 @@ static void bcm2835_spi_reset(DeviceState *dev)
>      s->dlen = 0;
>      s->ltoh = 0x1;
>      s->dc = 0x30201020;
> +
> +    bcm2835_spi_update_int(s);
>  }

No, device reset methods should not call qemu_set_irq on their
outbound IRQ lines. The qemu_irq itself has no state, so on
reset the expectation is that this device resets its internal
state, and the device it's connecting to will also reset its
internal state (which will be to the "signal is not asserted"
state)". Calling qemu_set_irq() from reset runs into problems
with ordering of reset between different devices.

> +/* A reset in the middle of a transfer drops the interrupt */
> +static void test_reset_irq(void)
> +{
> +    QTestState *qts = qtest_init("-M raspi3b");
> +
> +    qtest_irq_intercept_out_named(qts, 
> "/machine/soc/peripherals/bcm2835-spi0",
> +                                  "sysbus-irq");
> +    qtest_writel(qts, SPI0_BASE + SPI_CS, CS_CLEAR_RXTX | CS_TA);
> +    qtest_writel(qts, SPI0_BASE + SPI_FIFO, 0xa5);
> +    qtest_writel(qts, SPI0_BASE + SPI_CS, CS_TA | CS_INTD);
> +    g_assert_true(qtest_get_irq(qts, 0));
> +
> +    qtest_system_reset(qts);
> +    g_assert_false(qtest_get_irq(qts, 0));

This test is really running into the fact that qtest's
irq state for intercepted IRQs is not cleaned up on
reset; so you get a bogus answer if you call qtest_get_irq()
after qtest_system_reset().

-- PMM

Reply via email to