1 // SPDX-License-Identifier: GPL-2.0-only
3 * Contains CPU specific errata definitions
5 * Copyright (C) 2014 ARM Ltd.
8 #include <linux/arm-smccc.h>
9 #include <linux/types.h>
10 #include <linux/cpu.h>
12 #include <asm/cputype.h>
13 #include <asm/cpufeature.h>
14 #include <asm/kvm_asm.h>
15 #include <asm/smp_plat.h>
17 static bool __maybe_unused
18 is_affected_midr_range(const struct arm64_cpu_capabilities *entry, int scope)
20 const struct arm64_midr_revidr *fix;
21 u32 midr = read_cpuid_id(), revidr;
23 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
24 if (!is_midr_in_range(midr, &entry->midr_range))
27 midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK;
28 revidr = read_cpuid(REVIDR_EL1);
29 for (fix = entry->fixed_revs; fix && fix->revidr_mask; fix++)
30 if (midr == fix->midr_rv && (revidr & fix->revidr_mask))
36 static bool __maybe_unused
37 is_affected_midr_range_list(const struct arm64_cpu_capabilities *entry,
40 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
41 return is_midr_in_range_list(read_cpuid_id(), entry->midr_range_list);
44 static bool __maybe_unused
45 is_kryo_midr(const struct arm64_cpu_capabilities *entry, int scope)
49 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
51 model = read_cpuid_id();
52 model &= MIDR_IMPLEMENTOR_MASK | (0xf00 << MIDR_PARTNUM_SHIFT) |
53 MIDR_ARCHITECTURE_MASK;
55 return model == entry->midr_range.model;
59 has_mismatched_cache_type(const struct arm64_cpu_capabilities *entry,
62 u64 mask = arm64_ftr_reg_ctrel0.strict_mask;
63 u64 sys = arm64_ftr_reg_ctrel0.sys_val & mask;
64 u64 ctr_raw, ctr_real;
66 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
69 * We want to make sure that all the CPUs in the system expose
70 * a consistent CTR_EL0 to make sure that applications behaves
71 * correctly with migration.
73 * If a CPU has CTR_EL0.IDC but does not advertise it via CTR_EL0 :
75 * 1) It is safe if the system doesn't support IDC, as CPU anyway
76 * reports IDC = 0, consistent with the rest.
78 * 2) If the system has IDC, it is still safe as we trap CTR_EL0
79 * access on this CPU via the ARM64_HAS_CACHE_IDC capability.
81 * So, we need to make sure either the raw CTR_EL0 or the effective
82 * CTR_EL0 matches the system's copy to allow a secondary CPU to boot.
84 ctr_raw = read_cpuid_cachetype() & mask;
85 ctr_real = read_cpuid_effective_cachetype() & mask;
87 return (ctr_real != sys) && (ctr_raw != sys);
91 cpu_enable_trap_ctr_access(const struct arm64_cpu_capabilities *cap)
93 u64 mask = arm64_ftr_reg_ctrel0.strict_mask;
94 bool enable_uct_trap = false;
96 /* Trap CTR_EL0 access on this CPU, only if it has a mismatch */
97 if ((read_cpuid_cachetype() & mask) !=
98 (arm64_ftr_reg_ctrel0.sys_val & mask))
99 enable_uct_trap = true;
101 /* ... or if the system is affected by an erratum */
102 if (cap->capability == ARM64_WORKAROUND_1542419)
103 enable_uct_trap = true;
106 sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCT, 0);
109 #ifdef CONFIG_ARM64_ERRATUM_1463225
110 DEFINE_PER_CPU(int, __in_cortex_a76_erratum_1463225_wa);
113 has_cortex_a76_erratum_1463225(const struct arm64_cpu_capabilities *entry,
116 return is_affected_midr_range_list(entry, scope) && is_kernel_in_hyp_mode();
120 static void __maybe_unused
121 cpu_enable_cache_maint_trap(const struct arm64_cpu_capabilities *__unused)
123 sysreg_clear_set(sctlr_el1, SCTLR_EL1_UCI, 0);
126 #define CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
127 .matches = is_affected_midr_range, \
128 .midr_range = MIDR_RANGE(model, v_min, r_min, v_max, r_max)
130 #define CAP_MIDR_ALL_VERSIONS(model) \
131 .matches = is_affected_midr_range, \
132 .midr_range = MIDR_ALL_VERSIONS(model)
134 #define MIDR_FIXED(rev, revidr_mask) \
135 .fixed_revs = (struct arm64_midr_revidr[]){{ (rev), (revidr_mask) }, {}}
137 #define ERRATA_MIDR_RANGE(model, v_min, r_min, v_max, r_max) \
138 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
139 CAP_MIDR_RANGE(model, v_min, r_min, v_max, r_max)
141 #define CAP_MIDR_RANGE_LIST(list) \
142 .matches = is_affected_midr_range_list, \
143 .midr_range_list = list
145 /* Errata affecting a range of revisions of given model variant */
146 #define ERRATA_MIDR_REV_RANGE(m, var, r_min, r_max) \
147 ERRATA_MIDR_RANGE(m, var, r_min, var, r_max)
149 /* Errata affecting a single variant/revision of a model */
150 #define ERRATA_MIDR_REV(model, var, rev) \
151 ERRATA_MIDR_RANGE(model, var, rev, var, rev)
153 /* Errata affecting all variants/revisions of a given a model */
154 #define ERRATA_MIDR_ALL_VERSIONS(model) \
155 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
156 CAP_MIDR_ALL_VERSIONS(model)
158 /* Errata affecting a list of midr ranges, with same work around */
159 #define ERRATA_MIDR_RANGE_LIST(midr_list) \
160 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM, \
161 CAP_MIDR_RANGE_LIST(midr_list)
163 static const __maybe_unused struct midr_range tx2_family_cpus[] = {
164 MIDR_ALL_VERSIONS(MIDR_BRCM_VULCAN),
165 MIDR_ALL_VERSIONS(MIDR_CAVIUM_THUNDERX2),
169 static bool __maybe_unused
170 needs_tx2_tvm_workaround(const struct arm64_cpu_capabilities *entry,
175 if (!is_affected_midr_range_list(entry, scope) ||
176 !is_hyp_mode_available())
179 for_each_possible_cpu(i) {
180 if (MPIDR_AFFINITY_LEVEL(cpu_logical_map(i), 0) != 0)
187 static bool __maybe_unused
188 has_neoverse_n1_erratum_1542419(const struct arm64_cpu_capabilities *entry,
191 u32 midr = read_cpuid_id();
192 bool has_dic = read_cpuid_cachetype() & BIT(CTR_DIC_SHIFT);
193 const struct midr_range range = MIDR_ALL_VERSIONS(MIDR_NEOVERSE_N1);
195 WARN_ON(scope != SCOPE_LOCAL_CPU || preemptible());
196 return is_midr_in_range(midr, &range) && has_dic;
199 #ifdef CONFIG_RANDOMIZE_BASE
201 static const struct midr_range ca57_a72[] = {
202 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
203 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
209 #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
210 static const struct arm64_cpu_capabilities arm64_repeat_tlbi_list[] = {
211 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1009
213 ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0)
216 .midr_range.model = MIDR_QCOM_KRYO,
217 .matches = is_kryo_midr,
220 #ifdef CONFIG_ARM64_ERRATUM_1286807
222 ERRATA_MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 0),
229 #ifdef CONFIG_CAVIUM_ERRATUM_27456
230 const struct midr_range cavium_erratum_27456_cpus[] = {
231 /* Cavium ThunderX, T88 pass 1.x - 2.1 */
232 MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 1),
233 /* Cavium ThunderX, T81 pass 1.0 */
234 MIDR_REV(MIDR_THUNDERX_81XX, 0, 0),
239 #ifdef CONFIG_CAVIUM_ERRATUM_30115
240 static const struct midr_range cavium_erratum_30115_cpus[] = {
241 /* Cavium ThunderX, T88 pass 1.x - 2.2 */
242 MIDR_RANGE(MIDR_THUNDERX, 0, 0, 1, 2),
243 /* Cavium ThunderX, T81 pass 1.0 - 1.2 */
244 MIDR_REV_RANGE(MIDR_THUNDERX_81XX, 0, 0, 2),
245 /* Cavium ThunderX, T83 pass 1.0 */
246 MIDR_REV(MIDR_THUNDERX_83XX, 0, 0),
251 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
252 static const struct arm64_cpu_capabilities qcom_erratum_1003_list[] = {
254 ERRATA_MIDR_REV(MIDR_QCOM_FALKOR_V1, 0, 0),
257 .midr_range.model = MIDR_QCOM_KRYO,
258 .matches = is_kryo_midr,
264 #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
265 static const struct midr_range workaround_clean_cache[] = {
266 #if defined(CONFIG_ARM64_ERRATUM_826319) || \
267 defined(CONFIG_ARM64_ERRATUM_827319) || \
268 defined(CONFIG_ARM64_ERRATUM_824069)
269 /* Cortex-A53 r0p[012]: ARM errata 826319, 827319, 824069 */
270 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 2),
272 #ifdef CONFIG_ARM64_ERRATUM_819472
273 /* Cortex-A53 r0p[01] : ARM errata 819472 */
274 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 1),
280 #ifdef CONFIG_ARM64_ERRATUM_1418040
282 * - 1188873 affects r0p0 to r2p0
283 * - 1418040 affects r0p0 to r3p1
285 static const struct midr_range erratum_1418040_list[] = {
286 /* Cortex-A76 r0p0 to r3p1 */
287 MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1),
288 /* Neoverse-N1 r0p0 to r3p1 */
289 MIDR_RANGE(MIDR_NEOVERSE_N1, 0, 0, 3, 1),
290 /* Kryo4xx Gold (rcpe to rfpf) => (r0p0 to r3p1) */
291 MIDR_RANGE(MIDR_QCOM_KRYO_4XX_GOLD, 0xc, 0xe, 0xf, 0xf),
296 #ifdef CONFIG_ARM64_ERRATUM_845719
297 static const struct midr_range erratum_845719_list[] = {
298 /* Cortex-A53 r0p[01234] */
299 MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
300 /* Brahma-B53 r0p[0] */
301 MIDR_REV(MIDR_BRAHMA_B53, 0, 0),
306 #ifdef CONFIG_ARM64_ERRATUM_843419
307 static const struct arm64_cpu_capabilities erratum_843419_list[] = {
309 /* Cortex-A53 r0p[01234] */
310 .matches = is_affected_midr_range,
311 ERRATA_MIDR_REV_RANGE(MIDR_CORTEX_A53, 0, 0, 4),
312 MIDR_FIXED(0x4, BIT(8)),
315 /* Brahma-B53 r0p[0] */
316 .matches = is_affected_midr_range,
317 ERRATA_MIDR_REV(MIDR_BRAHMA_B53, 0, 0),
323 #ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_AT
324 static const struct midr_range erratum_speculative_at_list[] = {
325 #ifdef CONFIG_ARM64_ERRATUM_1165522
326 /* Cortex A76 r0p0 to r2p0 */
327 MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 2, 0),
329 #ifdef CONFIG_ARM64_ERRATUM_1319367
330 MIDR_ALL_VERSIONS(MIDR_CORTEX_A57),
331 MIDR_ALL_VERSIONS(MIDR_CORTEX_A72),
333 #ifdef CONFIG_ARM64_ERRATUM_1530923
334 /* Cortex A55 r0p0 to r2p0 */
335 MIDR_RANGE(MIDR_CORTEX_A55, 0, 0, 2, 0),
336 /* Kryo4xx Silver (rdpe => r1p0) */
337 MIDR_REV(MIDR_QCOM_KRYO_4XX_SILVER, 0xd, 0xe),
343 #ifdef CONFIG_ARM64_ERRATUM_1463225
344 static const struct midr_range erratum_1463225[] = {
345 /* Cortex-A76 r0p0 - r3p1 */
346 MIDR_RANGE(MIDR_CORTEX_A76, 0, 0, 3, 1),
347 /* Kryo4xx Gold (rcpe to rfpf) => (r0p0 to r3p1) */
348 MIDR_RANGE(MIDR_QCOM_KRYO_4XX_GOLD, 0xc, 0xe, 0xf, 0xf),
353 const struct arm64_cpu_capabilities arm64_errata[] = {
354 #ifdef CONFIG_ARM64_WORKAROUND_CLEAN_CACHE
356 .desc = "ARM errata 826319, 827319, 824069, or 819472",
357 .capability = ARM64_WORKAROUND_CLEAN_CACHE,
358 ERRATA_MIDR_RANGE_LIST(workaround_clean_cache),
359 .cpu_enable = cpu_enable_cache_maint_trap,
362 #ifdef CONFIG_ARM64_ERRATUM_832075
364 /* Cortex-A57 r0p0 - r1p2 */
365 .desc = "ARM erratum 832075",
366 .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
367 ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
372 #ifdef CONFIG_ARM64_ERRATUM_834220
374 /* Cortex-A57 r0p0 - r1p2 */
375 .desc = "ARM erratum 834220",
376 .capability = ARM64_WORKAROUND_834220,
377 ERRATA_MIDR_RANGE(MIDR_CORTEX_A57,
382 #ifdef CONFIG_ARM64_ERRATUM_843419
384 .desc = "ARM erratum 843419",
385 .capability = ARM64_WORKAROUND_843419,
386 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
387 .matches = cpucap_multi_entry_cap_matches,
388 .match_list = erratum_843419_list,
391 #ifdef CONFIG_ARM64_ERRATUM_845719
393 .desc = "ARM erratum 845719",
394 .capability = ARM64_WORKAROUND_845719,
395 ERRATA_MIDR_RANGE_LIST(erratum_845719_list),
398 #ifdef CONFIG_CAVIUM_ERRATUM_23154
400 /* Cavium ThunderX, pass 1.x */
401 .desc = "Cavium erratum 23154",
402 .capability = ARM64_WORKAROUND_CAVIUM_23154,
403 ERRATA_MIDR_REV_RANGE(MIDR_THUNDERX, 0, 0, 1),
406 #ifdef CONFIG_CAVIUM_ERRATUM_27456
408 .desc = "Cavium erratum 27456",
409 .capability = ARM64_WORKAROUND_CAVIUM_27456,
410 ERRATA_MIDR_RANGE_LIST(cavium_erratum_27456_cpus),
413 #ifdef CONFIG_CAVIUM_ERRATUM_30115
415 .desc = "Cavium erratum 30115",
416 .capability = ARM64_WORKAROUND_CAVIUM_30115,
417 ERRATA_MIDR_RANGE_LIST(cavium_erratum_30115_cpus),
421 .desc = "Mismatched cache type (CTR_EL0)",
422 .capability = ARM64_MISMATCHED_CACHE_TYPE,
423 .matches = has_mismatched_cache_type,
424 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
425 .cpu_enable = cpu_enable_trap_ctr_access,
427 #ifdef CONFIG_QCOM_FALKOR_ERRATUM_1003
429 .desc = "Qualcomm Technologies Falkor/Kryo erratum 1003",
430 .capability = ARM64_WORKAROUND_QCOM_FALKOR_E1003,
431 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
432 .matches = cpucap_multi_entry_cap_matches,
433 .match_list = qcom_erratum_1003_list,
436 #ifdef CONFIG_ARM64_WORKAROUND_REPEAT_TLBI
438 .desc = "Qualcomm erratum 1009, or ARM erratum 1286807",
439 .capability = ARM64_WORKAROUND_REPEAT_TLBI,
440 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
441 .matches = cpucap_multi_entry_cap_matches,
442 .match_list = arm64_repeat_tlbi_list,
445 #ifdef CONFIG_ARM64_ERRATUM_858921
447 /* Cortex-A73 all versions */
448 .desc = "ARM erratum 858921",
449 .capability = ARM64_WORKAROUND_858921,
450 ERRATA_MIDR_ALL_VERSIONS(MIDR_CORTEX_A73),
454 .desc = "Spectre-v2",
455 .capability = ARM64_SPECTRE_V2,
456 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
457 .matches = has_spectre_v2,
458 .cpu_enable = spectre_v2_enable_mitigation,
460 #ifdef CONFIG_RANDOMIZE_BASE
462 .desc = "EL2 vector hardening",
463 .capability = ARM64_HARDEN_EL2_VECTORS,
464 ERRATA_MIDR_RANGE_LIST(ca57_a72),
468 .desc = "Spectre-v4",
469 .capability = ARM64_SPECTRE_V4,
470 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
471 .matches = has_spectre_v4,
472 .cpu_enable = spectre_v4_enable_mitigation,
474 #ifdef CONFIG_ARM64_ERRATUM_1418040
476 .desc = "ARM erratum 1418040",
477 .capability = ARM64_WORKAROUND_1418040,
478 ERRATA_MIDR_RANGE_LIST(erratum_1418040_list),
480 * We need to allow affected CPUs to come in late, but
481 * also need the non-affected CPUs to be able to come
482 * in at any point in time. Wonderful.
484 .type = ARM64_CPUCAP_WEAK_LOCAL_CPU_FEATURE,
487 #ifdef CONFIG_ARM64_WORKAROUND_SPECULATIVE_AT
489 .desc = "ARM errata 1165522, 1319367, or 1530923",
490 .capability = ARM64_WORKAROUND_SPECULATIVE_AT,
491 ERRATA_MIDR_RANGE_LIST(erratum_speculative_at_list),
494 #ifdef CONFIG_ARM64_ERRATUM_1463225
496 .desc = "ARM erratum 1463225",
497 .capability = ARM64_WORKAROUND_1463225,
498 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
499 .matches = has_cortex_a76_erratum_1463225,
500 .midr_range_list = erratum_1463225,
503 #ifdef CONFIG_CAVIUM_TX2_ERRATUM_219
505 .desc = "Cavium ThunderX2 erratum 219 (KVM guest sysreg trapping)",
506 .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_TVM,
507 ERRATA_MIDR_RANGE_LIST(tx2_family_cpus),
508 .matches = needs_tx2_tvm_workaround,
511 .desc = "Cavium ThunderX2 erratum 219 (PRFM removal)",
512 .capability = ARM64_WORKAROUND_CAVIUM_TX2_219_PRFM,
513 ERRATA_MIDR_RANGE_LIST(tx2_family_cpus),
516 #ifdef CONFIG_ARM64_ERRATUM_1542419
518 /* we depend on the firmware portion for correctness */
519 .desc = "ARM erratum 1542419 (kernel portion)",
520 .capability = ARM64_WORKAROUND_1542419,
521 .type = ARM64_CPUCAP_LOCAL_CPU_ERRATUM,
522 .matches = has_neoverse_n1_erratum_1542419,
523 .cpu_enable = cpu_enable_trap_ctr_access,