xref: /rk3399_ARM-atf/include/lib/cpus/errata.h (revision 94a75ad456a8bda75ca1e4343f00be249a201a69)
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__
294f748cc4SBoyan 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 
344f748cc4SBoyan Karatotev /*
354f748cc4SBoyan Karatotev  * NOTE that this structure will be different on AArch32 and AArch64. The
364f748cc4SBoyan Karatotev  * uintptr_t will reflect the change and the alignment will be correct in both.
374f748cc4SBoyan Karatotev  */
384f748cc4SBoyan Karatotev struct erratum_entry {
394f748cc4SBoyan Karatotev 	uintptr_t (*wa_func)(uint64_t cpu_rev);
404f748cc4SBoyan Karatotev 	uintptr_t (*check_func)(uint64_t cpu_rev);
414f748cc4SBoyan Karatotev 	/* Will fit CVEs with up to 10 character in the ID field */
424f748cc4SBoyan Karatotev 	uint32_t id;
434f748cc4SBoyan Karatotev 	/* Denote CVEs with their year or errata with 0 */
444f748cc4SBoyan Karatotev 	uint16_t cve;
454f748cc4SBoyan Karatotev 	uint8_t chosen;
464f748cc4SBoyan Karatotev 	/* TODO(errata ABI): placeholder for the mitigated field */
474f748cc4SBoyan Karatotev 	uint8_t _mitigated;
484f748cc4SBoyan Karatotev } __packed;
494f748cc4SBoyan Karatotev 
504f748cc4SBoyan Karatotev CASSERT(sizeof(struct erratum_entry) == ERRATUM_ENTRY_SIZE,
514f748cc4SBoyan 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
67*94a75ad4SBoyan Karatotev #define NO_APPLY_AT_RESET	0
68*94a75ad4SBoyan Karatotev #define APPLY_AT_RESET		1
69*94a75ad4SBoyan Karatotev /* useful for errata that end up always being worked around */
70*94a75ad4SBoyan Karatotev #define ERRATUM_ALWAYS_CHOSEN	1
713f4c1e1eSBoyan Karatotev 
726bb96fa6SBoyan Karatotev #endif /* __ASSEMBLER__ */
736bb96fa6SBoyan Karatotev 
746bb96fa6SBoyan Karatotev /* Errata status */
756bb96fa6SBoyan Karatotev #define ERRATA_NOT_APPLIES	0
766bb96fa6SBoyan Karatotev #define ERRATA_APPLIES		1
776bb96fa6SBoyan Karatotev #define ERRATA_MISSING		2
786bb96fa6SBoyan Karatotev 
796bb96fa6SBoyan Karatotev /* Macro to get CPU revision code for checking errata version compatibility. */
806bb96fa6SBoyan Karatotev #define CPU_REV(r, p)		((r << 4) | p)
816bb96fa6SBoyan Karatotev 
826bb96fa6SBoyan Karatotev #endif /* ERRATA_REPORT_H */
83