blob: 42603cb6d9358fffc953841085c262e1a536a1c0 [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
9#include <arch_helpers.h>
10#include <assert.h>
11#include <cpu_data.h>
12#include <debug.h>
13#include <errata_report.h>
14#include <spinlock.h>
Antonio Nino Diaz9fe40fd2018-10-25 17:11:02 +010015#include <stdbool.h>
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000016#include <utils.h>
17
18#ifdef IMAGE_BL1
19# define BL_STRING "BL1"
20#elif defined(AARCH64) && defined(IMAGE_BL31)
21# define BL_STRING "BL31"
22#elif defined(AARCH32) && defined(IMAGE_BL32)
23# 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}