Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef __ASM_POWERPC_CPU_HAS_FEATURE_H
0003 #define __ASM_POWERPC_CPU_HAS_FEATURE_H
0004 
0005 #ifndef __ASSEMBLY__
0006 
0007 #include <linux/bug.h>
0008 #include <asm/cputable.h>
0009 
0010 static __always_inline bool early_cpu_has_feature(unsigned long feature)
0011 {
0012     return !!((CPU_FTRS_ALWAYS & feature) ||
0013           (CPU_FTRS_POSSIBLE & cur_cpu_spec->cpu_features & feature));
0014 }
0015 
0016 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
0017 #include <linux/jump_label.h>
0018 
0019 #define NUM_CPU_FTR_KEYS    BITS_PER_LONG
0020 
0021 extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
0022 
0023 static __always_inline bool cpu_has_feature(unsigned long feature)
0024 {
0025     int i;
0026 
0027 #ifndef __clang__ /* clang can't cope with this */
0028     BUILD_BUG_ON(!__builtin_constant_p(feature));
0029 #endif
0030 
0031 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
0032     if (!static_key_initialized) {
0033         printk("Warning! cpu_has_feature() used prior to jump label init!\n");
0034         dump_stack();
0035         return early_cpu_has_feature(feature);
0036     }
0037 #endif
0038 
0039     if (CPU_FTRS_ALWAYS & feature)
0040         return true;
0041 
0042     if (!(CPU_FTRS_POSSIBLE & feature))
0043         return false;
0044 
0045     i = __builtin_ctzl(feature);
0046     return static_branch_likely(&cpu_feature_keys[i]);
0047 }
0048 #else
0049 static __always_inline bool cpu_has_feature(unsigned long feature)
0050 {
0051     return early_cpu_has_feature(feature);
0052 }
0053 #endif
0054 
0055 #endif /* __ASSEMBLY__ */
0056 #endif /* __ASM_POWERPC_CPU_HAS_FEATURE_H */