cpufeature.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Contains CPU feature definitions
  3. *
  4. * Copyright (C) 2015 ARM Ltd.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #define pr_fmt(fmt) "alternatives: " fmt
  19. #include <linux/types.h>
  20. #include <asm/cpu.h>
  21. #include <asm/cpufeature.h>
  22. static bool
  23. has_id_aa64pfr0_feature(const struct arm64_cpu_capabilities *entry)
  24. {
  25. u64 val;
  26. val = read_cpuid(id_aa64pfr0_el1);
  27. return (val & entry->register_mask) == entry->register_value;
  28. }
  29. static const struct arm64_cpu_capabilities arm64_features[] = {
  30. {
  31. .desc = "GIC system register CPU interface",
  32. .capability = ARM64_HAS_SYSREG_GIC_CPUIF,
  33. .matches = has_id_aa64pfr0_feature,
  34. .register_mask = (0xf << 24),
  35. .register_value = (1 << 24),
  36. },
  37. {},
  38. };
  39. void check_cpu_capabilities(const struct arm64_cpu_capabilities *caps,
  40. const char *info)
  41. {
  42. int i;
  43. for (i = 0; caps[i].desc; i++) {
  44. if (!caps[i].matches(&caps[i]))
  45. continue;
  46. if (!cpus_have_cap(caps[i].capability))
  47. pr_info("%s %s\n", info, caps[i].desc);
  48. cpus_set_cap(caps[i].capability);
  49. }
  50. }
  51. void check_local_cpu_features(void)
  52. {
  53. check_cpu_capabilities(arm64_features, "detected feature");
  54. }