arm64/cpufeature: Pull out helper for CPUID register definitions
authorMark Brown <broonie@kernel.org>
Wed, 12 Apr 2023 17:13:29 +0000 (18:13 +0100)
committerWill Deacon <will@kernel.org>
Mon, 17 Apr 2023 12:03:14 +0000 (13:03 +0100)
We use the same structure to match hwcaps and CPU features so we can use
the same helper to generate the fields required. Pull the portion of the
current hwcaps helper that initialises the fields out into a separate
define placed earlier in the file so we can use it for cpufeatures.

No functional change.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230303-arm64-cpufeature-helpers-v2-1-4c8f28a6f203@kernel.org
Signed-off-by: Will Deacon <will@kernel.org>
arch/arm64/kernel/cpufeature.c

index 2e3e5513977733b7a324c4263218be2bfbeef580..77862b7c8908c7d6830f4f57c61e049f4433dcd5 100644 (file)
@@ -140,6 +140,13 @@ void dump_cpu_features(void)
        pr_emerg("0x%*pb\n", ARM64_NCAPS, &cpu_hwcaps);
 }
 
+#define ARM64_CPUID_FIELDS(reg, field, min_value)                      \
+               .sys_reg = SYS_##reg,                                                   \
+               .field_pos = reg##_##field##_SHIFT,                                             \
+               .field_width = reg##_##field##_WIDTH,                                           \
+               .sign = reg##_##field##_SIGNED,                                                 \
+               .min_field_value = reg##_##field##_##min_value,
+
 #define __ARM64_FTR_BITS(SIGNED, VISIBLE, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \
        {                                               \
                .sign = SIGNED,                         \
@@ -2776,12 +2783,8 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 };
 
 #define HWCAP_CPUID_MATCH(reg, field, min_value)                       \
-               .matches = has_user_cpuid_feature,                                      \
-               .sys_reg = SYS_##reg,                                                   \
-               .field_pos = reg##_##field##_SHIFT,                                             \
-               .field_width = reg##_##field##_WIDTH,                                           \
-               .sign = reg##_##field##_SIGNED,                                                 \
-               .min_field_value = reg##_##field##_##min_value,
+               .matches = has_user_cpuid_feature,                      \
+               ARM64_CPUID_FIELDS(reg, field, min_value)
 
 #define __HWCAP_CAP(name, cap_type, cap)                                       \
                .desc = name,                                                   \
@@ -2811,26 +2814,26 @@ static const struct arm64_cpu_capabilities arm64_features[] = {
 #ifdef CONFIG_ARM64_PTR_AUTH
 static const struct arm64_cpu_capabilities ptr_auth_hwcap_addr_matches[] = {
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR1_EL1, APA, PAuth)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR1_EL1, APA, PAuth)
        },
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR2_EL1, APA3, PAuth)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR2_EL1, APA3, PAuth)
        },
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR1_EL1, API, PAuth)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR1_EL1, API, PAuth)
        },
        {},
 };
 
 static const struct arm64_cpu_capabilities ptr_auth_hwcap_gen_matches[] = {
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR1_EL1, GPA, IMP)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR1_EL1, GPA, IMP)
        },
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR2_EL1, GPA3, IMP)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR2_EL1, GPA3, IMP)
        },
        {
-               HWCAP_CPUID_MATCH(ID_AA64ISAR1_EL1, GPI, IMP)
+               ARM64_CPUID_FIELDS(ID_AA64ISAR1_EL1, GPI, IMP)
        },
        {},
 };