xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_a53.S (revision 35b2bbf4942689fd52fa741ac7d93bc7f1d4c230)
19b476841SSoby Mathew/*
2*89dba82dSBoyan Karatotev * Copyright (c) 2014-2025, Arm Limited and Contributors. All rights reserved.
39b476841SSoby Mathew *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
59b476841SSoby Mathew */
69b476841SSoby Mathew#include <arch.h>
79b476841SSoby Mathew#include <asm_macros.S>
809d40e0eSAntonio Nino Diaz#include <common/bl_common.h>
909d40e0eSAntonio Nino Diaz#include <common/debug.h>
10add40351SSoby Mathew#include <cortex_a53.h>
119b476841SSoby Mathew#include <cpu_macros.S>
129b476841SSoby Mathew#include <plat_macros.S>
136bb96fa6SBoyan Karatotev#include <lib/cpus/errata.h>
149b476841SSoby Mathew
15*89dba82dSBoyan Karatotevcpu_reset_prologue cortex_a53
16*89dba82dSBoyan Karatotev
17add40351SSoby Mathew	/* ---------------------------------------------
18add40351SSoby Mathew	 * Disable intra-cluster coherency
19add40351SSoby Mathew	 * ---------------------------------------------
20add40351SSoby Mathew	 */
21add40351SSoby Mathewfunc cortex_a53_disable_smp
22d20fa4e4SBoyan Karatotev	sysreg_bit_clear CORTEX_A53_ECTLR_EL1, CORTEX_A53_ECTLR_SMP_BIT
23add40351SSoby Mathew	isb
24add40351SSoby Mathew	dsb	sy
25add40351SSoby Mathew	ret
268b779620SKévin Petitendfunc cortex_a53_disable_smp
279b476841SSoby Mathew
28b2d78e1cSBoyan Karatotev/* Due to the nature of the errata it is applied unconditionally when chosen */
29d20fa4e4SBoyan Karatotevcheck_erratum_ls cortex_a53, ERRATUM(819472), CPU_REV(0, 1)
30b2d78e1cSBoyan Karatotev/* erratum workaround is interleaved with generic code */
31*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(819472), ERRATUM_ALWAYS_CHOSEN
32b2d78e1cSBoyan Karatotev
33b2d78e1cSBoyan Karatotev/* Due to the nature of the errata it is applied unconditionally when chosen */
34d20fa4e4SBoyan Karatotevcheck_erratum_ls cortex_a53, ERRATUM(824069), CPU_REV(0, 2)
35b2d78e1cSBoyan Karatotev/* erratum workaround is interleaved with generic code */
36*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(824069), ERRATUM_ALWAYS_CHOSEN
37b2d78e1cSBoyan Karatotev
38b2d78e1cSBoyan Karatotevworkaround_reset_start cortex_a53, ERRATUM(826319), ERRATA_A53_826319
39fb7d32e5SVarun Wadekar	mrs	x1, CORTEX_A53_L2ACTLR_EL1
40fb7d32e5SVarun Wadekar	bic	x1, x1, #CORTEX_A53_L2ACTLR_ENABLE_UNIQUECLEAN
41fb7d32e5SVarun Wadekar	orr	x1, x1, #CORTEX_A53_L2ACTLR_DISABLE_CLEAN_PUSH
42fb7d32e5SVarun Wadekar	msr	CORTEX_A53_L2ACTLR_EL1, x1
43b2d78e1cSBoyan Karatotevworkaround_reset_end cortex_a53, ERRATUM(826319)
446b0d97b2SJimmy Huang
45b2d78e1cSBoyan Karatotevcheck_erratum_ls cortex_a53, ERRATUM(826319), CPU_REV(0, 2)
4610bcd761SJeenu Viswambharan
47b2d78e1cSBoyan Karatotev/* Due to the nature of the errata it is applied unconditionally when chosen */
48d20fa4e4SBoyan Karatotevcheck_erratum_ls cortex_a53, ERRATUM(827319), CPU_REV(0, 2)
49b2d78e1cSBoyan Karatotev/* erratum workaround is interleaved with generic code */
50*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(827319), ERRATUM_ALWAYS_CHOSEN
51b2d78e1cSBoyan Karatotev
52b2d78e1cSBoyan Karatotevcheck_erratum_custom_start cortex_a53, ERRATUM(835769)
53d20fa4e4SBoyan Karatotev	cmp	x0, CPU_REV(0, 4)
54e37dfd3cSBoyan Karatotev	b.hi	errata_not_applies
55e37dfd3cSBoyan Karatotev	/*
56e37dfd3cSBoyan Karatotev	 * Fix potentially available for revisions r0p2, r0p3 and r0p4.
57e37dfd3cSBoyan Karatotev	 * If r0p2, r0p3 or r0p4; check for fix in REVIDR, else exit.
58e37dfd3cSBoyan Karatotev	 */
59e37dfd3cSBoyan Karatotev	cmp	x0, #0x01
60e37dfd3cSBoyan Karatotev	mov	x0, #ERRATA_APPLIES
61e37dfd3cSBoyan Karatotev	b.ls	exit_check_errata_835769
62e37dfd3cSBoyan Karatotev	/* Load REVIDR. */
63e37dfd3cSBoyan Karatotev	mrs	x1, revidr_el1
64e37dfd3cSBoyan Karatotev	/* If REVIDR[7] is set (fix exists) set ERRATA_NOT_APPLIES, else exit. */
65e37dfd3cSBoyan Karatotev	tbz	x1, #7, exit_check_errata_835769
66e37dfd3cSBoyan Karatoteverrata_not_applies:
67e37dfd3cSBoyan Karatotev	mov	x0, #ERRATA_NOT_APPLIES
68e37dfd3cSBoyan Karatotevexit_check_errata_835769:
69e37dfd3cSBoyan Karatotev	ret
70b2d78e1cSBoyan Karatotevcheck_erratum_custom_end cortex_a53, ERRATUM(835769)
71e37dfd3cSBoyan Karatotev
72b2d78e1cSBoyan Karatotev/* workaround at build time */
73*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(835769), ERRATA_A53_835769
74b2d78e1cSBoyan Karatotev
75b2d78e1cSBoyan Karatotev	/*
7654035fc4SSandrine Bailleux	 * Disable the cache non-temporal hint.
7754035fc4SSandrine Bailleux	 *
7854035fc4SSandrine Bailleux	 * This ignores the Transient allocation hint in the MAIR and treats
7954035fc4SSandrine Bailleux	 * allocations the same as non-transient allocation types. As a result,
8054035fc4SSandrine Bailleux	 * the LDNP and STNP instructions in AArch64 behave the same as the
8154035fc4SSandrine Bailleux	 * equivalent LDP and STP instructions.
826b0d97b2SJimmy Huang	 */
83b2d78e1cSBoyan Karatotevworkaround_reset_start cortex_a53, ERRATUM(836870), ERRATA_A53_836870 | A53_DISABLE_NON_TEMPORAL_HINT
84d20fa4e4SBoyan Karatotev	sysreg_bit_set CORTEX_A53_CPUACTLR_EL1, CORTEX_A53_CPUACTLR_EL1_DTAH
85b2d78e1cSBoyan Karatotevworkaround_reset_end cortex_a53, ERRATUM(836870)
866b0d97b2SJimmy Huang
87b2d78e1cSBoyan Karatotevcheck_erratum_ls cortex_a53, ERRATUM(836870), CPU_REV(0, 3)
88e37dfd3cSBoyan Karatotev
89b2d78e1cSBoyan Karatotevcheck_erratum_custom_start cortex_a53, ERRATUM(843419)
90e37dfd3cSBoyan Karatotev	mov	x1, #ERRATA_APPLIES
91e37dfd3cSBoyan Karatotev	mov	x2, #ERRATA_NOT_APPLIES
92d20fa4e4SBoyan Karatotev	cmp	x0, CPU_REV(0, 4)
93e37dfd3cSBoyan Karatotev	csel	x0, x1, x2, ls
94e37dfd3cSBoyan Karatotev	/*
95e37dfd3cSBoyan Karatotev	 * Fix potentially available for revision r0p4.
96e37dfd3cSBoyan Karatotev	 * If r0p4 check for fix in REVIDR, else exit.
97e37dfd3cSBoyan Karatotev	 */
98e37dfd3cSBoyan Karatotev	b.ne	exit_check_errata_843419
99e37dfd3cSBoyan Karatotev	/* Load REVIDR. */
100e37dfd3cSBoyan Karatotev	mrs	x3, revidr_el1
101e37dfd3cSBoyan Karatotev	/* If REVIDR[8] is set (fix exists) set ERRATA_NOT_APPLIES, else exit. */
102e37dfd3cSBoyan Karatotev	tbz	x3, #8, exit_check_errata_843419
103e37dfd3cSBoyan Karatotev	mov	x0, x2
104e37dfd3cSBoyan Karatotevexit_check_errata_843419:
105e37dfd3cSBoyan Karatotev	ret
106b2d78e1cSBoyan Karatotevcheck_erratum_custom_end cortex_a53, ERRATUM(843419)
10710bcd761SJeenu Viswambharan
108b2d78e1cSBoyan Karatotev/* workaround at build time */
109*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(843419), ERRATA_A53_843419
110b2d78e1cSBoyan Karatotev
111b2d78e1cSBoyan Karatotev	/*
112b75dc0e4SAndre Przywara	 * Earlier revisions of the core are affected as well, but don't
113b75dc0e4SAndre Przywara	 * have the chicken bit in the CPUACTLR register. It is expected that
114b75dc0e4SAndre Przywara	 * the rich OS takes care of that, especially as the workaround is
115b75dc0e4SAndre Przywara	 * shared with other erratas in those revisions of the CPU.
116b75dc0e4SAndre Przywara	 */
117b2d78e1cSBoyan Karatotevworkaround_reset_start cortex_a53, ERRATUM(855873), ERRATA_A53_855873
118d20fa4e4SBoyan Karatotev	sysreg_bit_set CORTEX_A53_CPUACTLR_EL1, CORTEX_A53_CPUACTLR_EL1_ENDCCASCI
119b2d78e1cSBoyan Karatotevworkaround_reset_end cortex_a53, ERRATUM(855873)
120b75dc0e4SAndre Przywara
121b2d78e1cSBoyan Karatotevcheck_erratum_hs cortex_a53, ERRATUM(855873), CPU_REV(0, 3)
122b75dc0e4SAndre Przywara
123b2d78e1cSBoyan Karatotevcheck_erratum_chosen cortex_a53, ERRATUM(1530924), ERRATA_A53_1530924
124e1c49333SManish V Badarkhe
125b2d78e1cSBoyan Karatotev/* erratum has no workaround in the cpu. Generic code must take care */
126*89dba82dSBoyan Karatotevadd_erratum_entry cortex_a53, ERRATUM(1530924), ERRATA_A53_1530924
1276b0d97b2SJimmy Huang
128b2d78e1cSBoyan Karatotevcpu_reset_func_start cortex_a53
129d20fa4e4SBoyan Karatotev	/* Enable the SMP bit. */
130d20fa4e4SBoyan Karatotev	sysreg_bit_set CORTEX_A53_ECTLR_EL1, CORTEX_A53_ECTLR_SMP_BIT
131b2d78e1cSBoyan Karatotevcpu_reset_func_end cortex_a53
1329b476841SSoby Mathew
133add40351SSoby Mathewfunc cortex_a53_core_pwr_dwn
134add40351SSoby Mathew	mov	x18, x30
135add40351SSoby Mathew
136add40351SSoby Mathew	/* ---------------------------------------------
1378e857916SSoby Mathew	 * Flush L1 caches.
138add40351SSoby Mathew	 * ---------------------------------------------
139add40351SSoby Mathew	 */
140add40351SSoby Mathew	mov	x0, #DCCISW
1418e857916SSoby Mathew	bl	dcsw_op_level1
142add40351SSoby Mathew
143add40351SSoby Mathew	/* ---------------------------------------------
144add40351SSoby Mathew	 * Come out of intra cluster coherency
145add40351SSoby Mathew	 * ---------------------------------------------
146add40351SSoby Mathew	 */
147add40351SSoby Mathew	mov	x30, x18
148add40351SSoby Mathew	b	cortex_a53_disable_smp
1498b779620SKévin Petitendfunc cortex_a53_core_pwr_dwn
150add40351SSoby Mathew
151add40351SSoby Mathewfunc cortex_a53_cluster_pwr_dwn
152add40351SSoby Mathew	mov	x18, x30
153add40351SSoby Mathew
154add40351SSoby Mathew	/* ---------------------------------------------
1558e857916SSoby Mathew	 * Flush L1 caches.
1568e857916SSoby Mathew	 * ---------------------------------------------
1578e857916SSoby Mathew	 */
1588e857916SSoby Mathew	mov	x0, #DCCISW
1598e857916SSoby Mathew	bl	dcsw_op_level1
1608e857916SSoby Mathew
1618e857916SSoby Mathew	/* ---------------------------------------------
162add40351SSoby Mathew	 * Disable the optional ACP.
163add40351SSoby Mathew	 * ---------------------------------------------
164add40351SSoby Mathew	 */
165add40351SSoby Mathew	bl	plat_disable_acp
166add40351SSoby Mathew
167add40351SSoby Mathew	/* ---------------------------------------------
1688e857916SSoby Mathew	 * Flush L2 caches.
169add40351SSoby Mathew	 * ---------------------------------------------
170add40351SSoby Mathew	 */
171add40351SSoby Mathew	mov	x0, #DCCISW
1728e857916SSoby Mathew	bl	dcsw_op_level2
173add40351SSoby Mathew
174add40351SSoby Mathew	/* ---------------------------------------------
175add40351SSoby Mathew	 * Come out of intra cluster coherency
176add40351SSoby Mathew	 * ---------------------------------------------
177add40351SSoby Mathew	 */
178add40351SSoby Mathew	mov	x30, x18
179add40351SSoby Mathew	b	cortex_a53_disable_smp
1808b779620SKévin Petitendfunc cortex_a53_cluster_pwr_dwn
181add40351SSoby Mathew
182d3f70af6SSoby Mathew	/* ---------------------------------------------
183d3f70af6SSoby Mathew	 * This function provides cortex_a53 specific
184d3f70af6SSoby Mathew	 * register information for crash reporting.
185d3f70af6SSoby Mathew	 * It needs to return with x6 pointing to
186d3f70af6SSoby Mathew	 * a list of register names in ascii and
187d3f70af6SSoby Mathew	 * x8 - x15 having values of registers to be
188d3f70af6SSoby Mathew	 * reported.
189d3f70af6SSoby Mathew	 * ---------------------------------------------
190d3f70af6SSoby Mathew	 */
191d3f70af6SSoby Mathew.section .rodata.cortex_a53_regs, "aS"
192d3f70af6SSoby Mathewcortex_a53_regs:  /* The ascii list of register names to be reported */
193b75dc0e4SAndre Przywara	.asciz	"cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", \
194b75dc0e4SAndre Przywara		"cpuactlr_el1", ""
195d3f70af6SSoby Mathew
196d3f70af6SSoby Mathewfunc cortex_a53_cpu_reg_dump
197d3f70af6SSoby Mathew	adr	x6, cortex_a53_regs
198fb7d32e5SVarun Wadekar	mrs	x8, CORTEX_A53_ECTLR_EL1
199fb7d32e5SVarun Wadekar	mrs	x9, CORTEX_A53_MERRSR_EL1
200fb7d32e5SVarun Wadekar	mrs	x10, CORTEX_A53_L2MERRSR_EL1
20180bcf981SEleanor Bonnici	mrs	x11, CORTEX_A53_CPUACTLR_EL1
202d3f70af6SSoby Mathew	ret
2038b779620SKévin Petitendfunc cortex_a53_cpu_reg_dump
204d3f70af6SSoby Mathew
2055dd9dbb5SJeenu Viswambharandeclare_cpu_ops cortex_a53, CORTEX_A53_MIDR, \
2065dd9dbb5SJeenu Viswambharan	cortex_a53_reset_func, \
2075dd9dbb5SJeenu Viswambharan	cortex_a53_core_pwr_dwn, \
2085dd9dbb5SJeenu Viswambharan	cortex_a53_cluster_pwr_dwn
209