From 9d4c75c765f79f5cd9a7b0ba06c0390b2ddc1fcb Mon Sep 17 00:00:00 2001
From: Jonathan Bell <jonathan@raspberrypi.com>
Date: Thu, 12 Sep 2024 10:45:02 +0100
Subject: [PATCH] drivers: irq-bcm2836: preserve unrelated bits in
 LOCAL_GPU_ROUTING

Interrupts are dispatched round-robin but doing so trampled FIQ routing.
Taking a FIQ on a core without a handler installed is fatal.

Only modify bits 1:0 which are the IRQ route bits.

Signed-off-by: Jonathan Bell <jonathan@raspberrypi.com>
---
 drivers/irqchip/irq-bcm2836.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

--- a/drivers/irqchip/irq-bcm2836.c
+++ b/drivers/irqchip/irq-bcm2836.c
@@ -96,12 +96,17 @@ void bcm2836_arm_irqchip_spin_gpu_irq(vo
 	u32 i;
 	void __iomem *gpurouting = (intc.base + LOCAL_GPU_ROUTING);
 	u32 routing_val = readl(gpurouting);
+	u32 irq_route;
+
+	/* Preserve FIQ routing bits */
+	irq_route = routing_val & 0x3;
+	routing_val &= ~0x3;
 
 	for (i = 1; i <= 3; i++) {
-		u32 new_routing_val = (routing_val + i) & 3;
+		irq_route = (irq_route + i) & 0x3;
 
-		if (cpu_active(new_routing_val)) {
-			writel(new_routing_val, gpurouting);
+		if (cpu_active(irq_route)) {
+			writel(irq_route | routing_val, gpurouting);
 			return;
 		}
 	}
