xref: /rk3399_ARM-atf/lib/cpus/errata_report.c (revision 10bcd761574a5aaa208041382399e05275011603)
1 /*
2  * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of ARM nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific
16  * prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 /* Runtime firmware routines to report errata status for the current CPU. */
32 
33 #include <arch_helpers.h>
34 #include <assert.h>
35 #include <cpu_data.h>
36 #include <debug.h>
37 #include <errata_report.h>
38 #include <spinlock.h>
39 #include <utils.h>
40 
41 #ifdef IMAGE_BL1
42 # define BL_STRING	"BL1"
43 #elif defined(AARCH64) && defined(IMAGE_BL31)
44 # define BL_STRING	"BL31"
45 #elif defined(AARCH32) && defined(IMAGE_BL32)
46 # define BL_STRING	"BL32"
47 #else
48 # error This image should not be printing errata status
49 #endif
50 
51 /* Errata format: BL stage, CPU, errata ID, message */
52 #define ERRATA_FORMAT	"%s: %s: errata workaround for %s was %s\n"
53 
54 /*
55  * Returns whether errata needs to be reported. Passed arguments are private to
56  * a CPU type.
57  */
58 int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
59 {
60 	int report_now;
61 
62 	/* If already reported, return false. */
63 	if (*reported)
64 		return 0;
65 
66 	/*
67 	 * Acquire lock. Determine whether status needs reporting, and then mark
68 	 * report status to true.
69 	 */
70 	spin_lock(lock);
71 	report_now = !(*reported);
72 	if (report_now)
73 		*reported = 1;
74 	spin_unlock(lock);
75 
76 	return report_now;
77 }
78 
79 /*
80  * Print errata status message.
81  *
82  * Unknown: WARN
83  * Missing: WARN
84  * Applied: INFO
85  * Not applied: VERBOSE
86  */
87 void errata_print_msg(int status, const char *cpu, const char *id)
88 {
89 	/* Errata status strings */
90 	static const char *const errata_status_str[] = {
91 		[ERRATA_NOT_APPLIES] = "not applied",
92 		[ERRATA_APPLIES] = "applied",
93 		[ERRATA_MISSING] = "missing!"
94 	};
95 	static const char *const __unused bl_str = BL_STRING;
96 	const char *msg __unused;
97 
98 
99 	assert(status >= 0 && status < ARRAY_SIZE(errata_status_str));
100 	assert(cpu);
101 	assert(id);
102 
103 	msg = errata_status_str[status];
104 
105 	switch (status) {
106 	case ERRATA_NOT_APPLIES:
107 		VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg);
108 		break;
109 
110 	case ERRATA_APPLIES:
111 		INFO(ERRATA_FORMAT, bl_str, cpu, id, msg);
112 		break;
113 
114 	case ERRATA_MISSING:
115 		WARN(ERRATA_FORMAT, bl_str, cpu, id, msg);
116 		break;
117 
118 	default:
119 		WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown");
120 		break;
121 	}
122 }
123