Skip to contentSkip to conversation

ARM: bcm: Send the BCMBCA CFE wakeup SGI directly

PATCH New Linus Walleij 1 participant 1 message Dec 2

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ARM: bcm: Send the BCMBCA CFE wakeup SGI directly

The GICv2 driver learns a CPU's target bit when that CPU starts. Before then, its provisional target mask can address multiple CPU interfaces. CFE wakes the secondary when an interrupt arrives, so use an explicit target for this first SGI.

Map the Cortex-A7 GIC distributor using the CPU node's interrupt parent in DeviceTree. Use the core ID from MPIDR affinity level 0 as the target bit in the integrated Cortex-A7 GIC. Keep the barrier that completes the CFE mailbox write before sending SGI 0 to that target.

---
An LLM assisted in authoring the patch.
---
Changes in v2:
- Remove the CPU1-only wakeup restriction.
- Collect Jie's Tested-by.
- Derive the SGI target from MPIDR affinity level 0. Should mean not difference since BCMBCA doesn't use the cluster bits, but better
safe than sorry.
- Link to v1: https://patch.msgid.link/[email protected]

---
 arch/arm/mach-bcm/board_bcmbca.c | 46 ++++++++++++++++++++++++++++++++++------
 1 file changed, 39 insertions(+), 7 deletions(-)
arch/arm/mach-bcm/board_bcmbca.c +39 -7
index 248b8bd77645..e85dd48f3cca 100644
@@ -1,10 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-only
 // Copyright (C) 2024 Linus Walleij <[email protected]>
 
+#include <linux/bits.h>
 #include <linux/io.h>
+#include <linux/irqchip/arm-gic.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/of_irq.h>
 #include <linux/smp.h>
 
+#include <asm/cputype.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 #include <asm/smp_plat.h>
@@ -29,15 +34,19 @@ static void __init bcmbca_map_io(void)
 }
 
 #ifdef CONFIG_SMP
+#define BCMBCA_GIC_CPU_IFS	8
+#define BCMBCA_SGIR_TARGET_SHIFT	16
+#define BCMBCA_WAKEUP_SGI	0
+
 static int bcmbca_boot_secondary(unsigned int cpu, struct task_struct *idle)
 {
-	struct device_node *np;
-	void __iomem *mailbox;
+	unsigned int gic_cpu = MPIDR_AFFINITY_LEVEL(cpu_logical_map(cpu), 0);
+	struct device_node *np, *gic_node;
+	void __iomem *mailbox, *gic_dist;
 	u32 release_addr;
 	int ret;
 
-	/* CFE has already powered up CPU1 and left it waiting in WFI. */
-	if (cpu_logical_map(cpu) != 1)
+	if (gic_cpu >= BCMBCA_GIC_CPU_IFS)
 		return -EINVAL;
 
 	np = of_get_cpu_node(cpu, NULL);
@@ -45,15 +54,30 @@ static int bcmbca_boot_secondary(unsigned int cpu, struct task_struct *idle)
 		return -ENODEV;
 
 	ret = of_property_read_u32(np, "cpu-release-addr", &release_addr);
-	of_node_put(np);
 	if (ret) {
+		of_node_put(np);
 		pr_err("CPU%u: missing or invalid cpu-release-addr property\n", cpu);
 		return ret;
 	}
 
+	gic_node = of_irq_find_parent(np);
+	of_node_put(np);
+	if (!of_device_is_compatible(gic_node, "arm,cortex-a7-gic") ||
+	    !of_device_is_available(gic_node)) {
+		of_node_put(gic_node);
+		return -ENODEV;
+	}
+
+	gic_dist = of_iomap(gic_node, 0);
+	of_node_put(gic_node);
+	if (!gic_dist)
+		return -ENOMEM;
+
 	mailbox = ioremap(release_addr, sizeof(u32));
-	if (!mailbox)
+	if (!mailbox) {
+		iounmap(gic_dist);
 		return -ENOMEM;
+	}
 
 	/*
 	 * The CFE stub reads GPIO GeneralPurpose after an interrupt and
@@ -62,8 +86,16 @@ static int bcmbca_boot_secondary(unsigned int cpu, struct task_struct *idle)
 	 */
 	writel(__pa_symbol(secondary_startup_arm) & ~1, mailbox);
 	dsb(sy);
-	arch_send_wakeup_ipi_mask(cpumask_of(cpu));
+
+	/*
+	 * The integrated Cortex-A7 GIC uses the hardware core ID as its
+	 * target bit. Linux has yet to discover the secondary's GIC target.
+	 * Use SGI 0, the same interrupt as the ARM GICv2 wakeup IPI.
+	 */
+	writel_relaxed(BIT(BCMBCA_SGIR_TARGET_SHIFT + gic_cpu) | BCMBCA_WAKEUP_SGI,
+		       gic_dist + GIC_DIST_SOFTINT);
 	iounmap(mailbox);
+	iounmap(gic_dist);
 
 	return 0;
 }

---
base-commit: 21f8531821461fa0c05e4605c01d8d56d28b514e
change-id: 20261202-bcmbca-smp-gicv2-535b6d4c72cf

Best regards,

Signature · 1 line
Linus Walleij <[email protected]>