blob: ab6846778d453e2b6aa0d3c6f4e32ed4900a0705 [file] [log] [blame]
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00001/*
Govindraj Raja1a2f42c2025-04-10 17:44:59 -05002 * Copyright (c) 2017-2025, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00005 */
6
7/* Runtime firmware routines to report errata status for the current CPU. */
8
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00009#include <assert.h>
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010010#include <stdbool.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <arch_helpers.h>
13#include <common/debug.h>
Boyan Karatotev06236c92023-01-25 18:50:10 +000014#include <lib/cpus/cpu_ops.h>
Boyan Karatotev5d38cb32023-01-27 09:37:07 +000015#include <lib/cpus/errata.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <lib/el3_runtime/cpu_data.h>
17#include <lib/spinlock.h>
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000018
19#ifdef IMAGE_BL1
20# define BL_STRING "BL1"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070021#elif defined(__aarch64__) && defined(IMAGE_BL31)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000022# define BL_STRING "BL31"
Yann Gautier9335ff52021-10-06 17:34:12 +020023#elif !defined(__aarch64__) && defined(IMAGE_BL32)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000024# define BL_STRING "BL32"
Arvind Ram Prakash11b9b492022-11-22 14:41:00 -060025#elif defined(IMAGE_BL2) && RESET_TO_BL2
Roberto Vargase0e99462017-10-30 14:43:43 +000026# define BL_STRING "BL2"
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000027#else
28# error This image should not be printing errata status
29#endif
30
31/* Errata format: BL stage, CPU, errata ID, message */
Dimitris Papastamos84e02dc2018-01-16 10:42:20 +000032#define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n"
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000033
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000034#define CVE_FORMAT "%s: %s: CPU workaround for CVE %u_%u was %s\n"
35#define ERRATUM_FORMAT "%s: %s: CPU workaround for erratum %u was %s\n"
36
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000037
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010038static __unused void print_status(int status, char *cpu_str, uint16_t cve, uint32_t id)
39{
40 if (status == ERRATA_MISSING) {
41 if (cve) {
42 WARN(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "missing!");
43 } else {
44 WARN(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "missing!");
45 }
46 } else if (status == ERRATA_APPLIES) {
47 if (cve) {
48 INFO(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "applied");
49 } else {
50 INFO(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "applied");
51 }
52 } else {
53 if (cve) {
Sona Mathewd7a54c82024-07-18 21:53:09 -050054 VERBOSE(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "not applicable");
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010055 } else {
Sona Mathewd7a54c82024-07-18 21:53:09 -050056 VERBOSE(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "not applicable");
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010057 }
58 }
59}
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000060
Boyan Karatotev06236c92023-01-25 18:50:10 +000061#if !REPORT_ERRATA
62void print_errata_status(void) {}
63#else /* !REPORT_ERRATA */
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010064/*
65 * New errata status message printer
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010066 */
Ryan Everettd34d7fd2024-05-10 14:56:02 +010067void generic_errata_report(void)
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000068{
69 struct cpu_ops *cpu_ops = get_cpu_ops_ptr();
70 struct erratum_entry *entry = cpu_ops->errata_list_start;
71 struct erratum_entry *end = cpu_ops->errata_list_end;
72 long rev_var = cpu_get_rev_var();
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000073
74 for (; entry != end; entry += 1) {
75 uint64_t status = entry->check_func(rev_var);
76
77 assert(entry->id != 0);
78
79 /*
80 * Errata workaround has not been compiled in. If the errata
81 * would have applied had it been compiled in, print its status
82 * as missing.
83 */
84 if (status == ERRATA_APPLIES && entry->chosen == 0) {
85 status = ERRATA_MISSING;
86 }
87
Boyan Karatoteva3e1b072023-06-09 13:22:16 +010088 print_status(status, cpu_ops->cpu_str, entry->cve, entry->id);
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000089 }
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000090}
91
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000092/*
93 * Returns whether errata needs to be reported. Passed arguments are private to
94 * a CPU type.
95 */
Boyan Karatotev06236c92023-01-25 18:50:10 +000096static __unused int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000097{
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010098 bool report_now;
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000099
100 /* If already reported, return false. */
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +0100101 if (*reported != 0U)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000102 return 0;
103
104 /*
105 * Acquire lock. Determine whether status needs reporting, and then mark
106 * report status to true.
107 */
108 spin_lock(lock);
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +0100109 report_now = (*reported == 0U);
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000110 if (report_now)
111 *reported = 1;
112 spin_unlock(lock);
113
114 return report_now;
115}
116
117/*
Boyan Karatotev06236c92023-01-25 18:50:10 +0000118 * Function to print errata status for the calling CPU (and others of the same
119 * type). Must be called only:
120 * - when MMU and data caches are enabled;
121 * - after cpu_ops have been initialized in per-CPU data.
122 */
123void print_errata_status(void)
124{
Boyan Karatotev06236c92023-01-25 18:50:10 +0000125#ifdef IMAGE_BL1
Ryan Everettd34d7fd2024-05-10 14:56:02 +0100126 generic_errata_report();
Boyan Karatotev06236c92023-01-25 18:50:10 +0000127#else /* IMAGE_BL1 */
Ryan Everettd34d7fd2024-05-10 14:56:02 +0100128 struct cpu_ops *cpu_ops = (void *) get_cpu_data(cpu_ops_ptr);
Boyan Karatotev06236c92023-01-25 18:50:10 +0000129
130 assert(cpu_ops != NULL);
131
Boyan Karatotev06236c92023-01-25 18:50:10 +0000132 if (errata_needs_reporting(cpu_ops->errata_lock, cpu_ops->errata_reported)) {
Ryan Everettd34d7fd2024-05-10 14:56:02 +0100133 generic_errata_report();
Boyan Karatotev06236c92023-01-25 18:50:10 +0000134 }
135#endif /* IMAGE_BL1 */
136}
Boyan Karatotev06236c92023-01-25 18:50:10 +0000137#endif /* !REPORT_ERRATA */