blob: ed713c994c6751d0227975c1f2ae9540c9e2c0be [file] [log] [blame]
Vikram Kanigiric47e0112015-02-17 11:50:28 +00001/*
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +01002 * Copyright (c) 2015-2023, Arm Limited and Contributors. All rights reserved.
Vikram Kanigiric47e0112015-02-17 11:50:28 +00003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Vikram Kanigiric47e0112015-02-17 11:50:28 +00005 */
6#include <arch.h>
7#include <asm_macros.S>
8#include <assert_macros.S>
9#include <cortex_a72.h>
10#include <cpu_macros.S>
11#include <plat_macros.S>
Bipin Ravicf4d50a2022-02-15 23:24:51 -060012#include "wa_cve_2022_23960_bhb_vector.S"
13
14#if WORKAROUND_CVE_2022_23960
15 wa_cve_2022_23960_bhb_vector_table CORTEX_A72_BHB_LOOP_COUNT, cortex_a72
16#endif /* WORKAROUND_CVE_2022_23960 */
Vikram Kanigiric47e0112015-02-17 11:50:28 +000017
18 /* ---------------------------------------------
19 * Disable L1 data cache and unified L2 cache
20 * ---------------------------------------------
21 */
22func cortex_a72_disable_dcache
23 mrs x1, sctlr_el3
24 bic x1, x1, #SCTLR_C_BIT
25 msr sctlr_el3, x1
26 isb
27 ret
Kévin Petita877c252015-03-24 14:03:57 +000028endfunc cortex_a72_disable_dcache
Vikram Kanigiric47e0112015-02-17 11:50:28 +000029
30 /* ---------------------------------------------
31 * Disable all types of L2 prefetches.
32 * ---------------------------------------------
33 */
34func cortex_a72_disable_l2_prefetch
Varun Wadekar1384a162017-06-05 14:54:46 -070035 mrs x0, CORTEX_A72_ECTLR_EL1
36 orr x0, x0, #CORTEX_A72_ECTLR_DIS_TWD_ACC_PFTCH_BIT
37 mov x1, #CORTEX_A72_ECTLR_L2_IPFTCH_DIST_MASK
38 orr x1, x1, #CORTEX_A72_ECTLR_L2_DPFTCH_DIST_MASK
Vikram Kanigiric47e0112015-02-17 11:50:28 +000039 bic x0, x0, x1
Varun Wadekar1384a162017-06-05 14:54:46 -070040 msr CORTEX_A72_ECTLR_EL1, x0
Vikram Kanigiric47e0112015-02-17 11:50:28 +000041 isb
42 ret
Kévin Petita877c252015-03-24 14:03:57 +000043endfunc cortex_a72_disable_l2_prefetch
Vikram Kanigiric47e0112015-02-17 11:50:28 +000044
45 /* ---------------------------------------------
46 * Disable the load-store hardware prefetcher.
47 * ---------------------------------------------
48 */
49func cortex_a72_disable_hw_prefetcher
Eleanor Bonnici41b61be2017-08-09 16:42:40 +010050 mrs x0, CORTEX_A72_CPUACTLR_EL1
51 orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
52 msr CORTEX_A72_CPUACTLR_EL1, x0
Vikram Kanigiric47e0112015-02-17 11:50:28 +000053 isb
54 dsb ish
55 ret
Kévin Petita877c252015-03-24 14:03:57 +000056endfunc cortex_a72_disable_hw_prefetcher
Vikram Kanigiric47e0112015-02-17 11:50:28 +000057
58 /* ---------------------------------------------
59 * Disable intra-cluster coherency
60 * ---------------------------------------------
61 */
62func cortex_a72_disable_smp
Varun Wadekar1384a162017-06-05 14:54:46 -070063 mrs x0, CORTEX_A72_ECTLR_EL1
64 bic x0, x0, #CORTEX_A72_ECTLR_SMP_BIT
65 msr CORTEX_A72_ECTLR_EL1, x0
Vikram Kanigiric47e0112015-02-17 11:50:28 +000066 ret
Kévin Petita877c252015-03-24 14:03:57 +000067endfunc cortex_a72_disable_smp
Vikram Kanigiric47e0112015-02-17 11:50:28 +000068
69 /* ---------------------------------------------
70 * Disable debug interfaces
71 * ---------------------------------------------
72 */
73func cortex_a72_disable_ext_debug
74 mov x0, #1
75 msr osdlr_el1, x0
76 isb
77 dsb sy
78 ret
Kévin Petita877c252015-03-24 14:03:57 +000079endfunc cortex_a72_disable_ext_debug
Vikram Kanigiric47e0112015-02-17 11:50:28 +000080
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +010081func check_smccc_arch_workaround_3
82 cpu_check_csv2 x0, 1f
83 mov x0, #ERRATA_APPLIES
84 ret
851:
86 mov x0, #ERRATA_NOT_APPLIES
87 ret
88endfunc check_smccc_arch_workaround_3
89
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010090workaround_reset_start cortex_a72, ERRATUM(859971), ERRATA_A72_859971
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010091 mrs x1, CORTEX_A72_CPUACTLR_EL1
92 orr x1, x1, #CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH
93 msr CORTEX_A72_CPUACTLR_EL1, x1
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010094workaround_reset_end cortex_a72, ERRATUM(859971)
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010095
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010096check_erratum_ls cortex_a72, ERRATUM(859971), CPU_REV(0, 3)
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010097
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010098/* Due to the nature of the errata it is applied unconditionally when chosen */
99check_erratum_chosen cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367
100/* erratum workaround is interleaved with generic code */
101add_erratum_entry cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367, NO_APPLY_AT_RESET
102
103workaround_reset_start cortex_a72, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
104#if IMAGE_BL31
105 adr x0, wa_cve_2017_5715_mmu_vbar
106 msr vbar_el3, x0
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +0100107#endif
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100108workaround_reset_end cortex_a72, CVE(2017, 5715)
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +0100109
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100110check_erratum_custom_start cortex_a72, CVE(2017, 5715)
Dimitris Papastamos780cc952018-03-12 13:27:02 +0000111 cpu_check_csv2 x0, 1f
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000112#if WORKAROUND_CVE_2017_5715
113 mov x0, #ERRATA_APPLIES
114#else
115 mov x0, #ERRATA_MISSING
116#endif
117 ret
Dimitris Papastamos780cc952018-03-12 13:27:02 +00001181:
119 mov x0, #ERRATA_NOT_APPLIES
120 ret
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100121check_erratum_custom_end cortex_a72, CVE(2017, 5715)
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100122
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100123workaround_reset_start cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
124 mrs x0, CORTEX_A72_CPUACTLR_EL1
125 orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
126 msr CORTEX_A72_CPUACTLR_EL1, x0
127 isb
128 dsb sy
129workaround_reset_end cortex_a72, CVE(2018, 3639)
130check_erratum_chosen cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600131
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100132workaround_reset_start cortex_a72, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
133#if IMAGE_BL31
134 /* Skip installing vector table again if already done for CVE(2017, 5715) */
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600135 /*
136 * The Cortex-A72 generic vectors are overridden to apply the
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100137 * mitigation on exception entry from lower ELs for revisions >= r1p0
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600138 * which has CSV2 implemented.
139 */
140 adr x0, wa_cve_vbar_cortex_a72
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100141 mrs x1, vbar_el3
142 cmp x0, x1
143 b.eq 1f
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600144 msr vbar_el3, x0
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +01001451:
146#endif /* IMAGE_BL31 */
147workaround_reset_end cortex_a72, CVE(2022, 23960)
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600148
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100149check_erratum_custom_start cortex_a72, CVE(2022, 23960)
150#if WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960
151 cpu_check_csv2 x0, 1f
152 mov x0, #ERRATA_APPLIES
153 ret
1541:
155#if WORKAROUND_CVE_2022_23960
156 mov x0, #ERRATA_APPLIES
157#else
158 mov x0, #ERRATA_MISSING
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600159#endif /* WORKAROUND_CVE_2022_23960 */
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100160 ret
161#endif /* WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960 */
162 mov x0, #ERRATA_MISSING
163 ret
164check_erratum_custom_end cortex_a72, CVE(2022, 23960)
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000165
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100166cpu_reset_func_start cortex_a72
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100167
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000168 /* ---------------------------------------------
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100169 * Enable the SMP bit.
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000170 * ---------------------------------------------
171 */
Varun Wadekar1384a162017-06-05 14:54:46 -0700172 mrs x0, CORTEX_A72_ECTLR_EL1
173 orr x0, x0, #CORTEX_A72_ECTLR_SMP_BIT
174 msr CORTEX_A72_ECTLR_EL1, x0
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100175
176cpu_reset_func_end cortex_a72
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000177
178 /* ----------------------------------------------------
179 * The CPU Ops core power down function for Cortex-A72.
180 * ----------------------------------------------------
181 */
182func cortex_a72_core_pwr_dwn
183 mov x18, x30
184
185 /* ---------------------------------------------
186 * Turn off caches.
187 * ---------------------------------------------
188 */
189 bl cortex_a72_disable_dcache
190
191 /* ---------------------------------------------
192 * Disable the L2 prefetches.
193 * ---------------------------------------------
194 */
195 bl cortex_a72_disable_l2_prefetch
196
197 /* ---------------------------------------------
198 * Disable the load-store hardware prefetcher.
199 * ---------------------------------------------
200 */
201 bl cortex_a72_disable_hw_prefetcher
202
203 /* ---------------------------------------------
204 * Flush L1 caches.
205 * ---------------------------------------------
206 */
207 mov x0, #DCCISW
208 bl dcsw_op_level1
209
210 /* ---------------------------------------------
211 * Come out of intra cluster coherency
212 * ---------------------------------------------
213 */
214 bl cortex_a72_disable_smp
215
216 /* ---------------------------------------------
217 * Force the debug interfaces to be quiescent
218 * ---------------------------------------------
219 */
220 mov x30, x18
221 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000222endfunc cortex_a72_core_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000223
224 /* -------------------------------------------------------
225 * The CPU Ops cluster power down function for Cortex-A72.
226 * -------------------------------------------------------
227 */
228func cortex_a72_cluster_pwr_dwn
229 mov x18, x30
230
231 /* ---------------------------------------------
232 * Turn off caches.
233 * ---------------------------------------------
234 */
235 bl cortex_a72_disable_dcache
236
237 /* ---------------------------------------------
238 * Disable the L2 prefetches.
239 * ---------------------------------------------
240 */
241 bl cortex_a72_disable_l2_prefetch
242
243 /* ---------------------------------------------
244 * Disable the load-store hardware prefetcher.
245 * ---------------------------------------------
246 */
247 bl cortex_a72_disable_hw_prefetcher
248
249#if !SKIP_A72_L1_FLUSH_PWR_DWN
250 /* ---------------------------------------------
251 * Flush L1 caches.
252 * ---------------------------------------------
253 */
254 mov x0, #DCCISW
255 bl dcsw_op_level1
256#endif
257
258 /* ---------------------------------------------
259 * Disable the optional ACP.
260 * ---------------------------------------------
261 */
262 bl plat_disable_acp
263
264 /* -------------------------------------------------
265 * Flush the L2 caches.
266 * -------------------------------------------------
267 */
268 mov x0, #DCCISW
269 bl dcsw_op_level2
270
271 /* ---------------------------------------------
272 * Come out of intra cluster coherency
273 * ---------------------------------------------
274 */
275 bl cortex_a72_disable_smp
276
277 /* ---------------------------------------------
278 * Force the debug interfaces to be quiescent
279 * ---------------------------------------------
280 */
281 mov x30, x18
282 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000283endfunc cortex_a72_cluster_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000284
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100285errata_report_shim cortex_a72
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100286
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000287 /* ---------------------------------------------
288 * This function provides cortex_a72 specific
289 * register information for crash reporting.
290 * It needs to return with x6 pointing to
291 * a list of register names in ascii and
292 * x8 - x15 having values of registers to be
293 * reported.
294 * ---------------------------------------------
295 */
296.section .rodata.cortex_a72_regs, "aS"
297cortex_a72_regs: /* The ascii list of register names to be reported */
Naga Sureshkumar Relli6a72a912016-07-01 12:52:41 +0530298 .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000299
300func cortex_a72_cpu_reg_dump
301 adr x6, cortex_a72_regs
Varun Wadekar1384a162017-06-05 14:54:46 -0700302 mrs x8, CORTEX_A72_ECTLR_EL1
303 mrs x9, CORTEX_A72_MERRSR_EL1
304 mrs x10, CORTEX_A72_L2MERRSR_EL1
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000305 ret
Kévin Petita877c252015-03-24 14:03:57 +0000306endfunc cortex_a72_cpu_reg_dump
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000307
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100308declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000309 cortex_a72_reset_func, \
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100310 check_erratum_cortex_a72_5715, \
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100311 CPU_NO_EXTRA2_FUNC, \
Bipin Ravicaa2e052022-02-23 23:45:50 -0600312 check_smccc_arch_workaround_3, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000313 cortex_a72_core_pwr_dwn, \
314 cortex_a72_cluster_pwr_dwn