cpufeature.h 1.8 KB

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