xref: /rk3399_ARM-atf/include/lib/cpus/errata.h (revision 8ae6b1ad6c9c57b09b6d4e7ae3cbdf3aed6455b1)
16bb96fa6SBoyan Karatotev /*
2*8ae6b1adSArvind Ram Prakash  * Copyright (c) 2017-2025, Arm Limited and Contributors. All rights reserved.
36bb96fa6SBoyan Karatotev  *
46bb96fa6SBoyan Karatotev  * SPDX-License-Identifier: BSD-3-Clause
56bb96fa6SBoyan Karatotev  */
66bb96fa6SBoyan Karatotev 
76bb96fa6SBoyan Karatotev #ifndef ERRATA_REPORT_H
86bb96fa6SBoyan Karatotev #define ERRATA_REPORT_H
96bb96fa6SBoyan Karatotev 
103f4c1e1eSBoyan Karatotev #include <lib/cpus/cpu_ops.h>
113f4c1e1eSBoyan Karatotev 
123f4c1e1eSBoyan Karatotev 
133f4c1e1eSBoyan Karatotev #define ERRATUM_WA_FUNC_SIZE	CPU_WORD_SIZE
143f4c1e1eSBoyan Karatotev #define ERRATUM_CHECK_FUNC_SIZE	CPU_WORD_SIZE
153f4c1e1eSBoyan Karatotev #define ERRATUM_ID_SIZE		4
163f4c1e1eSBoyan Karatotev #define ERRATUM_CVE_SIZE	2
173f4c1e1eSBoyan Karatotev #define ERRATUM_CHOSEN_SIZE	1
183f4c1e1eSBoyan Karatotev #define ERRATUM_MITIGATED_SIZE	1
193f4c1e1eSBoyan Karatotev 
203f4c1e1eSBoyan Karatotev #define ERRATUM_WA_FUNC		0
213f4c1e1eSBoyan Karatotev #define ERRATUM_CHECK_FUNC	ERRATUM_WA_FUNC + ERRATUM_WA_FUNC_SIZE
223f4c1e1eSBoyan Karatotev #define ERRATUM_ID		ERRATUM_CHECK_FUNC + ERRATUM_CHECK_FUNC_SIZE
233f4c1e1eSBoyan Karatotev #define ERRATUM_CVE		ERRATUM_ID + ERRATUM_ID_SIZE
243f4c1e1eSBoyan Karatotev #define ERRATUM_CHOSEN		ERRATUM_CVE + ERRATUM_CVE_SIZE
253f4c1e1eSBoyan Karatotev #define ERRATUM_MITIGATED	ERRATUM_CHOSEN + ERRATUM_CHOSEN_SIZE
263f4c1e1eSBoyan Karatotev #define ERRATUM_ENTRY_SIZE	ERRATUM_MITIGATED + ERRATUM_MITIGATED_SIZE
273f4c1e1eSBoyan Karatotev 
284a97ff51SArvind Ram Prakash /* Errata status */
294a97ff51SArvind Ram Prakash #define ERRATA_NOT_APPLIES	0
304a97ff51SArvind Ram Prakash #define ERRATA_APPLIES		1
314a97ff51SArvind Ram Prakash #define ERRATA_MISSING		2
324a97ff51SArvind Ram Prakash 
336bb96fa6SBoyan Karatotev #ifndef __ASSEMBLER__
344f748cc4SBoyan Karatotev #include <lib/cassert.h>
356bb96fa6SBoyan Karatotev 
366bb96fa6SBoyan Karatotev void print_errata_status(void);
376bb96fa6SBoyan Karatotev 
387f152ea6SSona Mathew #if ERRATA_A75_764081
397f152ea6SSona Mathew bool errata_a75_764081_applies(void);
407f152ea6SSona Mathew #else
417f152ea6SSona Mathew static inline bool errata_a75_764081_applies(void)
427f152ea6SSona Mathew {
437f152ea6SSona Mathew        return false;
447f152ea6SSona Mathew }
457f152ea6SSona Mathew #endif
467f152ea6SSona Mathew 
474a97ff51SArvind Ram Prakash #if ERRATA_A520_2938996 || ERRATA_X4_2726228
484a97ff51SArvind Ram Prakash unsigned int check_if_affected_core(void);
494a97ff51SArvind Ram Prakash #endif
504a97ff51SArvind Ram Prakash 
51*8ae6b1adSArvind Ram Prakash int check_wa_cve_2024_7881(void);
52*8ae6b1adSArvind Ram Prakash 
534f748cc4SBoyan Karatotev /*
544f748cc4SBoyan Karatotev  * NOTE that this structure will be different on AArch32 and AArch64. The
554f748cc4SBoyan Karatotev  * uintptr_t will reflect the change and the alignment will be correct in both.
564f748cc4SBoyan Karatotev  */
574f748cc4SBoyan Karatotev struct erratum_entry {
584f748cc4SBoyan Karatotev 	uintptr_t (*wa_func)(uint64_t cpu_rev);
594f748cc4SBoyan Karatotev 	uintptr_t (*check_func)(uint64_t cpu_rev);
604f748cc4SBoyan Karatotev 	/* Will fit CVEs with up to 10 character in the ID field */
614f748cc4SBoyan Karatotev 	uint32_t id;
624f748cc4SBoyan Karatotev 	/* Denote CVEs with their year or errata with 0 */
634f748cc4SBoyan Karatotev 	uint16_t cve;
644f748cc4SBoyan Karatotev 	uint8_t chosen;
654f748cc4SBoyan Karatotev 	/* TODO(errata ABI): placeholder for the mitigated field */
664f748cc4SBoyan Karatotev 	uint8_t _mitigated;
674f748cc4SBoyan Karatotev } __packed;
684f748cc4SBoyan Karatotev 
694f748cc4SBoyan Karatotev CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE,
704f748cc4SBoyan Karatotev 	assert_erratum_entry_asm_c_different_sizes);
713f4c1e1eSBoyan Karatotev #else
723f4c1e1eSBoyan Karatotev 
733f4c1e1eSBoyan Karatotev /*
743f4c1e1eSBoyan Karatotev  * errata framework macro helpers
753f4c1e1eSBoyan Karatotev  *
763f4c1e1eSBoyan Karatotev  * NOTE an erratum and CVE id could clash. However, both numbers are very large
773f4c1e1eSBoyan Karatotev  * and the probablity is minuscule. Working around this makes code very
783f4c1e1eSBoyan Karatotev  * complicated and extremely difficult to read so it is not considered. In the
793f4c1e1eSBoyan Karatotev  * unlikely event that this does happen, prepending the CVE id with a 0 should
803f4c1e1eSBoyan Karatotev  * resolve the conflict
813f4c1e1eSBoyan Karatotev  */
823f4c1e1eSBoyan Karatotev #define ERRATUM(id)		0, id
833f4c1e1eSBoyan Karatotev #define CVE(year, id)		year, id
843f4c1e1eSBoyan Karatotev #define NO_ISB			1
853f4c1e1eSBoyan Karatotev #define NO_ASSERT		0
8694a75ad4SBoyan Karatotev #define NO_APPLY_AT_RESET	0
8794a75ad4SBoyan Karatotev #define APPLY_AT_RESET		1
884d22b0e5SHarrison Mutai #define GET_CPU_REV		1
894d22b0e5SHarrison Mutai #define NO_GET_CPU_REV		0
904d22b0e5SHarrison Mutai 
9194a75ad4SBoyan Karatotev /* useful for errata that end up always being worked around */
9294a75ad4SBoyan Karatotev #define ERRATUM_ALWAYS_CHOSEN	1
933f4c1e1eSBoyan Karatotev 
946bb96fa6SBoyan Karatotev #endif /* __ASSEMBLER__ */
956bb96fa6SBoyan Karatotev 
966bb96fa6SBoyan Karatotev /* Macro to get CPU revision code for checking errata version compatibility. */
976bb96fa6SBoyan Karatotev #define CPU_REV(r, p)		((r << 4) | p)
986bb96fa6SBoyan Karatotev 
996bb96fa6SBoyan Karatotev #endif /* ERRATA_REPORT_H */
100