xref: /rk3399_ARM-atf/lib/cpus/errata_report.c (revision ff2743e544f0f82381ebb9dff8f14eacb837d2e0)
1 /*
2  * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
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>
15 #include <utils.h>
16 
17 #ifdef IMAGE_BL1
18 # define BL_STRING	"BL1"
19 #elif defined(AARCH64) && defined(IMAGE_BL31)
20 # define BL_STRING	"BL31"
21 #elif defined(AARCH32) && defined(IMAGE_BL32)
22 # define BL_STRING	"BL32"
23 #elif defined(IMAGE_BL2) && BL2_AT_EL3
24 # define BL_STRING "BL2"
25 #else
26 # error This image should not be printing errata status
27 #endif
28 
29 /* Errata format: BL stage, CPU, errata ID, message */
30 #define ERRATA_FORMAT	"%s: %s: CPU workaround for %s was %s\n"
31 
32 /*
33  * Returns whether errata needs to be reported. Passed arguments are private to
34  * a CPU type.
35  */
36 int errata_needs_reporting(spinlock_t *lock, uint32_t *reported)
37 {
38 	int report_now;
39 
40 	/* If already reported, return false. */
41 	if (*reported)
42 		return 0;
43 
44 	/*
45 	 * Acquire lock. Determine whether status needs reporting, and then mark
46 	 * report status to true.
47 	 */
48 	spin_lock(lock);
49 	report_now = !(*reported);
50 	if (report_now)
51 		*reported = 1;
52 	spin_unlock(lock);
53 
54 	return report_now;
55 }
56 
57 /*
58  * Print errata status message.
59  *
60  * Unknown: WARN
61  * Missing: WARN
62  * Applied: INFO
63  * Not applied: VERBOSE
64  */
65 void errata_print_msg(unsigned int status, const char *cpu, const char *id)
66 {
67 	/* Errata status strings */
68 	static const char *const errata_status_str[] = {
69 		[ERRATA_NOT_APPLIES] = "not applied",
70 		[ERRATA_APPLIES] = "applied",
71 		[ERRATA_MISSING] = "missing!"
72 	};
73 	static const char *const __unused bl_str = BL_STRING;
74 	const char *msg __unused;
75 
76 
77 	assert(status < ARRAY_SIZE(errata_status_str));
78 	assert(cpu);
79 	assert(id);
80 
81 	msg = errata_status_str[status];
82 
83 	switch (status) {
84 	case ERRATA_NOT_APPLIES:
85 		VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg);
86 		break;
87 
88 	case ERRATA_APPLIES:
89 		INFO(ERRATA_FORMAT, bl_str, cpu, id, msg);
90 		break;
91 
92 	case ERRATA_MISSING:
93 		WARN(ERRATA_FORMAT, bl_str, cpu, id, msg);
94 		break;
95 
96 	default:
97 		WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown");
98 		break;
99 	}
100 }
101