diff options
author | Andre Przywara <andre.przywara@arm.com> | 2014-11-14 10:54:10 -0500 |
---|---|---|
committer | Will Deacon <will.deacon@arm.com> | 2014-11-25 10:56:21 -0500 |
commit | 301bcfac42897dbd1b0b3c1be49f24654a1bc49e (patch) | |
tree | bd42ce2fcf06bc99fb2b553969cdc2dba3cb1c0b | |
parent | e116a375423393cdb94714e90a96857005d58428 (diff) |
arm64: add Cortex-A53 cache errata workaround
The ARM errata 819472, 826319, 827319 and 824069 define the same
workaround for these hardware issues in certain Cortex-A53 parts.
Use the new alternatives framework and the CPU MIDR detection to
patch "cache clean" into "cache clean and invalidate" instructions if
an affected CPU is detected at runtime.
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
[will: add __maybe_unused to squash gcc warning]
Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r-- | arch/arm64/include/asm/alternative-asm.h | 13 | ||||
-rw-r--r-- | arch/arm64/include/asm/cpufeature.h | 8 | ||||
-rw-r--r-- | arch/arm64/include/asm/cputype.h | 5 | ||||
-rw-r--r-- | arch/arm64/kernel/cpu_errata.c | 33 | ||||
-rw-r--r-- | arch/arm64/mm/cache.S | 4 |
5 files changed, 60 insertions, 3 deletions
diff --git a/arch/arm64/include/asm/alternative-asm.h b/arch/arm64/include/asm/alternative-asm.h index 5ee9340459b8..919a67855b63 100644 --- a/arch/arm64/include/asm/alternative-asm.h +++ b/arch/arm64/include/asm/alternative-asm.h | |||
@@ -11,6 +11,19 @@ | |||
11 | .byte \alt_len | 11 | .byte \alt_len |
12 | .endm | 12 | .endm |
13 | 13 | ||
14 | .macro alternative_insn insn1 insn2 cap | ||
15 | 661: \insn1 | ||
16 | 662: .pushsection .altinstructions, "a" | ||
17 | altinstruction_entry 661b, 663f, \cap, 662b-661b, 664f-663f | ||
18 | .popsection | ||
19 | .pushsection .altinstr_replacement, "ax" | ||
20 | 663: \insn2 | ||
21 | 664: .popsection | ||
22 | .if ((664b-663b) != (662b-661b)) | ||
23 | .error "Alternatives instruction length mismatch" | ||
24 | .endif | ||
25 | .endm | ||
26 | |||
14 | #endif /* __ASSEMBLY__ */ | 27 | #endif /* __ASSEMBLY__ */ |
15 | 28 | ||
16 | #endif /* __ASM_ALTERNATIVE_ASM_H */ | 29 | #endif /* __ASM_ALTERNATIVE_ASM_H */ |
diff --git a/arch/arm64/include/asm/cpufeature.h b/arch/arm64/include/asm/cpufeature.h index 744eaf7fab0f..92b6ee44669b 100644 --- a/arch/arm64/include/asm/cpufeature.h +++ b/arch/arm64/include/asm/cpufeature.h | |||
@@ -21,7 +21,11 @@ | |||
21 | #define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap)) | 21 | #define MAX_CPU_FEATURES (8 * sizeof(elf_hwcap)) |
22 | #define cpu_feature(x) ilog2(HWCAP_ ## x) | 22 | #define cpu_feature(x) ilog2(HWCAP_ ## x) |
23 | 23 | ||
24 | #define NCAPS 0 | 24 | #define ARM64_WORKAROUND_CLEAN_CACHE 0 |
25 | |||
26 | #define NCAPS 1 | ||
27 | |||
28 | #ifndef __ASSEMBLY__ | ||
25 | 29 | ||
26 | extern DECLARE_BITMAP(cpu_hwcaps, NCAPS); | 30 | extern DECLARE_BITMAP(cpu_hwcaps, NCAPS); |
27 | 31 | ||
@@ -48,4 +52,6 @@ static inline void cpus_set_cap(unsigned int num) | |||
48 | 52 | ||
49 | void check_local_cpu_errata(void); | 53 | void check_local_cpu_errata(void); |
50 | 54 | ||
55 | #endif /* __ASSEMBLY__ */ | ||
56 | |||
51 | #endif | 57 | #endif |
diff --git a/arch/arm64/include/asm/cputype.h b/arch/arm64/include/asm/cputype.h index 379d0b874328..8adb986a3086 100644 --- a/arch/arm64/include/asm/cputype.h +++ b/arch/arm64/include/asm/cputype.h | |||
@@ -57,6 +57,11 @@ | |||
57 | #define MIDR_IMPLEMENTOR(midr) \ | 57 | #define MIDR_IMPLEMENTOR(midr) \ |
58 | (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT) | 58 | (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT) |
59 | 59 | ||
60 | #define MIDR_CPU_PART(imp, partnum) \ | ||
61 | (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \ | ||
62 | (0xf << MIDR_ARCHITECTURE_SHIFT) | \ | ||
63 | ((partnum) << MIDR_PARTNUM_SHIFT)) | ||
64 | |||
60 | #define ARM_CPU_IMP_ARM 0x41 | 65 | #define ARM_CPU_IMP_ARM 0x41 |
61 | #define ARM_CPU_IMP_APM 0x50 | 66 | #define ARM_CPU_IMP_APM 0x50 |
62 | 67 | ||
diff --git a/arch/arm64/kernel/cpu_errata.c b/arch/arm64/kernel/cpu_errata.c index 9332cf7c0826..e107ed2d66dc 100644 --- a/arch/arm64/kernel/cpu_errata.c +++ b/arch/arm64/kernel/cpu_errata.c | |||
@@ -23,6 +23,8 @@ | |||
23 | #include <asm/cputype.h> | 23 | #include <asm/cputype.h> |
24 | #include <asm/cpufeature.h> | 24 | #include <asm/cpufeature.h> |
25 | 25 | ||
26 | #define MIDR_CORTEX_A53 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53) | ||
27 | |||
26 | /* | 28 | /* |
27 | * Add a struct or another datatype to the union below if you need | 29 | * Add a struct or another datatype to the union below if you need |
28 | * different means to detect an affected CPU. | 30 | * different means to detect an affected CPU. |
@@ -39,8 +41,37 @@ struct arm64_cpu_capabilities { | |||
39 | }; | 41 | }; |
40 | }; | 42 | }; |
41 | 43 | ||
44 | #define CPU_MODEL_MASK (MIDR_IMPLEMENTOR_MASK | MIDR_PARTNUM_MASK | \ | ||
45 | MIDR_ARCHITECTURE_MASK) | ||
46 | |||
47 | static bool __maybe_unused | ||
48 | is_affected_midr_range(struct arm64_cpu_capabilities *entry) | ||
49 | { | ||
50 | u32 midr = read_cpuid_id(); | ||
51 | |||
52 | if ((midr & CPU_MODEL_MASK) != entry->midr_model) | ||
53 | return false; | ||
54 | |||
55 | midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK; | ||
56 | |||
57 | return (midr >= entry->midr_range_min && midr <= entry->midr_range_max); | ||
58 | } | ||
59 | |||
60 | #define MIDR_RANGE(model, min, max) \ | ||
61 | .is_affected = is_affected_midr_range, \ | ||
62 | .midr_model = model, \ | ||
63 | .midr_range_min = min, \ | ||
64 | .midr_range_max = max | ||
65 | |||
42 | struct arm64_cpu_capabilities arm64_errata[] = { | 66 | struct arm64_cpu_capabilities arm64_errata[] = { |
43 | {} | 67 | { |
68 | /* Cortex-A53 r0p[012] */ | ||
69 | .desc = "ARM errata 826319, 827319, 824069", | ||
70 | .capability = ARM64_WORKAROUND_CLEAN_CACHE, | ||
71 | MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x02), | ||
72 | }, | ||
73 | { | ||
74 | } | ||
44 | }; | 75 | }; |
45 | 76 | ||
46 | void check_local_cpu_errata(void) | 77 | void check_local_cpu_errata(void) |
diff --git a/arch/arm64/mm/cache.S b/arch/arm64/mm/cache.S index 23663837acff..8eaf18577d71 100644 --- a/arch/arm64/mm/cache.S +++ b/arch/arm64/mm/cache.S | |||
@@ -20,6 +20,8 @@ | |||
20 | #include <linux/linkage.h> | 20 | #include <linux/linkage.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <asm/assembler.h> | 22 | #include <asm/assembler.h> |
23 | #include <asm/cpufeature.h> | ||
24 | #include <asm/alternative-asm.h> | ||
23 | 25 | ||
24 | #include "proc-macros.S" | 26 | #include "proc-macros.S" |
25 | 27 | ||
@@ -210,7 +212,7 @@ __dma_clean_range: | |||
210 | dcache_line_size x2, x3 | 212 | dcache_line_size x2, x3 |
211 | sub x3, x2, #1 | 213 | sub x3, x2, #1 |
212 | bic x0, x0, x3 | 214 | bic x0, x0, x3 |
213 | 1: dc cvac, x0 // clean D / U line | 215 | 1: alternative_insn "dc cvac, x0", "dc civac, x0", ARM64_WORKAROUND_CLEAN_CACHE |
214 | add x0, x0, x2 | 216 | add x0, x0, x2 |
215 | cmp x0, x1 | 217 | cmp x0, x1 |
216 | b.lo 1b | 218 | b.lo 1b |