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