From 55a12bbda28d17258a493ed0fbb22caeca414474 Mon Sep 17 00:00:00 2001 From: Justin Hibbits Date: Sat, 5 May 2018 15:48:39 +0000 Subject: [PATCH] Break out the cpu_features setup to its own function, to be run earlier The new POWER9 MMU configuration is slightly different from current setups. Rather than special-casing on POWER9, move the initialization of cpu_features and cpu_features2 to as early as possible, so that platform and MMU configuration can be based upon CPU features instead of specific CPUs if at all possible. Reviewed by: nwhitehorn --- sys/powerpc/include/md_var.h | 1 + sys/powerpc/powerpc/cpu.c | 46 ++++++++++++++++++++++++----------- sys/powerpc/powerpc/machdep.c | 2 ++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/sys/powerpc/include/md_var.h b/sys/powerpc/include/md_var.h index b3e8e0cae199..5ebb87476682 100644 --- a/sys/powerpc/include/md_var.h +++ b/sys/powerpc/include/md_var.h @@ -63,6 +63,7 @@ void decr_init(void); void decr_ap_init(void); void decr_tc_init(void); +void cpu_feature_setup(void); void cpu_setup(u_int); struct trapframe; diff --git a/sys/powerpc/powerpc/cpu.c b/sys/powerpc/powerpc/cpu.c index 0e3f9f720718..72ad982fe581 100644 --- a/sys/powerpc/powerpc/cpu.c +++ b/sys/powerpc/powerpc/cpu.c @@ -231,6 +231,8 @@ static int cpu_feature_bit(SYSCTL_HANDLER_ARGS); static char model[64]; SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, model, 0, ""); +static const struct cputab *cput; + u_long cpu_features = PPC_FEATURE_32 | PPC_FEATURE_HAS_MMU; u_long cpu_features2 = 0; SYSCTL_OPAQUE(_hw, OID_AUTO, cpu_features, CTLFLAG_RD, @@ -245,14 +247,37 @@ SYSCTL_PROC(_hw, OID_AUTO, floatingpoint, CTLTYPE_INT | CTLFLAG_RD, SYSCTL_PROC(_hw, OID_AUTO, altivec, CTLTYPE_INT | CTLFLAG_RD, 0, PPC_FEATURE_HAS_ALTIVEC, cpu_feature_bit, "I", "CPU supports Altivec"); +/* + * Phase 1 (early) CPU setup. Setup the cpu_features/cpu_features2 variables, + * so they can be used during platform and MMU bringup. + */ +void +cpu_feature_setup() +{ + u_int pvr; + uint16_t vers; + const struct cputab *cp; + + pvr = mfpvr(); + vers = pvr >> 16; + for (cp = models; cp->version != 0; cp++) { + if (cp->version == vers) + break; + } + + cput = cp; + cpu_features |= cp->features; + cpu_features2 |= cp->features2; +} + + void cpu_setup(u_int cpuid) { - u_int pvr, maj, min; - uint16_t vers, rev, revfmt; uint64_t cps; - const struct cputab *cp; const char *name; + u_int maj, min, pvr; + uint16_t rev, revfmt, vers; pvr = mfpvr(); vers = pvr >> 16; @@ -274,13 +299,8 @@ cpu_setup(u_int cpuid) min = (pvr >> 0) & 0xf; } - for (cp = models; cp->version != 0; cp++) { - if (cp->version == vers) - break; - } - - revfmt = cp->revfmt; - name = cp->name; + revfmt = cput->revfmt; + name = cput->name; if (rev == MPC750 && pvr == 15) { name = "Motorola MPC755"; revfmt = REVFMT_HEX; @@ -305,8 +325,6 @@ cpu_setup(u_int cpuid) printf(", %jd.%02jd MHz", cps / 1000000, (cps / 10000) % 100); printf("\n"); - cpu_features |= cp->features; - cpu_features2 |= cp->features2; printf("cpu%d: Features %b\n", cpuid, (int)cpu_features, PPC_FEATURE_BITMASK); if (cpu_features2 != 0) @@ -316,8 +334,8 @@ cpu_setup(u_int cpuid) /* * Configure CPU */ - if (cp->cpu_setup != NULL) - cp->cpu_setup(cpuid, vers); + if (cput->cpu_setup != NULL) + cput->cpu_setup(cpuid, vers); } /* Get current clock frequency for the given cpu id. */ diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c index caf28c8ee8a8..ea315f586080 100644 --- a/sys/powerpc/powerpc/machdep.c +++ b/sys/powerpc/powerpc/machdep.c @@ -275,6 +275,8 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, bzero(__bss_start, _end - __bss_start); #endif + cpu_feature_setup(); + #ifdef AIM aim_early_init(fdt, toc, ofentry, mdp, mdp_cookie); #endif