Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/powerpc/oea Split cpu_model_init() into cpu_feature...



details:   https://anonhg.NetBSD.org/src/rev/9d870fbe6579
branches:  trunk
changeset: 953120:9d870fbe6579
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Fri Feb 26 21:15:20 2021 +0000

description:
Split cpu_model_init() into cpu_features_probe() and cpu_features_enable()
so that early bootstrap can do those two steps independently, if needed.

Continue to provide a cpu_model_init() wrapper for now.

diffstat:

 sys/arch/powerpc/include/oea/cpufeat.h |   9 ++-
 sys/arch/powerpc/oea/cpu_subr.c        |  79 ++++++++++++++++++++++++++-------
 2 files changed, 68 insertions(+), 20 deletions(-)

diffs (163 lines):

diff -r 9637a1295ff7 -r 9d870fbe6579 sys/arch/powerpc/include/oea/cpufeat.h
--- a/sys/arch/powerpc/include/oea/cpufeat.h    Fri Feb 26 19:25:12 2021 +0000
+++ b/sys/arch/powerpc/include/oea/cpufeat.h    Fri Feb 26 21:15:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpufeat.h,v 1.5 2018/03/22 21:26:27 macallan Exp $ */
+/* $NetBSD: cpufeat.h,v 1.6 2021/02/26 21:15:20 thorpej Exp $ */
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -30,7 +30,8 @@
 
 #ifndef _POWERPC_OEA_OEAFEAT_H_
 
-/* Cpu features for OEA Cpus.
+/*
+ * Cpu features for OEA Cpus.
  * These are only features that affect early bootstrap, and decisions
  * that need to be made very early on, like what pmap to use, if bats are
  * available, etc etc.  More can be added later. Some are not yet utilized.
@@ -48,7 +49,9 @@
 #define OEACPU_XBSEN           (1 << 7)        /* BATS > 256MB */
 
 #ifdef _KERNEL
-void cpu_model_init(void);
+void   cpu_features_probe(void);
+void   cpu_features_enable(void);
+void   cpu_model_init(void);
 extern unsigned long oeacpufeat;
 
 #define oea_mapiodev(addr, size) ((oeacpufeat & OEACPU_NOBAT) ? \
diff -r 9637a1295ff7 -r 9d870fbe6579 sys/arch/powerpc/oea/cpu_subr.c
--- a/sys/arch/powerpc/oea/cpu_subr.c   Fri Feb 26 19:25:12 2021 +0000
+++ b/sys/arch/powerpc/oea/cpu_subr.c   Fri Feb 26 21:15:20 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu_subr.c,v 1.106 2021/02/26 02:18:57 thorpej Exp $   */
+/*     $NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2001 Matt Thomas.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.106 2021/02/26 02:18:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cpu_subr.c,v 1.107 2021/02/26 21:15:20 thorpej Exp $");
 
 #include "sysmon_envsys.h"
 
@@ -267,20 +267,22 @@
 
 unsigned long oeacpufeat;
 
-/* This is to be called from locore.S, and nowhere else. */
+void
+cpu_features_probe(void)
+{
+       static bool feature_probe_done;
 
-void
-cpu_model_init(void)
-{
        u_int pvr, vers;
 
+       if (feature_probe_done) {
+               return;
+       }
+
        pvr = mfpvr();
        vers = pvr >> 16;
 
-       oeacpufeat = 0;
-
        if ((vers >= IBMRS64II && vers <= IBM970GX) || vers == MPC620 ||
-               vers == IBMCELL || vers == IBMPOWER6P5) {
+           vers == IBMCELL || vers == IBMPOWER6P5) {
                oeacpufeat |= OEACPU_64;
                oeacpufeat |= OEACPU_64_BRIDGE;
                oeacpufeat |= OEACPU_NOBAT;
@@ -289,22 +291,53 @@
                oeacpufeat |= OEACPU_601;
 
        } else if (MPC745X_P(vers)) {
-               register_t hid1 = mfspr(SPR_HID1);
-
                if (vers != MPC7450) {
-                       register_t hid0 = mfspr(SPR_HID0);
-
                        /* Enable more SPRG registers */
                        oeacpufeat |= OEACPU_HIGHSPRG;
 
                        /* Enable more BAT registers */
                        oeacpufeat |= OEACPU_HIGHBAT;
-                       hid0 |= HID0_HIGH_BAT_EN;
 
                        /* Enable larger BAT registers */
                        oeacpufeat |= OEACPU_XBSEN;
+               }
+
+       } else if (vers == IBM750FX || vers == IBM750GX) {
+               oeacpufeat |= OEACPU_HIGHBAT;
+       }
+
+       feature_probe_done = true;
+}
+
+void
+cpu_features_enable(void)
+{
+       static bool feature_enable_done;
+
+       if (feature_enable_done) {
+               return;
+       }
+
+       u_int pvr, vers;
+
+       pvr = mfpvr();
+       vers = pvr >> 16;
+
+       if (MPC745X_P(vers)) {
+               register_t hid0 = mfspr(SPR_HID0);
+               register_t hid1 = mfspr(SPR_HID1);
+
+               const register_t ohid0 = hid0;
+
+               if (oeacpufeat & OEACPU_HIGHBAT) {
+                       hid0 |= HID0_HIGH_BAT_EN;
+               }
+
+               if (oeacpufeat & OEACPU_XBSEN) {
                        hid0 |= HID0_XBSEN;
+               }
 
+               if (hid0 != ohid0) {
                        mtspr(SPR_HID0, hid0);
                        __asm volatile("sync;isync");
                }
@@ -314,10 +347,22 @@
 
                mtspr(SPR_HID1, hid1);
                __asm volatile("sync;isync");
+       }
 
-       } else if (vers == IBM750FX || vers == IBM750GX) {
-               oeacpufeat |= OEACPU_HIGHBAT;
-       }
+       feature_enable_done = true;
+}
+
+/* This is to be called from locore.S, and nowhere else. */
+
+void
+cpu_model_init(void)
+{
+       /*
+        * This is just a wrapper for backwards-compatibility, and will
+        * probably be garbage-collected in the near future.
+        */
+       cpu_features_probe();
+       cpu_features_enable();
 }
 
 void



Home | Main Index | Thread Index | Old Index