Module Name:    src
Committed By:   jmcneill
Date:           Fri Jun  2 20:16:06 UTC 2017

Modified Files:
        src/sys/arch/arm/vexpress: vexpress_platform.c
        src/sys/arch/evbarm/conf: VEXPRESS_A15
        src/sys/arch/evbarm/vexpress: vexpress_start.S
Added Files:
        src/sys/arch/arm/vexpress: vexpress_platform.h

Log Message:
Add SMP support to VEXPRESS_A15 kernel. Enable with '-smp 2' on qemu
command line.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/vexpress/vexpress_platform.c
cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/vexpress/vexpress_platform.h
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/evbarm/conf/VEXPRESS_A15
cvs rdiff -u -r1.3 -r1.4 src/sys/arch/evbarm/vexpress/vexpress_start.S

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/vexpress/vexpress_platform.c
diff -u src/sys/arch/arm/vexpress/vexpress_platform.c:1.1 src/sys/arch/arm/vexpress/vexpress_platform.c:1.2
--- src/sys/arch/arm/vexpress/vexpress_platform.c:1.1	Fri Jun  2 15:22:47 2017
+++ src/sys/arch/arm/vexpress/vexpress_platform.c	Fri Jun  2 20:16:05 2017
@@ -1,4 +1,4 @@
-/* $NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $ */
+/* $NetBSD: vexpress_platform.c,v 1.2 2017/06/02 20:16:05 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
@@ -30,7 +30,7 @@
 #include "opt_fdt_arm.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vexpress_platform.c,v 1.1 2017/06/02 15:22:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vexpress_platform.c,v 1.2 2017/06/02 20:16:05 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -49,13 +49,13 @@ __KERNEL_RCSID(0, "$NetBSD: vexpress_pla
 
 #include <arm/cortex/gtmr_var.h>
 
+#include <arm/cortex/gic_reg.h>
+
 #include <evbarm/dev/plcomvar.h>
 
-#define	VEXPRESS_REF_FREQ	24000000
+#include <arm/vexpress/vexpress_platform.h>
 
-#define	VEXPRESS_CORE_VBASE	0xf0000000
-#define	VEXPRESS_CORE_PBASE	0x10000000
-#define	VEXPRESS_CORE_SIZE	0x10000000
+#define	VEXPRESS_REF_FREQ	24000000
 
 #define	DEVMAP_ALIGN(a)	((a) & ~L1_S_OFFSET)
 #define	DEVMAP_SIZE(s)	roundup2((s), L1_S_SIZE)
@@ -100,6 +100,46 @@ static bus_space_handle_t sysreg_bsh;
 	bus_space_write_4(sysreg_bst, sysreg_bsh, (o), (v))
 
 
+static void
+vexpress_a15_smp_init(void)
+{
+	extern void cortex_mpstart(void);
+	bus_space_tag_t gicd_bst = &armv7_generic_bs_tag;
+	bus_space_handle_t gicd_bsh;
+	int started = 0;
+
+	/* Bitmask of CPUs (non-BSP) to start */
+	for (int i = 1; i < arm_cpu_max; i++)
+		started |= __BIT(i);
+
+	/* Write init vec to SYS_FLAGS register */
+	SYSREG_WRITE(SYS_FLAGSCLR, 0xffffffff);
+	SYSREG_WRITE(SYS_FLAGS, (uint32_t)cortex_mpstart);
+
+	/* Map GIC distributor */
+	bus_space_map(gicd_bst, VEXPRESS_GIC_PBASE + GICD_BASE,
+	    0x1000, 0, &gicd_bsh);
+
+	/* Enable GIC distributor */
+	bus_space_write_4(gicd_bst, gicd_bsh,
+	    GICD_CTRL, GICD_CTRL_Enable);
+
+	/* Send sw interrupt to APs */
+	const uint32_t sgir = GICD_SGIR_TargetListFilter_NotMe;
+	bus_space_write_4(gicd_bst, gicd_bsh, GICD_SGIR, sgir);
+
+	/* Wait for APs to start */
+	for (u_int i = 0x10000000; i > 0; i--) {
+		arm_dmb();
+		if (arm_cpu_hatched == started)
+			break;
+	}
+
+	/* Disable GIC distributor */
+	bus_space_write_4(gicd_bst, gicd_bsh, GICD_CTRL, 0);
+}
+
+
 static const struct pmap_devmap *
 vexpress_platform_devmap(void)
 {
@@ -107,6 +147,9 @@ vexpress_platform_devmap(void)
 		DEVMAP_ENTRY(VEXPRESS_CORE_VBASE,
 			     VEXPRESS_CORE_PBASE,
 			     VEXPRESS_CORE_SIZE),
+		DEVMAP_ENTRY(VEXPRESS_GIC_VBASE,
+			     VEXPRESS_GIC_PBASE,
+			     VEXPRESS_GIC_SIZE),
 		DEVMAP_ENTRY_END
 	};	
 
@@ -118,6 +161,10 @@ vexpress_platform_bootstrap(void)
 {
 	bus_space_map(sysreg_bst, SYSREG_BASE, SYSREG_SIZE, 0,
 	    &sysreg_bsh);
+
+	arm_cpu_max = 1 + __SHIFTOUT(armreg_l2ctrl_read(), L2CTRL_NUMCPU);
+
+	vexpress_a15_smp_init();
 }
 
 static void

