cpu_has_feature.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef __ASM_POWERPC_CPUFEATURES_H
  2. #define __ASM_POWERPC_CPUFEATURES_H
  3. #ifndef __ASSEMBLY__
  4. #include <linux/bug.h>
  5. #include <asm/cputable.h>
  6. static inline bool early_cpu_has_feature(unsigned long feature)
  7. {
  8. return !!((CPU_FTRS_ALWAYS & feature) ||
  9. (CPU_FTRS_POSSIBLE & cur_cpu_spec->cpu_features & feature));
  10. }
  11. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
  12. #include <linux/jump_label.h>
  13. #define NUM_CPU_FTR_KEYS BITS_PER_LONG
  14. extern struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS];
  15. static __always_inline bool cpu_has_feature(unsigned long feature)
  16. {
  17. int i;
  18. BUILD_BUG_ON(!__builtin_constant_p(feature));
  19. #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECK_DEBUG
  20. if (!static_key_initialized) {
  21. printk("Warning! cpu_has_feature() used prior to jump label init!\n");
  22. dump_stack();
  23. return early_cpu_has_feature(feature);
  24. }
  25. #endif
  26. if (CPU_FTRS_ALWAYS & feature)
  27. return true;
  28. if (!(CPU_FTRS_POSSIBLE & feature))
  29. return false;
  30. i = __builtin_ctzl(feature);
  31. return static_branch_likely(&cpu_feature_keys[i]);
  32. }
  33. #else
  34. static inline bool cpu_has_feature(unsigned long feature)
  35. {
  36. return early_cpu_has_feature(feature);
  37. }
  38. #endif
  39. #endif /* __ASSEMBLY__ */
  40. #endif /* __ASM_POWERPC_CPUFEATURE_H */