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> | |
24 | ||
18ffa046 JM |
25 | static bool |
26 | feature_matches(u64 reg, const struct arm64_cpu_capabilities *entry) | |
27 | { | |
28 | int val = cpuid_feature_extract_field(reg, entry->field_pos); | |
29 | ||
30 | return val >= entry->min_field_value; | |
31 | } | |
32 | ||
94a9e04a MZ |
33 | static bool |
34 | has_id_aa64pfr0_feature(const struct arm64_cpu_capabilities *entry) | |
35 | { | |
36 | u64 val; | |
37 | ||
38 | val = read_cpuid(id_aa64pfr0_el1); | |
18ffa046 | 39 | return feature_matches(val, entry); |
94a9e04a MZ |
40 | } |
41 | ||
359b7064 | 42 | static const struct arm64_cpu_capabilities arm64_features[] = { |
94a9e04a MZ |
43 | { |
44 | .desc = "GIC system register CPU interface", | |
45 | .capability = ARM64_HAS_SYSREG_GIC_CPUIF, | |
46 | .matches = has_id_aa64pfr0_feature, | |
18ffa046 JM |
47 | .field_pos = 24, |
48 | .min_field_value = 1, | |
94a9e04a | 49 | }, |
359b7064 MZ |
50 | {}, |
51 | }; | |
52 | ||
53 | void check_cpu_capabilities(const struct arm64_cpu_capabilities *caps, | |
54 | const char *info) | |
55 | { | |
56 | int i; | |
57 | ||
58 | for (i = 0; caps[i].desc; i++) { | |
59 | if (!caps[i].matches(&caps[i])) | |
60 | continue; | |
61 | ||
62 | if (!cpus_have_cap(caps[i].capability)) | |
63 | pr_info("%s %s\n", info, caps[i].desc); | |
64 | cpus_set_cap(caps[i].capability); | |
65 | } | |
1c076303 JM |
66 | |
67 | /* second pass allows enable() to consider interacting capabilities */ | |
68 | for (i = 0; caps[i].desc; i++) { | |
69 | if (cpus_have_cap(caps[i].capability) && caps[i].enable) | |
70 | caps[i].enable(); | |
71 | } | |
359b7064 MZ |
72 | } |
73 | ||
74 | void check_local_cpu_features(void) | |
75 | { | |
76 | check_cpu_capabilities(arm64_features, "detected feature"); | |
77 | } |