blob: b9ce6425fdea07e9d9a4e27e055862d898370133 [file] [log] [blame]
Kevin Haob92a2262016-07-23 14:42:40 +05301#ifndef __ASM_POWERPC_CPUFEATURES_H
2#define __ASM_POWERPC_CPUFEATURES_H
3
4#ifndef __ASSEMBLY__
5
6#include <asm/cputable.h>
7
8static inline bool early_cpu_has_feature(unsigned long feature)
9{
10 return !!((CPU_FTRS_ALWAYS & feature) ||
11 (CPU_FTRS_POSSIBLE & cur_cpu_spec->cpu_features & feature));
12}
13
Kevin Hao4db73272016-07-23 14:42:41 +053014#ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
15#include <linux/jump_label.h>
16
17#define NUM_CPU_FTR_KEYS 64
18
19extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
20
21static __always_inline bool cpu_has_feature(unsigned long feature)
22{
23 int i;
24
25 BUILD_BUG_ON(!__builtin_constant_p(feature));
26
27 if (CPU_FTRS_ALWAYS & feature)
28 return true;
29
30 if (!(CPU_FTRS_POSSIBLE & feature))
31 return false;
32
33 i = __builtin_ctzl(feature);
34 return static_branch_likely(&cpu_feature_keys[i]);
35}
36#else
Kevin Haob92a2262016-07-23 14:42:40 +053037static inline bool cpu_has_feature(unsigned long feature)
38{
39 return early_cpu_has_feature(feature);
40}
Kevin Hao4db73272016-07-23 14:42:41 +053041#endif
Kevin Haob92a2262016-07-23 14:42:40 +053042
43#endif /* __ASSEMBLY__ */
44#endif /* __ASM_POWERPC_CPUFEATURE_H */