errata.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2021 Sifive.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/memory.h>
  7. #include <linux/module.h>
  8. #include <linux/string.h>
  9. #include <linux/bug.h>
  10. #include <asm/patch.h>
  11. #include <asm/alternative.h>
  12. #include <asm/vendorid_list.h>
  13. #include <asm/errata_list.h>
  14. struct errata_info_t {
  15. char name[ERRATA_STRING_LENGTH_MAX];
  16. bool (*check_func)(unsigned long arch_id, unsigned long impid);
  17. };
  18. static bool errata_cip_453_check_func(unsigned long arch_id, unsigned long impid)
  19. {
  20. /*
  21. * Affected cores:
  22. * Architecture ID: 0x8000000000000007
  23. * Implement ID: 0x20181004 <= impid <= 0x20191105
  24. */
  25. if (arch_id != 0x8000000000000007 ||
  26. (impid < 0x20181004 || impid > 0x20191105))
  27. return false;
  28. return true;
  29. }
  30. static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long impid)
  31. {
  32. /*
  33. * Affected cores:
  34. * Architecture ID: 0x8000000000000007 or 0x1
  35. * Implement ID: mimpid[23:0] <= 0x200630 and mimpid != 0x01200626
  36. */
  37. if (arch_id != 0x8000000000000007 && arch_id != 0x1)
  38. return false;
  39. if ((impid & 0xffffff) > 0x200630 || impid == 0x1200626)
  40. return false;
  41. return true;
  42. }
  43. static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
  44. {
  45. .name = "cip-453",
  46. .check_func = errata_cip_453_check_func
  47. },
  48. {
  49. .name = "cip-1200",
  50. .check_func = errata_cip_1200_check_func
  51. },
  52. };
  53. static u32 __init_or_module sifive_errata_probe(unsigned long archid,
  54. unsigned long impid)
  55. {
  56. int idx;
  57. u32 cpu_req_errata = 0;
  58. for (idx = 0; idx < ERRATA_SIFIVE_NUMBER; idx++)
  59. if (errata_list[idx].check_func(archid, impid))
  60. cpu_req_errata |= (1U << idx);
  61. return cpu_req_errata;
  62. }
  63. static void __init_or_module warn_miss_errata(u32 miss_errata)
  64. {
  65. int i;
  66. pr_warn("----------------------------------------------------------------\n");
  67. pr_warn("WARNING: Missing the following errata may cause potential issues\n");
  68. for (i = 0; i < ERRATA_SIFIVE_NUMBER; i++)
  69. if (miss_errata & 0x1 << i)
  70. pr_warn("\tSiFive Errata[%d]:%s\n", i, errata_list[i].name);
  71. pr_warn("Please enable the corresponding Kconfig to apply them\n");
  72. pr_warn("----------------------------------------------------------------\n");
  73. }
  74. void __init_or_module sifive_errata_patch_func(struct alt_entry *begin,
  75. struct alt_entry *end,
  76. unsigned long archid,
  77. unsigned long impid,
  78. unsigned int stage)
  79. {
  80. struct alt_entry *alt;
  81. u32 cpu_req_errata;
  82. u32 cpu_apply_errata = 0;
  83. u32 tmp;
  84. if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
  85. return;
  86. cpu_req_errata = sifive_errata_probe(archid, impid);
  87. for (alt = begin; alt < end; alt++) {
  88. if (alt->vendor_id != SIFIVE_VENDOR_ID)
  89. continue;
  90. if (alt->errata_id >= ERRATA_SIFIVE_NUMBER) {
  91. WARN(1, "This errata id:%d is not in kernel errata list", alt->errata_id);
  92. continue;
  93. }
  94. tmp = (1U << alt->errata_id);
  95. if (cpu_req_errata & tmp) {
  96. mutex_lock(&text_mutex);
  97. patch_text_nosync(alt->old_ptr, alt->alt_ptr, alt->alt_len);
  98. mutex_unlock(&text_mutex);
  99. cpu_apply_errata |= tmp;
  100. }
  101. }
  102. if (stage != RISCV_ALTERNATIVES_MODULE &&
  103. cpu_apply_errata != cpu_req_errata)
  104. warn_miss_errata(cpu_req_errata - cpu_apply_errata);
  105. }