Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/aarch64 Make cache operations available early.



details:   https://anonhg.NetBSD.org/src/rev/39814fe1291a
branches:  trunk
changeset: 461302:39814fe1291a
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Fri Nov 22 05:21:19 2019 +0000

description:
Make cache operations available early.

diffstat:

 sys/arch/aarch64/aarch64/cpu.c     |  24 ++++++++-------------
 sys/arch/aarch64/aarch64/cpufunc.c |  42 ++++++++++++++++++++++++++++---------
 sys/arch/aarch64/aarch64/locore.S  |  11 ++++++++-
 sys/arch/aarch64/include/cpufunc.h |   5 ++-
 4 files changed, 52 insertions(+), 30 deletions(-)

diffs (202 lines):

diff -r 5d884f579dc1 -r 39814fe1291a sys/arch/aarch64/aarch64/cpu.c
--- a/sys/arch/aarch64/aarch64/cpu.c    Fri Nov 22 05:16:54 2019 +0000
+++ b/sys/arch/aarch64/aarch64/cpu.c    Fri Nov 22 05:21:19 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.c,v 1.25 2019/10/20 14:03:51 jmcneill Exp $ */
+/* $NetBSD: cpu.c,v 1.26 2019/11/22 05:21:19 mlelstv 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.25 2019/10/20 14:03:51 jmcneill Exp $");
+__KERNEL_RCSID(1, "$NetBSD: cpu.c,v 1.26 2019/11/22 05:21:19 mlelstv Exp $");
 
 #include "locators.h"
 #include "opt_arm_debug.h"
@@ -102,7 +102,6 @@
 {
        struct cpu_info *ci;
        const int unit = device_unit(dv);
-       uint64_t mpidr;
 
        if (unit == 0) {
                ci = curcpu();
@@ -142,19 +141,11 @@
 #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 @@
        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 @@
        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);
 
diff -r 5d884f579dc1 -r 39814fe1291a sys/arch/aarch64/aarch64/cpufunc.c
--- a/sys/arch/aarch64/aarch64/cpufunc.c        Fri Nov 22 05:16:54 2019 +0000
+++ b/sys/arch/aarch64/aarch64/cpufunc.c        Fri Nov 22 05:21:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.c,v 1.7 2019/10/01 18:00:07 chs Exp $  */
+/*     $NetBSD: cpufunc.c,v 1.8 2019/11/22 05:21:19 mlelstv Exp $      */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -29,7 +29,7 @@
 #include "opt_multiprocessor.h"
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.7 2019/10/01 18:00:07 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpufunc.c,v 1.8 2019/11/22 05:21:19 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -49,6 +49,7 @@
 /* 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 @@
 }
 
 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;
 
 
        /*
diff -r 5d884f579dc1 -r 39814fe1291a sys/arch/aarch64/aarch64/locore.S
--- a/sys/arch/aarch64/aarch64/locore.S Fri Nov 22 05:16:54 2019 +0000
+++ b/sys/arch/aarch64/aarch64/locore.S Fri Nov 22 05:21:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.44 2019/10/20 14:03:51 jmcneill Exp $     */
+/*     $NetBSD: locore.S,v 1.45 2019/11/22 05:21:19 mlelstv Exp $      */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -38,7 +38,7 @@
 #include <aarch64/hypervisor.h>
 #include "assym.h"
 
-RCSID("$NetBSD: locore.S,v 1.44 2019/10/20 14:03:51 jmcneill Exp $")
+RCSID("$NetBSD: locore.S,v 1.45 2019/11/22 05:21:19 mlelstv Exp $")
 
 
 /*#define DEBUG_LOCORE                 /* debug print */
@@ -180,6 +180,13 @@
        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)
diff -r 5d884f579dc1 -r 39814fe1291a sys/arch/aarch64/include/cpufunc.h
--- a/sys/arch/aarch64/include/cpufunc.h        Fri Nov 22 05:16:54 2019 +0000
+++ b/sys/arch/aarch64/include/cpufunc.h        Fri Nov 22 05:21:19 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpufunc.h,v 1.7 2019/09/13 18:07:30 ryo Exp $  */
+/*     $NetBSD: cpufunc.h,v 1.8 2019/11/22 05:21:19 mlelstv Exp $      */
 
 /*
  * Copyright (c) 2017 Ryo Shimizu <ryo%nerv.org@localhost>
@@ -70,7 +70,8 @@
 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);



Home | Main Index | Thread Index | Old Index