Module Name:    src
Committed By:   rin
Date:           Wed Sep  1 03:08:08 UTC 2021

Modified Files:
        src/sys/arch/arm/broadcom: bcm2835_intr.c

Log Message:
PR port-arm/56264

Register all PICs when bcmicu1 is attached, in order to avoid calling
pic_add() from cpu_hatch(), which blocks for aarch64 kernel on RPI3.
This prevented MP kernel to boot due to KASSERT failure as described
in the PR.

This is a kind of a workaround; the real fix should be to

(a) reorganize cpu_hatch() for aarch64 and arm:
http://mail-index.netbsd.org/port-arm/2021/06/21/msg007320.html

(b) or change MI abstraction of ``MP ready'':
http://mail-index.netbsd.org/port-arm/2021/06/22/msg007327.html

However, still, this fix does not bring about any penalty, and it is
not good to leave RPI3 broken for months...

Tested on RPI3 (aarch64 MP, armv7hf MP) as well as RPI1 (armv6hf UP).


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/arch/arm/broadcom/bcm2835_intr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/broadcom/bcm2835_intr.c
diff -u src/sys/arch/arm/broadcom/bcm2835_intr.c:1.38 src/sys/arch/arm/broadcom/bcm2835_intr.c:1.39
--- src/sys/arch/arm/broadcom/bcm2835_intr.c:1.38	Mon Mar  8 14:22:42 2021
+++ src/sys/arch/arm/broadcom/bcm2835_intr.c	Wed Sep  1 03:08:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_intr.c,v 1.38 2021/03/08 14:22:42 mlelstv Exp $	*/
+/*	$NetBSD: bcm2835_intr.c,v 1.39 2021/09/01 03:08:08 rin Exp $	*/
 
 /*-
  * Copyright (c) 2012, 2015, 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_intr.c,v 1.38 2021/03/08 14:22:42 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_intr.c,v 1.39 2021/09/01 03:08:08 rin Exp $");
 
 #define _INTR_PRIVATE
 
@@ -359,6 +359,34 @@ bcm2835_icu_attach(device_t parent, devi
 
 		ifuncs = &bcm2836mpicu_fdt_funcs;
 
+		/*
+		 * XXX
+		 * Register all PICs here in order to avoid pic_add() from
+		 * cpu_hatch(). See port-arm/56264.
+		 */
+		CPU_INFO_ITERATOR cii;
+		struct cpu_info *ci;
+		for (CPU_INFO_FOREACH(cii, ci)) {
+			const cpuid_t cpuid = ci->ci_core_id;
+			struct pic_softc * const pic = &bcm2836mp_pic[cpuid];
+
+			KASSERT(cpuid < BCM2836_NCPUS);
+
+#if defined(MULTIPROCESSOR)
+			pic->pic_cpus = ci->ci_kcpuset;
+			/*
+			 * Append "#n" to avoid duplication of .pic_name[]
+			 * It should be a unique id for intr_get_source()
+			 */
+			char suffix[sizeof("#00000")];
+			snprintf(suffix, sizeof(suffix), "#%lu", cpuid);
+			strlcat(pic->pic_name, suffix, sizeof(pic->pic_name));
+#endif
+
+			bcm2836mp_int_base[cpuid] =
+			    pic_add(pic, PIC_IRQBASE_ALLOC);
+		}
+
 		bcm2836mp_intr_init(self, curcpu());
 		arm_fdt_cpu_hatch_register(self, bcm2836mp_intr_init);
 	} else {
@@ -865,24 +893,10 @@ static void
 bcm2836mp_intr_init(void *priv, struct cpu_info *ci)
 {
 	const cpuid_t cpuid = ci->ci_core_id;
-	struct pic_softc * const pic = &bcm2836mp_pic[cpuid];
 
 	KASSERT(cpuid < BCM2836_NCPUS);
 
 #if defined(MULTIPROCESSOR)
-	pic->pic_cpus = ci->ci_kcpuset;
-
-	/*
-	 * Append "#n" to avoid duplication of .pic_name[]
-	 * It should be a unique id for intr_get_source()
-	 */
-	char suffix[sizeof("#00000")];
-	snprintf(suffix, sizeof(suffix), "#%lu", cpuid);
-	strlcat(pic->pic_name, suffix, sizeof(pic->pic_name));
-#endif
-	bcm2836mp_int_base[cpuid] = pic_add(pic, PIC_IRQBASE_ALLOC);
-
-#if defined(MULTIPROCESSOR)
 	intr_establish(BCM2836_INT_MAILBOX0_CPUN(cpuid), IPL_HIGH,
 	    IST_LEVEL | IST_MPSAFE, bcm2836mp_ipi_handler, NULL);
 

Reply via email to