Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 1 | /* |
Zelalem | 87675d4 | 2020-02-03 14:56:42 -0600 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* Runtime firmware routines to report errata status for the current CPU. */ |
| 8 | |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 9 | #include <assert.h> |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 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 Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 17 | |
| 18 | #ifdef IMAGE_BL1 |
| 19 | # define BL_STRING "BL1" |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 20 | #elif defined(__aarch64__) && defined(IMAGE_BL31) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 21 | # define BL_STRING "BL31" |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 22 | #elif !defined(__arch64__) && defined(IMAGE_BL32) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 23 | # define BL_STRING "BL32" |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 24 | #elif defined(IMAGE_BL2) && BL2_AT_EL3 |
| 25 | # define BL_STRING "BL2" |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 26 | #else |
| 27 | # error This image should not be printing errata status |
| 28 | #endif |
| 29 | |
| 30 | /* Errata format: BL stage, CPU, errata ID, message */ |
Dimitris Papastamos | 84e02dc | 2018-01-16 10:42:20 +0000 | [diff] [blame] | 31 | #define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n" |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * Returns whether errata needs to be reported. Passed arguments are private to |
| 35 | * a CPU type. |
| 36 | */ |
| 37 | int errata_needs_reporting(spinlock_t *lock, uint32_t *reported) |
| 38 | { |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 39 | bool report_now; |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 40 | |
| 41 | /* If already reported, return false. */ |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 42 | if (*reported != 0U) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 43 | 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 Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 50 | report_now = (*reported == 0U); |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 51 | 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 Wadekar | 66231d1 | 2017-06-07 09:57:42 -0700 | [diff] [blame] | 66 | void errata_print_msg(unsigned int status, const char *cpu, const char *id) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 67 | { |
| 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 Cunado | 8a354f1 | 2017-06-21 16:52:45 +0100 | [diff] [blame] | 78 | assert(status < ARRAY_SIZE(errata_status_str)); |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 79 | assert(cpu != NULL); |
| 80 | assert(id != NULL); |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 81 | |
| 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 | } |