xref: /rk3399_ARM-atf/include/lib/cpus/errata.h (revision 4f748cc44cb12160dfca86d94a1075f38f7c99e4)
16bb96fa6SBoyan Karatotev /*
23f4c1e1eSBoyan Karatotev  * Copyright (c) 2017-2023, 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 
286bb96fa6SBoyan Karatotev #ifndef __ASSEMBLER__
29*4f748cc4SBoyan Karatotev #include <lib/cassert.h>
306bb96fa6SBoyan Karatotev 
316bb96fa6SBoyan Karatotev void print_errata_status(void);
326bb96fa6SBoyan Karatotev void errata_print_msg(unsigned int status, const char *cpu, const char *id);
336bb96fa6SBoyan Karatotev 
34*4f748cc4SBoyan Karatotev /*
35*4f748cc4SBoyan Karatotev  * NOTE that this structure will be different on AArch32 and AArch64. The
36*4f748cc4SBoyan Karatotev  * uintptr_t will reflect the change and the alignment will be correct in both.
37*4f748cc4SBoyan Karatotev  */
38*4f748cc4SBoyan Karatotev struct erratum_entry {
39*4f748cc4SBoyan Karatotev 	uintptr_t (*wa_func)(uint64_t cpu_rev);
40*4f748cc4SBoyan Karatotev 	uintptr_t (*check_func)(uint64_t cpu_rev);
41*4f748cc4SBoyan Karatotev 	/* Will fit CVEs with up to 10 character in the ID field */
42*4f748cc4SBoyan Karatotev 	uint32_t id;
43*4f748cc4SBoyan Karatotev 	/* Denote CVEs with their year or errata with 0 */
44*4f748cc4SBoyan Karatotev 	uint16_t cve;
45*4f748cc4SBoyan Karatotev 	uint8_t chosen;
46*4f748cc4SBoyan Karatotev 	/* TODO(errata ABI): placeholder for the mitigated field */
47*4f748cc4SBoyan Karatotev 	uint8_t _mitigated;
48*4f748cc4SBoyan Karatotev } __packed;
49*4f748cc4SBoyan Karatotev 
50*4f748cc4SBoyan Karatotev CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE,
51*4f748cc4SBoyan Karatotev 	assert_erratum_entry_asm_c_different_sizes);
523f4c1e1eSBoyan Karatotev #else
533f4c1e1eSBoyan Karatotev 
543f4c1e1eSBoyan Karatotev /*
553f4c1e1eSBoyan Karatotev  * errata framework macro helpers
563f4c1e1eSBoyan Karatotev  *
573f4c1e1eSBoyan Karatotev  * NOTE an erratum and CVE id could clash. However, both numbers are very large
583f4c1e1eSBoyan Karatotev  * and the probablity is minuscule. Working around this makes code very
593f4c1e1eSBoyan Karatotev  * complicated and extremely difficult to read so it is not considered. In the
603f4c1e1eSBoyan Karatotev  * unlikely event that this does happen, prepending the CVE id with a 0 should
613f4c1e1eSBoyan Karatotev  * resolve the conflict
623f4c1e1eSBoyan Karatotev  */
633f4c1e1eSBoyan Karatotev #define ERRATUM(id)		0, id
643f4c1e1eSBoyan Karatotev #define CVE(year, id)		year, id
653f4c1e1eSBoyan Karatotev #define NO_ISB			1
663f4c1e1eSBoyan Karatotev #define NO_ASSERT		0
673f4c1e1eSBoyan Karatotev 
686bb96fa6SBoyan Karatotev #endif /* __ASSEMBLER__ */
696bb96fa6SBoyan Karatotev 
706bb96fa6SBoyan Karatotev /* Errata status */
716bb96fa6SBoyan Karatotev #define ERRATA_NOT_APPLIES	0
726bb96fa6SBoyan Karatotev #define ERRATA_APPLIES		1
736bb96fa6SBoyan Karatotev #define ERRATA_MISSING		2
746bb96fa6SBoyan Karatotev 
756bb96fa6SBoyan Karatotev /* Macro to get CPU revision code for checking errata version compatibility. */
766bb96fa6SBoyan Karatotev #define CPU_REV(r, p)		((r << 4) | p)
776bb96fa6SBoyan Karatotev 
786bb96fa6SBoyan Karatotev #endif /* ERRATA_REPORT_H */
79