blob: 1f5f5ead76036e1e4d0561581c7619e2858aa401 [file] [log] [blame]
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00001/*
Arvind Ram Prakashfaa857d2025-01-28 17:21:17 -06002 * Copyright (c) 2017-2025, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00005 */
6
Govindraj Raja988a7c72025-01-21 12:13:20 -06007#ifndef ERRATA_H
8#define ERRATA_H
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00009
Boyan Karatotev821364e2023-01-27 09:35:10 +000010#include <lib/cpus/cpu_ops.h>
11
Boyan Karatotev821364e2023-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 Karatotev74ddacc2025-01-22 13:54:43 +000016#define ERRATUM_ALIGNMENT_SIZE 1
Boyan Karatotev821364e2023-01-27 09:35:10 +000017
Boyan Karatotev74ddacc2025-01-22 13:54:43 +000018#define ERRATUM_CHECK_FUNC 0
Boyan Karatotev821364e2023-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 Karatotev74ddacc2025-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 Karatotev821364e2023-01-27 09:35:10 +000024
Arvind Ram Prakash2b433932024-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
Julius Werner53456fc2019-07-09 13:49:11 -070030#ifndef __ASSEMBLER__
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000031#include <lib/cassert.h>
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000032
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000033void print_errata_status(void);
Roberto Vargas05712702018-02-12 12:36:17 +000034
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000035/*
36 * NOTE that this structure will be different on AArch32 and AArch64. The
37 * uintptr_t will reflect the change and the alignment will be correct in both.
38 */
39struct erratum_entry {
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000040 uintptr_t (*check_func)(uint64_t cpu_rev);
41 /* Will fit CVEs with up to 10 character in the ID field */
42 uint32_t id;
43 /* Denote CVEs with their year or errata with 0 */
44 uint16_t cve;
Arvind Ram Prakash6585c6a2025-02-24 17:22:01 -060045 /*
46 * a bitfield:
47 * bit 0 - denotes if the erratum is enabled in build.
48 * bit 1 - denotes if the erratum workaround is split and
49 * also needs to be implemented at a lower EL.
50 */
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000051 uint8_t chosen;
Boyan Karatotev74ddacc2025-01-22 13:54:43 +000052 uint8_t _alignment;
Boyan Karatotev29fa56d2023-01-27 09:38:15 +000053} __packed;
54
55CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE,
56 assert_erratum_entry_asm_c_different_sizes);
Govindraj Raja988a7c72025-01-21 12:13:20 -060057
58/*
59 * Runtime errata helpers.
60 */
61#if ERRATA_A75_764081
62bool errata_a75_764081_applies(void);
63#else
64static inline bool errata_a75_764081_applies(void)
65{
66 return false;
67}
68#endif
69
John Powell4cccc772025-02-19 16:39:30 -060070bool check_if_trbe_disable_affected_core(void);
Govindraj Raja988a7c72025-01-21 12:13:20 -060071int check_wa_cve_2024_7881(void);
Govindraj Raja4c3a4612025-01-29 15:01:10 -060072bool errata_ich_vmcr_el2_applies(void);
Govindraj Raja988a7c72025-01-21 12:13:20 -060073
Boyan Karatotev821364e2023-01-27 09:35:10 +000074#else
75
76/*
77 * errata framework macro helpers
78 *
79 * NOTE an erratum and CVE id could clash. However, both numbers are very large
80 * and the probablity is minuscule. Working around this makes code very
81 * complicated and extremely difficult to read so it is not considered. In the
82 * unlikely event that this does happen, prepending the CVE id with a 0 should
83 * resolve the conflict
84 */
85#define ERRATUM(id) 0, id
86#define CVE(year, id) year, id
87#define NO_ISB 1
88#define NO_ASSERT 0
Boyan Karatotevcea0c262023-04-04 11:29:00 +010089#define NO_APPLY_AT_RESET 0
90#define APPLY_AT_RESET 1
Harrison Mutaide3fa1e2023-06-26 16:25:21 +010091#define GET_CPU_REV 1
92#define NO_GET_CPU_REV 0
93
Boyan Karatotevcea0c262023-04-04 11:29:00 +010094/* useful for errata that end up always being worked around */
95#define ERRATUM_ALWAYS_CHOSEN 1
Boyan Karatotev821364e2023-01-27 09:35:10 +000096
Julius Werner53456fc2019-07-09 13:49:11 -070097#endif /* __ASSEMBLER__ */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000098
johpow0185ea43d2020-10-07 15:08:01 -050099/* Macro to get CPU revision code for checking errata version compatibility. */
100#define CPU_REV(r, p) ((r << 4) | p)
101
Arvind Ram Prakash6585c6a2025-02-24 17:22:01 -0600102/* Used for errata that have split workaround */
103#define SPLIT_WA 1
104
105/* chosen bitfield entries */
106#define WA_ENABLED_MASK BIT(0)
107#define SPLIT_WA_MASK BIT(1)
108
Govindraj Raja988a7c72025-01-21 12:13:20 -0600109#endif /* ERRATA_H */