blob: 5d1e3c5cc828a8c5168321cc91ff03fad406e1fd [file] [log] [blame]
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00001/*
Zelalem87675d42020-02-03 14:56:42 -06002 * Copyright (c) 2017-2020, 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>
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000017
18#ifdef IMAGE_BL1
19# define BL_STRING "BL1"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070020#elif defined(__aarch64__) && defined(IMAGE_BL31)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000021# define BL_STRING "BL31"
Julius Werner8e0ef0f2019-07-09 14:02:43 -070022#elif !defined(__arch64__) && defined(IMAGE_BL32)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000023# define BL_STRING "BL32"
Roberto Vargase0e99462017-10-30 14:43:43 +000024#elif defined(IMAGE_BL2) && BL2_AT_EL3
25# define BL_STRING "BL2"
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000026#else
27# error This image should not be printing errata status
28#endif
29
30/* Errata format: BL stage, CPU, errata ID, message */
Dimitris Papastamos84e02dc2018-01-16 10:42:20 +000031#define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n"
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000032
33/*
34 * Returns whether errata needs to be reported. Passed arguments are private to
35 * a CPU type.
36 */
37int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
38{
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010039 bool report_now;
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000040
41 /* If already reported, return false. */
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010042 if (*reported != 0U)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000043 return 0;
44
45 /*
46 * Acquire lock. Determine whether status needs reporting, and then mark
47 * report status to true.
48 */
49 spin_lock(lock);
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010050 report_now = (*reported == 0U);
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000051 if (report_now)
52 *reported = 1;
53 spin_unlock(lock);
54
55 return report_now;
56}
57
58/*
59 * Print errata status message.
60 *
61 * Unknown: WARN
62 * Missing: WARN
63 * Applied: INFO
64 * Not applied: VERBOSE
65 */
Varun Wadekar66231d12017-06-07 09:57:42 -070066void errata_print_msg(unsigned int status, const char *cpu, const char *id)
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000067{
68 /* Errata status strings */
69 static const char *const errata_status_str[] = {
70 [ERRATA_NOT_APPLIES] = "not applied",
71 [ERRATA_APPLIES] = "applied",
72 [ERRATA_MISSING] = "missing!"
73 };
74 static const char *const __unused bl_str = BL_STRING;
75 const char *msg __unused;
76
77
David Cunado8a354f12017-06-21 16:52:45 +010078 assert(status < ARRAY_SIZE(errata_status_str));
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010079 assert(cpu != NULL);
80 assert(id != NULL);
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000081
82 msg = errata_status_str[status];
83
84 switch (status) {
85 case ERRATA_NOT_APPLIES:
86 VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg);
87 break;
88
89 case ERRATA_APPLIES:
90 INFO(ERRATA_FORMAT, bl_str, cpu, id, msg);
91 break;
92
93 case ERRATA_MISSING:
94 WARN(ERRATA_FORMAT, bl_str, cpu, id, msg);
95 break;
96
97 default:
98 WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown");
99 break;
100 }
101}