xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_x3.S (revision db5fe4f4934208ac8f8ae9283df2fbac6066e24e)
1/*
2 * Copyright (c) 2021-2025, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <common/bl_common.h>
10#include <cortex_x3.h>
11#include <cpu_macros.S>
12#include <plat_macros.S>
13#include "wa_cve_2022_23960_bhb_vector.S"
14
15/* Hardware handled coherency */
16#if HW_ASSISTED_COHERENCY == 0
17#error "Cortex-X3 must be compiled with HW_ASSISTED_COHERENCY enabled"
18#endif
19
20/* 64-bit only core */
21#if CTX_INCLUDE_AARCH32_REGS == 1
22#error "Cortex-X3 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
23#endif
24
25#if WORKAROUND_CVE_2022_23960
26	wa_cve_2022_23960_bhb_vector_table CORTEX_X3_BHB_LOOP_COUNT, cortex_x3
27#endif /* WORKAROUND_CVE_2022_23960 */
28
29/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
30workaround_reset_start cortex_x3, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
31	sysreg_bit_set CORTEX_X3_CPUECTLR_EL1, BIT(46)
32workaround_reset_end cortex_x3, CVE(2024, 5660)
33
34check_erratum_ls cortex_x3, CVE(2024, 5660), CPU_REV(1, 2)
35
36workaround_reset_start cortex_x3, ERRATUM(2070301), ERRATA_X3_2070301
37	sysreg_bitfield_insert CORTEX_X3_CPUECTLR2_EL1, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_CNSRV, \
38	CORTEX_X3_CPUECTLR2_EL1_PF_MODE_LSB, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_WIDTH
39workaround_reset_end cortex_x3, ERRATUM(2070301)
40
41check_erratum_ls cortex_x3, ERRATUM(2070301), CPU_REV(1, 2)
42
43workaround_reset_start cortex_x3, ERRATUM(2266875), ERRATA_X3_2266875
44        sysreg_bit_set CORTEX_X3_CPUACTLR_EL1, BIT(22)
45workaround_reset_end cortex_x3, ERRATUM(2266875)
46
47check_erratum_ls cortex_x3, ERRATUM(2266875), CPU_REV(1, 0)
48
49workaround_runtime_start cortex_x3, ERRATUM(2302506), ERRATA_X3_2302506
50	sysreg_bit_set	CORTEX_X3_CPUACTLR2_EL1, BIT(0)
51workaround_runtime_end cortex_x3, ERRATUM(2302506), NO_ISB
52
53check_erratum_ls cortex_x3, ERRATUM(2302506), CPU_REV(1, 1)
54
55.global erratum_cortex_x3_2313909_wa
56workaround_runtime_start cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909
57	/* Set/unset bit 36 in ACTLR2_EL1. The first call will set it, applying
58	 * the workaround. Second call clears it to undo it. */
59	sysreg_bit_toggle CORTEX_X3_CPUACTLR2_EL1, CORTEX_X3_CPUACTLR2_EL1_BIT_36
60workaround_runtime_end cortex_x3, ERRATUM(2313909), NO_ISB
61
62check_erratum_ls cortex_x3, ERRATUM(2313909), CPU_REV(1, 0)
63
64workaround_reset_start cortex_x3, ERRATUM(2372204), ERRATA_X3_2372204
65	/* Set bit 40 in CPUACTLR2_EL1 */
66	sysreg_bit_set CORTEX_X3_CPUACTLR2_EL1, BIT(40)
67workaround_reset_end cortex_x3, ERRATUM(2372204)
68
69check_erratum_ls cortex_x3, ERRATUM(2372204), CPU_REV(1, 0)
70
71workaround_reset_start cortex_x3, ERRATUM(2615812), ERRATA_X3_2615812
72	/* Disable retention control for WFI and WFE. */
73	mrs	x0, CORTEX_X3_CPUPWRCTLR_EL1
74	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFI_RET_CTRL_BITS_SHIFT, #3
75	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFE_RET_CTRL_BITS_SHIFT, #3
76	msr	CORTEX_X3_CPUPWRCTLR_EL1, x0
77workaround_reset_end cortex_x3, ERRATUM(2615812)
78
79check_erratum_ls cortex_x3, ERRATUM(2615812), CPU_REV(1, 1)
80
81workaround_runtime_start cortex_x3, ERRATUM(2641945), ERRATA_X3_2641945
82	sysreg_bit_set	CORTEX_X3_CPUACTLR6_EL1, BIT(41)
83workaround_runtime_end cortex_x3, ERRATUM(2641945), NO_ISB
84
85check_erratum_ls cortex_x3, ERRATUM(2641945), CPU_REV(1, 0)
86
87workaround_reset_start cortex_x3, ERRATUM(2742421), ERRATA_X3_2742421
88	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
89	sysreg_bit_set CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_55
90	sysreg_bit_clear CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_56
91workaround_reset_end cortex_x3, ERRATUM(2742421)
92
93check_erratum_ls cortex_x3, ERRATUM(2742421), CPU_REV(1, 1)
94
95workaround_runtime_start cortex_x3, ERRATUM(2743088), ERRATA_X3_2743088
96	/* dsb before isb of power down sequence */
97	dsb sy
98workaround_runtime_end cortex_x3, ERRATUM(2743088), NO_ISB
99
100check_erratum_ls cortex_x3, ERRATUM(2743088), CPU_REV(1, 1)
101
102workaround_reset_start cortex_x3, ERRATUM(2779509), ERRATA_X3_2779509
103	/* Set CPUACTLR3_EL1 bit 47 */
104	sysreg_bit_set CORTEX_X3_CPUACTLR3_EL1, CORTEX_X3_CPUACTLR3_EL1_BIT_47
105workaround_reset_end cortex_x3, ERRATUM(2779509)
106
107check_erratum_ls cortex_x3, ERRATUM(2779509), CPU_REV(1, 1)
108
109workaround_reset_start cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
110#if IMAGE_BL31
111	override_vector_table wa_cve_vbar_cortex_x3
112#endif /* IMAGE_BL31 */
113workaround_reset_end cortex_x3, CVE(2022, 23960)
114
115check_erratum_chosen cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
116
117workaround_reset_start cortex_x3, CVE(2024, 7881), WORKAROUND_CVE_2024_7881
118	/* ---------------------------------
119	 * Sets BIT41 of CPUACTLR6_EL1 which
120	 * disables L1 Data cache prefetcher
121	 * ---------------------------------
122	 */
123	sysreg_bit_set CORTEX_X3_CPUACTLR6_EL1, BIT(41)
124workaround_reset_end cortex_x3, CVE(2024, 7881)
125
126check_erratum_chosen cortex_x3, CVE(2024, 7881), WORKAROUND_CVE_2024_7881
127
128cpu_reset_func_start cortex_x3
129	/* Disable speculative loads */
130	msr	SSBS, xzr
131cpu_reset_func_end cortex_x3
132
133	/* ----------------------------------------------------
134	 * HW will do the cache maintenance while powering down
135	 * ----------------------------------------------------
136	 */
137func cortex_x3_core_pwr_dwn
138	apply_erratum cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909, NO_GET_CPU_REV
139	/* ---------------------------------------------------
140	 * Enable CPU power down bit in power control register
141	 * ---------------------------------------------------
142	 */
143	sysreg_bit_set CORTEX_X3_CPUPWRCTLR_EL1, CORTEX_X3_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
144	apply_erratum cortex_x3, ERRATUM(2743088), ERRATA_X3_2743088, NO_GET_CPU_REV
145	isb
146	ret
147endfunc cortex_x3_core_pwr_dwn
148
149	/* ---------------------------------------------
150	 * This function provides Cortex-X3-
151	 * specific register information for crash
152	 * reporting. It needs to return with x6
153	 * pointing to a list of register names in ascii
154	 * and x8 - x15 having values of registers to be
155	 * reported.
156	 * ---------------------------------------------
157	 */
158.section .rodata.cortex_x3_regs, "aS"
159cortex_x3_regs:  /* The ascii list of register names to be reported */
160	.asciz	"cpuectlr_el1", ""
161
162func cortex_x3_cpu_reg_dump
163	adr	x6, cortex_x3_regs
164	mrs	x8, CORTEX_X3_CPUECTLR_EL1
165	ret
166endfunc cortex_x3_cpu_reg_dump
167
168declare_cpu_ops_wa_4 cortex_x3, CORTEX_X3_MIDR, \
169	cortex_x3_reset_func, \
170	CPU_NO_EXTRA1_FUNC, \
171	CPU_NO_EXTRA2_FUNC, \
172	CPU_NO_EXTRA3_FUNC, \
173	check_erratum_cortex_x3_7881, \
174	cortex_x3_core_pwr_dwn
175