Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 1 | /* |
Arvind Ram Prakash | 42d4d3b | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 2 | * Copyright (c) 2017-2023, ARM Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 3 | * |
dp-arm | 82cb2c1 | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Jeenu Viswambharan | 10bcd76 | 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 | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 9 | #include <assert.h> |
Antonio Nino Diaz | 4353499 | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 10 | #include <stdbool.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | |
| 12 | #include <arch_helpers.h> |
| 13 | #include <common/debug.h> |
Boyan Karatotev | dd9fae1 | 2023-01-25 18:50:10 +0000 | [diff] [blame^] | 14 | #include <lib/cpus/cpu_ops.h> |
Boyan Karatotev | 6bb96fa | 2023-01-27 09:37:07 +0000 | [diff] [blame] | 15 | #include <lib/cpus/errata.h> |
Antonio Nino Diaz | 09d40e0 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <lib/el3_runtime/cpu_data.h> |
| 17 | #include <lib/spinlock.h> |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 18 | |
| 19 | #ifdef IMAGE_BL1 |
| 20 | # define BL_STRING "BL1" |
Julius Werner | 402b3cf | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 21 | #elif defined(__aarch64__) && defined(IMAGE_BL31) |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 22 | # define BL_STRING "BL31" |
Yann Gautier | 322e60a | 2021-10-06 17:34:12 +0200 | [diff] [blame] | 23 | #elif !defined(__aarch64__) && defined(IMAGE_BL32) |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 24 | # define BL_STRING "BL32" |
Arvind Ram Prakash | 42d4d3b | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 25 | #elif defined(IMAGE_BL2) && RESET_TO_BL2 |
Roberto Vargas | b1d27b4 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 26 | # define BL_STRING "BL2" |
Jeenu Viswambharan | 10bcd76 | 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 | c0ca14d | 2018-01-16 10:42:20 +0000 | [diff] [blame] | 32 | #define ERRATA_FORMAT "%s: %s: CPU workaround for %s was %s\n" |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 33 | |
Boyan Karatotev | dd9fae1 | 2023-01-25 18:50:10 +0000 | [diff] [blame^] | 34 | #if !REPORT_ERRATA |
| 35 | void print_errata_status(void) {} |
| 36 | #else /* !REPORT_ERRATA */ |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Returns whether errata needs to be reported. Passed arguments are private to |
| 39 | * a CPU type. |
| 40 | */ |
Boyan Karatotev | dd9fae1 | 2023-01-25 18:50:10 +0000 | [diff] [blame^] | 41 | static __unused int errata_needs_reporting(spinlock_t *lock, uint32_t *reported) |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 42 | { |
Antonio Nino Diaz | 4353499 | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 43 | bool report_now; |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 44 | |
| 45 | /* If already reported, return false. */ |
Antonio Nino Diaz | 4353499 | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 46 | if (*reported != 0U) |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 47 | return 0; |
| 48 | |
| 49 | /* |
| 50 | * Acquire lock. Determine whether status needs reporting, and then mark |
| 51 | * report status to true. |
| 52 | */ |
| 53 | spin_lock(lock); |
Antonio Nino Diaz | 4353499 | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 54 | report_now = (*reported == 0U); |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 55 | if (report_now) |
| 56 | *reported = 1; |
| 57 | spin_unlock(lock); |
| 58 | |
| 59 | return report_now; |
| 60 | } |
| 61 | |
| 62 | /* |
Boyan Karatotev | dd9fae1 | 2023-01-25 18:50:10 +0000 | [diff] [blame^] | 63 | * Function to print errata status for the calling CPU (and others of the same |
| 64 | * type). Must be called only: |
| 65 | * - when MMU and data caches are enabled; |
| 66 | * - after cpu_ops have been initialized in per-CPU data. |
| 67 | */ |
| 68 | void print_errata_status(void) |
| 69 | { |
| 70 | struct cpu_ops *cpu_ops; |
| 71 | #ifdef IMAGE_BL1 |
| 72 | /* |
| 73 | * BL1 doesn't have per-CPU data. So retrieve the CPU operations |
| 74 | * directly. |
| 75 | */ |
| 76 | cpu_ops = get_cpu_ops_ptr(); |
| 77 | |
| 78 | if (cpu_ops->errata_func != NULL) { |
| 79 | cpu_ops->errata_func(); |
| 80 | } |
| 81 | #else /* IMAGE_BL1 */ |
| 82 | cpu_ops = (void *) get_cpu_data(cpu_ops_ptr); |
| 83 | |
| 84 | assert(cpu_ops != NULL); |
| 85 | |
| 86 | if (cpu_ops->errata_func == NULL) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | if (errata_needs_reporting(cpu_ops->errata_lock, cpu_ops->errata_reported)) { |
| 91 | cpu_ops->errata_func(); |
| 92 | } |
| 93 | #endif /* IMAGE_BL1 */ |
| 94 | } |
| 95 | |
| 96 | /* |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 97 | * Print errata status message. |
| 98 | * |
| 99 | * Unknown: WARN |
| 100 | * Missing: WARN |
| 101 | * Applied: INFO |
| 102 | * Not applied: VERBOSE |
| 103 | */ |
Varun Wadekar | 6311f63 | 2017-06-07 09:57:42 -0700 | [diff] [blame] | 104 | void errata_print_msg(unsigned int status, const char *cpu, const char *id) |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 105 | { |
| 106 | /* Errata status strings */ |
| 107 | static const char *const errata_status_str[] = { |
| 108 | [ERRATA_NOT_APPLIES] = "not applied", |
| 109 | [ERRATA_APPLIES] = "applied", |
| 110 | [ERRATA_MISSING] = "missing!" |
| 111 | }; |
| 112 | static const char *const __unused bl_str = BL_STRING; |
| 113 | const char *msg __unused; |
| 114 | |
| 115 | |
David Cunado | 0dd4195 | 2017-06-21 16:52:45 +0100 | [diff] [blame] | 116 | assert(status < ARRAY_SIZE(errata_status_str)); |
Antonio Nino Diaz | 4353499 | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 117 | assert(cpu != NULL); |
| 118 | assert(id != NULL); |
Jeenu Viswambharan | 10bcd76 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 119 | |
| 120 | msg = errata_status_str[status]; |
| 121 | |
| 122 | switch (status) { |
| 123 | case ERRATA_NOT_APPLIES: |
| 124 | VERBOSE(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 125 | break; |
| 126 | |
| 127 | case ERRATA_APPLIES: |
| 128 | INFO(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 129 | break; |
| 130 | |
| 131 | case ERRATA_MISSING: |
| 132 | WARN(ERRATA_FORMAT, bl_str, cpu, id, msg); |
| 133 | break; |
| 134 | |
| 135 | default: |
| 136 | WARN(ERRATA_FORMAT, bl_str, cpu, id, "unknown"); |
| 137 | break; |
| 138 | } |
| 139 | } |
Boyan Karatotev | dd9fae1 | 2023-01-25 18:50:10 +0000 | [diff] [blame^] | 140 | #endif /* !REPORT_ERRATA */ |