xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_a57.S (revision 35b2bbf4942689fd52fa741ac7d93bc7f1d4c230)
19b476841SSoby Mathew/*
25cba510eSBoyan Karatotev * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
3cd0ea184SVarun Wadekar * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
49b476841SSoby Mathew *
582cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
69b476841SSoby Mathew */
79b476841SSoby Mathew#include <arch.h>
89b476841SSoby Mathew#include <asm_macros.S>
9d9bdaf2dSSoby Mathew#include <assert_macros.S>
1009d40e0eSAntonio Nino Diaz#include <common/bl_common.h>
1109d40e0eSAntonio Nino Diaz#include <common/debug.h>
12add40351SSoby Mathew#include <cortex_a57.h>
139b476841SSoby Mathew#include <cpu_macros.S>
149b476841SSoby Mathew#include <plat_macros.S>
159b476841SSoby Mathew
1689dba82dSBoyan Karatotevcpu_reset_prologue cortex_a57
1789dba82dSBoyan Karatotev
18add40351SSoby Mathew	/* ---------------------------------------------
19add40351SSoby Mathew	 * Disable all types of L2 prefetches.
20add40351SSoby Mathew	 * ---------------------------------------------
21add40351SSoby Mathew	 */
22add40351SSoby Mathewfunc cortex_a57_disable_l2_prefetch
23fb7d32e5SVarun Wadekar	mrs	x0, CORTEX_A57_ECTLR_EL1
24fb7d32e5SVarun Wadekar	orr	x0, x0, #CORTEX_A57_ECTLR_DIS_TWD_ACC_PFTCH_BIT
25fb7d32e5SVarun Wadekar	mov	x1, #CORTEX_A57_ECTLR_L2_IPFTCH_DIST_MASK
26fb7d32e5SVarun Wadekar	orr	x1, x1, #CORTEX_A57_ECTLR_L2_DPFTCH_DIST_MASK
27add40351SSoby Mathew	bic	x0, x0, x1
28fb7d32e5SVarun Wadekar	msr	CORTEX_A57_ECTLR_EL1, x0
29add40351SSoby Mathew	isb
30b1a9631dSSoby Mathew	dsb	ish
31add40351SSoby Mathew	ret
328b779620SKévin Petitendfunc cortex_a57_disable_l2_prefetch
33add40351SSoby Mathew
34add40351SSoby Mathew	/* ---------------------------------------------
35add40351SSoby Mathew	 * Disable intra-cluster coherency
36add40351SSoby Mathew	 * ---------------------------------------------
37add40351SSoby Mathew	 */
38add40351SSoby Mathewfunc cortex_a57_disable_smp
39dbab05efSBoyan Karatotev	sysreg_bit_clear CORTEX_A57_ECTLR_EL1, CORTEX_A57_ECTLR_SMP_BIT
40add40351SSoby Mathew	ret
418b779620SKévin Petitendfunc cortex_a57_disable_smp
42add40351SSoby Mathew
43add40351SSoby Mathew	/* ---------------------------------------------
44add40351SSoby Mathew	 * Disable debug interfaces
45add40351SSoby Mathew	 * ---------------------------------------------
46add40351SSoby Mathew	 */
47add40351SSoby Mathewfunc cortex_a57_disable_ext_debug
48add40351SSoby Mathew	mov	x0, #1
49add40351SSoby Mathew	msr	osdlr_el1, x0
50add40351SSoby Mathew	isb
514ac54693SBoyan Karatotev
52*645917abSBoyan Karatotev	apply_erratum cortex_a57, ERRATUM(817169), ERRATA_A57_817169
534ac54693SBoyan Karatotev
54add40351SSoby Mathew	dsb	sy
55add40351SSoby Mathew	ret
568b779620SKévin Petitendfunc cortex_a57_disable_ext_debug
579b476841SSoby Mathew
58fd04156eSArvind Ram Prakash/* Erratum entry and check function for SMCCC_ARCH_WORKAROUND_3 */
59fd04156eSArvind Ram Prakashadd_erratum_entry cortex_a57, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
60fd04156eSArvind Ram Prakash
61fd04156eSArvind Ram Prakashcheck_erratum_chosen cortex_a57, ERRATUM(ARCH_WORKAROUND_3), WORKAROUND_CVE_2022_23960
62fd04156eSArvind Ram Prakash
63f08cfc31SBoyan Karatotev/*
644ac54693SBoyan Karatotev * Disable the over-read from the LDNP/STNP instruction. The SDEN doesn't
65fd04156eSArvind Ram Prakash * provide and erratum number, so assign it an obvious 99999
66f08cfc31SBoyan Karatotev */
67fd04156eSArvind Ram Prakashworkaround_reset_start cortex_a57, ERRATUM(99999), A57_DISABLE_NON_TEMPORAL_HINT
68dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_OVERREAD
69fd04156eSArvind Ram Prakashworkaround_reset_end cortex_a57, ERRATUM(99999)
70f08cfc31SBoyan Karatotev
71fd04156eSArvind Ram Prakashcheck_erratum_ls cortex_a57, ERRATUM(99999), CPU_REV(1, 2)
72f08cfc31SBoyan Karatotev
734ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(806969), ERRATA_A57_806969
74dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
754ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(806969)
767395a725SSoby Mathew
774ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(806969), CPU_REV(0, 0)
787395a725SSoby Mathew
794ac54693SBoyan Karatotev/* erratum always worked around, but report it correctly */
80dbab05efSBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(813419), CPU_REV(0, 0)
8189dba82dSBoyan Karatotevadd_erratum_entry cortex_a57, ERRATUM(813419), ERRATUM_ALWAYS_CHOSEN
82ccbec91cSAntonio Nino Diaz
834ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(813420), ERRATA_A57_813420
84dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DCC_AS_DCCI
854ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(813420)
867395a725SSoby Mathew
874ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(813420), CPU_REV(0, 0)
8810bcd761SJeenu Viswambharan
894ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(814670), ERRATA_A57_814670
90dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_DMB_NULLIFICATION
914ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(814670)
920f6fbbd2SAmbroise Vincent
934ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(814670), CPU_REV(0, 0)
940f6fbbd2SAmbroise Vincent
955cba510eSBoyan Karatotevworkaround_runtime_start cortex_a57, ERRATUM(817169), ERRATA_A57_817169
964ac54693SBoyan Karatotev	/* Invalidate any TLB address */
974ac54693SBoyan Karatotev	mov	x0, #0
984ac54693SBoyan Karatotev	tlbi	vae3, x0
994ac54693SBoyan Karatotevworkaround_runtime_end cortex_a57, ERRATUM(817169), NO_ISB
1004ac54693SBoyan Karatotev
101dbab05efSBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(817169), CPU_REV(0, 1)
1025bd2c24fSAmbroise Vincent
1034ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(826974), ERRATA_A57_826974
104dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_DMB
1054ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(826974)
106df22d602SSandrine Bailleux
1074ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(826974), CPU_REV(1, 1)
10810bcd761SJeenu Viswambharan
1094ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(826977), ERRATA_A57_826977
110dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_GRE_NGRE_AS_NGNRE
1114ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(826977)
11207288865SSandrine Bailleux
1134ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(826977), CPU_REV(1, 1)
11410bcd761SJeenu Viswambharan
1154ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(828024), ERRATA_A57_828024
11680bcf981SEleanor Bonnici	mrs	x1, CORTEX_A57_CPUACTLR_EL1
117a8b1c769SSandrine Bailleux	/*
118a8b1c769SSandrine Bailleux	 * Setting the relevant bits in CPUACTLR_EL1 has to be done in 2
119a8b1c769SSandrine Bailleux	 * instructions here because the resulting bitmask doesn't fit in a
120a8b1c769SSandrine Bailleux	 * 16-bit value so it cannot be encoded in a single instruction.
121a8b1c769SSandrine Bailleux	 */
12280bcf981SEleanor Bonnici	orr	x1, x1, #CORTEX_A57_CPUACTLR_EL1_NO_ALLOC_WBWA
12380bcf981SEleanor Bonnici	orr	x1, x1, #(CORTEX_A57_CPUACTLR_EL1_DIS_L1_STREAMING | \
12480bcf981SEleanor Bonnici			  CORTEX_A57_CPUACTLR_EL1_DIS_STREAMING)
12580bcf981SEleanor Bonnici	msr	CORTEX_A57_CPUACTLR_EL1, x1
1264ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(828024)
127df22d602SSandrine Bailleux
1284ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(828024), CPU_REV(1, 1)
12910bcd761SJeenu Viswambharan
1304ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(829520), ERRATA_A57_829520
131dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_INDIRECT_PREDICTOR
1324ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(829520)
1330b77197bSSandrine Bailleux
1344ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(829520), CPU_REV(1, 2)
13510bcd761SJeenu Viswambharan
1364ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(833471), ERRATA_A57_833471
137dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_FORCE_FPSCR_FLUSH
1384ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(833471)
139adeecf92SSandrine Bailleux
1404ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(833471), CPU_REV(1, 2)
14110bcd761SJeenu Viswambharan
1424ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, ERRATUM(859972), ERRATA_A57_859972
143dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_INSTR_PREFETCH
1444ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, ERRATUM(859972)
14545b52c20SEleanor Bonnici
1464ac54693SBoyan Karatotevcheck_erratum_ls cortex_a57, ERRATUM(859972), CPU_REV(1, 3)
14745b52c20SEleanor Bonnici
1484ac54693SBoyan Karatotevcheck_erratum_chosen cortex_a57, ERRATUM(1319537), ERRATA_A57_1319537
1494ac54693SBoyan Karatotev/* erratum has no workaround in the cpu. Generic code must take care */
15089dba82dSBoyan Karatotevadd_erratum_entry cortex_a57, ERRATUM(1319537), ERRATA_A57_1319537
151f08cfc31SBoyan Karatotev
1524ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
1534ac54693SBoyan Karatotev#if IMAGE_BL31
154dbab05efSBoyan Karatotev	override_vector_table wa_cve_2017_5715_mmu_vbar
155f62ad322SDimitris Papastamos#endif
1564ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, CVE(2017, 5715)
157f62ad322SDimitris Papastamos
1584ac54693SBoyan Karatotevcheck_erratum_chosen cortex_a57, CVE(2017, 5715), WORKAROUND_CVE_2017_5715
1594ac54693SBoyan Karatotev
1604ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
161dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_DIS_LOAD_PASS_STORE
162b8a25bbbSDimitris Papastamos	isb
163b8a25bbbSDimitris Papastamos	dsb	sy
1644ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, CVE(2018, 3639)
165b8a25bbbSDimitris Papastamos
1664ac54693SBoyan Karatotevcheck_erratum_chosen cortex_a57, CVE(2018, 3639), WORKAROUND_CVE_2018_3639
1674ac54693SBoyan Karatotev
1684ac54693SBoyan Karatotevworkaround_reset_start cortex_a57, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
1694ac54693SBoyan Karatotev#if IMAGE_BL31
170dbab05efSBoyan Karatotev	override_vector_table wa_cve_2017_5715_mmu_vbar
1714ac54693SBoyan Karatotev#endif
1724ac54693SBoyan Karatotevworkaround_reset_end cortex_a57, CVE(2022, 23960)
1734ac54693SBoyan Karatotev
1744ac54693SBoyan Karatotevcheck_erratum_chosen cortex_a57, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
1754ac54693SBoyan Karatotev
1764ac54693SBoyan Karatotevcpu_reset_func_start cortex_a57
177cd0ea184SVarun Wadekar#if A57_ENABLE_NONCACHEABLE_LOAD_FWD
178dbab05efSBoyan Karatotev	/* Enable higher performance non-cacheable load forwarding */
179dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_CPUACTLR_EL1, CORTEX_A57_CPUACTLR_EL1_EN_NC_LOAD_FWD
180cd0ea184SVarun Wadekar#endif
181dbab05efSBoyan Karatotev	/* Enable the SMP bit. */
182dbab05efSBoyan Karatotev	sysreg_bit_set CORTEX_A57_ECTLR_EL1, CORTEX_A57_ECTLR_SMP_BIT
1834ac54693SBoyan Karatotevcpu_reset_func_end cortex_a57
1849b476841SSoby Mathew
1857395a725SSoby Mathew	/* ----------------------------------------------------
1867395a725SSoby Mathew	 * The CPU Ops core power down function for Cortex-A57.
1877395a725SSoby Mathew	 * ----------------------------------------------------
1887395a725SSoby Mathew	 */
189add40351SSoby Mathewfunc cortex_a57_core_pwr_dwn
190add40351SSoby Mathew	mov	x18, x30
191add40351SSoby Mathew
192add40351SSoby Mathew	/* ---------------------------------------------
193add40351SSoby Mathew	 * Disable the L2 prefetches.
194add40351SSoby Mathew	 * ---------------------------------------------
195add40351SSoby Mathew	 */
196add40351SSoby Mathew	bl	cortex_a57_disable_l2_prefetch
197add40351SSoby Mathew
198add40351SSoby Mathew	/* ---------------------------------------------
1998e857916SSoby Mathew	 * Flush L1 caches.
200add40351SSoby Mathew	 * ---------------------------------------------
201add40351SSoby Mathew	 */
202add40351SSoby Mathew	mov	x0, #DCCISW
2038e857916SSoby Mathew	bl	dcsw_op_level1
204add40351SSoby Mathew
205add40351SSoby Mathew	/* ---------------------------------------------
206add40351SSoby Mathew	 * Come out of intra cluster coherency
207add40351SSoby Mathew	 * ---------------------------------------------
208add40351SSoby Mathew	 */
209add40351SSoby Mathew	bl	cortex_a57_disable_smp
210add40351SSoby Mathew
211add40351SSoby Mathew	/* ---------------------------------------------
212add40351SSoby Mathew	 * Force the debug interfaces to be quiescent
213add40351SSoby Mathew	 * ---------------------------------------------
214add40351SSoby Mathew	 */
215add40351SSoby Mathew	mov	x30, x18
216add40351SSoby Mathew	b	cortex_a57_disable_ext_debug
2178b779620SKévin Petitendfunc cortex_a57_core_pwr_dwn
218add40351SSoby Mathew
2197395a725SSoby Mathew	/* -------------------------------------------------------
2207395a725SSoby Mathew	 * The CPU Ops cluster power down function for Cortex-A57.
2217395a725SSoby Mathew	 * -------------------------------------------------------
2227395a725SSoby Mathew	 */
223add40351SSoby Mathewfunc cortex_a57_cluster_pwr_dwn
224add40351SSoby Mathew	mov	x18, x30
225add40351SSoby Mathew
226add40351SSoby Mathew	/* ---------------------------------------------
227add40351SSoby Mathew	 * Disable the L2 prefetches.
228add40351SSoby Mathew	 * ---------------------------------------------
229add40351SSoby Mathew	 */
230add40351SSoby Mathew	bl	cortex_a57_disable_l2_prefetch
231add40351SSoby Mathew
2325541bb3fSSoby Mathew#if !SKIP_A57_L1_FLUSH_PWR_DWN
2338e857916SSoby Mathew	/* -------------------------------------------------
2348e857916SSoby Mathew	 * Flush the L1 caches.
2358e857916SSoby Mathew	 * -------------------------------------------------
2368e857916SSoby Mathew	 */
2378e857916SSoby Mathew	mov	x0, #DCCISW
2388e857916SSoby Mathew	bl	dcsw_op_level1
2395541bb3fSSoby Mathew#endif
240add40351SSoby Mathew	/* ---------------------------------------------
241add40351SSoby Mathew	 * Disable the optional ACP.
242add40351SSoby Mathew	 * ---------------------------------------------
243add40351SSoby Mathew	 */
244add40351SSoby Mathew	bl	plat_disable_acp
245add40351SSoby Mathew
2468e857916SSoby Mathew	/* -------------------------------------------------
2478e857916SSoby Mathew	 * Flush the L2 caches.
2488e857916SSoby Mathew	 * -------------------------------------------------
249add40351SSoby Mathew	 */
250add40351SSoby Mathew	mov	x0, #DCCISW
2518e857916SSoby Mathew	bl	dcsw_op_level2
252add40351SSoby Mathew
253add40351SSoby Mathew	/* ---------------------------------------------
254add40351SSoby Mathew	 * Come out of intra cluster coherency
255add40351SSoby Mathew	 * ---------------------------------------------
256add40351SSoby Mathew	 */
257add40351SSoby Mathew	bl	cortex_a57_disable_smp
258add40351SSoby Mathew
259add40351SSoby Mathew	/* ---------------------------------------------
260add40351SSoby Mathew	 * Force the debug interfaces to be quiescent
261add40351SSoby Mathew	 * ---------------------------------------------
262add40351SSoby Mathew	 */
263add40351SSoby Mathew	mov	x30, x18
264add40351SSoby Mathew	b	cortex_a57_disable_ext_debug
2658b779620SKévin Petitendfunc cortex_a57_cluster_pwr_dwn
266add40351SSoby Mathew
267d3f70af6SSoby Mathew	/* ---------------------------------------------
268d3f70af6SSoby Mathew	 * This function provides cortex_a57 specific
269d3f70af6SSoby Mathew	 * register information for crash reporting.
270d3f70af6SSoby Mathew	 * It needs to return with x6 pointing to
271d3f70af6SSoby Mathew	 * a list of register names in ascii and
272d3f70af6SSoby Mathew	 * x8 - x15 having values of registers to be
273d3f70af6SSoby Mathew	 * reported.
274d3f70af6SSoby Mathew	 * ---------------------------------------------
275d3f70af6SSoby Mathew	 */
276d3f70af6SSoby Mathew.section .rodata.cortex_a57_regs, "aS"
277d3f70af6SSoby Mathewcortex_a57_regs:  /* The ascii list of register names to be reported */
27884629f2fSNaga Sureshkumar Relli	.asciz	"cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", ""
279d3f70af6SSoby Mathew
280d3f70af6SSoby Mathewfunc cortex_a57_cpu_reg_dump
281d3f70af6SSoby Mathew	adr	x6, cortex_a57_regs
282fb7d32e5SVarun Wadekar	mrs	x8, CORTEX_A57_ECTLR_EL1
283fb7d32e5SVarun Wadekar	mrs	x9, CORTEX_A57_MERRSR_EL1
284fb7d32e5SVarun Wadekar	mrs	x10, CORTEX_A57_L2MERRSR_EL1
285d3f70af6SSoby Mathew	ret
2868b779620SKévin Petitendfunc cortex_a57_cpu_reg_dump
287d3f70af6SSoby Mathew
288fd04156eSArvind Ram Prakashdeclare_cpu_ops cortex_a57, CORTEX_A57_MIDR, \
2895dd9dbb5SJeenu Viswambharan	cortex_a57_reset_func, \
2905dd9dbb5SJeenu Viswambharan	cortex_a57_core_pwr_dwn, \
2915dd9dbb5SJeenu Viswambharan	cortex_a57_cluster_pwr_dwn
292