Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Contains CPU feature definitions |
| 3 | * |
| 4 | * Copyright (C) 2015 ARM Ltd. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 19 | #define pr_fmt(fmt) "CPU features: " fmt |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 20 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 21 | #include <linux/bsearch.h> |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 22 | #include <linux/cpumask.h> |
James Morse | 1451b7f | 2022-04-06 17:45:41 +0100 | [diff] [blame] | 23 | #include <linux/percpu.h> |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 24 | #include <linux/sort.h> |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 25 | #include <linux/stop_machine.h> |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 26 | #include <linux/types.h> |
Laura Abbott | f8fee94e | 2017-01-10 13:35:49 -0800 | [diff] [blame] | 27 | #include <linux/mm.h> |
James Morse | 1451b7f | 2022-04-06 17:45:41 +0100 | [diff] [blame] | 28 | |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 29 | #include <asm/cpu.h> |
| 30 | #include <asm/cpufeature.h> |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 31 | #include <asm/cpu_ops.h> |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 32 | #include <asm/mmu_context.h> |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 33 | #include <asm/processor.h> |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 34 | #include <asm/sysreg.h> |
James Morse | 1451b7f | 2022-04-06 17:45:41 +0100 | [diff] [blame] | 35 | #include <asm/vectors.h> |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 36 | #include <asm/virt.h> |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 37 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 38 | unsigned long elf_hwcap __read_mostly; |
| 39 | EXPORT_SYMBOL_GPL(elf_hwcap); |
| 40 | |
| 41 | #ifdef CONFIG_COMPAT |
| 42 | #define COMPAT_ELF_HWCAP_DEFAULT \ |
| 43 | (COMPAT_HWCAP_HALF|COMPAT_HWCAP_THUMB|\ |
| 44 | COMPAT_HWCAP_FAST_MULT|COMPAT_HWCAP_EDSP|\ |
| 45 | COMPAT_HWCAP_TLS|COMPAT_HWCAP_VFP|\ |
| 46 | COMPAT_HWCAP_VFPv3|COMPAT_HWCAP_VFPv4|\ |
| 47 | COMPAT_HWCAP_NEON|COMPAT_HWCAP_IDIV|\ |
| 48 | COMPAT_HWCAP_LPAE) |
| 49 | unsigned int compat_elf_hwcap __read_mostly = COMPAT_ELF_HWCAP_DEFAULT; |
| 50 | unsigned int compat_elf_hwcap2 __read_mostly; |
| 51 | #endif |
| 52 | |
| 53 | DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS); |
Catalin Marinas | 005bf1a | 2016-07-01 16:53:00 +0100 | [diff] [blame] | 54 | EXPORT_SYMBOL(cpu_hwcaps); |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 55 | |
James Morse | 1451b7f | 2022-04-06 17:45:41 +0100 | [diff] [blame] | 56 | DEFINE_PER_CPU_READ_MOSTLY(const char *, this_cpu_vector) = vectors; |
| 57 | |
Catalin Marinas | efd9e03 | 2016-09-05 18:25:48 +0100 | [diff] [blame] | 58 | DEFINE_STATIC_KEY_ARRAY_FALSE(cpu_hwcap_keys, ARM64_NCAPS); |
| 59 | EXPORT_SYMBOL(cpu_hwcap_keys); |
| 60 | |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 61 | #define __ARM64_FTR_BITS(SIGNED, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 62 | { \ |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 63 | .sign = SIGNED, \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 64 | .strict = STRICT, \ |
| 65 | .type = TYPE, \ |
| 66 | .shift = SHIFT, \ |
| 67 | .width = WIDTH, \ |
| 68 | .safe_val = SAFE_VAL, \ |
| 69 | } |
| 70 | |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 71 | /* Define a feature with unsigned values */ |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 72 | #define ARM64_FTR_BITS(STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
Suzuki K. Poulose | 4f0a606 | 2015-11-18 17:08:57 +0000 | [diff] [blame] | 73 | __ARM64_FTR_BITS(FTR_UNSIGNED, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) |
| 74 | |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 75 | /* Define a feature with a signed value */ |
| 76 | #define S_ARM64_FTR_BITS(STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) \ |
| 77 | __ARM64_FTR_BITS(FTR_SIGNED, STRICT, TYPE, SHIFT, WIDTH, SAFE_VAL) |
| 78 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 79 | #define ARM64_FTR_END \ |
| 80 | { \ |
| 81 | .width = 0, \ |
| 82 | } |
| 83 | |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 84 | /* meta feature for alternatives */ |
| 85 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 86 | cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused); |
| 87 | |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 88 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 89 | static const struct arm64_ftr_bits ftr_id_aa64isar0[] = { |
Suzuki K Poulose | ba62b30 | 2017-10-11 14:01:02 +0100 | [diff] [blame] | 90 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64ISAR0_DP_SHIFT, 4, 0), |
| 91 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64ISAR0_SM4_SHIFT, 4, 0), |
| 92 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64ISAR0_SM3_SHIFT, 4, 0), |
| 93 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64ISAR0_SHA3_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 94 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64ISAR0_RDM_SHIFT, 4, 0), |
| 95 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 24, 4, 0), |
| 96 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_ATOMICS_SHIFT, 4, 0), |
| 97 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_CRC32_SHIFT, 4, 0), |
| 98 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA2_SHIFT, 4, 0), |
| 99 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_SHA1_SHIFT, 4, 0), |
| 100 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64ISAR0_AES_SHIFT, 4, 0), |
| 101 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 4, 0), /* RAZ */ |
| 102 | ARM64_FTR_END, |
| 103 | }; |
| 104 | |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 105 | static const struct arm64_ftr_bits ftr_id_aa64isar2[] = { |
James Morse | 7815cbf | 2022-04-06 17:45:46 +0100 | [diff] [blame] | 106 | ARM64_FTR_BITS(FTR_STRICT, FTR_HIGHER_SAFE, ID_AA64ISAR2_CLEARBHB_SHIFT, 4, 0), |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 107 | ARM64_FTR_END, |
| 108 | }; |
| 109 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 110 | static const struct arm64_ftr_bits ftr_id_aa64pfr0[] = { |
Will Deacon | 7354772 | 2018-04-03 12:09:14 +0100 | [diff] [blame] | 111 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV3_SHIFT, 4, 0), |
Mark Rutland | 4732001 | 2018-04-12 12:11:13 +0100 | [diff] [blame] | 112 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64PFR0_CSV2_SHIFT, 4, 0), |
| 113 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 24, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 114 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 28, 4, 0), |
| 115 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_GIC_SHIFT, 4, 0), |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 116 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_ASIMD_SHIFT, 4, ID_AA64PFR0_ASIMD_NI), |
| 117 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64PFR0_FP_SHIFT, 4, ID_AA64PFR0_FP_NI), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 118 | /* Linux doesn't care about the EL3 */ |
| 119 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_EXACT, ID_AA64PFR0_EL3_SHIFT, 4, 0), |
| 120 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_EL2_SHIFT, 4, 0), |
| 121 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_EL1_SHIFT, 4, ID_AA64PFR0_EL1_64BIT_ONLY), |
| 122 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64PFR0_EL0_SHIFT, 4, ID_AA64PFR0_EL0_64BIT_ONLY), |
| 123 | ARM64_FTR_END, |
| 124 | }; |
| 125 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 126 | static const struct arm64_ftr_bits ftr_id_aa64mmfr0[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 127 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 32, 0), |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 128 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_TGRAN4_SHIFT, 4, ID_AA64MMFR0_TGRAN4_NI), |
| 129 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_TGRAN64_SHIFT, 4, ID_AA64MMFR0_TGRAN64_NI), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 130 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_TGRAN16_SHIFT, 4, ID_AA64MMFR0_TGRAN16_NI), |
| 131 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_BIGENDEL0_SHIFT, 4, 0), |
| 132 | /* Linux shouldn't care about secure memory */ |
| 133 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_EXACT, ID_AA64MMFR0_SNSMEM_SHIFT, 4, 0), |
| 134 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_BIGENDEL_SHIFT, 4, 0), |
| 135 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR0_ASID_SHIFT, 4, 0), |
| 136 | /* |
| 137 | * Differing PARange is fine as long as all peripherals and memory are mapped |
| 138 | * within the minimum PARange of all CPUs |
| 139 | */ |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 140 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, ID_AA64MMFR0_PARANGE_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 141 | ARM64_FTR_END, |
| 142 | }; |
| 143 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 144 | static const struct arm64_ftr_bits ftr_id_aa64mmfr1[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 145 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 32, 0), |
| 146 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64MMFR1_PAN_SHIFT, 4, 0), |
| 147 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR1_LOR_SHIFT, 4, 0), |
| 148 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR1_HPD_SHIFT, 4, 0), |
| 149 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR1_VHE_SHIFT, 4, 0), |
| 150 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR1_VMIDBITS_SHIFT, 4, 0), |
| 151 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR1_HADBS_SHIFT, 4, 0), |
| 152 | ARM64_FTR_END, |
| 153 | }; |
| 154 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 155 | static const struct arm64_ftr_bits ftr_id_aa64mmfr2[] = { |
Kefeng Wang | 7d7b4ae | 2016-03-25 17:30:07 +0800 | [diff] [blame] | 156 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR2_LVA_SHIFT, 4, 0), |
| 157 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR2_IESB_SHIFT, 4, 0), |
| 158 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR2_LSM_SHIFT, 4, 0), |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 159 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR2_UAO_SHIFT, 4, 0), |
Kefeng Wang | 7d7b4ae | 2016-03-25 17:30:07 +0800 | [diff] [blame] | 160 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64MMFR2_CNP_SHIFT, 4, 0), |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 161 | ARM64_FTR_END, |
| 162 | }; |
| 163 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 164 | static const struct arm64_ftr_bits ftr_ctr[] = { |
Will Deacon | e364e9a | 2019-08-05 18:13:54 +0100 | [diff] [blame] | 165 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 31, 1, 1), /* RES1 */ |
| 166 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 30, 1, 0), |
| 167 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 29, 1, 1), /* DIC */ |
| 168 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 28, 1, 1), /* IDC */ |
Will Deacon | 3c5dbb9 | 2019-08-05 18:13:55 +0100 | [diff] [blame] | 169 | ARM64_FTR_BITS(FTR_STRICT, FTR_HIGHER_OR_ZERO_SAFE, 24, 4, 0), /* CWG */ |
| 170 | ARM64_FTR_BITS(FTR_STRICT, FTR_HIGHER_OR_ZERO_SAFE, 20, 4, 0), /* ERG */ |
Suzuki K Poulose | a683009 | 2018-07-04 23:07:45 +0100 | [diff] [blame] | 171 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, CTR_DMINLINE_SHIFT, 4, 1), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 172 | /* |
| 173 | * Linux can handle differing I-cache policies. Userspace JITs will |
Suzuki K Poulose | ee7bc63 | 2016-09-09 14:07:08 +0100 | [diff] [blame] | 174 | * make use of *minLine. |
| 175 | * If we have differing I-cache policies, report it as the weakest - AIVIVT. |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 176 | */ |
Suzuki K Poulose | ee7bc63 | 2016-09-09 14:07:08 +0100 | [diff] [blame] | 177 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_EXACT, 14, 2, ICACHE_POLICY_AIVIVT), /* L1Ip */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 178 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 10, 0), /* RAZ */ |
Suzuki K Poulose | a683009 | 2018-07-04 23:07:45 +0100 | [diff] [blame] | 179 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, CTR_IMINLINE_SHIFT, 4, 0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 180 | ARM64_FTR_END, |
| 181 | }; |
| 182 | |
Ard Biesheuvel | 675b056 | 2016-08-31 11:31:10 +0100 | [diff] [blame] | 183 | struct arm64_ftr_reg arm64_ftr_reg_ctrel0 = { |
| 184 | .name = "SYS_CTR_EL0", |
| 185 | .ftr_bits = ftr_ctr |
| 186 | }; |
| 187 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 188 | static const struct arm64_ftr_bits ftr_id_mmfr0[] = { |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 189 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 28, 4, 0xf), /* InnerShr */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 190 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 24, 4, 0), /* FCSE */ |
| 191 | ARM64_FTR_BITS(FTR_NONSTRICT, FTR_LOWER_SAFE, 20, 4, 0), /* AuxReg */ |
| 192 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 16, 4, 0), /* TCM */ |
| 193 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 12, 4, 0), /* ShareLvl */ |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 194 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 8, 4, 0xf), /* OuterShr */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 195 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 4, 0), /* PMSA */ |
| 196 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 4, 0), /* VMSA */ |
| 197 | ARM64_FTR_END, |
| 198 | }; |
| 199 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 200 | static const struct arm64_ftr_bits ftr_id_aa64dfr0[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 201 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 32, 32, 0), |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 202 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_CTX_CMPS_SHIFT, 4, 0), |
| 203 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_WRPS_SHIFT, 4, 0), |
| 204 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, ID_AA64DFR0_BRPS_SHIFT, 4, 0), |
| 205 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64DFR0_PMUVER_SHIFT, 4, 0), |
| 206 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64DFR0_TRACEVER_SHIFT, 4, 0), |
| 207 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_AA64DFR0_DEBUGVER_SHIFT, 4, 0x6), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 208 | ARM64_FTR_END, |
| 209 | }; |
| 210 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 211 | static const struct arm64_ftr_bits ftr_mvfr2[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 212 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 8, 24, 0), /* RAZ */ |
| 213 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 4, 0), /* FPMisc */ |
| 214 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 4, 0), /* SIMDMisc */ |
| 215 | ARM64_FTR_END, |
| 216 | }; |
| 217 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 218 | static const struct arm64_ftr_bits ftr_dczid[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 219 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 5, 27, 0), /* RAZ */ |
| 220 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 1, 1), /* DZP */ |
| 221 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), /* BS */ |
| 222 | ARM64_FTR_END, |
| 223 | }; |
| 224 | |
| 225 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 226 | static const struct arm64_ftr_bits ftr_id_isar5[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 227 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_RDM_SHIFT, 4, 0), |
| 228 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 20, 4, 0), /* RAZ */ |
| 229 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_CRC32_SHIFT, 4, 0), |
| 230 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_SHA2_SHIFT, 4, 0), |
| 231 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_SHA1_SHIFT, 4, 0), |
| 232 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_AES_SHIFT, 4, 0), |
| 233 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, ID_ISAR5_SEVL_SHIFT, 4, 0), |
| 234 | ARM64_FTR_END, |
| 235 | }; |
| 236 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 237 | static const struct arm64_ftr_bits ftr_id_mmfr4[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 238 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 8, 24, 0), /* RAZ */ |
| 239 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 4, 0), /* ac2 */ |
| 240 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 4, 0), /* RAZ */ |
| 241 | ARM64_FTR_END, |
| 242 | }; |
| 243 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 244 | static const struct arm64_ftr_bits ftr_id_pfr0[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 245 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 16, 16, 0), /* RAZ */ |
| 246 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 12, 4, 0), /* State3 */ |
| 247 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 8, 4, 0), /* State2 */ |
| 248 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 4, 4, 0), /* State1 */ |
| 249 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 4, 0), /* State0 */ |
| 250 | ARM64_FTR_END, |
| 251 | }; |
| 252 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 253 | static const struct arm64_ftr_bits ftr_id_dfr0[] = { |
Suzuki K Poulose | e534350 | 2016-01-26 10:58:13 +0000 | [diff] [blame] | 254 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 28, 4, 0), |
Suzuki K Poulose | 0710cfd | 2016-01-26 10:58:14 +0000 | [diff] [blame] | 255 | S_ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 24, 4, 0xf), /* PerfMon */ |
Suzuki K Poulose | e534350 | 2016-01-26 10:58:13 +0000 | [diff] [blame] | 256 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), |
| 257 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 0), |
| 258 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), |
| 259 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0), |
| 260 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), |
| 261 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), |
| 262 | ARM64_FTR_END, |
| 263 | }; |
| 264 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 265 | /* |
| 266 | * Common ftr bits for a 32bit register with all hidden, strict |
| 267 | * attributes, with 4bit feature fields and a default safe value of |
| 268 | * 0. Covers the following 32bit registers: |
| 269 | * id_isar[0-4], id_mmfr[1-3], id_pfr1, mvfr[0-1] |
| 270 | */ |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 271 | static const struct arm64_ftr_bits ftr_generic_32bits[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 272 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 28, 4, 0), |
| 273 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 24, 4, 0), |
| 274 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 20, 4, 0), |
| 275 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 16, 4, 0), |
| 276 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 12, 4, 0), |
| 277 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 8, 4, 0), |
| 278 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 4, 4, 0), |
| 279 | ARM64_FTR_BITS(FTR_STRICT, FTR_LOWER_SAFE, 0, 4, 0), |
| 280 | ARM64_FTR_END, |
| 281 | }; |
| 282 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 283 | static const struct arm64_ftr_bits ftr_generic[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 284 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 64, 0), |
| 285 | ARM64_FTR_END, |
| 286 | }; |
| 287 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 288 | static const struct arm64_ftr_bits ftr_generic32[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 289 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 32, 0), |
| 290 | ARM64_FTR_END, |
| 291 | }; |
| 292 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 293 | static const struct arm64_ftr_bits ftr_aa64raz[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 294 | ARM64_FTR_BITS(FTR_STRICT, FTR_EXACT, 0, 64, 0), |
| 295 | ARM64_FTR_END, |
| 296 | }; |
| 297 | |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 298 | #define ARM64_FTR_REG(id, table) { \ |
| 299 | .sys_id = id, \ |
| 300 | .reg = &(struct arm64_ftr_reg){ \ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 301 | .name = #id, \ |
| 302 | .ftr_bits = &((table)[0]), \ |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 303 | }} |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 304 | |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 305 | static const struct __ftr_reg_entry { |
| 306 | u32 sys_id; |
| 307 | struct arm64_ftr_reg *reg; |
| 308 | } arm64_ftr_regs[] = { |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 309 | |
| 310 | /* Op1 = 0, CRn = 0, CRm = 1 */ |
| 311 | ARM64_FTR_REG(SYS_ID_PFR0_EL1, ftr_id_pfr0), |
| 312 | ARM64_FTR_REG(SYS_ID_PFR1_EL1, ftr_generic_32bits), |
Suzuki K Poulose | e534350 | 2016-01-26 10:58:13 +0000 | [diff] [blame] | 313 | ARM64_FTR_REG(SYS_ID_DFR0_EL1, ftr_id_dfr0), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 314 | ARM64_FTR_REG(SYS_ID_MMFR0_EL1, ftr_id_mmfr0), |
| 315 | ARM64_FTR_REG(SYS_ID_MMFR1_EL1, ftr_generic_32bits), |
| 316 | ARM64_FTR_REG(SYS_ID_MMFR2_EL1, ftr_generic_32bits), |
| 317 | ARM64_FTR_REG(SYS_ID_MMFR3_EL1, ftr_generic_32bits), |
| 318 | |
| 319 | /* Op1 = 0, CRn = 0, CRm = 2 */ |
| 320 | ARM64_FTR_REG(SYS_ID_ISAR0_EL1, ftr_generic_32bits), |
| 321 | ARM64_FTR_REG(SYS_ID_ISAR1_EL1, ftr_generic_32bits), |
| 322 | ARM64_FTR_REG(SYS_ID_ISAR2_EL1, ftr_generic_32bits), |
| 323 | ARM64_FTR_REG(SYS_ID_ISAR3_EL1, ftr_generic_32bits), |
| 324 | ARM64_FTR_REG(SYS_ID_ISAR4_EL1, ftr_generic_32bits), |
| 325 | ARM64_FTR_REG(SYS_ID_ISAR5_EL1, ftr_id_isar5), |
| 326 | ARM64_FTR_REG(SYS_ID_MMFR4_EL1, ftr_id_mmfr4), |
| 327 | |
| 328 | /* Op1 = 0, CRn = 0, CRm = 3 */ |
| 329 | ARM64_FTR_REG(SYS_MVFR0_EL1, ftr_generic_32bits), |
| 330 | ARM64_FTR_REG(SYS_MVFR1_EL1, ftr_generic_32bits), |
| 331 | ARM64_FTR_REG(SYS_MVFR2_EL1, ftr_mvfr2), |
| 332 | |
| 333 | /* Op1 = 0, CRn = 0, CRm = 4 */ |
| 334 | ARM64_FTR_REG(SYS_ID_AA64PFR0_EL1, ftr_id_aa64pfr0), |
| 335 | ARM64_FTR_REG(SYS_ID_AA64PFR1_EL1, ftr_aa64raz), |
| 336 | |
| 337 | /* Op1 = 0, CRn = 0, CRm = 5 */ |
| 338 | ARM64_FTR_REG(SYS_ID_AA64DFR0_EL1, ftr_id_aa64dfr0), |
| 339 | ARM64_FTR_REG(SYS_ID_AA64DFR1_EL1, ftr_generic), |
| 340 | |
| 341 | /* Op1 = 0, CRn = 0, CRm = 6 */ |
| 342 | ARM64_FTR_REG(SYS_ID_AA64ISAR0_EL1, ftr_id_aa64isar0), |
| 343 | ARM64_FTR_REG(SYS_ID_AA64ISAR1_EL1, ftr_aa64raz), |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 344 | ARM64_FTR_REG(SYS_ID_AA64ISAR2_EL1, ftr_id_aa64isar2), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 345 | |
| 346 | /* Op1 = 0, CRn = 0, CRm = 7 */ |
| 347 | ARM64_FTR_REG(SYS_ID_AA64MMFR0_EL1, ftr_id_aa64mmfr0), |
| 348 | ARM64_FTR_REG(SYS_ID_AA64MMFR1_EL1, ftr_id_aa64mmfr1), |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 349 | ARM64_FTR_REG(SYS_ID_AA64MMFR2_EL1, ftr_id_aa64mmfr2), |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 350 | |
| 351 | /* Op1 = 3, CRn = 0, CRm = 0 */ |
Ard Biesheuvel | 675b056 | 2016-08-31 11:31:10 +0100 | [diff] [blame] | 352 | { SYS_CTR_EL0, &arm64_ftr_reg_ctrel0 }, |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 353 | ARM64_FTR_REG(SYS_DCZID_EL0, ftr_dczid), |
| 354 | |
| 355 | /* Op1 = 3, CRn = 14, CRm = 0 */ |
| 356 | ARM64_FTR_REG(SYS_CNTFRQ_EL0, ftr_generic32), |
| 357 | }; |
| 358 | |
| 359 | static int search_cmp_ftr_reg(const void *id, const void *regp) |
| 360 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 361 | return (int)(unsigned long)id - (int)((const struct __ftr_reg_entry *)regp)->sys_id; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /* |
| 365 | * get_arm64_ftr_reg - Lookup a feature register entry using its |
| 366 | * sys_reg() encoding. With the array arm64_ftr_regs sorted in the |
| 367 | * ascending order of sys_id , we use binary search to find a matching |
| 368 | * entry. |
| 369 | * |
| 370 | * returns - Upon success, matching ftr_reg entry for id. |
| 371 | * - NULL on failure. It is upto the caller to decide |
| 372 | * the impact of a failure. |
| 373 | */ |
| 374 | static struct arm64_ftr_reg *get_arm64_ftr_reg(u32 sys_id) |
| 375 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 376 | const struct __ftr_reg_entry *ret; |
| 377 | |
| 378 | ret = bsearch((const void *)(unsigned long)sys_id, |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 379 | arm64_ftr_regs, |
| 380 | ARRAY_SIZE(arm64_ftr_regs), |
| 381 | sizeof(arm64_ftr_regs[0]), |
| 382 | search_cmp_ftr_reg); |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 383 | if (ret) |
| 384 | return ret->reg; |
| 385 | return NULL; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 388 | static u64 arm64_ftr_set_value(const struct arm64_ftr_bits *ftrp, s64 reg, |
| 389 | s64 ftr_val) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 390 | { |
| 391 | u64 mask = arm64_ftr_mask(ftrp); |
| 392 | |
| 393 | reg &= ~mask; |
| 394 | reg |= (ftr_val << ftrp->shift) & mask; |
| 395 | return reg; |
| 396 | } |
| 397 | |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 398 | static s64 arm64_ftr_safe_value(const struct arm64_ftr_bits *ftrp, s64 new, |
| 399 | s64 cur) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 400 | { |
| 401 | s64 ret = 0; |
| 402 | |
| 403 | switch (ftrp->type) { |
| 404 | case FTR_EXACT: |
| 405 | ret = ftrp->safe_val; |
| 406 | break; |
| 407 | case FTR_LOWER_SAFE: |
| 408 | ret = new < cur ? new : cur; |
| 409 | break; |
Will Deacon | 3c5dbb9 | 2019-08-05 18:13:55 +0100 | [diff] [blame] | 410 | case FTR_HIGHER_OR_ZERO_SAFE: |
| 411 | if (!cur || !new) |
| 412 | break; |
| 413 | /* Fallthrough */ |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 414 | case FTR_HIGHER_SAFE: |
| 415 | ret = new > cur ? new : cur; |
| 416 | break; |
| 417 | default: |
| 418 | BUG(); |
| 419 | } |
| 420 | |
| 421 | return ret; |
| 422 | } |
| 423 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 424 | static void __init sort_ftr_regs(void) |
| 425 | { |
Ard Biesheuvel | 6f2b7ee | 2016-08-31 11:31:09 +0100 | [diff] [blame] | 426 | int i; |
| 427 | |
| 428 | /* Check that the array is sorted so that we can do the binary search */ |
| 429 | for (i = 1; i < ARRAY_SIZE(arm64_ftr_regs); i++) |
| 430 | BUG_ON(arm64_ftr_regs[i].sys_id < arm64_ftr_regs[i - 1].sys_id); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Initialise the CPU feature register from Boot CPU values. |
| 435 | * Also initiliases the strict_mask for the register. |
| 436 | */ |
| 437 | static void __init init_cpu_ftr_reg(u32 sys_reg, u64 new) |
| 438 | { |
| 439 | u64 val = 0; |
| 440 | u64 strict_mask = ~0x0ULL; |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 441 | const struct arm64_ftr_bits *ftrp; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 442 | struct arm64_ftr_reg *reg = get_arm64_ftr_reg(sys_reg); |
| 443 | |
| 444 | BUG_ON(!reg); |
| 445 | |
| 446 | for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) { |
| 447 | s64 ftr_new = arm64_ftr_value(ftrp, new); |
| 448 | |
| 449 | val = arm64_ftr_set_value(ftrp, val, ftr_new); |
| 450 | if (!ftrp->strict) |
| 451 | strict_mask &= ~arm64_ftr_mask(ftrp); |
| 452 | } |
| 453 | reg->sys_val = val; |
| 454 | reg->strict_mask = strict_mask; |
| 455 | } |
| 456 | |
Suzuki K Poulose | 454f7ba | 2022-04-06 17:45:09 +0100 | [diff] [blame] | 457 | extern const struct arm64_cpu_capabilities arm64_errata[]; |
| 458 | static void update_cpu_errata_workarounds(void); |
| 459 | |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 460 | void __init init_cpu_features(struct cpuinfo_arm64 *info) |
| 461 | { |
| 462 | /* Before we start using the tables, make sure it is sorted */ |
| 463 | sort_ftr_regs(); |
| 464 | |
| 465 | init_cpu_ftr_reg(SYS_CTR_EL0, info->reg_ctr); |
| 466 | init_cpu_ftr_reg(SYS_DCZID_EL0, info->reg_dczid); |
| 467 | init_cpu_ftr_reg(SYS_CNTFRQ_EL0, info->reg_cntfrq); |
| 468 | init_cpu_ftr_reg(SYS_ID_AA64DFR0_EL1, info->reg_id_aa64dfr0); |
| 469 | init_cpu_ftr_reg(SYS_ID_AA64DFR1_EL1, info->reg_id_aa64dfr1); |
| 470 | init_cpu_ftr_reg(SYS_ID_AA64ISAR0_EL1, info->reg_id_aa64isar0); |
| 471 | init_cpu_ftr_reg(SYS_ID_AA64ISAR1_EL1, info->reg_id_aa64isar1); |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 472 | init_cpu_ftr_reg(SYS_ID_AA64ISAR2_EL1, info->reg_id_aa64isar2); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 473 | init_cpu_ftr_reg(SYS_ID_AA64MMFR0_EL1, info->reg_id_aa64mmfr0); |
| 474 | init_cpu_ftr_reg(SYS_ID_AA64MMFR1_EL1, info->reg_id_aa64mmfr1); |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 475 | init_cpu_ftr_reg(SYS_ID_AA64MMFR2_EL1, info->reg_id_aa64mmfr2); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 476 | init_cpu_ftr_reg(SYS_ID_AA64PFR0_EL1, info->reg_id_aa64pfr0); |
| 477 | init_cpu_ftr_reg(SYS_ID_AA64PFR1_EL1, info->reg_id_aa64pfr1); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 478 | |
| 479 | if (id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0)) { |
| 480 | init_cpu_ftr_reg(SYS_ID_DFR0_EL1, info->reg_id_dfr0); |
| 481 | init_cpu_ftr_reg(SYS_ID_ISAR0_EL1, info->reg_id_isar0); |
| 482 | init_cpu_ftr_reg(SYS_ID_ISAR1_EL1, info->reg_id_isar1); |
| 483 | init_cpu_ftr_reg(SYS_ID_ISAR2_EL1, info->reg_id_isar2); |
| 484 | init_cpu_ftr_reg(SYS_ID_ISAR3_EL1, info->reg_id_isar3); |
| 485 | init_cpu_ftr_reg(SYS_ID_ISAR4_EL1, info->reg_id_isar4); |
| 486 | init_cpu_ftr_reg(SYS_ID_ISAR5_EL1, info->reg_id_isar5); |
| 487 | init_cpu_ftr_reg(SYS_ID_MMFR0_EL1, info->reg_id_mmfr0); |
| 488 | init_cpu_ftr_reg(SYS_ID_MMFR1_EL1, info->reg_id_mmfr1); |
| 489 | init_cpu_ftr_reg(SYS_ID_MMFR2_EL1, info->reg_id_mmfr2); |
| 490 | init_cpu_ftr_reg(SYS_ID_MMFR3_EL1, info->reg_id_mmfr3); |
| 491 | init_cpu_ftr_reg(SYS_ID_PFR0_EL1, info->reg_id_pfr0); |
| 492 | init_cpu_ftr_reg(SYS_ID_PFR1_EL1, info->reg_id_pfr1); |
| 493 | init_cpu_ftr_reg(SYS_MVFR0_EL1, info->reg_mvfr0); |
| 494 | init_cpu_ftr_reg(SYS_MVFR1_EL1, info->reg_mvfr1); |
| 495 | init_cpu_ftr_reg(SYS_MVFR2_EL1, info->reg_mvfr2); |
| 496 | } |
| 497 | |
Suzuki K Poulose | b63ccc3 | 2022-04-06 17:45:08 +0100 | [diff] [blame] | 498 | /* |
| 499 | * Run the errata work around checks on the boot CPU, once we have |
| 500 | * initialised the cpu feature infrastructure. |
| 501 | */ |
| 502 | update_cpu_errata_workarounds(); |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 503 | } |
| 504 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 505 | static void update_cpu_ftr_reg(struct arm64_ftr_reg *reg, u64 new) |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 506 | { |
Ard Biesheuvel | 5e49d73 | 2016-08-31 11:31:08 +0100 | [diff] [blame] | 507 | const struct arm64_ftr_bits *ftrp; |
Suzuki K. Poulose | 3c739b5 | 2015-10-19 14:24:45 +0100 | [diff] [blame] | 508 | |
| 509 | for (ftrp = reg->ftr_bits; ftrp->width; ftrp++) { |
| 510 | s64 ftr_cur = arm64_ftr_value(ftrp, reg->sys_val); |
| 511 | s64 ftr_new = arm64_ftr_value(ftrp, new); |
| 512 | |
| 513 | if (ftr_cur == ftr_new) |
| 514 | continue; |
| 515 | /* Find a safe value */ |
| 516 | ftr_new = arm64_ftr_safe_value(ftrp, ftr_new, ftr_cur); |
| 517 | reg->sys_val = arm64_ftr_set_value(ftrp, reg->sys_val, ftr_new); |
| 518 | } |
| 519 | |
| 520 | } |
| 521 | |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 522 | static int check_update_ftr_reg(u32 sys_id, int cpu, u64 val, u64 boot) |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 523 | { |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 524 | struct arm64_ftr_reg *regp = get_arm64_ftr_reg(sys_id); |
| 525 | |
| 526 | BUG_ON(!regp); |
| 527 | update_cpu_ftr_reg(regp, val); |
| 528 | if ((boot & regp->strict_mask) == (val & regp->strict_mask)) |
| 529 | return 0; |
| 530 | pr_warn("SANITY CHECK: Unexpected variation in %s. Boot CPU: %#016llx, CPU%d: %#016llx\n", |
| 531 | regp->name, boot, cpu, val); |
| 532 | return 1; |
| 533 | } |
| 534 | |
| 535 | /* |
| 536 | * Update system wide CPU feature registers with the values from a |
| 537 | * non-boot CPU. Also performs SANITY checks to make sure that there |
| 538 | * aren't any insane variations from that of the boot CPU. |
| 539 | */ |
| 540 | void update_cpu_features(int cpu, |
| 541 | struct cpuinfo_arm64 *info, |
| 542 | struct cpuinfo_arm64 *boot) |
| 543 | { |
| 544 | int taint = 0; |
| 545 | |
| 546 | /* |
| 547 | * The kernel can handle differing I-cache policies, but otherwise |
| 548 | * caches should look identical. Userspace JITs will make use of |
| 549 | * *minLine. |
| 550 | */ |
| 551 | taint |= check_update_ftr_reg(SYS_CTR_EL0, cpu, |
| 552 | info->reg_ctr, boot->reg_ctr); |
| 553 | |
| 554 | /* |
| 555 | * Userspace may perform DC ZVA instructions. Mismatched block sizes |
| 556 | * could result in too much or too little memory being zeroed if a |
| 557 | * process is preempted and migrated between CPUs. |
| 558 | */ |
| 559 | taint |= check_update_ftr_reg(SYS_DCZID_EL0, cpu, |
| 560 | info->reg_dczid, boot->reg_dczid); |
| 561 | |
| 562 | /* If different, timekeeping will be broken (especially with KVM) */ |
| 563 | taint |= check_update_ftr_reg(SYS_CNTFRQ_EL0, cpu, |
| 564 | info->reg_cntfrq, boot->reg_cntfrq); |
| 565 | |
| 566 | /* |
| 567 | * The kernel uses self-hosted debug features and expects CPUs to |
| 568 | * support identical debug features. We presently need CTX_CMPs, WRPs, |
| 569 | * and BRPs to be identical. |
| 570 | * ID_AA64DFR1 is currently RES0. |
| 571 | */ |
| 572 | taint |= check_update_ftr_reg(SYS_ID_AA64DFR0_EL1, cpu, |
| 573 | info->reg_id_aa64dfr0, boot->reg_id_aa64dfr0); |
| 574 | taint |= check_update_ftr_reg(SYS_ID_AA64DFR1_EL1, cpu, |
| 575 | info->reg_id_aa64dfr1, boot->reg_id_aa64dfr1); |
| 576 | /* |
| 577 | * Even in big.LITTLE, processors should be identical instruction-set |
| 578 | * wise. |
| 579 | */ |
| 580 | taint |= check_update_ftr_reg(SYS_ID_AA64ISAR0_EL1, cpu, |
| 581 | info->reg_id_aa64isar0, boot->reg_id_aa64isar0); |
| 582 | taint |= check_update_ftr_reg(SYS_ID_AA64ISAR1_EL1, cpu, |
| 583 | info->reg_id_aa64isar1, boot->reg_id_aa64isar1); |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 584 | taint |= check_update_ftr_reg(SYS_ID_AA64ISAR2_EL1, cpu, |
| 585 | info->reg_id_aa64isar2, boot->reg_id_aa64isar2); |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * Differing PARange support is fine as long as all peripherals and |
| 589 | * memory are mapped within the minimum PARange of all CPUs. |
| 590 | * Linux should not care about secure memory. |
| 591 | */ |
| 592 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR0_EL1, cpu, |
| 593 | info->reg_id_aa64mmfr0, boot->reg_id_aa64mmfr0); |
| 594 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR1_EL1, cpu, |
| 595 | info->reg_id_aa64mmfr1, boot->reg_id_aa64mmfr1); |
James Morse | 406e308 | 2016-02-05 14:58:47 +0000 | [diff] [blame] | 596 | taint |= check_update_ftr_reg(SYS_ID_AA64MMFR2_EL1, cpu, |
| 597 | info->reg_id_aa64mmfr2, boot->reg_id_aa64mmfr2); |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * EL3 is not our concern. |
| 601 | * ID_AA64PFR1 is currently RES0. |
| 602 | */ |
| 603 | taint |= check_update_ftr_reg(SYS_ID_AA64PFR0_EL1, cpu, |
| 604 | info->reg_id_aa64pfr0, boot->reg_id_aa64pfr0); |
| 605 | taint |= check_update_ftr_reg(SYS_ID_AA64PFR1_EL1, cpu, |
| 606 | info->reg_id_aa64pfr1, boot->reg_id_aa64pfr1); |
| 607 | |
| 608 | /* |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 609 | * If we have AArch32, we care about 32-bit features for compat. |
| 610 | * If the system doesn't support AArch32, don't update them. |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 611 | */ |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 612 | if (id_aa64pfr0_32bit_el0(read_system_reg(SYS_ID_AA64PFR0_EL1)) && |
| 613 | id_aa64pfr0_32bit_el0(info->reg_id_aa64pfr0)) { |
| 614 | |
| 615 | taint |= check_update_ftr_reg(SYS_ID_DFR0_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 616 | info->reg_id_dfr0, boot->reg_id_dfr0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 617 | taint |= check_update_ftr_reg(SYS_ID_ISAR0_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 618 | info->reg_id_isar0, boot->reg_id_isar0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 619 | taint |= check_update_ftr_reg(SYS_ID_ISAR1_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 620 | info->reg_id_isar1, boot->reg_id_isar1); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 621 | taint |= check_update_ftr_reg(SYS_ID_ISAR2_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 622 | info->reg_id_isar2, boot->reg_id_isar2); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 623 | taint |= check_update_ftr_reg(SYS_ID_ISAR3_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 624 | info->reg_id_isar3, boot->reg_id_isar3); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 625 | taint |= check_update_ftr_reg(SYS_ID_ISAR4_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 626 | info->reg_id_isar4, boot->reg_id_isar4); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 627 | taint |= check_update_ftr_reg(SYS_ID_ISAR5_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 628 | info->reg_id_isar5, boot->reg_id_isar5); |
| 629 | |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 630 | /* |
| 631 | * Regardless of the value of the AuxReg field, the AIFSR, ADFSR, and |
| 632 | * ACTLR formats could differ across CPUs and therefore would have to |
| 633 | * be trapped for virtualization anyway. |
| 634 | */ |
| 635 | taint |= check_update_ftr_reg(SYS_ID_MMFR0_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 636 | info->reg_id_mmfr0, boot->reg_id_mmfr0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 637 | taint |= check_update_ftr_reg(SYS_ID_MMFR1_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 638 | info->reg_id_mmfr1, boot->reg_id_mmfr1); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 639 | taint |= check_update_ftr_reg(SYS_ID_MMFR2_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 640 | info->reg_id_mmfr2, boot->reg_id_mmfr2); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 641 | taint |= check_update_ftr_reg(SYS_ID_MMFR3_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 642 | info->reg_id_mmfr3, boot->reg_id_mmfr3); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 643 | taint |= check_update_ftr_reg(SYS_ID_PFR0_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 644 | info->reg_id_pfr0, boot->reg_id_pfr0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 645 | taint |= check_update_ftr_reg(SYS_ID_PFR1_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 646 | info->reg_id_pfr1, boot->reg_id_pfr1); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 647 | taint |= check_update_ftr_reg(SYS_MVFR0_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 648 | info->reg_mvfr0, boot->reg_mvfr0); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 649 | taint |= check_update_ftr_reg(SYS_MVFR1_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 650 | info->reg_mvfr1, boot->reg_mvfr1); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 651 | taint |= check_update_ftr_reg(SYS_MVFR2_EL1, cpu, |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 652 | info->reg_mvfr2, boot->reg_mvfr2); |
Suzuki K Poulose | a6dc3cd | 2016-04-18 10:28:35 +0100 | [diff] [blame] | 653 | } |
Suzuki K. Poulose | 3086d39 | 2015-10-19 14:24:46 +0100 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | * Mismatched CPU features are a recipe for disaster. Don't even |
| 657 | * pretend to support them. |
| 658 | */ |
| 659 | WARN_TAINT_ONCE(taint, TAINT_CPU_OUT_OF_SPEC, |
| 660 | "Unsupported CPU feature variation.\n"); |
Suzuki K. Poulose | cdcf817 | 2015-10-19 14:24:42 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Suzuki K. Poulose | b3f1537 | 2015-10-19 14:24:47 +0100 | [diff] [blame] | 663 | u64 read_system_reg(u32 id) |
| 664 | { |
| 665 | struct arm64_ftr_reg *regp = get_arm64_ftr_reg(id); |
| 666 | |
| 667 | /* We shouldn't get a request for an unsupported register */ |
| 668 | BUG_ON(!regp); |
| 669 | return regp->sys_val; |
| 670 | } |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 671 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 672 | /* |
| 673 | * __raw_read_system_reg() - Used by a STARTING cpu before cpuinfo is populated. |
| 674 | * Read the system register on the current CPU |
| 675 | */ |
| 676 | static u64 __raw_read_system_reg(u32 sys_id) |
| 677 | { |
| 678 | switch (sys_id) { |
| 679 | case SYS_ID_PFR0_EL1: return read_cpuid(ID_PFR0_EL1); |
| 680 | case SYS_ID_PFR1_EL1: return read_cpuid(ID_PFR1_EL1); |
| 681 | case SYS_ID_DFR0_EL1: return read_cpuid(ID_DFR0_EL1); |
| 682 | case SYS_ID_MMFR0_EL1: return read_cpuid(ID_MMFR0_EL1); |
| 683 | case SYS_ID_MMFR1_EL1: return read_cpuid(ID_MMFR1_EL1); |
| 684 | case SYS_ID_MMFR2_EL1: return read_cpuid(ID_MMFR2_EL1); |
| 685 | case SYS_ID_MMFR3_EL1: return read_cpuid(ID_MMFR3_EL1); |
| 686 | case SYS_ID_ISAR0_EL1: return read_cpuid(ID_ISAR0_EL1); |
| 687 | case SYS_ID_ISAR1_EL1: return read_cpuid(ID_ISAR1_EL1); |
| 688 | case SYS_ID_ISAR2_EL1: return read_cpuid(ID_ISAR2_EL1); |
| 689 | case SYS_ID_ISAR3_EL1: return read_cpuid(ID_ISAR3_EL1); |
| 690 | case SYS_ID_ISAR4_EL1: return read_cpuid(ID_ISAR4_EL1); |
Mark Rutland | 7127d43 | 2017-02-02 17:32:14 +0000 | [diff] [blame] | 691 | case SYS_ID_ISAR5_EL1: return read_cpuid(ID_ISAR5_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 692 | case SYS_MVFR0_EL1: return read_cpuid(MVFR0_EL1); |
| 693 | case SYS_MVFR1_EL1: return read_cpuid(MVFR1_EL1); |
| 694 | case SYS_MVFR2_EL1: return read_cpuid(MVFR2_EL1); |
| 695 | |
| 696 | case SYS_ID_AA64PFR0_EL1: return read_cpuid(ID_AA64PFR0_EL1); |
Mark Rutland | 7127d43 | 2017-02-02 17:32:14 +0000 | [diff] [blame] | 697 | case SYS_ID_AA64PFR1_EL1: return read_cpuid(ID_AA64PFR1_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 698 | case SYS_ID_AA64DFR0_EL1: return read_cpuid(ID_AA64DFR0_EL1); |
Mark Rutland | 7127d43 | 2017-02-02 17:32:14 +0000 | [diff] [blame] | 699 | case SYS_ID_AA64DFR1_EL1: return read_cpuid(ID_AA64DFR1_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 700 | case SYS_ID_AA64MMFR0_EL1: return read_cpuid(ID_AA64MMFR0_EL1); |
| 701 | case SYS_ID_AA64MMFR1_EL1: return read_cpuid(ID_AA64MMFR1_EL1); |
| 702 | case SYS_ID_AA64MMFR2_EL1: return read_cpuid(ID_AA64MMFR2_EL1); |
| 703 | case SYS_ID_AA64ISAR0_EL1: return read_cpuid(ID_AA64ISAR0_EL1); |
| 704 | case SYS_ID_AA64ISAR1_EL1: return read_cpuid(ID_AA64ISAR1_EL1); |
James Morse | 9396d5e | 2022-04-06 17:45:45 +0100 | [diff] [blame] | 705 | case SYS_ID_AA64ISAR2_EL1: return read_cpuid(ID_AA64ISAR2_EL1); |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 706 | |
| 707 | case SYS_CNTFRQ_EL0: return read_cpuid(CNTFRQ_EL0); |
| 708 | case SYS_CTR_EL0: return read_cpuid(CTR_EL0); |
| 709 | case SYS_DCZID_EL0: return read_cpuid(DCZID_EL0); |
| 710 | default: |
| 711 | BUG(); |
| 712 | return 0; |
| 713 | } |
| 714 | } |
| 715 | |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 716 | #include <linux/irqchip/arm-gic-v3.h> |
| 717 | |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 718 | static bool |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 719 | feature_matches(u64 reg, const struct arm64_cpu_capabilities *entry) |
| 720 | { |
Suzuki K Poulose | 28c5dcb | 2016-01-26 10:58:16 +0000 | [diff] [blame] | 721 | int val = cpuid_feature_extract_field(reg, entry->field_pos, entry->sign); |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 722 | |
| 723 | return val >= entry->min_field_value; |
| 724 | } |
| 725 | |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 726 | static bool |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 727 | has_cpuid_feature(const struct arm64_cpu_capabilities *entry, int scope) |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 728 | { |
| 729 | u64 val; |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 730 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 731 | WARN_ON(scope == SCOPE_LOCAL_CPU && preemptible()); |
| 732 | if (scope == SCOPE_SYSTEM) |
| 733 | val = read_system_reg(entry->sys_reg); |
| 734 | else |
| 735 | val = __raw_read_system_reg(entry->sys_reg); |
| 736 | |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 737 | return feature_matches(val, entry); |
| 738 | } |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 739 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 740 | static bool has_useable_gicv3_cpuif(const struct arm64_cpu_capabilities *entry, int scope) |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 741 | { |
| 742 | bool has_sre; |
| 743 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 744 | if (!has_cpuid_feature(entry, scope)) |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 745 | return false; |
| 746 | |
| 747 | has_sre = gic_enable_sre(); |
| 748 | if (!has_sre) |
| 749 | pr_warn_once("%s present but disabled by higher exception level\n", |
| 750 | entry->desc); |
| 751 | |
| 752 | return has_sre; |
| 753 | } |
| 754 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 755 | static bool has_no_hw_prefetch(const struct arm64_cpu_capabilities *entry, int __unused) |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 756 | { |
| 757 | u32 midr = read_cpuid_id(); |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 758 | |
| 759 | /* Cavium ThunderX pass 1.x and 2.x */ |
Robert Richter | 6e1ad7a | 2022-04-06 17:45:04 +0100 | [diff] [blame] | 760 | return MIDR_IS_CPU_MODEL_RANGE(midr, MIDR_THUNDERX, |
| 761 | MIDR_CPU_VAR_REV(0, 0), |
| 762 | MIDR_CPU_VAR_REV(1, MIDR_REVISION_MASK)); |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 763 | } |
| 764 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 765 | static bool runs_at_el2(const struct arm64_cpu_capabilities *entry, int __unused) |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 766 | { |
| 767 | return is_kernel_in_hyp_mode(); |
| 768 | } |
| 769 | |
Marc Zyngier | d174591 | 2016-06-30 18:40:42 +0100 | [diff] [blame] | 770 | static bool hyp_offset_low(const struct arm64_cpu_capabilities *entry, |
| 771 | int __unused) |
| 772 | { |
Laura Abbott | f8fee94e | 2017-01-10 13:35:49 -0800 | [diff] [blame] | 773 | phys_addr_t idmap_addr = __pa_symbol(__hyp_idmap_text_start); |
Marc Zyngier | d174591 | 2016-06-30 18:40:42 +0100 | [diff] [blame] | 774 | |
| 775 | /* |
| 776 | * Activate the lower HYP offset only if: |
| 777 | * - the idmap doesn't clash with it, |
| 778 | * - the kernel is not running at EL2. |
| 779 | */ |
| 780 | return idmap_addr > GENMASK(VA_BITS - 2, 0) && !is_kernel_in_hyp_mode(); |
| 781 | } |
| 782 | |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 783 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
| 784 | static int __kpti_forced; /* 0: not forced, >0: forced on, <0: forced off */ |
| 785 | |
| 786 | static bool unmap_kernel_at_el0(const struct arm64_cpu_capabilities *entry, |
| 787 | int __unused) |
| 788 | { |
Suzuki K Poulose | c681550 | 2022-04-06 17:45:14 +0100 | [diff] [blame] | 789 | /* List of CPUs that are not vulnerable and don't need KPTI */ |
| 790 | static const struct midr_range kpti_safe_list[] = { |
| 791 | MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2), |
| 792 | MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN), |
| 793 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A35), |
| 794 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A53), |
| 795 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A55), |
| 796 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A57), |
| 797 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A72), |
| 798 | MIDR_ALL_VERSIONS(MIDR_CORTEX_A73), |
| 799 | }; |
Marc Zyngier | da93510 | 2018-04-03 12:09:21 +0100 | [diff] [blame] | 800 | char const *str = "command line option"; |
Will Deacon | 7354772 | 2018-04-03 12:09:14 +0100 | [diff] [blame] | 801 | u64 pfr0 = read_system_reg(SYS_ID_AA64PFR0_EL1); |
| 802 | |
Marc Zyngier | da93510 | 2018-04-03 12:09:21 +0100 | [diff] [blame] | 803 | /* |
| 804 | * For reasons that aren't entirely clear, enabling KPTI on Cavium |
| 805 | * ThunderX leads to apparent I-cache corruption of kernel text, which |
| 806 | * ends as well as you might imagine. Don't even try. |
| 807 | */ |
Suzuki K Poulose | fe64d7d | 2016-11-08 13:56:20 +0000 | [diff] [blame] | 808 | if (cpus_have_const_cap(ARM64_WORKAROUND_CAVIUM_27456)) { |
Marc Zyngier | da93510 | 2018-04-03 12:09:21 +0100 | [diff] [blame] | 809 | str = "ARM64_WORKAROUND_CAVIUM_27456"; |
| 810 | __kpti_forced = -1; |
| 811 | } |
| 812 | |
| 813 | /* Forced? */ |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 814 | if (__kpti_forced) { |
Marc Zyngier | da93510 | 2018-04-03 12:09:21 +0100 | [diff] [blame] | 815 | pr_info_once("kernel page table isolation forced %s by %s\n", |
| 816 | __kpti_forced > 0 ? "ON" : "OFF", str); |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 817 | return __kpti_forced > 0; |
| 818 | } |
| 819 | |
| 820 | /* Useful for KASLR robustness */ |
| 821 | if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) |
| 822 | return true; |
| 823 | |
Jayachandran C | 2adcb1f | 2018-04-03 12:09:18 +0100 | [diff] [blame] | 824 | /* Don't force KPTI for CPUs that are not vulnerable */ |
Suzuki K Poulose | c681550 | 2022-04-06 17:45:14 +0100 | [diff] [blame] | 825 | if (is_midr_in_range_list(read_cpuid_id(), kpti_safe_list)) |
Jayachandran C | 2adcb1f | 2018-04-03 12:09:18 +0100 | [diff] [blame] | 826 | return false; |
Jayachandran C | 2adcb1f | 2018-04-03 12:09:18 +0100 | [diff] [blame] | 827 | |
Will Deacon | 7354772 | 2018-04-03 12:09:14 +0100 | [diff] [blame] | 828 | /* Defer to CPU feature registers */ |
| 829 | return !cpuid_feature_extract_unsigned_field(pfr0, |
| 830 | ID_AA64PFR0_CSV3_SHIFT); |
Will Deacon | bfca157 | 2018-04-03 12:09:09 +0100 | [diff] [blame] | 831 | } |
| 832 | |
Greg Kroah-Hartman | 28d1339 | 2022-04-12 08:16:55 +0200 | [diff] [blame] | 833 | static void __nocfi |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 834 | kpti_install_ng_mappings(const struct arm64_cpu_capabilities *__unused) |
Will Deacon | 4025fe1 | 2018-04-03 12:09:20 +0100 | [diff] [blame] | 835 | { |
| 836 | typedef void (kpti_remap_fn)(int, int, phys_addr_t); |
| 837 | extern kpti_remap_fn idmap_kpti_install_ng_mappings; |
| 838 | kpti_remap_fn *remap_fn; |
| 839 | |
| 840 | static bool kpti_applied = false; |
| 841 | int cpu = smp_processor_id(); |
| 842 | |
James Morse | 1451b7f | 2022-04-06 17:45:41 +0100 | [diff] [blame] | 843 | if (__this_cpu_read(this_cpu_vector) == vectors) { |
| 844 | const char *v = arm64_get_bp_hardening_vector(EL1_VECTOR_KPTI); |
| 845 | |
| 846 | __this_cpu_write(this_cpu_vector, v); |
| 847 | } |
| 848 | |
Will Deacon | 4025fe1 | 2018-04-03 12:09:20 +0100 | [diff] [blame] | 849 | if (kpti_applied) |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 850 | return; |
Will Deacon | 4025fe1 | 2018-04-03 12:09:20 +0100 | [diff] [blame] | 851 | |
| 852 | remap_fn = (void *)__pa_symbol(idmap_kpti_install_ng_mappings); |
| 853 | |
| 854 | cpu_install_idmap(); |
| 855 | remap_fn(cpu, num_online_cpus(), __pa_symbol(swapper_pg_dir)); |
| 856 | cpu_uninstall_idmap(); |
| 857 | |
| 858 | if (!cpu) |
| 859 | kpti_applied = true; |
| 860 | |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 861 | return; |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | static int __init parse_kpti(char *str) |
| 865 | { |
| 866 | bool enabled; |
| 867 | int ret = strtobool(str, &enabled); |
| 868 | |
| 869 | if (ret) |
| 870 | return ret; |
| 871 | |
| 872 | __kpti_forced = enabled ? 1 : -1; |
| 873 | return 0; |
| 874 | } |
Will Deacon | 12942d5 | 2018-06-22 10:25:25 +0100 | [diff] [blame] | 875 | early_param("kpti", parse_kpti); |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 876 | #endif /* CONFIG_UNMAP_KERNEL_AT_EL0 */ |
| 877 | |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 878 | static void cpu_copy_el2regs(const struct arm64_cpu_capabilities *__unused) |
James Morse | eea5902 | 2018-07-20 10:56:16 +0100 | [diff] [blame] | 879 | { |
| 880 | /* |
| 881 | * Copy register values that aren't redirected by hardware. |
| 882 | * |
| 883 | * Before code patching, we only set tpidr_el1, all CPUs need to copy |
| 884 | * this value to tpidr_el2 before we patch the code. Once we've done |
| 885 | * that, freshly-onlined CPUs will set tpidr_el2, so we don't need to |
| 886 | * do anything here. |
| 887 | */ |
| 888 | if (!alternatives_applied) |
| 889 | write_sysreg(read_sysreg(tpidr_el1), tpidr_el2); |
James Morse | eea5902 | 2018-07-20 10:56:16 +0100 | [diff] [blame] | 890 | } |
| 891 | |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 892 | static const struct arm64_cpu_capabilities arm64_features[] = { |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 893 | { |
| 894 | .desc = "GIC system register CPU interface", |
| 895 | .capability = ARM64_HAS_SYSREG_GIC_CPUIF, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 896 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Marc Zyngier | 963fcd4 | 2015-09-30 11:50:04 +0100 | [diff] [blame] | 897 | .matches = has_useable_gicv3_cpuif, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 898 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 899 | .field_pos = ID_AA64PFR0_GIC_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 900 | .sign = FTR_UNSIGNED, |
James Morse | 18ffa04 | 2015-07-21 13:23:29 +0100 | [diff] [blame] | 901 | .min_field_value = 1, |
Marc Zyngier | 94a9e04 | 2015-06-12 12:06:36 +0100 | [diff] [blame] | 902 | }, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 903 | #ifdef CONFIG_ARM64_PAN |
| 904 | { |
| 905 | .desc = "Privileged Access Never", |
| 906 | .capability = ARM64_HAS_PAN, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 907 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 908 | .matches = has_cpuid_feature, |
| 909 | .sys_reg = SYS_ID_AA64MMFR1_EL1, |
| 910 | .field_pos = ID_AA64MMFR1_PAN_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 911 | .sign = FTR_UNSIGNED, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 912 | .min_field_value = 1, |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 913 | .cpu_enable = cpu_enable_pan, |
James Morse | 338d4f4 | 2015-07-22 19:05:54 +0100 | [diff] [blame] | 914 | }, |
| 915 | #endif /* CONFIG_ARM64_PAN */ |
Will Deacon | 2e94da1 | 2015-07-27 16:23:58 +0100 | [diff] [blame] | 916 | #if defined(CONFIG_AS_LSE) && defined(CONFIG_ARM64_LSE_ATOMICS) |
| 917 | { |
| 918 | .desc = "LSE atomic instructions", |
| 919 | .capability = ARM64_HAS_LSE_ATOMICS, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 920 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K. Poulose | da8d02d | 2015-10-19 14:24:51 +0100 | [diff] [blame] | 921 | .matches = has_cpuid_feature, |
| 922 | .sys_reg = SYS_ID_AA64ISAR0_EL1, |
| 923 | .field_pos = ID_AA64ISAR0_ATOMICS_SHIFT, |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 924 | .sign = FTR_UNSIGNED, |
Will Deacon | 2e94da1 | 2015-07-27 16:23:58 +0100 | [diff] [blame] | 925 | .min_field_value = 2, |
| 926 | }, |
| 927 | #endif /* CONFIG_AS_LSE && CONFIG_ARM64_LSE_ATOMICS */ |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 928 | { |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 929 | .desc = "Software prefetching using PRFM", |
| 930 | .capability = ARM64_HAS_NO_HW_PREFETCH, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 931 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Will Deacon | d5370f7 | 2016-02-02 12:46:24 +0000 | [diff] [blame] | 932 | .matches = has_no_hw_prefetch, |
| 933 | }, |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 934 | #ifdef CONFIG_ARM64_UAO |
| 935 | { |
| 936 | .desc = "User Access Override", |
| 937 | .capability = ARM64_HAS_UAO, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 938 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 939 | .matches = has_cpuid_feature, |
| 940 | .sys_reg = SYS_ID_AA64MMFR2_EL1, |
| 941 | .field_pos = ID_AA64MMFR2_UAO_SHIFT, |
| 942 | .min_field_value = 1, |
James Morse | 7f319f3 | 2022-04-06 17:45:05 +0100 | [diff] [blame] | 943 | /* |
| 944 | * We rely on stop_machine() calling uao_thread_switch() to set |
| 945 | * UAO immediately after patching. |
| 946 | */ |
James Morse | 57f4959 | 2016-02-05 14:58:48 +0000 | [diff] [blame] | 947 | }, |
| 948 | #endif /* CONFIG_ARM64_UAO */ |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 949 | #ifdef CONFIG_ARM64_PAN |
| 950 | { |
| 951 | .capability = ARM64_ALT_PAN_NOT_UAO, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 952 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 953 | .matches = cpufeature_pan_not_uao, |
| 954 | }, |
| 955 | #endif /* CONFIG_ARM64_PAN */ |
Linus Torvalds | 588ab3f | 2016-03-17 20:03:47 -0700 | [diff] [blame] | 956 | { |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 957 | .desc = "Virtualization Host Extensions", |
| 958 | .capability = ARM64_HAS_VIRT_HOST_EXTN, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 959 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 960 | .matches = runs_at_el2, |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 961 | .cpu_enable = cpu_copy_el2regs, |
Marc Zyngier | d88701b | 2015-01-29 11:24:05 +0000 | [diff] [blame] | 962 | }, |
Suzuki K Poulose | 042446a | 2016-04-18 10:28:36 +0100 | [diff] [blame] | 963 | { |
| 964 | .desc = "32-bit EL0 Support", |
| 965 | .capability = ARM64_HAS_32BIT_EL0, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 966 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Suzuki K Poulose | 042446a | 2016-04-18 10:28:36 +0100 | [diff] [blame] | 967 | .matches = has_cpuid_feature, |
| 968 | .sys_reg = SYS_ID_AA64PFR0_EL1, |
| 969 | .sign = FTR_UNSIGNED, |
| 970 | .field_pos = ID_AA64PFR0_EL0_SHIFT, |
| 971 | .min_field_value = ID_AA64PFR0_EL0_32BIT_64BIT, |
| 972 | }, |
Marc Zyngier | d174591 | 2016-06-30 18:40:42 +0100 | [diff] [blame] | 973 | { |
| 974 | .desc = "Reduced HYP mapping offset", |
| 975 | .capability = ARM64_HYP_OFFSET_LOW, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 976 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Marc Zyngier | d174591 | 2016-06-30 18:40:42 +0100 | [diff] [blame] | 977 | .matches = hyp_offset_low, |
| 978 | }, |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 979 | #ifdef CONFIG_UNMAP_KERNEL_AT_EL0 |
| 980 | { |
Will Deacon | 7354772 | 2018-04-03 12:09:14 +0100 | [diff] [blame] | 981 | .desc = "Kernel page table isolation (KPTI)", |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 982 | .capability = ARM64_UNMAP_KERNEL_AT_EL0, |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 983 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 984 | .matches = unmap_kernel_at_el0, |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 985 | .cpu_enable = kpti_install_ng_mappings, |
Will Deacon | f79ff2d | 2017-11-14 14:38:19 +0000 | [diff] [blame] | 986 | }, |
| 987 | #endif |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 988 | {}, |
| 989 | }; |
| 990 | |
Suzuki K Poulose | 3d108b7 | 2022-04-06 17:45:10 +0100 | [diff] [blame] | 991 | #define HWCAP_CAP(reg, field, s, min_value, cap_type, cap) \ |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 992 | { \ |
| 993 | .desc = #cap, \ |
Suzuki K Poulose | b49720b | 2022-04-06 17:45:11 +0100 | [diff] [blame] | 994 | .type = ARM64_CPUCAP_SYSTEM_FEATURE, \ |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 995 | .matches = has_cpuid_feature, \ |
| 996 | .sys_reg = reg, \ |
| 997 | .field_pos = field, \ |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 998 | .sign = s, \ |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 999 | .min_field_value = min_value, \ |
Suzuki K Poulose | 3d108b7 | 2022-04-06 17:45:10 +0100 | [diff] [blame] | 1000 | .hwcap_type = cap_type, \ |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1001 | .hwcap = cap, \ |
| 1002 | } |
| 1003 | |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 1004 | static const struct arm64_cpu_capabilities arm64_elf_hwcaps[] = { |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1005 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_PMULL), |
| 1006 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_AES_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_AES), |
| 1007 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA1), |
| 1008 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA2), |
Suzuki K Poulose | ba62b30 | 2017-10-11 14:01:02 +0100 | [diff] [blame] | 1009 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA2_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_SHA512), |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1010 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_CRC32), |
| 1011 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_ATOMICS_SHIFT, FTR_UNSIGNED, 2, CAP_HWCAP, HWCAP_ATOMICS), |
Suzuki K Poulose | ba62b30 | 2017-10-11 14:01:02 +0100 | [diff] [blame] | 1012 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SHA3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SHA3), |
| 1013 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM3_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SM3), |
| 1014 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_SM4_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_SM4), |
| 1015 | HWCAP_CAP(SYS_ID_AA64ISAR0_EL1, ID_AA64ISAR0_DP_SHIFT, FTR_UNSIGNED, 1, CAP_HWCAP, HWCAP_ASIMDDP), |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1016 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_FP), |
Suzuki K Poulose | bf50061 | 2016-01-26 15:52:46 +0000 | [diff] [blame] | 1017 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_FP_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_FPHP), |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1018 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 0, CAP_HWCAP, HWCAP_ASIMD), |
Suzuki K Poulose | bf50061 | 2016-01-26 15:52:46 +0000 | [diff] [blame] | 1019 | HWCAP_CAP(SYS_ID_AA64PFR0_EL1, ID_AA64PFR0_ASIMD_SHIFT, FTR_SIGNED, 1, CAP_HWCAP, HWCAP_ASIMDHP), |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1020 | {}, |
| 1021 | }; |
| 1022 | |
| 1023 | static const struct arm64_cpu_capabilities compat_elf_hwcaps[] = { |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1024 | #ifdef CONFIG_COMPAT |
Suzuki K Poulose | ff96f7b | 2016-01-26 10:58:15 +0000 | [diff] [blame] | 1025 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 2, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_PMULL), |
| 1026 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_AES_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_AES), |
| 1027 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA1_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA1), |
| 1028 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_SHA2_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_SHA2), |
| 1029 | HWCAP_CAP(SYS_ID_ISAR5_EL1, ID_ISAR5_CRC32_SHIFT, FTR_UNSIGNED, 1, CAP_COMPAT_HWCAP2, COMPAT_HWCAP2_CRC32), |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1030 | #endif |
| 1031 | {}, |
| 1032 | }; |
| 1033 | |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 1034 | static void __init cap_set_elf_hwcap(const struct arm64_cpu_capabilities *cap) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1035 | { |
| 1036 | switch (cap->hwcap_type) { |
| 1037 | case CAP_HWCAP: |
| 1038 | elf_hwcap |= cap->hwcap; |
| 1039 | break; |
| 1040 | #ifdef CONFIG_COMPAT |
| 1041 | case CAP_COMPAT_HWCAP: |
| 1042 | compat_elf_hwcap |= (u32)cap->hwcap; |
| 1043 | break; |
| 1044 | case CAP_COMPAT_HWCAP2: |
| 1045 | compat_elf_hwcap2 |= (u32)cap->hwcap; |
| 1046 | break; |
| 1047 | #endif |
| 1048 | default: |
| 1049 | WARN_ON(1); |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | /* Check if we have a particular HWCAP enabled */ |
Suzuki K Poulose | f3efb67 | 2016-04-18 10:28:32 +0100 | [diff] [blame] | 1055 | static bool cpus_have_elf_hwcap(const struct arm64_cpu_capabilities *cap) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1056 | { |
| 1057 | bool rc; |
| 1058 | |
| 1059 | switch (cap->hwcap_type) { |
| 1060 | case CAP_HWCAP: |
| 1061 | rc = (elf_hwcap & cap->hwcap) != 0; |
| 1062 | break; |
| 1063 | #ifdef CONFIG_COMPAT |
| 1064 | case CAP_COMPAT_HWCAP: |
| 1065 | rc = (compat_elf_hwcap & (u32)cap->hwcap) != 0; |
| 1066 | break; |
| 1067 | case CAP_COMPAT_HWCAP2: |
| 1068 | rc = (compat_elf_hwcap2 & (u32)cap->hwcap) != 0; |
| 1069 | break; |
| 1070 | #endif |
| 1071 | default: |
| 1072 | WARN_ON(1); |
| 1073 | rc = false; |
| 1074 | } |
| 1075 | |
| 1076 | return rc; |
| 1077 | } |
| 1078 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1079 | static void __init setup_elf_hwcaps(const struct arm64_cpu_capabilities *hwcaps) |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1080 | { |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1081 | for (; hwcaps->matches; hwcaps++) |
Suzuki K Poulose | 3d108b7 | 2022-04-06 17:45:10 +0100 | [diff] [blame] | 1082 | if (hwcaps->matches(hwcaps, cpucap_default_scope(hwcaps))) |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1083 | cap_set_elf_hwcap(hwcaps); |
Suzuki K. Poulose | 37b01d53 | 2015-10-19 14:24:52 +0100 | [diff] [blame] | 1084 | } |
| 1085 | |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1086 | /* |
| 1087 | * Check if the current CPU has a given feature capability. |
| 1088 | * Should be called from non-preemptible context. |
| 1089 | */ |
| 1090 | static bool __this_cpu_has_cap(const struct arm64_cpu_capabilities *cap_array, |
| 1091 | unsigned int cap) |
| 1092 | { |
| 1093 | const struct arm64_cpu_capabilities *caps; |
| 1094 | |
| 1095 | if (WARN_ON(preemptible())) |
| 1096 | return false; |
| 1097 | |
Mark Rutland | 93f339e | 2018-04-12 12:11:07 +0100 | [diff] [blame] | 1098 | for (caps = cap_array; caps->matches; caps++) |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1099 | if (caps->capability == cap && |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1100 | caps->matches(caps, SCOPE_LOCAL_CPU)) |
| 1101 | return true; |
| 1102 | return false; |
| 1103 | } |
| 1104 | |
Suzuki K Poulose | 454f7ba | 2022-04-06 17:45:09 +0100 | [diff] [blame] | 1105 | static void update_cpu_capabilities(const struct arm64_cpu_capabilities *caps, |
| 1106 | const char *info) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1107 | { |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1108 | for (; caps->matches; caps++) { |
Suzuki K Poulose | 3d108b7 | 2022-04-06 17:45:10 +0100 | [diff] [blame] | 1109 | if (!caps->matches(caps, cpucap_default_scope(caps))) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1110 | continue; |
| 1111 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1112 | if (!cpus_have_cap(caps->capability) && caps->desc) |
| 1113 | pr_info("%s %s\n", info, caps->desc); |
| 1114 | cpus_set_cap(caps->capability); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1115 | } |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 1116 | } |
James Morse | 1c07630 | 2015-07-21 13:23:28 +0100 | [diff] [blame] | 1117 | |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 1118 | static int __enable_cpu_capability(void *arg) |
| 1119 | { |
| 1120 | const struct arm64_cpu_capabilities *cap = arg; |
| 1121 | |
| 1122 | cap->cpu_enable(cap); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 1126 | /* |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1127 | * Run through the enabled capabilities and enable() it on all active |
| 1128 | * CPUs |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 1129 | */ |
Suzuki K Poulose | 454f7ba | 2022-04-06 17:45:09 +0100 | [diff] [blame] | 1130 | static void __init |
| 1131 | enable_cpu_capabilities(const struct arm64_cpu_capabilities *caps) |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 1132 | { |
Mark Rutland | b1d5708 | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 1133 | for (; caps->matches; caps++) { |
| 1134 | unsigned int num = caps->capability; |
| 1135 | |
| 1136 | if (!cpus_have_cap(num)) |
| 1137 | continue; |
| 1138 | |
| 1139 | /* Ensure cpus_have_const_cap(num) works */ |
| 1140 | static_branch_enable(&cpu_hwcap_keys[num]); |
| 1141 | |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 1142 | if (caps->cpu_enable) { |
James Morse | 2a6dcb2 | 2016-10-18 11:27:46 +0100 | [diff] [blame] | 1143 | /* |
| 1144 | * Use stop_machine() as it schedules the work allowing |
| 1145 | * us to modify PSTATE, instead of on_each_cpu() which |
| 1146 | * uses an IPI, giving us a PSTATE that disappears when |
| 1147 | * we return. |
| 1148 | */ |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 1149 | stop_machine(__enable_cpu_capability, (void *)caps, |
| 1150 | cpu_online_mask); |
Mark Rutland | b1d5708 | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 1151 | } |
| 1152 | } |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1155 | /* |
| 1156 | * Flag to indicate if we have computed the system wide |
| 1157 | * capabilities based on the boot time active CPUs. This |
| 1158 | * will be used to determine if a new booting CPU should |
| 1159 | * go through the verification process to make sure that it |
| 1160 | * supports the system capabilities, without using a hotplug |
| 1161 | * notifier. |
| 1162 | */ |
| 1163 | static bool sys_caps_initialised; |
| 1164 | |
| 1165 | static inline void set_sys_caps_initialised(void) |
| 1166 | { |
| 1167 | sys_caps_initialised = true; |
| 1168 | } |
| 1169 | |
| 1170 | /* |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 1171 | * Check for CPU features that are used in early boot |
| 1172 | * based on the Boot CPU value. |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1173 | */ |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 1174 | static void check_early_cpu_features(void) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1175 | { |
Suzuki K Poulose | ac1ad20 | 2016-04-13 14:41:33 +0100 | [diff] [blame] | 1176 | verify_cpu_run_el(); |
Suzuki K Poulose | 13f417f | 2016-02-23 10:31:45 +0000 | [diff] [blame] | 1177 | verify_cpu_asid_bits(); |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1180 | static void |
| 1181 | verify_local_elf_hwcaps(const struct arm64_cpu_capabilities *caps) |
| 1182 | { |
| 1183 | |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 1184 | for (; caps->matches; caps++) |
| 1185 | if (cpus_have_elf_hwcap(caps) && !caps->matches(caps, SCOPE_LOCAL_CPU)) { |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1186 | pr_crit("CPU%d: missing HWCAP: %s\n", |
| 1187 | smp_processor_id(), caps->desc); |
| 1188 | cpu_die_early(); |
| 1189 | } |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | static void |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1193 | verify_local_cpu_features(const struct arm64_cpu_capabilities *caps_list) |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1194 | { |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1195 | const struct arm64_cpu_capabilities *caps = caps_list; |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1196 | for (; caps->matches; caps++) { |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 1197 | if (!cpus_have_cap(caps->capability)) |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1198 | continue; |
| 1199 | /* |
| 1200 | * If the new CPU misses an advertised feature, we cannot proceed |
| 1201 | * further, park the cpu. |
| 1202 | */ |
Suzuki K Poulose | 1e0946d | 2018-04-03 12:09:16 +0100 | [diff] [blame] | 1203 | if (!__this_cpu_has_cap(caps_list, caps->capability)) { |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1204 | pr_crit("CPU%d: missing feature: %s\n", |
| 1205 | smp_processor_id(), caps->desc); |
| 1206 | cpu_die_early(); |
| 1207 | } |
Dave Martin | 3f74ad6 | 2022-04-06 17:45:07 +0100 | [diff] [blame] | 1208 | if (caps->cpu_enable) |
| 1209 | caps->cpu_enable(caps); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1213 | /* |
Suzuki K Poulose | 454f7ba | 2022-04-06 17:45:09 +0100 | [diff] [blame] | 1214 | * The CPU Errata work arounds are detected and applied at boot time |
| 1215 | * and the related information is freed soon after. If the new CPU requires |
| 1216 | * an errata not detected at boot, fail this CPU. |
| 1217 | */ |
| 1218 | static void verify_local_cpu_errata_workarounds(void) |
| 1219 | { |
| 1220 | const struct arm64_cpu_capabilities *caps = arm64_errata; |
| 1221 | |
| 1222 | for (; caps->matches; caps++) { |
| 1223 | if (cpus_have_cap(caps->capability)) { |
| 1224 | if (caps->cpu_enable) |
| 1225 | caps->cpu_enable(caps); |
| 1226 | } else if (caps->matches(caps, SCOPE_LOCAL_CPU)) { |
| 1227 | pr_crit("CPU%d: Requires work around for %s, not detected" |
| 1228 | " at boot time\n", |
| 1229 | smp_processor_id(), |
| 1230 | caps->desc ? : "an erratum"); |
| 1231 | cpu_die_early(); |
| 1232 | } |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static void update_cpu_errata_workarounds(void) |
| 1237 | { |
| 1238 | update_cpu_capabilities(arm64_errata, "enabling workaround for"); |
| 1239 | } |
| 1240 | |
| 1241 | static void __init enable_errata_workarounds(void) |
| 1242 | { |
| 1243 | enable_cpu_capabilities(arm64_errata); |
| 1244 | } |
| 1245 | |
| 1246 | /* |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1247 | * Run through the enabled system capabilities and enable() it on this CPU. |
| 1248 | * The capabilities were decided based on the available CPUs at the boot time. |
| 1249 | * Any new CPU should match the system wide status of the capability. If the |
| 1250 | * new CPU doesn't have a capability which the system now has enabled, we |
| 1251 | * cannot do anything to fix it up and could cause unexpected failures. So |
| 1252 | * we park the CPU. |
| 1253 | */ |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 1254 | static void verify_local_cpu_capabilities(void) |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1255 | { |
Suzuki K Poulose | 89ba264 | 2016-09-09 14:07:09 +0100 | [diff] [blame] | 1256 | verify_local_cpu_errata_workarounds(); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1257 | verify_local_cpu_features(arm64_features); |
| 1258 | verify_local_elf_hwcaps(arm64_elf_hwcaps); |
Suzuki K Poulose | 643d703 | 2016-04-18 10:28:37 +0100 | [diff] [blame] | 1259 | if (system_supports_32bit_el0()) |
| 1260 | verify_local_elf_hwcaps(compat_elf_hwcaps); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Suzuki K Poulose | c47a190 | 2016-09-09 14:07:10 +0100 | [diff] [blame] | 1263 | void check_local_cpu_capabilities(void) |
| 1264 | { |
| 1265 | /* |
| 1266 | * All secondary CPUs should conform to the early CPU features |
| 1267 | * in use by the kernel based on boot CPU. |
| 1268 | */ |
| 1269 | check_early_cpu_features(); |
| 1270 | |
| 1271 | /* |
| 1272 | * If we haven't finalised the system capabilities, this CPU gets |
| 1273 | * a chance to update the errata work arounds. |
| 1274 | * Otherwise, this CPU should verify that it has all the system |
| 1275 | * advertised capabilities. |
| 1276 | */ |
| 1277 | if (!sys_caps_initialised) |
| 1278 | update_cpu_errata_workarounds(); |
| 1279 | else |
| 1280 | verify_local_cpu_capabilities(); |
| 1281 | } |
| 1282 | |
Jisheng Zhang | a7c61a3 | 2015-11-20 17:59:10 +0800 | [diff] [blame] | 1283 | static void __init setup_feature_capabilities(void) |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1284 | { |
Suzuki K. Poulose | ce8b602 | 2015-10-19 14:24:49 +0100 | [diff] [blame] | 1285 | update_cpu_capabilities(arm64_features, "detected feature:"); |
| 1286 | enable_cpu_capabilities(arm64_features); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1287 | } |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 1288 | |
Mark Rutland | b1d5708 | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 1289 | DEFINE_STATIC_KEY_FALSE(arm64_const_caps_ready); |
| 1290 | EXPORT_SYMBOL(arm64_const_caps_ready); |
| 1291 | |
| 1292 | static void __init mark_const_caps_ready(void) |
| 1293 | { |
| 1294 | static_branch_enable(&arm64_const_caps_ready); |
| 1295 | } |
| 1296 | |
Marc Zyngier | 1d648e4 | 2018-04-03 12:09:15 +0100 | [diff] [blame] | 1297 | extern const struct arm64_cpu_capabilities arm64_errata[]; |
| 1298 | |
Marc Zyngier | e3661b1 | 2016-04-22 12:25:32 +0100 | [diff] [blame] | 1299 | bool this_cpu_has_cap(unsigned int cap) |
| 1300 | { |
Marc Zyngier | 1d648e4 | 2018-04-03 12:09:15 +0100 | [diff] [blame] | 1301 | return (__this_cpu_has_cap(arm64_features, cap) || |
| 1302 | __this_cpu_has_cap(arm64_errata, cap)); |
Marc Zyngier | e3661b1 | 2016-04-22 12:25:32 +0100 | [diff] [blame] | 1303 | } |
| 1304 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 1305 | void __init setup_cpu_features(void) |
| 1306 | { |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 1307 | u32 cwg; |
| 1308 | int cls; |
| 1309 | |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1310 | /* Set the CPU feature capabilies */ |
| 1311 | setup_feature_capabilities(); |
Andre Przywara | 8e23185 | 2016-06-28 18:07:30 +0100 | [diff] [blame] | 1312 | enable_errata_workarounds(); |
Mark Rutland | b1d5708 | 2017-05-16 15:18:05 +0100 | [diff] [blame] | 1313 | mark_const_caps_ready(); |
Suzuki K Poulose | 7528350 | 2016-04-18 10:28:33 +0100 | [diff] [blame] | 1314 | setup_elf_hwcaps(arm64_elf_hwcaps); |
Suzuki K Poulose | 643d703 | 2016-04-18 10:28:37 +0100 | [diff] [blame] | 1315 | |
| 1316 | if (system_supports_32bit_el0()) |
| 1317 | setup_elf_hwcaps(compat_elf_hwcaps); |
Suzuki K. Poulose | dbb4e15 | 2015-10-19 14:24:50 +0100 | [diff] [blame] | 1318 | |
| 1319 | /* Advertise that we have computed the system capabilities */ |
| 1320 | set_sys_caps_initialised(); |
| 1321 | |
Suzuki K. Poulose | 9cdf8ec | 2015-10-19 14:24:41 +0100 | [diff] [blame] | 1322 | /* |
| 1323 | * Check for sane CTR_EL0.CWG value. |
| 1324 | */ |
| 1325 | cwg = cache_type_cwg(); |
| 1326 | cls = cache_line_size(); |
| 1327 | if (!cwg) |
| 1328 | pr_warn("No Cache Writeback Granule information, assuming cache line size %d\n", |
| 1329 | cls); |
| 1330 | if (L1_CACHE_BYTES < cls) |
| 1331 | pr_warn("L1_CACHE_BYTES smaller than the Cache Writeback Granule (%d < %d)\n", |
| 1332 | L1_CACHE_BYTES, cls); |
Marc Zyngier | 359b706 | 2015-03-27 13:09:23 +0000 | [diff] [blame] | 1333 | } |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 1334 | |
| 1335 | static bool __maybe_unused |
Suzuki K Poulose | 92406f0 | 2016-04-22 12:25:31 +0100 | [diff] [blame] | 1336 | cpufeature_pan_not_uao(const struct arm64_cpu_capabilities *entry, int __unused) |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 1337 | { |
Suzuki K Poulose | fe64d7d | 2016-11-08 13:56:20 +0000 | [diff] [blame] | 1338 | return (cpus_have_const_cap(ARM64_HAS_PAN) && !cpus_have_const_cap(ARM64_HAS_UAO)); |
James Morse | 7054419 | 2016-02-05 14:58:50 +0000 | [diff] [blame] | 1339 | } |