Index: src/sys/arch/evbarm/conf/VEXPRESS_A15
diff -u src/sys/arch/evbarm/conf/VEXPRESS_A15:1.8 src/sys/arch/evbarm/conf/VEXPRESS_A15:1.9
--- src/sys/arch/evbarm/conf/VEXPRESS_A15:1.8	Fri Jun  2 15:22:47 2017
+++ src/sys/arch/evbarm/conf/VEXPRESS_A15	Fri Jun  2 20:16:05 2017
@@ -1,5 +1,5 @@
 #
-#	$NetBSD: VEXPRESS_A15,v 1.8 2017/06/02 15:22:47 jmcneill Exp $
+#	$NetBSD: VEXPRESS_A15,v 1.9 2017/06/02 20:16:05 jmcneill Exp $
 #
 #	ARM Versatile Express A15
 #
@@ -8,8 +8,7 @@ include	"arch/evbarm/conf/std.vexpress"
 include	"arch/evbarm/conf/GENERIC.common"
 
 options 	CPU_CORTEXA15
-options 	SOC_TEGRA124
-#options 	MULTIPROCESSOR
+options 	MULTIPROCESSOR
 
 pseudo-device 	openfirm	# /dev/openfirm
 

Index: src/sys/arch/evbarm/vexpress/vexpress_start.S
diff -u src/sys/arch/evbarm/vexpress/vexpress_start.S:1.3 src/sys/arch/evbarm/vexpress/vexpress_start.S:1.4
--- src/sys/arch/evbarm/vexpress/vexpress_start.S:1.3	Fri Jun  2 15:22:47 2017
+++ src/sys/arch/evbarm/vexpress/vexpress_start.S	Fri Jun  2 20:16:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: vexpress_start.S,v 1.3 2017/06/02 15:22:47 jmcneill Exp $	*/
+/*	$NetBSD: vexpress_start.S,v 1.4 2017/06/02 20:16:05 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -38,14 +38,17 @@
 #include <arm/armreg.h>
 #include "assym.h"
 
-#define VEXPRESS_CORE_VBASE	0xf0000000
-#define VEXPRESS_CORE_PBASE	0x10000000
-#define VEXPRESS_CORE_SIZE	0x10000000
+#include <arm/vexpress/vexpress_platform.h>
 
-RCSID("$NetBSD: vexpress_start.S,v 1.3 2017/06/02 15:22:47 jmcneill Exp $")
+RCSID("$NetBSD: vexpress_start.S,v 1.4 2017/06/02 20:16:05 jmcneill Exp $")
 
+#ifdef VERBOSE_INIT_ARM
 #define	XPUTC(n)	mov r0, n; bl xputc
 #define	XPUTC2(n)	mov r0, n; blx r11
+#else
+#define	XPUTC(n)
+#define	XPUTC2(n)
+#endif
 
 #define	INIT_MEMSIZE	128
 #define	TEMP_L1_TABLE	(KERNEL_BASE - KERNEL_BASE_VOFFSET + INIT_MEMSIZE * L1_S_SIZE - L1_TABLE_SIZE)
@@ -141,6 +144,16 @@ xputc:
 		VEXPRESS_CORE_SIZE / L1_S_SIZE,
 		L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN)
 
+	/* Map VEXPRESS GIC */
+	MMU_INIT(VEXPRESS_GIC_VBASE, VEXPRESS_GIC_PBASE,
+		VEXPRESS_GIC_SIZE / L1_S_SIZE,
+		L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN)
+
+	/* Map VEXPRESS GIC */
+	MMU_INIT(VEXPRESS_GIC_PBASE, VEXPRESS_GIC_PBASE,
+		VEXPRESS_GIC_SIZE / L1_S_SIZE,
+		L1_S_PROTO_armv7 | L1_S_APv7_KRW | L1_S_V6_XN)
+
         /* end of table */
         MMU_INIT(0, 0, 0, 0)
 

Added files:

Index: src/sys/arch/arm/vexpress/vexpress_platform.h
diff -u /dev/null src/sys/arch/arm/vexpress/vexpress_platform.h:1.1
--- /dev/null	Fri Jun  2 20:16:06 2017
+++ src/sys/arch/arm/vexpress/vexpress_platform.h	Fri Jun  2 20:16:05 2017
@@ -0,0 +1,40 @@
+/* $NetBSD: vexpress_platform.h,v 1.1 2017/06/02 20:16:05 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2017 Jared McNeill <jmcne...@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _ARM_VEXPRESS_PLATFORM_H
+#define _ARM_VEXPRESS_PLATFORM_H
+
+#define	VEXPRESS_CORE_VBASE	0xf0000000
+#define	VEXPRESS_CORE_PBASE	0x10000000
+#define	VEXPRESS_CORE_SIZE	0x0ff00000
+
+#define	VEXPRESS_GIC_VBASE	(VEXPRESS_CORE_VBASE + VEXPRESS_CORE_SIZE)
+#define	VEXPRESS_GIC_PBASE	0x2c000000
+#define	VEXPRESS_GIC_SIZE	0x00100000
+
+#endif /* _ARM_VEXPRESS_PLATFORM_H */

Reply via email to