blob: f43b2176db151edd98d59fc889c55b4a66b4f452 [file] [log] [blame]
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00001/*
Dimitris Papastamos84e02dc2018-01-16 10:42:20 +00002 * Copyright (c) 2017-2018, 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>
14#include <lib/cpus/errata_report.h>
15#include <lib/el3_runtime/cpu_data.h>
16#include <lib/spinlock.h>
17#include <lib/utils.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"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070023#elif !defined(__arch64__) && defined(IMAGE_BL32)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000024# define BL_STRING "BL32"
Roberto Vargase0e99462017-10-30 14:43:43 +000025#elif defined(IMAGE_BL2) && BL2_AT_EL3
26# 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
34/*
35 * Returns whether errata needs to be reported. Passed arguments are private to
36 * a CPU type.
37 */
38int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
39{
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010040 bool report_now;
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000041
42 /* If already reported, return false. */
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010043 if (*reported != 0U)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000044 return 0;
45
46 /*
47 * Acquire lock. Determine whether status needs reporting, and then mark
48 * report status to true.
49 */
50 spin_lock(lock);
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010051 report_now = (*reported == 0U);
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000052 if (report_now)
53 *reported = 1;
54 spin_unlock(lock);
55
56 return report_now;
57}
58
59/*
60 * Print errata status message.
61 *
62 * Unknown: WARN
63 * Missing: WARN
64 * Applied: INFO
65 * Not applied: VERBOSE
66 */
Varun Wadekar66231d12017-06-07 09:57:42 -070067void errata_print_msg(unsigned int status, const char *cpu, const char *id)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000068{
69 /* Errata status strings */
70 static const char *const errata_status_str[] = {
71 [ERRATA_NOT_APPLIES] = "not applied",
72 [ERRATA_APPLIES] = "applied",
73 [ERRATA_MISSING] = "missing!"
74 };
75 static const char *const __unused bl_str = BL_STRING;
76 const char *msg __unused;
77
78
David Cunado8a354f12017-06-21 16:52:45 +010079 assert(status < ARRAY_SIZE(errata_status_str));
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010080 assert(cpu != NULL);
81 assert(id != NULL);
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000082
83 msg = errata_status_str[status];
84
85 switch (status) {
86 case ERRATA_NOT_APPLIES:
87 VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg);
88 break;
89
90 case ERRATA_APPLIES:
91 INFO(ERRATA_FORMAT, bl_str, cpu, id, msg);
92 break;
93
94 case ERRATA_MISSING:
95 WARN(ERRATA_FORMAT, bl_str, cpu, id, msg);
96 break;
97
98 default:
99 WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown");
100 break;
101 }
102}