cpu_errata.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Contains CPU specific errata definitions
  3. *
  4. * Copyright (C) 2014 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/cputype.h>
  22. #include <asm/cpufeature.h>
  23. #define MIDR_CORTEX_A53 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
  24. #define MIDR_CORTEX_A57 MIDR_CPU_PART(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
  25. /*
  26. * Add a struct or another datatype to the union below if you need
  27. * different means to detect an affected CPU.
  28. */
  29. struct arm64_cpu_capabilities {
  30. const char *desc;
  31. u16 capability;
  32. bool (*is_affected)(struct arm64_cpu_capabilities *);
  33. union {
  34. struct {
  35. u32 midr_model;
  36. u32 midr_range_min, midr_range_max;
  37. };
  38. };
  39. };
  40. #define CPU_MODEL_MASK (MIDR_IMPLEMENTOR_MASK | MIDR_PARTNUM_MASK | \
  41. MIDR_ARCHITECTURE_MASK)
  42. static bool __maybe_unused
  43. is_affected_midr_range(struct arm64_cpu_capabilities *entry)
  44. {
  45. u32 midr = read_cpuid_id();
  46. if ((midr & CPU_MODEL_MASK) != entry->midr_model)
  47. return false;
  48. midr &= MIDR_REVISION_MASK | MIDR_VARIANT_MASK;
  49. return (midr >= entry->midr_range_min && midr <= entry->midr_range_max);
  50. }
  51. #define MIDR_RANGE(model, min, max) \
  52. .is_affected = is_affected_midr_range, \
  53. .midr_model = model, \
  54. .midr_range_min = min, \
  55. .midr_range_max = max
  56. struct arm64_cpu_capabilities arm64_errata[] = {
  57. #if defined(CONFIG_ARM64_ERRATUM_826319) || \
  58. defined(CONFIG_ARM64_ERRATUM_827319) || \
  59. defined(CONFIG_ARM64_ERRATUM_824069)
  60. {
  61. /* Cortex-A53 r0p[012] */
  62. .desc = "ARM errata 826319, 827319, 824069",
  63. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  64. MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x02),
  65. },
  66. #endif
  67. #ifdef CONFIG_ARM64_ERRATUM_819472
  68. {
  69. /* Cortex-A53 r0p[01] */
  70. .desc = "ARM errata 819472",
  71. .capability = ARM64_WORKAROUND_CLEAN_CACHE,
  72. MIDR_RANGE(MIDR_CORTEX_A53, 0x00, 0x01),
  73. },
  74. #endif
  75. #ifdef CONFIG_ARM64_ERRATUM_832075
  76. {
  77. /* Cortex-A57 r0p0 - r1p2 */
  78. .desc = "ARM erratum 832075",
  79. .capability = ARM64_WORKAROUND_DEVICE_LOAD_ACQUIRE,
  80. MIDR_RANGE(MIDR_CORTEX_A57, 0x00, 0x12),
  81. },
  82. #endif
  83. {
  84. }
  85. };
  86. void check_local_cpu_errata(void)
  87. {
  88. struct arm64_cpu_capabilities *cpus = arm64_errata;
  89. int i;
  90. for (i = 0; cpus[i].desc; i++) {
  91. if (!cpus[i].is_affected(&cpus[i]))
  92. continue;
  93. if (!cpus_have_cap(cpus[i].capability))
  94. pr_info("enabling workaround for %s\n", cpus[i].desc);
  95. cpus_set_cap(cpus[i].capability);
  96. }
  97. }