arm64: cpufeature: Use IDreg override in __read_sysreg_by_encoding()
authorMarc Zyngier <maz@kernel.org>
Mon, 8 Feb 2021 09:57:20 +0000 (09:57 +0000)
committerWill Deacon <will@kernel.org>
Tue, 9 Feb 2021 13:47:12 +0000 (13:47 +0000)
__read_sysreg_by_encoding() is used by a bunch of cpufeature helpers,
which should take the feature override into account. Let's do that.

For a good measure (and because we are likely to need to further
down the line), make this helper available to the rest of the
non-modular kernel.

Code that needs to know the *real* features of a CPU can still
use read_sysreg_s(), and find the bare, ugly truth.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Acked-by: David Brazdil <dbrazdil@google.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20210208095732.3267263-12-maz@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/include/asm/cpufeature.h
arch/arm64/kernel/cpufeature.c

index b1f53147e2b26cf460d55bea17721131ad6b01c8..b5bf7af6869119f4ba4785412c9b198fcb7e8480 100644 (file)
@@ -606,6 +606,7 @@ void __init setup_cpu_features(void);
 void check_local_cpu_capabilities(void);
 
 u64 read_sanitised_ftr_reg(u32 id);
+u64 __read_sysreg_by_encoding(u32 sys_id);
 
 static inline bool cpu_supports_mixed_endian_el0(void)
 {
index a4e5c619a51642d65df6f967ca329d25fac5a73f..97da9ed4b79dad70d7af47e76ea17d8b5d14c852 100644 (file)
@@ -1148,14 +1148,17 @@ u64 read_sanitised_ftr_reg(u32 id)
 EXPORT_SYMBOL_GPL(read_sanitised_ftr_reg);
 
 #define read_sysreg_case(r)    \
-       case r:         return read_sysreg_s(r)
+       case r:         val = read_sysreg_s(r); break;
 
 /*
  * __read_sysreg_by_encoding() - Used by a STARTING cpu before cpuinfo is populated.
  * Read the system register on the current CPU
  */
-static u64 __read_sysreg_by_encoding(u32 sys_id)
+u64 __read_sysreg_by_encoding(u32 sys_id)
 {
+       struct arm64_ftr_reg *regp;
+       u64 val;
+
        switch (sys_id) {
        read_sysreg_case(SYS_ID_PFR0_EL1);
        read_sysreg_case(SYS_ID_PFR1_EL1);
@@ -1198,6 +1201,14 @@ static u64 __read_sysreg_by_encoding(u32 sys_id)
                BUG();
                return 0;
        }
+
+       regp  = get_arm64_ftr_reg(sys_id);
+       if (regp) {
+               val &= ~regp->override->mask;
+               val |= (regp->override->val & regp->override->mask);
+       }
+
+       return val;
 }
 
 #include <linux/irqchip/arm-gic-v3.h>