cpufeature.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017 Linaro Ltd. <[email protected]>
  4. */
  5. #ifndef __ASM_CPUFEATURE_H
  6. #define __ASM_CPUFEATURE_H
  7. #include <linux/log2.h>
  8. #include <asm/hwcap.h>
  9. /*
  10. * Due to the fact that ELF_HWCAP is a 32-bit type on ARM, and given the number
  11. * of optional CPU features it defines, ARM's CPU hardware capability bits have
  12. * been distributed over separate elf_hwcap and elf_hwcap2 variables, each of
  13. * which covers a subset of the available CPU features.
  14. *
  15. * Currently, only a few of those are suitable for automatic module loading
  16. * (which is the primary use case of this facility) and those happen to be all
  17. * covered by HWCAP2. So let's only cover those via the cpu_feature()
  18. * convenience macro for now (which is used by module_cpu_feature_match()).
  19. * However, all capabilities are exposed via the modalias, and can be matched
  20. * using an explicit MODULE_DEVICE_TABLE() that uses __hwcap_feature() directly.
  21. */
  22. #define MAX_CPU_FEATURES 64
  23. #define __hwcap_feature(x) ilog2(HWCAP_ ## x)
  24. #define __hwcap2_feature(x) (32 + ilog2(HWCAP2_ ## x))
  25. #define cpu_feature(x) __hwcap2_feature(x)
  26. static inline bool cpu_have_feature(unsigned int num)
  27. {
  28. return num < 32 ? elf_hwcap & BIT(num) : elf_hwcap2 & BIT(num - 32);
  29. }
  30. #endif