errata_report.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2017-2023, ARM Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. /* Runtime firmware routines to report errata status for the current CPU. */
  7. #include <assert.h>
  8. #include <stdbool.h>
  9. #include <arch_helpers.h>
  10. #include <common/debug.h>
  11. #include <lib/cpus/errata_report.h>
  12. #include <lib/el3_runtime/cpu_data.h>
  13. #include <lib/spinlock.h>
  14. #ifdef IMAGE_BL1
  15. # define BL_STRING "BL1"
  16. #elif defined(__aarch64__) && defined(IMAGE_BL31)
  17. # define BL_STRING "BL31"
  18. #elif !defined(__aarch64__) && defined(IMAGE_BL32)
  19. # define BL_STRING "BL32"
  20. #elif defined(IMAGE_BL2) && RESET_TO_BL2
  21. # define BL_STRING "BL2"
  22. #else
  23. # error This image should not be printing errata status
  24. #endif
  25. /* Errata format: BL stage, CPU, errata ID, message */
  26. #define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n"
  27. /*
  28. * Returns whether errata needs to be reported. Passed arguments are private to
  29. * a CPU type.
  30. */
  31. int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
  32. {
  33. bool report_now;
  34. /* If already reported, return false. */
  35. if (*reported != 0U)
  36. return 0;
  37. /*
  38. * Acquire lock. Determine whether status needs reporting, and then mark
  39. * report status to true.
  40. */
  41. spin_lock(lock);
  42. report_now = (*reported == 0U);
  43. if (report_now)
  44. *reported = 1;
  45. spin_unlock(lock);
  46. return report_now;
  47. }
  48. /*
  49. * Print errata status message.
  50. *
  51. * Unknown: WARN
  52. * Missing: WARN
  53. * Applied: INFO
  54. * Not applied: VERBOSE
  55. */
  56. void errata_print_msg(unsigned int status, const char *cpu, const char *id)
  57. {
  58. /* Errata status strings */
  59. static const char *const errata_status_str[] = {
  60. [ERRATA_NOT_APPLIES] = "not applied",
  61. [ERRATA_APPLIES] = "applied",
  62. [ERRATA_MISSING] = "missing!"
  63. };
  64. static const char *const __unused bl_str = BL_STRING;
  65. const char *msg __unused;
  66. assert(status < ARRAY_SIZE(errata_status_str));
  67. assert(cpu != NULL);
  68. assert(id != NULL);
  69. msg = errata_status_str[status];
  70. switch (status) {
  71. case ERRATA_NOT_APPLIES:
  72. VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg);
  73. break;
  74. case ERRATA_APPLIES:
  75. INFO(ERRATA_FORMAT, bl_str, cpu, id, msg);
  76. break;
  77. case ERRATA_MISSING:
  78. WARN(ERRATA_FORMAT, bl_str, cpu, id, msg);
  79. break;
  80. default:
  81. WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown");
  82. break;
  83. }
  84. }