Commit | Line | Data |
---|---|---|
359b7064 MZ |
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 | ||
19 | #define pr_fmt(fmt) "alternatives: " fmt | |
20 | ||
21 | #include <linux/types.h> | |
22 | #include <asm/cpu.h> | |
23 | #include <asm/cpufeature.h> | |
338d4f49 | 24 | #include <asm/processor.h> |
359b7064 | 25 | |
18ffa046 JM |
26 | static bool |
27 | feature_matches(u64 reg, const struct arm64_cpu_capabilities *entry) | |
28 | { | |
29 | int val = cpuid_feature_extract_field(reg, entry->field_pos); | |
30 | ||
31 | return val >= entry->min_field_value; | |
32 | } | |
33 | ||
94a9e04a MZ |
34 | static bool |
35 | has_id_aa64pfr0_feature(const struct arm64_cpu_capabilities *entry) | |
36 | { | |
37 | u64 val; | |
38 | ||
39 | val = read_cpuid(id_aa64pfr0_el1); | |
18ffa046 | 40 | return feature_matches(val, entry); |
94a9e04a MZ |
41 | } |
42 | ||
338d4f49 JM |
43 | static bool __maybe_unused |
44 | has_id_aa64mmfr1_feature(const struct arm64_cpu_capabilities *entry) | |
45 | { | |
46 | u64 val; | |
47 | ||
48 | val = read_cpuid(id_aa64mmfr1_el1); | |
49 | return feature_matches(val, entry); | |
50 | } | |
51 | ||
359b7064 | 52 | static const struct arm64_cpu_capabilities arm64_features[] = { |
94a9e04a MZ |
53 | { |
54 | .desc = "GIC system register CPU interface", | |
55 | .capability = ARM64_HAS_SYSREG_GIC_CPUIF, | |
56 | .matches = has_id_aa64pfr0_feature, | |
18ffa046 JM |
57 | .field_pos = 24, |
58 | .min_field_value = 1, | |
94a9e04a | 59 | }, |
338d4f49 JM |
60 | #ifdef CONFIG_ARM64_PAN |
61 | { | |
62 | .desc = "Privileged Access Never", | |
63 | .capability = ARM64_HAS_PAN, | |
64 | .matches = has_id_aa64mmfr1_feature, | |
65 | .field_pos = 20, | |
66 | .min_field_value = 1, | |
67 | .enable = cpu_enable_pan, | |
68 | }, | |
69 | #endif /* CONFIG_ARM64_PAN */ | |
359b7064 MZ |
70 | {}, |
71 | }; | |
72 | ||
73 | void check_cpu_capabilities(const struct arm64_cpu_capabilities *caps, | |
74 | const char *info) | |
75 | { | |
76 | int i; | |
77 | ||
78 | for (i = 0; caps[i].desc; i++) { | |
79 | if (!caps[i].matches(&caps[i])) | |
80 | continue; | |
81 | ||
82 | if (!cpus_have_cap(caps[i].capability)) | |
83 | pr_info("%s %s\n", info, caps[i].desc); | |
84 | cpus_set_cap(caps[i].capability); | |
85 | } | |
1c076303 JM |
86 | |
87 | /* second pass allows enable() to consider interacting capabilities */ | |
88 | for (i = 0; caps[i].desc; i++) { | |
89 | if (cpus_have_cap(caps[i].capability) && caps[i].enable) | |
90 | caps[i].enable(); | |
91 | } | |
359b7064 MZ |
92 | } |
93 | ||
94 | void check_local_cpu_features(void) | |
95 | { | |
96 | check_cpu_capabilities(arm64_features, "detected feature"); | |
97 | } |