Skip to content

Commit e3661b1

Browse files
Marc Zyngierwildea01
authored andcommitted
arm64: Allow a capability to be checked on a single CPU
Now that the capabilities are only available once all the CPUs have booted, we're unable to check for a particular feature in any subsystem that gets initialized before then. In order to support this, introduce a local_cpu_has_cap() function that tests for the presence of a given capability independently of the whole framework. Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com> [ Added preemptible() check ] Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com> [will: remove duplicate initialisation of caps in this_cpu_has_cap] Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent 92406f0 commit e3661b1

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

arch/arm64/include/asm/cpufeature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ struct arm64_cpu_capabilities {
109109

110110
extern DECLARE_BITMAP(cpu_hwcaps, ARM64_NCAPS);
111111

112+
bool this_cpu_has_cap(unsigned int cap);
113+
112114
static inline bool cpu_have_feature(unsigned int num)
113115
{
114116
return elf_hwcap & (1UL << num);

arch/arm64/kernel/cpufeature.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,24 @@ static void __init setup_feature_capabilities(void)
10101010
enable_cpu_capabilities(arm64_features);
10111011
}
10121012

1013+
/*
1014+
* Check if the current CPU has a given feature capability.
1015+
* Should be called from non-preemptible context.
1016+
*/
1017+
bool this_cpu_has_cap(unsigned int cap)
1018+
{
1019+
const struct arm64_cpu_capabilities *caps;
1020+
1021+
if (WARN_ON(preemptible()))
1022+
return false;
1023+
1024+
for (caps = arm64_features; caps->desc; caps++)
1025+
if (caps->capability == cap && caps->matches)
1026+
return caps->matches(caps, SCOPE_LOCAL_CPU);
1027+
1028+
return false;
1029+
}
1030+
10131031
void __init setup_cpu_features(void)
10141032
{
10151033
u32 cwg;

0 commit comments

Comments
 (0)