blob: 3766ec769234a4d1fe72b64e5a818eee63fae498 [file] [log] [blame]
Achin Gupta4f6ad662013-10-25 09:08:21 +01001/*
Bipin Ravicaa2e052022-02-23 23:45:50 -06002 * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved.
Varun Wadekar5ee3abc2018-06-12 16:49:12 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Achin Gupta4f6ad662013-10-25 09:08:21 +01004 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Achin Gupta4f6ad662013-10-25 09:08:21 +01006 */
Achin Gupta4f6ad662013-10-25 09:08:21 +01007#include <arch.h>
Andrew Thoelke38bde412014-03-18 13:46:55 +00008#include <asm_macros.S>
Soby Mathew802f8652014-08-14 16:19:29 +01009#include <assert_macros.S>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <common/bl_common.h>
11#include <common/debug.h>
Soby Mathew8e2f2872014-08-14 12:49:05 +010012#include <cortex_a57.h>
Soby Mathewc704cbc2014-08-14 11:33:56 +010013#include <cpu_macros.S>
14#include <plat_macros.S>
Achin Gupta4f6ad662013-10-25 09:08:21 +010015
Soby Mathew8e2f2872014-08-14 12:49:05 +010016 /* ---------------------------------------------
17 * Disable L1 data cache and unified L2 cache
18 * ---------------------------------------------
19 */
20func cortex_a57_disable_dcache
21 mrs x1, sctlr_el3
22 bic x1, x1, #SCTLR_C_BIT
23 msr sctlr_el3, x1
24 isb
25 ret
Kévin Petita877c252015-03-24 14:03:57 +000026endfunc cortex_a57_disable_dcache
Soby Mathew8e2f2872014-08-14 12:49:05 +010027
28 /* ---------------------------------------------
29 * Disable all types of L2 prefetches.
30 * ---------------------------------------------
31 */
32func cortex_a57_disable_l2_prefetch
Varun Wadekar1384a162017-06-05 14:54:46 -070033 mrs x0, CORTEX_A57_ECTLR_EL1
34 orr x0, x0, #CORTEX_A57_ECTLR_DIS_TWD_ACC_PFTCH_BIT
35 mov x1, #CORTEX_A57_ECTLR_L2_IPFTCH_DIST_MASK
36 orr x1, x1, #CORTEX_A57_ECTLR_L2_DPFTCH_DIST_MASK
Soby Mathew8e2f2872014-08-14 12:49:05 +010037 bic x0, x0, x1
Varun Wadekar1384a162017-06-05 14:54:46 -070038 msr CORTEX_A57_ECTLR_EL1, x0
Soby Mathew8e2f2872014-08-14 12:49:05 +010039 isb
Soby Mathew1604fa02014-09-22 12:15:26 +010040 dsb ish
Soby Mathew8e2f2872014-08-14 12:49:05 +010041 ret
Kévin Petita877c252015-03-24 14:03:57 +000042endfunc cortex_a57_disable_l2_prefetch
Soby Mathew8e2f2872014-08-14 12:49:05 +010043
44 /* ---------------------------------------------
45 * Disable intra-cluster coherency
46 * ---------------------------------------------
47 */
48func cortex_a57_disable_smp
Varun Wadekar1384a162017-06-05 14:54:46 -070049 mrs x0, CORTEX_A57_ECTLR_EL1
50 bic x0, x0, #CORTEX_A57_ECTLR_SMP_BIT
51 msr CORTEX_A57_ECTLR_EL1, x0
Soby Mathew8e2f2872014-08-14 12:49:05 +010052 ret
Kévin Petita877c252015-03-24 14:03:57 +000053endfunc cortex_a57_disable_smp
Soby Mathew8e2f2872014-08-14 12:49:05 +010054
55 /* ---------------------------------------------
56 * Disable debug interfaces
57 * ---------------------------------------------
58 */
59func cortex_a57_disable_ext_debug
60 mov x0, #1
61 msr osdlr_el1, x0
62 isb
Ambroise Vincentaa2c0292019-02-21 16:35:49 +000063#if ERRATA_A57_817169
64 /*
65 * Invalidate any TLB address
66 */
67 mov x0, #0
68 tlbi vae3, x0
69#endif
Soby Mathew8e2f2872014-08-14 12:49:05 +010070 dsb sy
71 ret
Kévin Petita877c252015-03-24 14:03:57 +000072endfunc cortex_a57_disable_ext_debug
Achin Gupta4f6ad662013-10-25 09:08:21 +010073
Soby Mathewc0884332014-09-22 12:11:36 +010074 /* --------------------------------------------------
75 * Errata Workaround for Cortex A57 Errata #806969.
76 * This applies only to revision r0p0 of Cortex A57.
77 * Inputs:
78 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000079 * Shall clobber: x0-x17
Soby Mathewc0884332014-09-22 12:11:36 +010080 * --------------------------------------------------
Soby Mathew802f8652014-08-14 16:19:29 +010081 */
Soby Mathewc0884332014-09-22 12:11:36 +010082func errata_a57_806969_wa
83 /*
84 * Compare x0 against revision r0p0
85 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000086 mov x17, x30
87 bl check_errata_806969
88 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +010089 mrs x1, CORTEX_A57_CPUACTLR_EL1
90 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
91 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000921:
93 ret x17
Kévin Petita877c252015-03-24 14:03:57 +000094endfunc errata_a57_806969_wa
Soby Mathewc0884332014-09-22 12:11:36 +010095
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +000096func check_errata_806969
97 mov x1, #0x00
98 b cpu_rev_var_ls
99endfunc check_errata_806969
Soby Mathewc0884332014-09-22 12:11:36 +0100100
101 /* ---------------------------------------------------
Antonio Nino Diaz3f13c352017-02-24 11:39:22 +0000102 * Errata Workaround for Cortex A57 Errata #813419.
103 * This applies only to revision r0p0 of Cortex A57.
104 * ---------------------------------------------------
105 */
106func check_errata_813419
107 /*
108 * Even though this is only needed for revision r0p0, it
109 * is always applied due to limitations of the current
110 * errata framework.
111 */
112 mov x0, #ERRATA_APPLIES
113 ret
114endfunc check_errata_813419
115
116 /* ---------------------------------------------------
Soby Mathewc0884332014-09-22 12:11:36 +0100117 * Errata Workaround for Cortex A57 Errata #813420.
118 * This applies only to revision r0p0 of Cortex A57.
119 * Inputs:
120 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000121 * Shall clobber: x0-x17
Soby Mathewc0884332014-09-22 12:11:36 +0100122 * ---------------------------------------------------
123 */
124func errata_a57_813420_wa
125 /*
126 * Compare x0 against revision r0p0
127 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000128 mov x17, x30
129 bl check_errata_813420
130 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100131 mrs x1, CORTEX_A57_CPUACTLR_EL1
132 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DCC_AS_DCCI
133 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00001341:
135 ret x17
Kévin Petita877c252015-03-24 14:03:57 +0000136endfunc errata_a57_813420_wa
Soby Mathewc0884332014-09-22 12:11:36 +0100137
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000138func check_errata_813420
139 mov x1, #0x00
140 b cpu_rev_var_ls
141endfunc check_errata_813420
142
Ambroise Vincent1b0db762019-02-21 16:35:07 +0000143 /* ---------------------------------------------------
144 * Errata Workaround for Cortex A57 Errata #814670.
145 * This applies only to revision r0p0 of Cortex A57.
146 * Inputs:
147 * x0: variant[4:7] and revision[0:3] of current cpu.
148 * Shall clobber: x0-x17
149 * ---------------------------------------------------
150 */
151func errata_a57_814670_wa
152 /*
153 * Compare x0 against revision r0p0
154 */
155 mov x17, x30
156 bl check_errata_814670
157 cbz x0, 1f
158 mrs x1, CORTEX_A57_CPUACTLR_EL1
159 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DIS_DMB_NULLIFICATION
160 msr CORTEX_A57_CPUACTLR_EL1, x1
161 isb
1621:
163 ret x17
164endfunc errata_a57_814670_wa
165
166func check_errata_814670
167 mov x1, #0x00
168 b cpu_rev_var_ls
169endfunc check_errata_814670
170
Ambroise Vincentaa2c0292019-02-21 16:35:49 +0000171 /* ----------------------------------------------------
172 * Errata Workaround for Cortex A57 Errata #817169.
173 * This applies only to revision <= r0p1 of Cortex A57.
174 * ----------------------------------------------------
175 */
176func check_errata_817169
177 /*
178 * Even though this is only needed for revision <= r0p1, it
179 * is always applied because of the low cost of the workaround.
180 */
181 mov x0, #ERRATA_APPLIES
182 ret
183endfunc check_errata_817169
184
Sandrine Bailleuxd4817592016-01-13 14:57:38 +0000185 /* --------------------------------------------------------------------
186 * Disable the over-read from the LDNP instruction.
187 *
188 * This applies to all revisions <= r1p2. The performance degradation
189 * observed with LDNP/STNP has been fixed on r1p3 and onwards.
190 *
191 * Inputs:
192 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000193 * Shall clobber: x0-x17
Sandrine Bailleuxd4817592016-01-13 14:57:38 +0000194 * ---------------------------------------------------------------------
195 */
196func a57_disable_ldnp_overread
197 /*
198 * Compare x0 against revision r1p2
199 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000200 mov x17, x30
201 bl check_errata_disable_ldnp_overread
202 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100203 mrs x1, CORTEX_A57_CPUACTLR_EL1
204 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DIS_OVERREAD
205 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00002061:
207 ret x17
Sandrine Bailleuxd4817592016-01-13 14:57:38 +0000208endfunc a57_disable_ldnp_overread
209
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000210func check_errata_disable_ldnp_overread
211 mov x1, #0x12
212 b cpu_rev_var_ls
213endfunc check_errata_disable_ldnp_overread
214
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100215 /* ---------------------------------------------------
216 * Errata Workaround for Cortex A57 Errata #826974.
217 * This applies only to revision <= r1p1 of Cortex A57.
218 * Inputs:
219 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000220 * Shall clobber: x0-x17
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100221 * ---------------------------------------------------
222 */
223func errata_a57_826974_wa
224 /*
225 * Compare x0 against revision r1p1
226 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000227 mov x17, x30
228 bl check_errata_826974
229 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100230 mrs x1, CORTEX_A57_CPUACTLR_EL1
231 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_DMB
232 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00002331:
234 ret x17
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100235endfunc errata_a57_826974_wa
236
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000237func check_errata_826974
238 mov x1, #0x11
239 b cpu_rev_var_ls
240endfunc check_errata_826974
241
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100242 /* ---------------------------------------------------
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100243 * Errata Workaround for Cortex A57 Errata #826977.
244 * This applies only to revision <= r1p1 of Cortex A57.
245 * Inputs:
246 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000247 * Shall clobber: x0-x17
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100248 * ---------------------------------------------------
249 */
250func errata_a57_826977_wa
251 /*
252 * Compare x0 against revision r1p1
253 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000254 mov x17, x30
255 bl check_errata_826977
256 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100257 mrs x1, CORTEX_A57_CPUACTLR_EL1
258 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_GRE_NGRE_AS_NGNRE
259 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00002601:
261 ret x17
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100262endfunc errata_a57_826977_wa
263
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000264func check_errata_826977
265 mov x1, #0x11
266 b cpu_rev_var_ls
267endfunc check_errata_826977
268
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100269 /* ---------------------------------------------------
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100270 * Errata Workaround for Cortex A57 Errata #828024.
271 * This applies only to revision <= r1p1 of Cortex A57.
272 * Inputs:
273 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000274 * Shall clobber: x0-x17
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100275 * ---------------------------------------------------
276 */
277func errata_a57_828024_wa
278 /*
279 * Compare x0 against revision r1p1
280 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000281 mov x17, x30
282 bl check_errata_828024
283 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100284 mrs x1, CORTEX_A57_CPUACTLR_EL1
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100285 /*
286 * Setting the relevant bits in CPUACTLR_EL1 has to be done in 2
287 * instructions here because the resulting bitmask doesn't fit in a
288 * 16-bit value so it cannot be encoded in a single instruction.
289 */
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100290 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
291 orr x1, x1, #(CORTEX_A57_CPUACTLR_EL1_DIS_L1_STREAMING | \
292 CORTEX_A57_CPUACTLR_EL1_DIS_STREAMING)
293 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00002941:
295 ret x17
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100296endfunc errata_a57_828024_wa
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100297
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000298func check_errata_828024
299 mov x1, #0x11
300 b cpu_rev_var_ls
301endfunc check_errata_828024
302
Sandrine Bailleux48cbe852016-04-14 14:18:07 +0100303 /* ---------------------------------------------------
304 * Errata Workaround for Cortex A57 Errata #829520.
305 * This applies only to revision <= r1p2 of Cortex A57.
306 * Inputs:
307 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000308 * Shall clobber: x0-x17
Sandrine Bailleux48cbe852016-04-14 14:18:07 +0100309 * ---------------------------------------------------
310 */
311func errata_a57_829520_wa
312 /*
313 * Compare x0 against revision r1p2
314 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000315 mov x17, x30
316 bl check_errata_829520
317 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100318 mrs x1, CORTEX_A57_CPUACTLR_EL1
319 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DIS_INDIRECT_PREDICTOR
320 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00003211:
322 ret x17
Sandrine Bailleux48cbe852016-04-14 14:18:07 +0100323endfunc errata_a57_829520_wa
324
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000325func check_errata_829520
326 mov x1, #0x12
327 b cpu_rev_var_ls
328endfunc check_errata_829520
329
Sandrine Bailleux143ef1a2016-04-21 11:10:52 +0100330 /* ---------------------------------------------------
331 * Errata Workaround for Cortex A57 Errata #833471.
332 * This applies only to revision <= r1p2 of Cortex A57.
333 * Inputs:
334 * x0: variant[4:7] and revision[0:3] of current cpu.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000335 * Shall clobber: x0-x17
Sandrine Bailleux143ef1a2016-04-21 11:10:52 +0100336 * ---------------------------------------------------
337 */
338func errata_a57_833471_wa
339 /*
340 * Compare x0 against revision r1p2
341 */
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000342 mov x17, x30
343 bl check_errata_833471
344 cbz x0, 1f
Eleanor Bonnici41b61be2017-08-09 16:42:40 +0100345 mrs x1, CORTEX_A57_CPUACTLR_EL1
346 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_FORCE_FPSCR_FLUSH
347 msr CORTEX_A57_CPUACTLR_EL1, x1
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +00003481:
349 ret x17
Sandrine Bailleux143ef1a2016-04-21 11:10:52 +0100350endfunc errata_a57_833471_wa
351
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000352func check_errata_833471
353 mov x1, #0x12
354 b cpu_rev_var_ls
355endfunc check_errata_833471
356
Eleanor Bonnici0c9bd272017-08-02 16:35:04 +0100357 /* --------------------------------------------------
358 * Errata Workaround for Cortex A57 Errata #859972.
359 * This applies only to revision <= r1p3 of Cortex A57.
360 * Inputs:
361 * x0: variant[4:7] and revision[0:3] of current cpu.
362 * Shall clobber:
363 * --------------------------------------------------
364 */
365func errata_a57_859972_wa
366 mov x17, x30
367 bl check_errata_859972
368 cbz x0, 1f
369 mrs x1, CORTEX_A57_CPUACTLR_EL1
370 orr x1, x1, #CORTEX_A57_CPUACTLR_EL1_DIS_INSTR_PREFETCH
371 msr CORTEX_A57_CPUACTLR_EL1, x1
3721:
373 ret x17
374endfunc errata_a57_859972_wa
375
376func check_errata_859972
377 mov x1, #0x13
378 b cpu_rev_var_ls
379endfunc check_errata_859972
380
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000381func check_errata_cve_2017_5715
382#if WORKAROUND_CVE_2017_5715
383 mov x0, #ERRATA_APPLIES
384#else
385 mov x0, #ERRATA_MISSING
386#endif
387 ret
388endfunc check_errata_cve_2017_5715
389
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100390func check_errata_cve_2018_3639
391#if WORKAROUND_CVE_2018_3639
392 mov x0, #ERRATA_APPLIES
393#else
394 mov x0, #ERRATA_MISSING
395#endif
396 ret
397endfunc check_errata_cve_2018_3639
398
Manish V Badarkhe7672edf2020-08-03 18:43:14 +0100399 /* --------------------------------------------------
400 * Errata workaround for Cortex A57 Errata #1319537.
401 * This applies to all revisions of Cortex A57.
402 * --------------------------------------------------
403 */
404func check_errata_1319537
405#if ERRATA_A57_1319537
406 mov x0, #ERRATA_APPLIES
407#else
408 mov x0, #ERRATA_MISSING
409#endif
410 ret
411endfunc check_errata_1319537
412
Soby Mathewc0884332014-09-22 12:11:36 +0100413 /* -------------------------------------------------
414 * The CPU Ops reset function for Cortex-A57.
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000415 * Shall clobber: x0-x19
Soby Mathewc0884332014-09-22 12:11:36 +0100416 * -------------------------------------------------
417 */
418func cortex_a57_reset_func
419 mov x19, x30
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000420 bl cpu_get_rev_var
421 mov x18, x0
Soby Mathewc0884332014-09-22 12:11:36 +0100422
423#if ERRATA_A57_806969
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000424 mov x0, x18
Soby Mathewc0884332014-09-22 12:11:36 +0100425 bl errata_a57_806969_wa
Soby Mathew802f8652014-08-14 16:19:29 +0100426#endif
427
Soby Mathewc0884332014-09-22 12:11:36 +0100428#if ERRATA_A57_813420
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000429 mov x0, x18
Soby Mathewc0884332014-09-22 12:11:36 +0100430 bl errata_a57_813420_wa
431#endif
Yatharth Kochar36433d12014-11-20 18:09:41 +0000432
Ambroise Vincent1b0db762019-02-21 16:35:07 +0000433#if ERRATA_A57_814670
434 mov x0, x18
435 bl errata_a57_814670_wa
436#endif
437
Sandrine Bailleuxd4817592016-01-13 14:57:38 +0000438#if A57_DISABLE_NON_TEMPORAL_HINT
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000439 mov x0, x18
Sandrine Bailleuxd4817592016-01-13 14:57:38 +0000440 bl a57_disable_ldnp_overread
441#endif
442
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100443#if ERRATA_A57_826974
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000444 mov x0, x18
Sandrine Bailleuxa7e0c532016-04-14 13:32:31 +0100445 bl errata_a57_826974_wa
446#endif
447
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100448#if ERRATA_A57_826977
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000449 mov x0, x18
Sandrine Bailleuxadcbd552016-04-14 14:24:13 +0100450 bl errata_a57_826977_wa
451#endif
452
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100453#if ERRATA_A57_828024
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000454 mov x0, x18
Sandrine Bailleuxc11116f2016-04-14 14:04:48 +0100455 bl errata_a57_828024_wa
456#endif
Sandrine Bailleux48cbe852016-04-14 14:18:07 +0100457
458#if ERRATA_A57_829520
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000459 mov x0, x18
Sandrine Bailleux48cbe852016-04-14 14:18:07 +0100460 bl errata_a57_829520_wa
461#endif
462
Sandrine Bailleux143ef1a2016-04-21 11:10:52 +0100463#if ERRATA_A57_833471
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000464 mov x0, x18
Sandrine Bailleux143ef1a2016-04-21 11:10:52 +0100465 bl errata_a57_833471_wa
466#endif
467
Eleanor Bonnici0c9bd272017-08-02 16:35:04 +0100468#if ERRATA_A57_859972
469 mov x0, x18
470 bl errata_a57_859972_wa
471#endif
472
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600473#if IMAGE_BL31 && ( WORKAROUND_CVE_2017_5715 || WORKAROUND_CVE_2022_23960 )
474 /* ---------------------------------------------------------------
475 * Override vector table & enable existing workaround if either of
476 * the build flags are enabled
477 * ---------------------------------------------------------------
478 */
Dimitris Papastamos570c06a2018-04-06 15:29:34 +0100479 adr x0, wa_cve_2017_5715_mmu_vbar
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000480 msr vbar_el3, x0
Dimitris Papastamosbb0aa392018-06-07 13:20:19 +0100481 /* isb will be performed before returning from this function */
Dimitris Papastamos446f7f12017-11-30 14:53:53 +0000482#endif
483
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100484#if WORKAROUND_CVE_2018_3639
485 mrs x0, CORTEX_A57_CPUACTLR_EL1
486 orr x0, x0, #CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
487 msr CORTEX_A57_CPUACTLR_EL1, x0
488 isb
489 dsb sy
490#endif
491
Varun Wadekar5ee3abc2018-06-12 16:49:12 -0700492#if A57_ENABLE_NONCACHEABLE_LOAD_FWD
493 /* ---------------------------------------------
494 * Enable higher performance non-cacheable load
495 * forwarding
496 * ---------------------------------------------
497 */
498 mrs x0, CORTEX_A57_CPUACTLR_EL1
499 orr x0, x0, #CORTEX_A57_CPUACTLR_EL1_EN_NC_LOAD_FWD
500 msr CORTEX_A57_CPUACTLR_EL1, x0
501#endif
502
Achin Gupta4f6ad662013-10-25 09:08:21 +0100503 /* ---------------------------------------------
Sandrine Bailleuxf12a31d2016-01-29 14:37:58 +0000504 * Enable the SMP bit.
Achin Gupta4f6ad662013-10-25 09:08:21 +0100505 * ---------------------------------------------
506 */
Varun Wadekar1384a162017-06-05 14:54:46 -0700507 mrs x0, CORTEX_A57_ECTLR_EL1
508 orr x0, x0, #CORTEX_A57_ECTLR_SMP_BIT
509 msr CORTEX_A57_ECTLR_EL1, x0
Andrew Thoelke42e75a72014-04-28 12:28:39 +0100510 isb
Soby Mathewc0884332014-09-22 12:11:36 +0100511 ret x19
Kévin Petita877c252015-03-24 14:03:57 +0000512endfunc cortex_a57_reset_func
Soby Mathewc704cbc2014-08-14 11:33:56 +0100513
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600514func check_errata_cve_2022_23960
515#if WORKAROUND_CVE_2022_23960
516 mov x0, #ERRATA_APPLIES
517#else
518 mov x0, #ERRATA_MISSING
519#endif
520 ret
521endfunc check_errata_cve_2022_23960
522
Bipin Ravicaa2e052022-02-23 23:45:50 -0600523func check_smccc_arch_workaround_3
524 mov x0, #ERRATA_APPLIES
525 ret
526endfunc check_smccc_arch_workaround_3
527
Soby Mathewc0884332014-09-22 12:11:36 +0100528 /* ----------------------------------------------------
529 * The CPU Ops core power down function for Cortex-A57.
530 * ----------------------------------------------------
531 */
Soby Mathew8e2f2872014-08-14 12:49:05 +0100532func cortex_a57_core_pwr_dwn
533 mov x18, x30
534
535 /* ---------------------------------------------
536 * Turn off caches.
537 * ---------------------------------------------
538 */
539 bl cortex_a57_disable_dcache
540
541 /* ---------------------------------------------
542 * Disable the L2 prefetches.
543 * ---------------------------------------------
544 */
545 bl cortex_a57_disable_l2_prefetch
546
547 /* ---------------------------------------------
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100548 * Flush L1 caches.
Soby Mathew8e2f2872014-08-14 12:49:05 +0100549 * ---------------------------------------------
550 */
551 mov x0, #DCCISW
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100552 bl dcsw_op_level1
Soby Mathew8e2f2872014-08-14 12:49:05 +0100553
554 /* ---------------------------------------------
555 * Come out of intra cluster coherency
556 * ---------------------------------------------
557 */
558 bl cortex_a57_disable_smp
559
560 /* ---------------------------------------------
561 * Force the debug interfaces to be quiescent
562 * ---------------------------------------------
563 */
564 mov x30, x18
565 b cortex_a57_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000566endfunc cortex_a57_core_pwr_dwn
Soby Mathew8e2f2872014-08-14 12:49:05 +0100567
Soby Mathewc0884332014-09-22 12:11:36 +0100568 /* -------------------------------------------------------
569 * The CPU Ops cluster power down function for Cortex-A57.
570 * -------------------------------------------------------
571 */
Soby Mathew8e2f2872014-08-14 12:49:05 +0100572func cortex_a57_cluster_pwr_dwn
573 mov x18, x30
574
575 /* ---------------------------------------------
576 * Turn off caches.
577 * ---------------------------------------------
578 */
579 bl cortex_a57_disable_dcache
580
581 /* ---------------------------------------------
582 * Disable the L2 prefetches.
583 * ---------------------------------------------
584 */
585 bl cortex_a57_disable_l2_prefetch
586
Soby Mathew937488b2014-09-22 14:13:34 +0100587#if !SKIP_A57_L1_FLUSH_PWR_DWN
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100588 /* -------------------------------------------------
589 * Flush the L1 caches.
590 * -------------------------------------------------
591 */
592 mov x0, #DCCISW
593 bl dcsw_op_level1
Soby Mathew937488b2014-09-22 14:13:34 +0100594#endif
Soby Mathew8e2f2872014-08-14 12:49:05 +0100595 /* ---------------------------------------------
596 * Disable the optional ACP.
597 * ---------------------------------------------
598 */
599 bl plat_disable_acp
600
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100601 /* -------------------------------------------------
602 * Flush the L2 caches.
603 * -------------------------------------------------
Soby Mathew8e2f2872014-08-14 12:49:05 +0100604 */
605 mov x0, #DCCISW
Soby Mathew42aa5eb2014-09-02 10:47:33 +0100606 bl dcsw_op_level2
Soby Mathew8e2f2872014-08-14 12:49:05 +0100607
608 /* ---------------------------------------------
609 * Come out of intra cluster coherency
610 * ---------------------------------------------
611 */
612 bl cortex_a57_disable_smp
613
614 /* ---------------------------------------------
615 * Force the debug interfaces to be quiescent
616 * ---------------------------------------------
617 */
618 mov x30, x18
619 b cortex_a57_disable_ext_debug
Kévin Petita877c252015-03-24 14:03:57 +0000620endfunc cortex_a57_cluster_pwr_dwn
Soby Mathew8e2f2872014-08-14 12:49:05 +0100621
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000622#if REPORT_ERRATA
623/*
624 * Errata printing function for Cortex A57. Must follow AAPCS.
625 */
626func cortex_a57_errata_report
627 stp x8, x30, [sp, #-16]!
628
629 bl cpu_get_rev_var
630 mov x8, x0
631
632 /*
633 * Report all errata. The revision-variant information is passed to
634 * checking functions of each errata.
635 */
636 report_errata ERRATA_A57_806969, cortex_a57, 806969
Antonio Nino Diaz3f13c352017-02-24 11:39:22 +0000637 report_errata ERRATA_A57_813419, cortex_a57, 813419
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000638 report_errata ERRATA_A57_813420, cortex_a57, 813420
Ambroise Vincent1b0db762019-02-21 16:35:07 +0000639 report_errata ERRATA_A57_814670, cortex_a57, 814670
Ambroise Vincentaa2c0292019-02-21 16:35:49 +0000640 report_errata ERRATA_A57_817169, cortex_a57, 817169
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000641 report_errata A57_DISABLE_NON_TEMPORAL_HINT, cortex_a57, \
642 disable_ldnp_overread
643 report_errata ERRATA_A57_826974, cortex_a57, 826974
644 report_errata ERRATA_A57_826977, cortex_a57, 826977
645 report_errata ERRATA_A57_828024, cortex_a57, 828024
646 report_errata ERRATA_A57_829520, cortex_a57, 829520
647 report_errata ERRATA_A57_833471, cortex_a57, 833471
Eleanor Bonnici0c9bd272017-08-02 16:35:04 +0100648 report_errata ERRATA_A57_859972, cortex_a57, 859972
Manish V Badarkhe7672edf2020-08-03 18:43:14 +0100649 report_errata ERRATA_A57_1319537, cortex_a57, 1319537
Dimitris Papastamos858bd612018-01-16 10:32:47 +0000650 report_errata WORKAROUND_CVE_2017_5715, cortex_a57, cve_2017_5715
Dimitris Papastamose6625ec2018-04-05 14:38:26 +0100651 report_errata WORKAROUND_CVE_2018_3639, cortex_a57, cve_2018_3639
Bipin Ravicf4d50a2022-02-15 23:24:51 -0600652 report_errata WORKAROUND_CVE_2022_23960, cortex_a57, cve_2022_23960
Jeenu Viswambharand5ec3672017-01-03 11:01:51 +0000653
654 ldp x8, x30, [sp], #16
655 ret
656endfunc cortex_a57_errata_report
657#endif
658
Soby Mathew38b4bc92014-08-14 13:36:41 +0100659 /* ---------------------------------------------
660 * This function provides cortex_a57 specific
661 * register information for crash reporting.
662 * It needs to return with x6 pointing to
663 * a list of register names in ascii and
664 * x8 - x15 having values of registers to be
665 * reported.
666 * ---------------------------------------------
667 */
668.section .rodata.cortex_a57_regs, "aS"
669cortex_a57_regs: /* The ascii list of register names to be reported */
Naga Sureshkumar Relli6a72a912016-07-01 12:52:41 +0530670 .asciz "cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
Soby Mathew38b4bc92014-08-14 13:36:41 +0100671
672func cortex_a57_cpu_reg_dump
673 adr x6, cortex_a57_regs
Varun Wadekar1384a162017-06-05 14:54:46 -0700674 mrs x8, CORTEX_A57_ECTLR_EL1
675 mrs x9, CORTEX_A57_MERRSR_EL1
676 mrs x10, CORTEX_A57_L2MERRSR_EL1
Soby Mathew38b4bc92014-08-14 13:36:41 +0100677 ret
Kévin Petita877c252015-03-24 14:03:57 +0000678endfunc cortex_a57_cpu_reg_dump
Soby Mathew38b4bc92014-08-14 13:36:41 +0100679
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100680declare_cpu_ops_wa cortex_a57, CORTEX_A57_MIDR, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000681 cortex_a57_reset_func, \
Dimitris Papastamos914757c2018-03-12 14:47:09 +0000682 check_errata_cve_2017_5715, \
Dimitris Papastamosba51d9e2018-05-16 11:36:14 +0100683 CPU_NO_EXTRA2_FUNC, \
Bipin Ravicaa2e052022-02-23 23:45:50 -0600684 check_smccc_arch_workaround_3, \
Jeenu Viswambharanee5eb802016-11-18 12:58:28 +0000685 cortex_a57_core_pwr_dwn, \
686 cortex_a57_cluster_pwr_dwn