blob: 6be54d6b2074b75a6538c4b5f4c8b9bb07ad6d81 [file] [log] [blame]
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +00001/*
Arvind Ram Prakash9427c062025-02-07 16:28:32 +01002 * Copyright (c) 2017-2025, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +00003 *
dp-arm82cb2c12017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +00005 */
6
Govindraj Raja7e4bf042025-01-21 12:13:20 -06007#ifndef ERRATA_H
8#define ERRATA_H
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +00009
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000010#include <lib/cpus/cpu_ops.h>
11
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000012#define ERRATUM_CHECK_FUNC_SIZE CPU_WORD_SIZE
13#define ERRATUM_ID_SIZE 4
14#define ERRATUM_CVE_SIZE 2
15#define ERRATUM_CHOSEN_SIZE 1
Boyan Karatotev3bfa5a02025-01-22 13:54:43 +000016#define ERRATUM_ALIGNMENT_SIZE 1
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000017
Boyan Karatotev3bfa5a02025-01-22 13:54:43 +000018#define ERRATUM_CHECK_FUNC 0
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000019#define ERRATUM_ID ERRATUM_CHECK_FUNC + ERRATUM_CHECK_FUNC_SIZE
20#define ERRATUM_CVE ERRATUM_ID + ERRATUM_ID_SIZE
21#define ERRATUM_CHOSEN ERRATUM_CVE + ERRATUM_CVE_SIZE
Boyan Karatotev3bfa5a02025-01-22 13:54:43 +000022#define ERRATUM_ALIGNMENT ERRATUM_CHOSEN + ERRATUM_CHOSEN_SIZE
23#define ERRATUM_ENTRY_SIZE ERRATUM_ALIGNMENT + ERRATUM_ALIGNMENT_SIZE
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000024
Arvind Ram Prakash4a97ff52024-08-05 16:04:37 -050025/* Errata status */
26#define ERRATA_NOT_APPLIES 0
27#define ERRATA_APPLIES 1
28#define ERRATA_MISSING 2
29
Arvind Ram Prakash481e1612025-04-04 14:19:16 -050030/* Errata ID for smc workarounds */
31#define ARCH_WORKAROUND_2 2
32#define ARCH_WORKAROUND_3 3
33
34#define INCLUDE_ERRATA_LIST ( \
35 REPORT_ERRATA | \
36 ERRATA_ABI_SUPPORT | \
37 WORKAROUND_CVE_2017_5715 | \
38 WORKAROUND_CVE_2018_3639 | \
39 WORKAROUND_CVE_2022_23960 | \
40 WORKAROUND_CVE_2024_7881)
41
Julius Wernerd5dfdeb2019-07-09 13:49:11 -070042#ifndef __ASSEMBLER__
Boyan Karatotev4f748cc2023-01-27 09:38:15 +000043#include <lib/cassert.h>
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +000044
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +000045void print_errata_status(void);
Roberto Vargas7fabe1a2018-02-12 12:36:17 +000046
Boyan Karatotev4f748cc2023-01-27 09:38:15 +000047/*
48 * NOTE that this structure will be different on AArch32 and AArch64. The
49 * uintptr_t will reflect the change and the alignment will be correct in both.
50 */
51struct erratum_entry {
Boyan Karatotev4f748cc2023-01-27 09:38:15 +000052 uintptr_t (*check_func)(uint64_t cpu_rev);
53 /* Will fit CVEs with up to 10 character in the ID field */
54 uint32_t id;
55 /* Denote CVEs with their year or errata with 0 */
56 uint16_t cve;
Arvind Ram Prakashfd2df322025-02-24 17:22:01 -060057 /*
58 * a bitfield:
59 * bit 0 - denotes if the erratum is enabled in build.
60 * bit 1 - denotes if the erratum workaround is split and
61 * also needs to be implemented at a lower EL.
62 */
Boyan Karatotev4f748cc2023-01-27 09:38:15 +000063 uint8_t chosen;
Boyan Karatotev3bfa5a02025-01-22 13:54:43 +000064 uint8_t _alignment;
Boyan Karatotev4f748cc2023-01-27 09:38:15 +000065} __packed;
66
67CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE,
68 assert_erratum_entry_asm_c_different_sizes);
Govindraj Raja7e4bf042025-01-21 12:13:20 -060069
70/*
71 * Runtime errata helpers.
72 */
73#if ERRATA_A75_764081
74bool errata_a75_764081_applies(void);
75#else
76static inline bool errata_a75_764081_applies(void)
77{
78 return false;
79}
80#endif
81
Govindraj Raja7e4bf042025-01-21 12:13:20 -060082
John Powell4fa822e2025-02-19 16:39:30 -060083bool check_if_trbe_disable_affected_core(void);
Govindraj Raja7e4bf042025-01-21 12:13:20 -060084int check_wa_cve_2024_7881(void);
Govindraj Raja9d6143e2025-01-29 15:01:10 -060085bool errata_ich_vmcr_el2_applies(void);
Arvind Ram Prakash1ca07cd2025-04-10 16:27:46 -050086struct erratum_entry *find_erratum_entry(uint32_t errata_id);
Arvind Ram Prakash481e1612025-04-04 14:19:16 -050087int check_erratum_applies(uint32_t cve, int errata_id);
Govindraj Raja7e4bf042025-01-21 12:13:20 -060088
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +000089#else
90
91/*
92 * errata framework macro helpers
93 *
94 * NOTE an erratum and CVE id could clash. However, both numbers are very large
95 * and the probablity is minuscule. Working around this makes code very
96 * complicated and extremely difficult to read so it is not considered. In the
97 * unlikely event that this does happen, prepending the CVE id with a 0 should
98 * resolve the conflict
99 */
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +0000100#define NO_ISB 1
101#define NO_ASSERT 0
Boyan Karatotev94a75ad2023-04-04 11:29:00 +0100102#define NO_APPLY_AT_RESET 0
103#define APPLY_AT_RESET 1
Harrison Mutai4d22b0e2023-06-26 16:25:21 +0100104#define GET_CPU_REV 1
105#define NO_GET_CPU_REV 0
106
Boyan Karatotev94a75ad2023-04-04 11:29:00 +0100107/* useful for errata that end up always being worked around */
108#define ERRATUM_ALWAYS_CHOSEN 1
Boyan Karatotev3f4c1e12023-01-27 09:35:10 +0000109
Julius Wernerd5dfdeb2019-07-09 13:49:11 -0700110#endif /* __ASSEMBLER__ */
Jeenu Viswambharan10bcd762017-01-03 11:01:51 +0000111
Arvind Ram Prakash481e1612025-04-04 14:19:16 -0500112#define ERRATUM(id) 0, id
113#define CVE(year, id) year, id
114
johpow013a2710d2020-10-07 15:08:01 -0500115/* Macro to get CPU revision code for checking errata version compatibility. */
116#define CPU_REV(r, p) ((r << 4) | p)
117
Arvind Ram Prakashfd2df322025-02-24 17:22:01 -0600118/* Used for errata that have split workaround */
119#define SPLIT_WA 1
120
121/* chosen bitfield entries */
122#define WA_ENABLED_MASK BIT(0)
123#define SPLIT_WA_MASK BIT(1)
124
Govindraj Raja7e4bf042025-01-21 12:13:20 -0600125#endif /* ERRATA_H */