Clean up the cpi_id_aa64xxx variables at the end of autoconf such that
authorkettenis <kettenis@openbsd.org>
Wed, 17 Jul 2024 15:21:59 +0000 (15:21 +0000)
committerkettenis <kettenis@openbsd.org>
Wed, 17 Jul 2024 15:21:59 +0000 (15:21 +0000)
sysclt(2) and ID register access emulation can share the variables.

ok jca@

sys/arch/arm64/arm64/autoconf.c
sys/arch/arm64/arm64/cpu.c
sys/arch/arm64/arm64/machdep.c
sys/arch/arm64/include/cpu.h

index 207f509..75ef6d7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: autoconf.c,v 1.14 2022/09/08 10:22:06 kn Exp $        */
+/*     $OpenBSD: autoconf.c,v 1.15 2024/07/17 15:21:59 kettenis Exp $  */
 /*
  * Copyright (c) 2009 Miodrag Vallat.
  *
@@ -61,6 +61,8 @@ cpu_configure(void)
 
        unmap_startup();
 
+       cpu_identify_cleanup();
+
 #ifdef CRYPTO
        if (arm64_has_aes)
                cryptox_setup();
index 6989805..3738387 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: cpu.c,v 1.126 2024/07/14 09:48:48 jca Exp $   */
+/*     $OpenBSD: cpu.c,v 1.127 2024/07/17 15:21:59 kettenis Exp $      */
 
 /*
  * Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
@@ -1024,6 +1024,40 @@ cpu_identify(struct cpu_info *ci)
 #endif
 }
 
+void
+cpu_identify_cleanup(void)
+{
+       uint64_t value;
+
+       /* ID_AA64ISAR0_EL1 */
+       value = cpu_id_aa64isar0 & ID_AA64ISAR0_MASK;
+       value &= ~ID_AA64ISAR0_TLB_MASK;
+       cpu_id_aa64isar0 = value;
+
+       /* ID_AA64ISAR1_EL1 */
+       value = cpu_id_aa64isar1 &= ID_AA64ISAR1_MASK;
+       value &= ~ID_AA64ISAR1_SPECRES_MASK;
+       cpu_id_aa64isar1 = value;
+
+       /* ID_AA64ISAR2_EL1 */
+       value = cpu_id_aa64isar2 &= ID_AA64ISAR2_MASK;
+       value &= ~ID_AA64ISAR2_CLRBHB_MASK;
+       cpu_id_aa64isar2 = value;
+
+       /* ID_AA64PFR0_EL1 */
+       value = 0;
+       value |= cpu_id_aa64pfr0 & ID_AA64PFR0_FP_MASK;
+       value |= cpu_id_aa64pfr0 & ID_AA64PFR0_ADV_SIMD_MASK;
+       value |= cpu_id_aa64pfr0 & ID_AA64PFR0_DIT_MASK;
+       cpu_id_aa64pfr0 = value;
+
+       /* ID_AA64PFR1_EL1 */
+       value = 0;
+       value |= cpu_id_aa64pfr1 & ID_AA64PFR1_BT_MASK;
+       value |= cpu_id_aa64pfr1 & ID_AA64PFR1_SSBS_MASK;
+       cpu_id_aa64pfr1 = value;
+}
+
 void   cpu_init(void);
 int    cpu_start_secondary(struct cpu_info *ci, int, uint64_t);
 int    cpu_clockspeed(int *);
index 7b53ee1..c3605a0 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.90 2024/07/03 21:04:04 kettenis Exp $ */
+/* $OpenBSD: machdep.c,v 1.91 2024/07/17 15:21:59 kettenis Exp $ */
 /*
  * Copyright (c) 2014 Patrick Wildt <patrick@blueri.se>
  * Copyright (c) 2021 Mark Kettenis <kettenis@openbsd.org>
@@ -332,7 +332,6 @@ cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
 {
        char *compatible;
        int node, len, error;
-       uint64_t value;
 
        /* all sysctl names at this level are terminal */
        if (namelen != 1)
@@ -351,25 +350,15 @@ cpu_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
                free(compatible, M_TEMP, len);
                return error;
        case CPU_ID_AA64ISAR0:
-               value = cpu_id_aa64isar0 & ID_AA64ISAR0_MASK;
-               value &= ~ID_AA64ISAR0_TLB_MASK;
-               return sysctl_rdquad(oldp, oldlenp, newp, value);
+               return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar0);
        case CPU_ID_AA64ISAR1:
-               value = cpu_id_aa64isar1 & ID_AA64ISAR1_MASK;
-               value &= ~ID_AA64ISAR1_SPECRES_MASK;
-               return sysctl_rdquad(oldp, oldlenp, newp, value);
+               return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar1);
+       case CPU_ID_AA64ISAR2:
+               return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64isar2);
        case CPU_ID_AA64PFR0:
-               value = 0;
-               value |= cpu_id_aa64pfr0 & ID_AA64PFR0_FP_MASK;
-               value |= cpu_id_aa64pfr0 & ID_AA64PFR0_ADV_SIMD_MASK;
-               value |= cpu_id_aa64pfr0 & ID_AA64PFR0_DIT_MASK;
-               return sysctl_rdquad(oldp, oldlenp, newp, value);
+               return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64pfr0);
        case CPU_ID_AA64PFR1:
-               value = 0;
-               value |= cpu_id_aa64pfr1 & ID_AA64PFR1_BT_MASK;
-               value |= cpu_id_aa64pfr1 & ID_AA64PFR1_SSBS_MASK;
-               return sysctl_rdquad(oldp, oldlenp, newp, value);
-       case CPU_ID_AA64ISAR2:
+               return sysctl_rdquad(oldp, oldlenp, newp, cpu_id_aa64pfr1);
        case CPU_ID_AA64MMFR0:
        case CPU_ID_AA64MMFR1:
        case CPU_ID_AA64MMFR2:
index c9b0e10..33084f6 100644 (file)
@@ -1,4 +1,4 @@
-/* $OpenBSD: cpu.h,v 1.48 2024/07/10 11:01:24 kettenis Exp $ */
+/* $OpenBSD: cpu.h,v 1.49 2024/07/17 15:21:59 kettenis Exp $ */
 /*
  * Copyright (c) 2016 Dale Rahn <drahn@dalerahn.com>
  *
 
 extern uint64_t cpu_id_aa64isar0;
 extern uint64_t cpu_id_aa64isar1;
+extern uint64_t cpu_id_aa64isar2;
 extern uint64_t cpu_id_aa64pfr0;
 extern uint64_t cpu_id_aa64pfr1;
 
+void cpu_identify_cleanup(void);
+
 #include <machine/intr.h>
 #include <machine/frame.h>
 #include <machine/armreg.h>