cpufeature.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2014 Linaro Ltd. <ard.biesheuvel@linaro.org>
  4. */
  5. #ifndef __LINUX_CPUFEATURE_H
  6. #define __LINUX_CPUFEATURE_H
  7. #ifdef CONFIG_GENERIC_CPU_AUTOPROBE
  8. #include <linux/init.h>
  9. #include <linux/mod_devicetable.h>
  10. #include <asm/cpufeature.h>
  11. /*
  12. * Macros imported from <asm/cpufeature.h>:
  13. * - cpu_feature(x) ordinal value of feature called 'x'
  14. * - cpu_have_feature(u32 n) whether feature #n is available
  15. * - MAX_CPU_FEATURES upper bound for feature ordinal values
  16. * Optional:
  17. * - CPU_FEATURE_TYPEFMT format string fragment for printing the cpu type
  18. * - CPU_FEATURE_TYPEVAL set of values matching the format string above
  19. */
  20. #ifndef CPU_FEATURE_TYPEFMT
  21. #define CPU_FEATURE_TYPEFMT "%s"
  22. #endif
  23. #ifndef CPU_FEATURE_TYPEVAL
  24. #define CPU_FEATURE_TYPEVAL ELF_PLATFORM
  25. #endif
  26. /*
  27. * Use module_cpu_feature_match(feature, module_init_function) to
  28. * declare that
  29. * a) the module shall be probed upon discovery of CPU feature 'feature'
  30. * (typically at boot time using udev)
  31. * b) the module must not be loaded if CPU feature 'feature' is not present
  32. * (not even by manual insmod).
  33. *
  34. * For a list of legal values for 'feature', please consult the file
  35. * 'asm/cpufeature.h' of your favorite architecture.
  36. */
  37. #define module_cpu_feature_match(x, __initfunc) \
  38. static struct cpu_feature const __maybe_unused cpu_feature_match_ ## x[] = \
  39. { { .feature = cpu_feature(x) }, { } }; \
  40. MODULE_DEVICE_TABLE(cpu, cpu_feature_match_ ## x); \
  41. \
  42. static int __init cpu_feature_match_ ## x ## _init(void) \
  43. { \
  44. if (!cpu_have_feature(cpu_feature(x))) \
  45. return -ENODEV; \
  46. return __initfunc(); \
  47. } \
  48. module_init(cpu_feature_match_ ## x ## _init)
  49. #endif
  50. #endif