Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 1 | /* |
Sona Mathew | d7a54c8 | 2024-07-18 21:53:09 -0500 | [diff] [blame] | 2 | * Copyright (c) 2017-2024, 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> |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 14 | #include <lib/cpus/cpu_ops.h> |
Boyan Karatotev | 5d38cb3 | 2023-01-27 09:37:07 +0000 | [diff] [blame] | 15 | #include <lib/cpus/errata.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <lib/el3_runtime/cpu_data.h> |
| 17 | #include <lib/spinlock.h> |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 18 | |
| 19 | #ifdef IMAGE_BL1 |
| 20 | # define BL_STRING "BL1" |
Julius Werner | 8e0ef0f | 2019-07-09 14:02:43 -0700 | [diff] [blame] | 21 | #elif defined(__aarch64__) && defined(IMAGE_BL31) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 22 | # define BL_STRING "BL31" |
Yann Gautier | 9335ff5 | 2021-10-06 17:34:12 +0200 | [diff] [blame] | 23 | #elif !defined(__aarch64__) && defined(IMAGE_BL32) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 24 | # define BL_STRING "BL32" |
Arvind Ram Prakash | 11b9b49 | 2022-11-22 14:41:00 -0600 | [diff] [blame] | 25 | #elif defined(IMAGE_BL2) && RESET_TO_BL2 |
Roberto Vargas | e0e9946 | 2017-10-30 14:43:43 +0000 | [diff] [blame] | 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 | |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 34 | #define CVE_FORMAT "%s: %s: CPU workaround for CVE %u_%u was %s\n" |
| 35 | #define ERRATUM_FORMAT "%s: %s: CPU workaround for erratum %u was %s\n" |
| 36 | |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 37 | |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 38 | static __unused void print_status(int status, char *cpu_str, uint16_t cve, uint32_t id) |
| 39 | { |
| 40 | if (status == ERRATA_MISSING) { |
| 41 | if (cve) { |
| 42 | WARN(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "missing!"); |
| 43 | } else { |
| 44 | WARN(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "missing!"); |
| 45 | } |
| 46 | } else if (status == ERRATA_APPLIES) { |
| 47 | if (cve) { |
| 48 | INFO(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "applied"); |
| 49 | } else { |
| 50 | INFO(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "applied"); |
| 51 | } |
| 52 | } else { |
| 53 | if (cve) { |
Sona Mathew | d7a54c8 | 2024-07-18 21:53:09 -0500 | [diff] [blame] | 54 | VERBOSE(CVE_FORMAT, BL_STRING, cpu_str, cve, id, "not applicable"); |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 55 | } else { |
Sona Mathew | d7a54c8 | 2024-07-18 21:53:09 -0500 | [diff] [blame] | 56 | VERBOSE(ERRATUM_FORMAT, BL_STRING, cpu_str, id, "not applicable"); |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | } |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 60 | |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 61 | #if !REPORT_ERRATA |
| 62 | void print_errata_status(void) {} |
| 63 | #else /* !REPORT_ERRATA */ |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 64 | /* |
| 65 | * New errata status message printer |
| 66 | * The order checking function is hidden behind the FEATURE_DETECTION flag to |
| 67 | * save space. This functionality is only useful on development and platform |
| 68 | * bringup builds, when FEATURE_DETECTION should be used anyway |
| 69 | */ |
Ryan Everett | d34d7fd | 2024-05-10 14:56:02 +0100 | [diff] [blame] | 70 | void generic_errata_report(void) |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 71 | { |
| 72 | struct cpu_ops *cpu_ops = get_cpu_ops_ptr(); |
| 73 | struct erratum_entry *entry = cpu_ops->errata_list_start; |
| 74 | struct erratum_entry *end = cpu_ops->errata_list_end; |
| 75 | long rev_var = cpu_get_rev_var(); |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 76 | #if FEATURE_DETECTION |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 77 | uint32_t last_erratum_id = 0; |
| 78 | uint16_t last_cve_yr = 0; |
| 79 | bool check_cve = false; |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 80 | #endif /* FEATURE_DETECTION */ |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 81 | |
| 82 | for (; entry != end; entry += 1) { |
| 83 | uint64_t status = entry->check_func(rev_var); |
| 84 | |
| 85 | assert(entry->id != 0); |
| 86 | |
| 87 | /* |
| 88 | * Errata workaround has not been compiled in. If the errata |
| 89 | * would have applied had it been compiled in, print its status |
| 90 | * as missing. |
| 91 | */ |
| 92 | if (status == ERRATA_APPLIES && entry->chosen == 0) { |
| 93 | status = ERRATA_MISSING; |
| 94 | } |
| 95 | |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 96 | print_status(status, cpu_ops->cpu_str, entry->cve, entry->id); |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 97 | |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 98 | #if FEATURE_DETECTION |
| 99 | if (entry->cve) { |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 100 | if (last_cve_yr > entry->cve || |
| 101 | (last_cve_yr == entry->cve && last_erratum_id >= entry->id)) { |
Arvind Ram Prakash | b73b786 | 2025-03-19 16:09:34 -0500 | [diff] [blame] | 102 | WARN("CVE %u_%u was out of order!\n", |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 103 | entry->cve, entry->id); |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 104 | } |
| 105 | check_cve = true; |
| 106 | last_cve_yr = entry->cve; |
| 107 | } else { |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 108 | if (last_erratum_id >= entry->id || check_cve) { |
Arvind Ram Prakash | b73b786 | 2025-03-19 16:09:34 -0500 | [diff] [blame] | 109 | WARN("Erratum %u was out of order!\n", |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 110 | entry->id); |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | last_erratum_id = entry->id; |
Boyan Karatotev | a3e1b07 | 2023-06-09 13:22:16 +0100 | [diff] [blame] | 114 | #endif /* FEATURE_DETECTION */ |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 115 | } |
Boyan Karatotev | 29fa56d | 2023-01-27 09:38:15 +0000 | [diff] [blame] | 116 | } |
| 117 | |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 118 | /* |
| 119 | * Returns whether errata needs to be reported. Passed arguments are private to |
| 120 | * a CPU type. |
| 121 | */ |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 122 | static __unused int errata_needs_reporting(spinlock_t *lock, uint32_t *reported) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 123 | { |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 124 | bool report_now; |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 125 | |
| 126 | /* If already reported, return false. */ |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 127 | if (*reported != 0U) |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 128 | return 0; |
| 129 | |
| 130 | /* |
| 131 | * Acquire lock. Determine whether status needs reporting, and then mark |
| 132 | * report status to true. |
| 133 | */ |
| 134 | spin_lock(lock); |
Antonio Nino Diaz | 9fe40fd | 2018-10-25 17:11:02 +0100 | [diff] [blame] | 135 | report_now = (*reported == 0U); |
Jeenu Viswambharan | d5ec367 | 2017-01-03 11:01:51 +0000 | [diff] [blame] | 136 | if (report_now) |
| 137 | *reported = 1; |
| 138 | spin_unlock(lock); |
| 139 | |
| 140 | return report_now; |
| 141 | } |
| 142 | |
| 143 | /* |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 144 | * Function to print errata status for the calling CPU (and others of the same |
| 145 | * type). Must be called only: |
| 146 | * - when MMU and data caches are enabled; |
| 147 | * - after cpu_ops have been initialized in per-CPU data. |
| 148 | */ |
| 149 | void print_errata_status(void) |
| 150 | { |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 151 | #ifdef IMAGE_BL1 |
Ryan Everett | d34d7fd | 2024-05-10 14:56:02 +0100 | [diff] [blame] | 152 | generic_errata_report(); |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 153 | #else /* IMAGE_BL1 */ |
Ryan Everett | d34d7fd | 2024-05-10 14:56:02 +0100 | [diff] [blame] | 154 | struct cpu_ops *cpu_ops = (void *) get_cpu_data(cpu_ops_ptr); |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 155 | |
| 156 | assert(cpu_ops != NULL); |
| 157 | |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 158 | if (errata_needs_reporting(cpu_ops->errata_lock, cpu_ops->errata_reported)) { |
Ryan Everett | d34d7fd | 2024-05-10 14:56:02 +0100 | [diff] [blame] | 159 | generic_errata_report(); |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 160 | } |
| 161 | #endif /* IMAGE_BL1 */ |
| 162 | } |
Boyan Karatotev | 06236c9 | 2023-01-25 18:50:10 +0000 | [diff] [blame] | 163 | #endif /* !REPORT_ERRATA */ |