Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch cleanup aarch64 mpstart and fdt bootstrap
details: https://anonhg.NetBSD.org/src/rev/da0dc1a22d60
branches: trunk
changeset: 433368:da0dc1a22d60
user: ryo <ryo%NetBSD.org@localhost>
date: Mon Sep 10 11:05:12 2018 +0000
description:
cleanup aarch64 mpstart and fdt bootstrap
* arm_cpu_hatch_arg is a bad idea. avoid serializing CPU startup, and eliminate arm_cpu_hatch_arg.
in mpstart, resolve own cpu index using array of cpu_mpidr[] (aarch64)
* add support fdt enable-method "spin-table"
* add support fdt enable-method "brcm,bcm2836-smp" (for 32bit RaspberryPi)
* use arm_fdt_cpu_bootstrap() instead of psci_fdt_bootstrap()
* rename "arm/fdt/psci_fdt.h" to "arm/fdt/psci_fdtvar.h" because of conflict of include file for needs-flag
* add devmap for cpu spin-table of raspberrypi3/aarch64
* no need to force hatch APs for raspberrypi3/arm32 ifndef MULTIPROCESSOR.
* fix to work pmap_extract(kerneltext/data/bss) even if before calling pmap_bootstrap
idea to use cpu_mpidr[] by jmcneill@. reviewd by skrll@. thanks.
diffstat:
sys/arch/aarch64/aarch64/cpu.c | 7 +-
sys/arch/aarch64/aarch64/locore.S | 26 +++-
sys/arch/aarch64/aarch64/pmap.c | 12 +-
sys/arch/aarch64/include/cpu.h | 4 +-
sys/arch/arm/broadcom/bcm2835reg.h | 5 +-
sys/arch/arm/broadcom/bcm283x_platform.c | 130 +++++++++----------------
sys/arch/arm/broadcom/bcm283x_platform.h | 5 +-
sys/arch/arm/fdt/arm_fdtvar.h | 3 +-
sys/arch/arm/fdt/cpu_fdt.c | 154 ++++++++++++++++++++++++++++++-
sys/arch/arm/fdt/files.fdt | 4 +-
sys/arch/arm/fdt/psci_fdt.c | 111 +---------------------
sys/arch/arm/fdt/psci_fdt.h | 38 -------
sys/arch/arm/fdt/psci_fdtvar.h | 37 +++++++
sys/arch/arm/nvidia/tegra_platform.c | 8 +-
sys/arch/arm/rockchip/rk_platform.c | 8 +-
sys/arch/arm/sunxi/sunxi_platform.c | 8 +-
sys/arch/arm/virt/virt_platform.c | 8 +-
17 files changed, 302 insertions(+), 266 deletions(-)
diffs (truncated from 947 to 300 lines):
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/aarch64/aarch64/cpu.c
--- a/sys/arch/aarch64/aarch64/cpu.c Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/aarch64/aarch64/cpu.c Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.6 2018/08/26 18:15:49 ryo Exp $ */
+/* $NetBSD: cpu.c,v 1.7 2018/09/10 11:05:12 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.6 2018/08/26 18:15:49 ryo Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.7 2018/09/10 11:05:12 ryo Exp $");
#include "locators.h"
#include "opt_arm_debug.h"
@@ -63,8 +63,9 @@
static void cpu_identify2(device_t self, struct cpu_info *);
#ifdef MULTIPROCESSOR
+uint64_t cpu_mpidr[MAXCPUS];
+
volatile u_int arm_cpu_hatched __cacheline_aligned = 0;
-volatile u_int arm_cpu_hatch_arg __cacheline_aligned;
volatile uint32_t arm_cpu_mbox __cacheline_aligned = 0;
u_int arm_cpu_max = 1;
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.24 2018/09/10 07:30:33 skrll Exp $ */
+/* $NetBSD: locore.S,v 1.25 2018/09/10 11:05:12 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -35,7 +35,7 @@
#include <aarch64/hypervisor.h>
#include "assym.h"
-RCSID("$NetBSD: locore.S,v 1.24 2018/09/10 07:30:33 skrll Exp $")
+RCSID("$NetBSD: locore.S,v 1.25 2018/09/10 11:05:12 ryo Exp $")
/* #define DEBUG_LOCORE */
/* #define DEBUG_MMU */
@@ -299,14 +299,26 @@
ENTRY_NP(aarch64_mpstart)
ENTRY_NP(cortex_mpstart) /* compat arm */
- ADDR x0, arm_cpu_hatch_arg /* from cpu0 */
- ldr w27, [x0] /* x27 = cpuindex */
+ mrs x3, mpidr_el1
+ ldr x0, =(MPIDR_AFF0|MPIDR_AFF1|MPIDR_AFF2|MPIDR_AFF3)
+ and x3, x3, x0
+
+ ADDR x0, cpu_mpidr
+ mov x1, xzr
+1:
+ add x1, x1, #1
+ cmp x1, MAXCPUS /* cpuindex >= MAXCPUS ? */
+ bge toomanycpus
+ ldr x2, [x0, x1, lsl #3] /* cpu_mpidr[cpunidex] */
+ cmp x2, x3 /* == mpidr_el1 & MPIDR_AFF ? */
+ bne 1b
+
+ mov x27, x1 /* x27 = cpuindex */
+
mov x0, #1
lsl x28, x0, x27 /* x28 = 1 << cpuindex */
/* x27 = cpuindex, x28 = (1 << cpuindex) */
- cmp x27, MAXCPUS
- bge toomanycpus
/* set stack pointer for boot */
#define BOOT_STACKSIZE 256
@@ -477,7 +489,7 @@
toomanycpus:
PRINTCPU()
- PRINT("too many cpus\r\n")
+ PRINT("too many cpus, or MPIDR not exists in cpu_mpidr[]\r\n")
1: wfi
b 1b
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/aarch64/aarch64/pmap.c
--- a/sys/arch/aarch64/aarch64/pmap.c Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/aarch64/aarch64/pmap.c Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.20 2018/08/27 15:43:37 ryo Exp $ */
+/* $NetBSD: pmap.c,v 1.21 2018/09/10 11:05:12 ryo Exp $ */
/*
* Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.20 2018/08/27 15:43:37 ryo Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.21 2018/09/10 11:05:12 ryo Exp $");
#include "opt_arm_debug.h"
#include "opt_ddb.h"
@@ -46,6 +46,7 @@
#include <aarch64/pte.h>
#include <aarch64/armreg.h>
#include <aarch64/cpufunc.h>
+#include <aarch64/machdep.h>
//#define PMAP_DEBUG
//#define PMAP_PV_DEBUG
@@ -683,7 +684,12 @@
return false;
#endif
- if (AARCH64_KSEG_START <= va && va < AARCH64_KSEG_END) {
+ extern char __kernel_text[];
+ extern char _end[];
+ if ((vaddr_t)__kernel_text <= va && va < (vaddr_t)_end) {
+ pa = KERN_VTOPHYS(va);
+ found = true;
+ } else if (AARCH64_KSEG_START <= va && va < AARCH64_KSEG_END) {
pa = AARCH64_KVA_TO_PA(va);
found = true;
} else {
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/aarch64/include/cpu.h
--- a/sys/arch/aarch64/include/cpu.h Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/aarch64/include/cpu.h Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.7 2018/08/26 18:15:49 ryo Exp $ */
+/* $NetBSD: cpu.h,v 1.8 2018/09/10 11:05:12 ryo Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -111,7 +111,7 @@
extern struct cpu_info *cpu_info[];
extern volatile u_int arm_cpu_hatched; /* MULTIPROCESSOR */
-extern volatile u_int arm_cpu_hatch_arg;/* MULTIPROCESSOR */
+extern uint64_t cpu_mpidr[]; /* MULTIPROCESSOR */
#define CPU_INFO_ITERATOR cpuid_t
#ifdef MULTIPROCESSOR
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/arm/broadcom/bcm2835reg.h
--- a/sys/arch/arm/broadcom/bcm2835reg.h Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/arm/broadcom/bcm2835reg.h Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835reg.h,v 1.22 2018/04/01 04:35:03 ryo Exp $ */
+/* $NetBSD: bcm2835reg.h,v 1.23 2018/09/10 11:05:12 ryo Exp $ */
/*-
* Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -245,4 +245,7 @@
#define BCM2836_LOCAL_MAILBOX2_CLRN(n) (0xc8 + 0x10 * (n))
#define BCM2836_LOCAL_MAILBOX3_CLRN(n) (0xcc + 0x10 * (n))
+#define BCM2836_ARM_SMP_BASE 0x00000000
+#define BCM2836_ARM_SMP_SIZE 0x00001000 /* 4KBytes */
+
#endif /* _BCM2835REG_H_ */
diff -r 55871c254872 -r da0dc1a22d60 sys/arch/arm/broadcom/bcm283x_platform.c
--- a/sys/arch/arm/broadcom/bcm283x_platform.c Mon Sep 10 10:55:02 2018 +0000
+++ b/sys/arch/arm/broadcom/bcm283x_platform.c Mon Sep 10 11:05:12 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm283x_platform.c,v 1.17 2018/09/03 16:29:23 riastradh Exp $ */
+/* $NetBSD: bcm283x_platform.c,v 1.18 2018/09/10 11:05:12 ryo Exp $ */
/*-
* Copyright (c) 2017 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.17 2018/09/03 16:29:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm283x_platform.c,v 1.18 2018/09/10 11:05:12 ryo Exp $");
#include "opt_arm_debug.h"
#include "opt_bcm283x.h"
@@ -253,7 +253,11 @@
DEVMAP_ENTRY(BCM2836_ARM_LOCAL_VBASE, BCM2836_ARM_LOCAL_BASE,
BCM2836_ARM_LOCAL_SIZE),
-
+#if defined(MULTIPROCESSOR) && defined(__aarch64__)
+ /* for fdt cpu spin-table */
+ DEVMAP_ENTRY(BCM2836_ARM_SMP_VBASE, BCM2836_ARM_SMP_BASE,
+ BCM2836_ARM_SMP_SIZE),
+#endif
DEVMAP_ENTRY_END
};
@@ -720,7 +724,8 @@
static void
bcm2836_bootstrap(void)
{
-#define RPI_CPU_MAX 4
+#ifdef MULTIPROCESSOR
+#ifdef __arm__
#ifdef VERBOSE_INIT_ARM
#define DPRINTF(...) printf(__VA_ARGS__)
@@ -728,97 +733,56 @@
#define DPRINTF(...)
#endif
-#ifdef MULTIPROCESSOR
- arm_cpu_max = RPI_CPU_MAX;
- DPRINTF("%s: %d cpus present\n", __func__, arm_cpu_max);
-#ifdef __arm__
- extern int cortex_mmuinfo;
- cortex_mmuinfo = armreg_ttbr_read();
- DPRINTF("%s: cortex_mmuinfo %x\n", __func__, cortex_mmuinfo);
-#endif
-#endif /* MULTIPROCESSOR */
+#define RPI_CPU_MAX 4
+
+ const char *method;
+
+ const int cpus = OF_finddevice("/cpus");
+ if (cpus == -1) {
+ aprint_error("%s: no /cpus node found\n", __func__);
+ arm_cpu_max = 1;
+ return;
+ }
- /*
- * XXX: TODO:
- * should make cpu_fdt_bootstrap() that support spin-table and use it
- * to share with arm/aarch64.
- */
-#ifdef __aarch64__
- extern void aarch64_mpstart(void);
- for (int i = 1; i < RPI_CPU_MAX; i++) {
- /* argument for mpstart() */
- arm_cpu_hatch_arg = i;
- cpu_dcache_wb_range((vaddr_t)&arm_cpu_hatch_arg,
- sizeof(arm_cpu_hatch_arg));
+ /* implementation dependent string "brcm,bcm2836-smp" for ARM 32-bit */
+ method = fdtbus_get_string(cpus, "enable-method");
+ if ((method != NULL) && (strcmp(method, "brcm,bcm2836-smp") == 0)) {
+ arm_cpu_max = RPI_CPU_MAX;
+ DPRINTF("%s: %d cpus present\n", __func__, arm_cpu_max);
+
+ extern void cortex_mpstart(void);
- /*
- * Reference:
- * armstubs/armstub8.S
- * in https://github.com/raspberrypi/tools
- */
- volatile uint64_t *cpu_release_addr;
-#define RPI3_ARMSTUB8_SPINADDR_BASE 0x000000d8
- cpu_release_addr = (void *)
- AARCH64_PA_TO_KVA(RPI3_ARMSTUB8_SPINADDR_BASE + i * 8);
- *cpu_release_addr =
- aarch64_kern_vtophys((vaddr_t)aarch64_mpstart);
+ for (size_t i = 1; i < RPI_CPU_MAX; i++) {
+ bus_space_tag_t iot = &bcm2836_bs_tag;
+ bus_space_handle_t ioh = BCM2836_ARM_LOCAL_VBASE;
- /* need flush cache. secondary processors are cache disabled */
- cpu_dcache_wb_range((vaddr_t)cpu_release_addr,
- sizeof(cpu_release_addr));
+ bus_space_write_4(iot, ioh,
+ BCM2836_LOCAL_MAILBOX3_SETN(i),
+ (uint32_t)cortex_mpstart);
+ }
+
/* Wake up AP in case firmware has placed it in WFE state */
__asm __volatile("sev" ::: "memory");
- /* Wait for APs to start */
for (int loop = 0; loop < 16; loop++) {
- membar_consumer();
- if (arm_cpu_hatched & __BIT(i))
+ if (arm_cpu_hatched == __BITS(arm_cpu_max - 1, 1))
break;
gtmr_delay(10000);
}
- }
-#endif /* __aarch64__ */
-
-#ifdef __arm__
- /*
- * Even if no options MULTIPROCESSOR,
- * It is need to initialize the secondary CPU,
- * and go into wfi loop (cortex_mpstart),
- * otherwise system would be freeze...
- * (because netbsd will use the spinning address)
- */
- extern void cortex_mpstart(void);
-
- for (size_t i = 1; i < RPI_CPU_MAX; i++) {
- bus_space_tag_t iot = &bcm2836_bs_tag;
- bus_space_handle_t ioh = BCM2836_ARM_LOCAL_VBASE;
- bus_space_write_4(iot, ioh,
- BCM2836_LOCAL_MAILBOX3_SETN(i),
Home |
Main Index |
Thread Index |
Old Index