Index: aarch64/aarch64/locore.S
===================================================================
RCS file: /cvsroot/src/sys/arch/aarch64/aarch64/locore.S,v
retrieving revision 1.44
diff -p -u -r1.44 locore.S
--- aarch64/aarch64/locore.S	20 Oct 2019 14:03:51 -0000	1.44
+++ aarch64/aarch64/locore.S	16 Nov 2019 17:22:12 -0000
@@ -180,6 +180,13 @@ vstart:
 	msr	tpidr_el1, x0		/* curcpu is cpu_info[0] */
 	DPRINTREG("curcpu           = ", x0);
 
+	/* get cache configuration */
+	mrs	x0, tpidr_el1		/* curcpu */
+	mrs     x1, mpidr_el1
+	bl	aarch64_gettopology
+	mov	x0, xzr
+	bl	aarch64_getcacheinfo
+
 #ifdef KASAN
 	ADDR	x0, lwp0uspace
 	bl	_C_LABEL(kasan_early_init)
Index: aarch64/aarch64/cpu.c
===================================================================
RCS file: /cvsroot/src/sys/arch/aarch64/aarch64/cpu.c,v
retrieving revision 1.25
diff -p -u -r1.25 cpu.c
--- aarch64/aarch64/cpu.c	20 Oct 2019 14:03:51 -0000	1.25
+++ aarch64/aarch64/cpu.c	16 Nov 2019 17:22:12 -0000
@@ -102,7 +102,6 @@ cpu_attach(device_t dv, cpuid_t id)
 {
 	struct cpu_info *ci;
 	const int unit = device_unit(dv);
-	uint64_t mpidr;
 
 	if (unit == 0) {
 		ci = curcpu();
@@ -142,19 +141,11 @@ cpu_attach(device_t dv, cpuid_t id)
 #endif /* MULTIPROCESSOR */
 	}
 
-	mpidr = ci->ci_id.ac_mpidr;
-	if (mpidr & MPIDR_MT) {
-		ci->ci_smt_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-		ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
-		ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF2);
-	} else {
-		ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
-		ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
-	}
-
 	ci->ci_dev = dv;
 	dv->dv_private = ci;
 
+	aarch64_gettopology(ci, ci->ci_id.ac_mpidr);
+
 	cpu_identify(ci->ci_dev, ci);
 #ifdef MULTIPROCESSOR
 	if (unit != 0) {
@@ -167,7 +158,10 @@ cpu_attach(device_t dv, cpuid_t id)
 	fpu_attach(ci);
 
 	cpu_identify1(dv, ci);
-	aarch64_getcacheinfo();
+#if 0
+	/* already done in locore */
+	aarch64_getcacheinfo(unit); 
+#endif
 	aarch64_printcacheinfo(dv);
 	cpu_identify2(dv, ci);
 
@@ -539,7 +533,7 @@ cpu_hatch(struct cpu_info *ci)
 	fpu_attach(ci);
 
 	cpu_identify1(ci->ci_dev, ci);
-	aarch64_getcacheinfo();
+	aarch64_getcacheinfo(device_unit(ci->ci_dev));
 	aarch64_printcacheinfo(ci->ci_dev);
 	cpu_identify2(ci->ci_dev, ci);
 
Index: aarch64/aarch64/cpufunc.c
===================================================================
RCS file: /cvsroot/src/sys/arch/aarch64/aarch64/cpufunc.c,v
retrieving revision 1.7
diff -p -u -r1.7 cpufunc.c
--- aarch64/aarch64/cpufunc.c	1 Oct 2019 18:00:07 -0000	1.7
+++ aarch64/aarch64/cpufunc.c	16 Nov 2019 17:22:12 -0000
@@ -49,6 +49,7 @@ u_int aarch64_cache_prefer_mask;
 /* cache info per cluster. the same cluster has the same cache configuration? */
 #define MAXCPUPACKAGES	MAXCPUS		/* maximum of ci->ci_package_id */
 static struct aarch64_cache_info *aarch64_cacheinfo[MAXCPUPACKAGES];
+static struct aarch64_cache_info aarch64_cacheinfo0;
 
 
 static void
@@ -88,27 +89,46 @@ extract_cacheunit(int level, bool insn, 
 }
 
 void
-aarch64_getcacheinfo(void)
+aarch64_gettopology(struct cpu_info * const ci, uint64_t mpidr)
 {
+
+	if (mpidr & MPIDR_MT) {
+		ci->ci_smt_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
+		ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
+		ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF2);
+	} else {
+		ci->ci_core_id = __SHIFTOUT(mpidr, MPIDR_AFF0);
+		ci->ci_package_id = __SHIFTOUT(mpidr, MPIDR_AFF1);
+	}
+}
+
+void
+aarch64_getcacheinfo(int unit)
+{
+	struct cpu_info * const ci = curcpu();
 	uint32_t clidr, ctr;
 	int level, cachetype;
-	struct aarch64_cache_info *cinfo;
+	struct aarch64_cache_info *cinfo = NULL;
 
 	if (cputype == 0)
 		cputype = aarch64_cpuid();
 
 	/* already extract about this cluster? */
-	KASSERT(curcpu()->ci_package_id < MAXCPUPACKAGES);
-	cinfo = aarch64_cacheinfo[curcpu()->ci_package_id];
+	KASSERT(ci->ci_package_id < MAXCPUPACKAGES);
+	cinfo = aarch64_cacheinfo[ci->ci_package_id];
 	if (cinfo != NULL) {
-		curcpu()->ci_cacheinfo = cinfo;
+		ci->ci_cacheinfo = cinfo;
 		return;
 	}
 
-	cinfo = aarch64_cacheinfo[curcpu()->ci_package_id] =
-	    kmem_zalloc(sizeof(struct aarch64_cache_info) * MAX_CACHE_LEVEL,
-	    KM_SLEEP);
-	curcpu()->ci_cacheinfo = cinfo;
+	/* Need static buffer for the boot CPU */
+	if (unit == 0)
+		cinfo = &aarch64_cacheinfo0;
+	else
+		cinfo = kmem_zalloc(sizeof(struct aarch64_cache_info)
+		    * MAX_CACHE_LEVEL, KM_SLEEP);
+	aarch64_cacheinfo[ci->ci_package_id] = cinfo;
+	ci->ci_cacheinfo = cinfo;
 
 
 	/*
Index: aarch64/include/cpufunc.h
===================================================================
RCS file: /cvsroot/src/sys/arch/aarch64/include/cpufunc.h,v
retrieving revision 1.7
diff -p -u -r1.7 cpufunc.h
--- aarch64/include/cpufunc.h	13 Sep 2019 18:07:30 -0000	1.7
+++ aarch64/include/cpufunc.h	16 Nov 2019 17:22:12 -0000
@@ -70,7 +70,8 @@ extern u_int aarch64_cache_prefer_mask;
 extern u_int cputype;			/* compat arm */
 
 int set_cpufuncs(void);
-void aarch64_getcacheinfo(void);
+void aarch64_gettopology(struct cpu_info *, uint64_t);
+void aarch64_getcacheinfo(int);
 void aarch64_printcacheinfo(device_t);
 
 void aarch64_dcache_wbinv_all(void);
