Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 1 | /* |
Dimitris Papastamos | 84e02dc | 2018-01-16 10:42:20 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, 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> |
| 17 | #include <lib/utils.h> |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 18 | |
| 19 | #ifdef IMAGE_BL1 |
| 20 | # define BL_STRING "BL1" |
| 21 | #elif defined(AARCH64) && defined(IMAGE_BL31) |
| 22 | # define BL_STRING "BL31" |
| 23 | #elif defined(AARCH32) && defined(IMAGE_BL32) |
| 24 | # define BL_STRING "BL32" |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 25 | #elif defined(IMAGE_BL2) && BL2_AT_EL3 |
| 26 | # define BL_STRING "BL2" |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 27 | #else |
| 28 | # error This image should not be printing errata status |
| 29 | #endif |
| 30 | |
| 31 | /* Errata format: BL stage, CPU, errata ID, message */ |
Dimitris Papastamos | 84e02dc | 2018-01-16 10:42:20 +0000 | [diff] [blame] | 32 | #define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n" |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 33 | |
| 34 | /* |
| 35 | * Returns whether errata needs to be reported. Passed arguments are private to |
| 36 | * a CPU type. |
| 37 | */ |
| 38 | int errata_needs_reporting(spinlock_t *lock, uint32_t *reported) |
| 39 | { |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 40 | bool report_now; |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 41 | |
| 42 | /* If already reported, return false. */ |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 43 | if (*reported != 0U) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 44 | return 0; |
| 45 | |
| 46 | /* |
| 47 | * Acquire lock. Determine whether status needs reporting, and then mark |
| 48 | * report status to true. |
| 49 | */ |
| 50 | spin_lock(lock); |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 51 | report_now = (*reported == 0U); |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 52 | if (report_now) |
| 53 | *reported = 1; |
| 54 | spin_unlock(lock); |
| 55 | |
| 56 | return report_now; |
| 57 | } |
| 58 | |
| 59 | /* |
| 60 | * Print errata status message. |
| 61 | * |
| 62 | * Unknown: WARN |
| 63 | * Missing: WARN |
| 64 | * Applied: INFO |
| 65 | * Not applied: VERBOSE |
| 66 | */ |
Varun Wadekar | 66231d1 | 2017-06-07 09:57:42 -0700 | [diff] [blame] | 67 | 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] | 68 | { |
| 69 | /* Errata status strings */ |
| 70 | static const char *const errata_status_str[] = { |
| 71 | [ERRATA_NOT_APPLIES] = "not applied", |
| 72 | [ERRATA_APPLIES] = "applied", |
| 73 | [ERRATA_MISSING] = "missing!" |
| 74 | }; |
| 75 | static const char *const __unused bl_str = BL_STRING; |
| 76 | const char *msg __unused; |
| 77 | |
| 78 | |
David Cunado | 8a354f1 | 2017-06-21 16:52:45 +0100 | [diff] [blame] | 79 | assert(status < ARRAY_SIZE(errata_status_str)); |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 80 | assert(cpu != NULL); |
| 81 | assert(id != NULL); |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 82 | |
| 83 | msg = errata_status_str[status]; |
| 84 | |
| 85 | switch (status) { |
| 86 | case ERRATA_NOT_APPLIES: |
| 87 | VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 88 | break; |
| 89 | |
| 90 | case ERRATA_APPLIES: |
| 91 | INFO(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 92 | break; |
| 93 | |
| 94 | case ERRATA_MISSING: |
| 95 | WARN(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 96 | break; |
| 97 | |
| 98 | default: |
| 99 | WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown"); |
| 100 | break; |
| 101 | } |
| 102 | } |