cpufeature.h 1.8 KB

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