blob: 3dc44805e7da01776fa5e8c79aa4e09cca70b00f [file] [log] [blame]
Vikram Kanigiric47e0112015-02-17 11:50:28 +00001/*
Bipin Ravicf4d50a2022-02-15 23:24:51 -06002 * Copyright (c) 2015-2022, 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
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +010081 /* --------------------------------------------------
82 * Errata Workaround for Cortex A72 Errata #859971.
83 * This applies only to revision <= r0p3 of Cortex A72.
84 * Inputs:
85 * x0: variant[4:7] and revision[0:3] of current cpu.
86 * Shall clobber:
87 * --------------------------------------------------
88 */
89func errata_a72_859971_wa
90 mov x17,x30
91 bl check_errata_859971
92 cbz x0, 1f
93 mrs x1, CORTEX_A72_CPUACTLR_EL1
94 orr x1, x1, #CORTEX_A72_CPUACTLR_EL1_DIS_INSTR_PREFETCH
95 msr CORTEX_A72_CPUACTLR_EL1, x1
961:
97 ret x17
98endfunc errata_a72_859971_wa
99
100func check_errata_859971
101 mov x1, #0x03
102 b cpu_rev_var_ls
103endfunc check_errata_859971
104
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000105func check_errata_cve_2017_5715
Dimitris Papastamos780cc952018-03-12 13:27:02 +0000106 cpu_check_csv2 x0, 1f
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000107#if WORKAROUND_CVE_2017_5715
108 mov x0, #ERRATA_APPLIES
109#else
110 mov x0, #ERRATA_MISSING
111#endif
112 ret
Dimitris Papastamos780cc952018-03-12 13:27:02 +00001131:
114 mov x0, #ERRATA_NOT_APPLIES
115 ret
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000116endfunc check_errata_cve_2017_5715
117
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100118func check_errata_cve_2018_3639
119#if WORKAROUND_CVE_2018_3639
120 mov x0, #ERRATA_APPLIES
121#else
122 mov x0, #ERRATA_MISSING
123#endif
124 ret
125endfunc check_errata_cve_2018_3639
126
Manish V Badarkhe7672edf2020-08-03 18:43:14 +0100127 /* --------------------------------------------------
128 * Errata workaround for Cortex A72 Errata #1319367.
129 * This applies to all revisions of Cortex A72.
130 * --------------------------------------------------
131 */
132func check_errata_1319367
133#if ERRATA_A72_1319367
134 mov x0, #ERRATA_APPLIES
135#else
136 mov x0, #ERRATA_MISSING
137#endif
138 ret
139endfunc check_errata_1319367
140
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600141func check_errata_cve_2022_23960
142#if WORKAROUND_CVE_2022_23960
143 mov x0, #ERRATA_APPLIES
144#else
145 mov x0, #ERRATA_MISSING
146#endif
147 ret
148endfunc check_errata_cve_2022_23960
149
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000150 /* -------------------------------------------------
151 * The CPU Ops reset function for Cortex-A72.
152 * -------------------------------------------------
153 */
154func cortex_a72_reset_func
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100155 mov x19, x30
156 bl cpu_get_rev_var
157 mov x18, x0
158
159#if ERRATA_A72_859971
160 mov x0, x18
161 bl errata_a72_859971_wa
162#endif
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000163
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600164#if IMAGE_BL31 && (WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960)
Dimitris Papastamos780cc952018-03-12 13:27:02 +0000165 cpu_check_csv2 x0, 1f
Dimitris Papastamos570c06a2018-04-06 15:29:34 +0100166 adr x0, wa_cve_2017_5715_mmu_vbar
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000167 msr vbar_el3, x0
Dimitris Papastamosbb0aa392018-06-07 13:20:19 +0100168 /* isb will be performed before returning from this function */
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600169
170 /* Skip CVE_2022_23960 mitigation if cve_2017_5715 mitigation applied */
171 b 2f
Dimitris Papastamos780cc952018-03-12 13:27:02 +00001721:
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600173#if WORKAROUND_CVE_2022_23960
174 /*
175 * The Cortex-A72 generic vectors are overridden to apply the
176 * mitigation on exception entry from lower ELs for revisions >= r1p0
177 * which has CSV2 implemented.
178 */
179 adr x0, wa_cve_vbar_cortex_a72
180 msr vbar_el3, x0
181
182 /* isb will be performed before returning from this function */
183#endif /* WORKAROUND_CVE_2022_23960 */
1842:
185#endif /* IMAGE_BL31 && (WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960) */
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000186
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100187#if WORKAROUND_CVE_2018_3639
188 mrs x0, CORTEX_A72_CPUACTLR_EL1
189 orr x0, x0, #CORTEX_A72_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
190 msr CORTEX_A72_CPUACTLR_EL1, x0
191 isb
192 dsb sy
193#endif
194
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000195 /* ---------------------------------------------
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100196 * Enable the SMP bit.
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000197 * ---------------------------------------------
198 */
Varun Wadekar1384a162017-06-05 14:54:46 -0700199 mrs x0, CORTEX_A72_ECTLR_EL1
200 orr x0, x0, #CORTEX_A72_ECTLR_SMP_BIT
201 msr CORTEX_A72_ECTLR_EL1, x0
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000202 isb
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100203 ret x19
Kévin Petita877c252015-03-24 14:03:57 +0000204endfunc cortex_a72_reset_func
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000205
206 /* ----------------------------------------------------
207 * The CPU Ops core power down function for Cortex-A72.
208 * ----------------------------------------------------
209 */
210func cortex_a72_core_pwr_dwn
211 mov x18, x30
212
213 /* ---------------------------------------------
214 * Turn off caches.
215 * ---------------------------------------------
216 */
217 bl cortex_a72_disable_dcache
218
219 /* ---------------------------------------------
220 * Disable the L2 prefetches.
221 * ---------------------------------------------
222 */
223 bl cortex_a72_disable_l2_prefetch
224
225 /* ---------------------------------------------
226 * Disable the load-store hardware prefetcher.
227 * ---------------------------------------------
228 */
229 bl cortex_a72_disable_hw_prefetcher
230
231 /* ---------------------------------------------
232 * Flush L1 caches.
233 * ---------------------------------------------
234 */
235 mov x0, #DCCISW
236 bl dcsw_op_level1
237
238 /* ---------------------------------------------
239 * Come out of intra cluster coherency
240 * ---------------------------------------------
241 */
242 bl cortex_a72_disable_smp
243
244 /* ---------------------------------------------
245 * Force the debug interfaces to be quiescent
246 * ---------------------------------------------
247 */
248 mov x30, x18
249 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000250endfunc cortex_a72_core_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000251
252 /* -------------------------------------------------------
253 * The CPU Ops cluster power down function for Cortex-A72.
254 * -------------------------------------------------------
255 */
256func cortex_a72_cluster_pwr_dwn
257 mov x18, x30
258
259 /* ---------------------------------------------
260 * Turn off caches.
261 * ---------------------------------------------
262 */
263 bl cortex_a72_disable_dcache
264
265 /* ---------------------------------------------
266 * Disable the L2 prefetches.
267 * ---------------------------------------------
268 */
269 bl cortex_a72_disable_l2_prefetch
270
271 /* ---------------------------------------------
272 * Disable the load-store hardware prefetcher.
273 * ---------------------------------------------
274 */
275 bl cortex_a72_disable_hw_prefetcher
276
277#if !SKIP_A72_L1_FLUSH_PWR_DWN
278 /* ---------------------------------------------
279 * Flush L1 caches.
280 * ---------------------------------------------
281 */
282 mov x0, #DCCISW
283 bl dcsw_op_level1
284#endif
285
286 /* ---------------------------------------------
287 * Disable the optional ACP.
288 * ---------------------------------------------
289 */
290 bl plat_disable_acp
291
292 /* -------------------------------------------------
293 * Flush the L2 caches.
294 * -------------------------------------------------
295 */
296 mov x0, #DCCISW
297 bl dcsw_op_level2
298
299 /* ---------------------------------------------
300 * Come out of intra cluster coherency
301 * ---------------------------------------------
302 */
303 bl cortex_a72_disable_smp
304
305 /* ---------------------------------------------
306 * Force the debug interfaces to be quiescent
307 * ---------------------------------------------
308 */
309 mov x30, x18
310 b cortex_a72_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000311endfunc cortex_a72_cluster_pwr_dwn
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000312
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100313#if REPORT_ERRATA
314/*
315 * Errata printing function for Cortex A72. Must follow AAPCS.
316 */
317func cortex_a72_errata_report
318 stp x8, x30, [sp, #-16]!
319
320 bl cpu_get_rev_var
321 mov x8, x0
322
323 /*
324 * Report all errata. The revision-variant information is passed to
325 * checking functions of each errata.
326 */
327 report_errata ERRATA_A72_859971, cortex_a72, 859971
Manish V Badarkhe7672edf2020-08-03 18:43:14 +0100328 report_errata ERRATA_A72_1319367, cortex_a72, 1319367
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000329 report_errata WORKAROUND_CVE_2017_5715, cortex_a72, cve_2017_5715
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100330 report_errata WORKAROUND_CVE_2018_3639, cortex_a72, cve_2018_3639
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600331 report_errata WORKAROUND_CVE_2022_23960, cortex_a72, cve_2022_23960
Eleanor Bonnicic3b4ca12017-08-02 18:33:41 +0100332
333 ldp x8, x30, [sp], #16
334 ret
335endfunc cortex_a72_errata_report
336#endif
337
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000338 /* ---------------------------------------------
339 * This function provides cortex_a72 specific
340 * register information for crash reporting.
341 * It needs to return with x6 pointing to
342 * a list of register names in ascii and
343 * x8 - x15 having values of registers to be
344 * reported.
345 * ---------------------------------------------
346 */
347.section .rodata.cortex_a72_regs, "aS"
348cortex_a72_regs: /* The ascii list of register names to be reported */
Naga Sureshkumar Relli6a72a912016-07-01 12:52:41 +0530349 .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000350
351func cortex_a72_cpu_reg_dump
352 adr x6, cortex_a72_regs
Varun Wadekar1384a162017-06-05 14:54:46 -0700353 mrs x8, CORTEX_A72_ECTLR_EL1
354 mrs x9, CORTEX_A72_MERRSR_EL1
355 mrs x10, CORTEX_A72_L2MERRSR_EL1
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000356 ret
Kévin Petita877c252015-03-24 14:03:57 +0000357endfunc cortex_a72_cpu_reg_dump
Vikram Kanigiric47e0112015-02-17 11:50:28 +0000358
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100359declare_cpu_ops_wa cortex_a72, CORTEX_A72_MIDR, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000360 cortex_a72_reset_func, \
Dimitris Papastamos914757c2018-03-12 14:47:09 +0000361 check_errata_cve_2017_5715, \
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100362 CPU_NO_EXTRA2_FUNC, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000363 cortex_a72_core_pwr_dwn, \
364 cortex_a72_cluster_pwr_dwn