blob: 997f261b7904c5e2f6002c340fc41b00c92039ab [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
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +010050 sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DISABLE_L1_DCACHE_HW_PFTCH
Vikram Kanigiric47e0112015-02-17 11:50:28 +000051 isb
52 dsb ish
53 ret
Kévin Petita877c252015-03-24 14:03:57 +000054endfunc cortex_a72_disable_hw_prefetcher
Vikram Kanigiric47e0112015-02-17 11:50:28 +000055
56 /* ---------------------------------------------
57 * Disable intra-cluster coherency
58 * ---------------------------------------------
59 */
60func cortex_a72_disable_smp
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +010061 sysreg_bit_clear CORTEX_A72_ECTLR_EL1, CORTEX_A72_ECTLR_SMP_BIT
Vikram Kanigiric47e0112015-02-17 11:50:28 +000062 ret
Kévin Petita877c252015-03-24 14:03:57 +000063endfunc cortex_a72_disable_smp
Vikram Kanigiric47e0112015-02-17 11:50:28 +000064
65 /* ---------------------------------------------
66 * Disable debug interfaces
67 * ---------------------------------------------
68 */
69func cortex_a72_disable_ext_debug
70 mov x0, #1
71 msr osdlr_el1, x0
72 isb
73 dsb sy
74 ret
Kévin Petita877c252015-03-24 14:03:57 +000075endfunc cortex_a72_disable_ext_debug
Vikram Kanigiric47e0112015-02-17 11:50:28 +000076
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +010077func check_smccc_arch_workaround_3
78 cpu_check_csv2 x0, 1f
79 mov x0, #ERRATA_APPLIES
80 ret
811:
82 mov x0, #ERRATA_NOT_APPLIES
83 ret
84endfunc check_smccc_arch_workaround_3
85
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010086workaround_reset_start cortex_a72, ERRATUM(859971), ERRATA_A72_859971
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +010087 sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010088workaround_reset_end cortex_a72, ERRATUM(859971)
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010089
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010090check_erratum_ls cortex_a72, ERRATUM(859971), CPU_REV(0, 3)
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010091
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +010092/* Due to the nature of the errata it is applied unconditionally when chosen */
93check_erratum_chosen cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367
94/* erratum workaround is interleaved with generic code */
95add_erratum_entry cortex_a72, ERRATUM(1319367), ERRATA_A72_1319367, NO_APPLY_AT_RESET
96
97workaround_reset_start cortex_a72, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
98#if IMAGE_BL31
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +010099 override_vector_table wa_cve_2017_5715_mmu_vbar
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +0100100#endif
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100101workaround_reset_end cortex_a72, CVE(2017, 5715)
Jayanth Dodderi Chidanandcc02b962023-04-12 18:05:58 +0100102
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100103check_erratum_custom_start cortex_a72, CVE(2017, 5715)
Dimitris Papastamos780cc952018-03-12 13:27:02 +0000104 cpu_check_csv2 x0, 1f
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000105#if WORKAROUND_CVE_2017_5715
106 mov x0, #ERRATA_APPLIES
107#else
108 mov x0, #ERRATA_MISSING
109#endif
110 ret
Dimitris Papastamos780cc952018-03-12 13:27:02 +00001111:
112 mov x0, #ERRATA_NOT_APPLIES
113 ret
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100114check_erratum_custom_end cortex_a72, CVE(2017, 5715)
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100115
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100116workaround_reset_start cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +0100117 sysreg_bit_set CORTEX_A72_CPUACTLR_EL1, CORTEX_A72_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100118 isb
119 dsb sy
120workaround_reset_end cortex_a72, CVE(2018, 3639)
121check_erratum_chosen cortex_a72, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600122
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100123workaround_reset_start cortex_a72, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
124#if IMAGE_BL31
125 /* Skip installing vector table again if already done for CVE(2017, 5715) */
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600126 /*
127 * The Cortex-A72 generic vectors are overridden to apply the
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100128 * mitigation on exception entry from lower ELs for revisions >= r1p0
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600129 * which has CSV2 implemented.
130 */
131 adr x0, wa_cve_vbar_cortex_a72
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100132 mrs x1, vbar_el3
133 cmp x0, x1
134 b.eq 1f
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600135 msr vbar_el3, x0
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +01001361:
137#endif /* IMAGE_BL31 */
138workaround_reset_end cortex_a72, CVE(2022, 23960)
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600139
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100140check_erratum_custom_start cortex_a72, CVE(2022, 23960)
141#if WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960
142 cpu_check_csv2 x0, 1f
143 mov x0, #ERRATA_APPLIES
144 ret
1451:
146#if WORKAROUND_CVE_2022_23960
147 mov x0, #ERRATA_APPLIES
148#else
149 mov x0, #ERRATA_MISSING
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600150#endif /* WORKAROUND_CVE_2022_23960 */
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100151 ret
152#endif /* WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960 */
153 mov x0, #ERRATA_MISSING
154 ret
155check_erratum_custom_end cortex_a72, CVE(2022, 23960)
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000156
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100157cpu_reset_func_start cortex_a72
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100158
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000159 /* ---------------------------------------------
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100160 * Enable the SMP bit.
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000161 * ---------------------------------------------
162 */
Jayanth Dodderi Chidanand30da8af2023-06-23 08:27:09 +0100163 sysreg_bit_set CORTEX_A72_ECTLR_EL1, CORTEX_A72_ECTLR_SMP_BIT
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100164
165cpu_reset_func_end cortex_a72
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000166
167 /* ----------------------------------------------------
168 * The CPU Ops core power down function for Cortex-A72.
169 * ----------------------------------------------------
170 */
171func cortex_a72_core_pwr_dwn
172 mov x18, x30
173
174 /* ---------------------------------------------
175 * Turn off caches.
176 * ---------------------------------------------
177 */
178 bl cortex_a72_disable_dcache
179
180 /* ---------------------------------------------
181 * Disable the L2 prefetches.
182 * ---------------------------------------------
183 */
184 bl cortex_a72_disable_l2_prefetch
185
186 /* ---------------------------------------------
187 * Disable the load-store hardware prefetcher.
188 * ---------------------------------------------
189 */
190 bl cortex_a72_disable_hw_prefetcher
191
192 /* ---------------------------------------------
193 * Flush L1 caches.
194 * ---------------------------------------------
195 */
196 mov x0, #DCCISW
197 bl dcsw_op_level1
198
199 /* ---------------------------------------------
200 * Come out of intra cluster coherency
201 * ---------------------------------------------
202 */
203 bl cortex_a72_disable_smp
204
205 /* ---------------------------------------------
206 * Force the debug interfaces to be quiescent
207 * ---------------------------------------------
208 */
209 mov x30, x18
210 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000211endfunc cortex_a72_core_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000212
213 /* -------------------------------------------------------
214 * The CPU Ops cluster power down function for Cortex-A72.
215 * -------------------------------------------------------
216 */
217func cortex_a72_cluster_pwr_dwn
218 mov x18, x30
219
220 /* ---------------------------------------------
221 * Turn off caches.
222 * ---------------------------------------------
223 */
224 bl cortex_a72_disable_dcache
225
226 /* ---------------------------------------------
227 * Disable the L2 prefetches.
228 * ---------------------------------------------
229 */
230 bl cortex_a72_disable_l2_prefetch
231
232 /* ---------------------------------------------
233 * Disable the load-store hardware prefetcher.
234 * ---------------------------------------------
235 */
236 bl cortex_a72_disable_hw_prefetcher
237
238#if !SKIP_A72_L1_FLUSH_PWR_DWN
239 /* ---------------------------------------------
240 * Flush L1 caches.
241 * ---------------------------------------------
242 */
243 mov x0, #DCCISW
244 bl dcsw_op_level1
245#endif
246
247 /* ---------------------------------------------
248 * Disable the optional ACP.
249 * ---------------------------------------------
250 */
251 bl plat_disable_acp
252
253 /* -------------------------------------------------
254 * Flush the L2 caches.
255 * -------------------------------------------------
256 */
257 mov x0, #DCCISW
258 bl dcsw_op_level2
259
260 /* ---------------------------------------------
261 * Come out of intra cluster coherency
262 * ---------------------------------------------
263 */
264 bl cortex_a72_disable_smp
265
266 /* ---------------------------------------------
267 * Force the debug interfaces to be quiescent
268 * ---------------------------------------------
269 */
270 mov x30, x18
271 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000272endfunc cortex_a72_cluster_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000273
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100274errata_report_shim cortex_a72
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100275
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000276 /* ---------------------------------------------
277 * This function provides cortex_a72 specific
278 * register information for crash reporting.
279 * It needs to return with x6 pointing to
280 * a list of register names in ascii and
281 * x8 - x15 having values of registers to be
282 * reported.
283 * ---------------------------------------------
284 */
285.section .rodata.cortex_a72_regs, "aS"
286cortex_a72_regs: /* The ascii list of register names to be reported */
Naga Sureshkumar Relli6a72a912016-07-01 12:52:41 +0530287 .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000288
289func cortex_a72_cpu_reg_dump
290 adr x6, cortex_a72_regs
Varun Wadekar1384a162017-06-05 14:54:46 -0700291 mrs x8, CORTEX_A72_ECTLR_EL1
292 mrs x9, CORTEX_A72_MERRSR_EL1
293 mrs x10, CORTEX_A72_L2MERRSR_EL1
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000294 ret
Kévin Petita877c252015-03-24 14:03:57 +0000295endfunc cortex_a72_cpu_reg_dump
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000296
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100297declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000298 cortex_a72_reset_func, \
Jayanth Dodderi Chidanandb1cd7d52023-04-12 18:35:45 +0100299 check_erratum_cortex_a72_5715, \
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100300 CPU_NO_EXTRA2_FUNC, \
Bipin Ravicaa2e052022-02-23 23:45:50 -0600301 check_smccc_arch_workaround_3, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000302 cortex_a72_core_pwr_dwn, \
303 cortex_a72_cluster_pwr_dwn