xref: /arm-trusted-firmware/lib/cpus/aarch64/cortex_a53.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2014-2023, Arm Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu#include <arch.h>
7*91f16700Schasinglulu#include <asm_macros.S>
8*91f16700Schasinglulu#include <common/bl_common.h>
9*91f16700Schasinglulu#include <common/debug.h>
10*91f16700Schasinglulu#include <cortex_a53.h>
11*91f16700Schasinglulu#include <cpu_macros.S>
12*91f16700Schasinglulu#include <plat_macros.S>
13*91f16700Schasinglulu#include <lib/cpus/errata.h>
14*91f16700Schasinglulu
15*91f16700Schasinglulu	/* ---------------------------------------------
16*91f16700Schasinglulu	 * Disable L1 data cache and unified L2 cache
17*91f16700Schasinglulu	 * ---------------------------------------------
18*91f16700Schasinglulu	 */
19*91f16700Schasinglulufunc cortex_a53_disable_dcache
20*91f16700Schasinglulu	sysreg_bit_clear sctlr_el3, SCTLR_C_BIT
21*91f16700Schasinglulu	isb
22*91f16700Schasinglulu	ret
23*91f16700Schasingluluendfunc cortex_a53_disable_dcache
24*91f16700Schasinglulu
25*91f16700Schasinglulu	/* ---------------------------------------------
26*91f16700Schasinglulu	 * Disable intra-cluster coherency
27*91f16700Schasinglulu	 * ---------------------------------------------
28*91f16700Schasinglulu	 */
29*91f16700Schasinglulufunc cortex_a53_disable_smp
30*91f16700Schasinglulu	sysreg_bit_clear CORTEX_A53_ECTLR_EL1, CORTEX_A53_ECTLR_SMP_BIT
31*91f16700Schasinglulu	isb
32*91f16700Schasinglulu	dsb	sy
33*91f16700Schasinglulu	ret
34*91f16700Schasingluluendfunc cortex_a53_disable_smp
35*91f16700Schasinglulu
36*91f16700Schasinglulu/* Due to the nature of the errata it is applied unconditionally when chosen */
37*91f16700Schasinglulucheck_erratum_ls cortex_a53, ERRATUM(819472), CPU_REV(0, 1)
38*91f16700Schasinglulu/* erratum workaround is interleaved with generic code */
39*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(819472), ERRATUM_ALWAYS_CHOSEN, NO_APPLY_AT_RESET
40*91f16700Schasinglulu
41*91f16700Schasinglulu/* Due to the nature of the errata it is applied unconditionally when chosen */
42*91f16700Schasinglulucheck_erratum_ls cortex_a53, ERRATUM(824069), CPU_REV(0, 2)
43*91f16700Schasinglulu/* erratum workaround is interleaved with generic code */
44*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(824069), ERRATUM_ALWAYS_CHOSEN, NO_APPLY_AT_RESET
45*91f16700Schasinglulu
46*91f16700Schasingluluworkaround_reset_start cortex_a53, ERRATUM(826319), ERRATA_A53_826319
47*91f16700Schasinglulu	mrs	x1, CORTEX_A53_L2ACTLR_EL1
48*91f16700Schasinglulu	bic	x1, x1, #CORTEX_A53_L2ACTLR_ENABLE_UNIQUECLEAN
49*91f16700Schasinglulu	orr	x1, x1, #CORTEX_A53_L2ACTLR_DISABLE_CLEAN_PUSH
50*91f16700Schasinglulu	msr	CORTEX_A53_L2ACTLR_EL1, x1
51*91f16700Schasingluluworkaround_reset_end cortex_a53, ERRATUM(826319)
52*91f16700Schasinglulu
53*91f16700Schasinglulucheck_erratum_ls cortex_a53, ERRATUM(826319), CPU_REV(0, 2)
54*91f16700Schasinglulu
55*91f16700Schasinglulu/* Due to the nature of the errata it is applied unconditionally when chosen */
56*91f16700Schasinglulucheck_erratum_ls cortex_a53, ERRATUM(827319), CPU_REV(0, 2)
57*91f16700Schasinglulu/* erratum workaround is interleaved with generic code */
58*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(827319), ERRATUM_ALWAYS_CHOSEN, NO_APPLY_AT_RESET
59*91f16700Schasinglulu
60*91f16700Schasinglulucheck_erratum_custom_start cortex_a53, ERRATUM(835769)
61*91f16700Schasinglulu	cmp	x0, CPU_REV(0, 4)
62*91f16700Schasinglulu	b.hi	errata_not_applies
63*91f16700Schasinglulu	/*
64*91f16700Schasinglulu	 * Fix potentially available for revisions r0p2, r0p3 and r0p4.
65*91f16700Schasinglulu	 * If r0p2, r0p3 or r0p4; check for fix in REVIDR, else exit.
66*91f16700Schasinglulu	 */
67*91f16700Schasinglulu	cmp	x0, #0x01
68*91f16700Schasinglulu	mov	x0, #ERRATA_APPLIES
69*91f16700Schasinglulu	b.ls	exit_check_errata_835769
70*91f16700Schasinglulu	/* Load REVIDR. */
71*91f16700Schasinglulu	mrs	x1, revidr_el1
72*91f16700Schasinglulu	/* If REVIDR[7] is set (fix exists) set ERRATA_NOT_APPLIES, else exit. */
73*91f16700Schasinglulu	tbz	x1, #7, exit_check_errata_835769
74*91f16700Schasingluluerrata_not_applies:
75*91f16700Schasinglulu	mov	x0, #ERRATA_NOT_APPLIES
76*91f16700Schasingluluexit_check_errata_835769:
77*91f16700Schasinglulu	ret
78*91f16700Schasinglulucheck_erratum_custom_end cortex_a53, ERRATUM(835769)
79*91f16700Schasinglulu
80*91f16700Schasinglulu/* workaround at build time */
81*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(835769), ERRATA_A53_835769, NO_APPLY_AT_RESET
82*91f16700Schasinglulu
83*91f16700Schasinglulu	/*
84*91f16700Schasinglulu	 * Disable the cache non-temporal hint.
85*91f16700Schasinglulu	 *
86*91f16700Schasinglulu	 * This ignores the Transient allocation hint in the MAIR and treats
87*91f16700Schasinglulu	 * allocations the same as non-transient allocation types. As a result,
88*91f16700Schasinglulu	 * the LDNP and STNP instructions in AArch64 behave the same as the
89*91f16700Schasinglulu	 * equivalent LDP and STP instructions.
90*91f16700Schasinglulu	 */
91*91f16700Schasingluluworkaround_reset_start cortex_a53, ERRATUM(836870), ERRATA_A53_836870 | A53_DISABLE_NON_TEMPORAL_HINT
92*91f16700Schasinglulu	sysreg_bit_set CORTEX_A53_CPUACTLR_EL1, CORTEX_A53_CPUACTLR_EL1_DTAH
93*91f16700Schasingluluworkaround_reset_end cortex_a53, ERRATUM(836870)
94*91f16700Schasinglulu
95*91f16700Schasinglulucheck_erratum_ls cortex_a53, ERRATUM(836870), CPU_REV(0, 3)
96*91f16700Schasinglulu
97*91f16700Schasinglulucheck_erratum_custom_start cortex_a53, ERRATUM(843419)
98*91f16700Schasinglulu	mov	x1, #ERRATA_APPLIES
99*91f16700Schasinglulu	mov	x2, #ERRATA_NOT_APPLIES
100*91f16700Schasinglulu	cmp	x0, CPU_REV(0, 4)
101*91f16700Schasinglulu	csel	x0, x1, x2, ls
102*91f16700Schasinglulu	/*
103*91f16700Schasinglulu	 * Fix potentially available for revision r0p4.
104*91f16700Schasinglulu	 * If r0p4 check for fix in REVIDR, else exit.
105*91f16700Schasinglulu	 */
106*91f16700Schasinglulu	b.ne	exit_check_errata_843419
107*91f16700Schasinglulu	/* Load REVIDR. */
108*91f16700Schasinglulu	mrs	x3, revidr_el1
109*91f16700Schasinglulu	/* If REVIDR[8] is set (fix exists) set ERRATA_NOT_APPLIES, else exit. */
110*91f16700Schasinglulu	tbz	x3, #8, exit_check_errata_843419
111*91f16700Schasinglulu	mov	x0, x2
112*91f16700Schasingluluexit_check_errata_843419:
113*91f16700Schasinglulu	ret
114*91f16700Schasinglulucheck_erratum_custom_end cortex_a53, ERRATUM(843419)
115*91f16700Schasinglulu
116*91f16700Schasinglulu/* workaround at build time */
117*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(843419), ERRATA_A53_843419, NO_APPLY_AT_RESET
118*91f16700Schasinglulu
119*91f16700Schasinglulu	/*
120*91f16700Schasinglulu	 * Earlier revisions of the core are affected as well, but don't
121*91f16700Schasinglulu	 * have the chicken bit in the CPUACTLR register. It is expected that
122*91f16700Schasinglulu	 * the rich OS takes care of that, especially as the workaround is
123*91f16700Schasinglulu	 * shared with other erratas in those revisions of the CPU.
124*91f16700Schasinglulu	 */
125*91f16700Schasingluluworkaround_reset_start cortex_a53, ERRATUM(855873), ERRATA_A53_855873
126*91f16700Schasinglulu	sysreg_bit_set CORTEX_A53_CPUACTLR_EL1, CORTEX_A53_CPUACTLR_EL1_ENDCCASCI
127*91f16700Schasingluluworkaround_reset_end cortex_a53, ERRATUM(855873)
128*91f16700Schasinglulu
129*91f16700Schasinglulucheck_erratum_hs cortex_a53, ERRATUM(855873), CPU_REV(0, 3)
130*91f16700Schasinglulu
131*91f16700Schasinglulucheck_erratum_chosen cortex_a53, ERRATUM(1530924), ERRATA_A53_1530924
132*91f16700Schasinglulu
133*91f16700Schasinglulu/* erratum has no workaround in the cpu. Generic code must take care */
134*91f16700Schasingluluadd_erratum_entry cortex_a53, ERRATUM(1530924), ERRATA_A53_1530924, NO_APPLY_AT_RESET
135*91f16700Schasinglulu
136*91f16700Schasinglulucpu_reset_func_start cortex_a53
137*91f16700Schasinglulu	/* Enable the SMP bit. */
138*91f16700Schasinglulu	sysreg_bit_set CORTEX_A53_ECTLR_EL1, CORTEX_A53_ECTLR_SMP_BIT
139*91f16700Schasinglulucpu_reset_func_end cortex_a53
140*91f16700Schasinglulu
141*91f16700Schasinglulufunc cortex_a53_core_pwr_dwn
142*91f16700Schasinglulu	mov	x18, x30
143*91f16700Schasinglulu
144*91f16700Schasinglulu	/* ---------------------------------------------
145*91f16700Schasinglulu	 * Turn off caches.
146*91f16700Schasinglulu	 * ---------------------------------------------
147*91f16700Schasinglulu	 */
148*91f16700Schasinglulu	bl	cortex_a53_disable_dcache
149*91f16700Schasinglulu
150*91f16700Schasinglulu	/* ---------------------------------------------
151*91f16700Schasinglulu	 * Flush L1 caches.
152*91f16700Schasinglulu	 * ---------------------------------------------
153*91f16700Schasinglulu	 */
154*91f16700Schasinglulu	mov	x0, #DCCISW
155*91f16700Schasinglulu	bl	dcsw_op_level1
156*91f16700Schasinglulu
157*91f16700Schasinglulu	/* ---------------------------------------------
158*91f16700Schasinglulu	 * Come out of intra cluster coherency
159*91f16700Schasinglulu	 * ---------------------------------------------
160*91f16700Schasinglulu	 */
161*91f16700Schasinglulu	mov	x30, x18
162*91f16700Schasinglulu	b	cortex_a53_disable_smp
163*91f16700Schasingluluendfunc cortex_a53_core_pwr_dwn
164*91f16700Schasinglulu
165*91f16700Schasinglulufunc cortex_a53_cluster_pwr_dwn
166*91f16700Schasinglulu	mov	x18, x30
167*91f16700Schasinglulu
168*91f16700Schasinglulu	/* ---------------------------------------------
169*91f16700Schasinglulu	 * Turn off caches.
170*91f16700Schasinglulu	 * ---------------------------------------------
171*91f16700Schasinglulu	 */
172*91f16700Schasinglulu	bl	cortex_a53_disable_dcache
173*91f16700Schasinglulu
174*91f16700Schasinglulu	/* ---------------------------------------------
175*91f16700Schasinglulu	 * Flush L1 caches.
176*91f16700Schasinglulu	 * ---------------------------------------------
177*91f16700Schasinglulu	 */
178*91f16700Schasinglulu	mov	x0, #DCCISW
179*91f16700Schasinglulu	bl	dcsw_op_level1
180*91f16700Schasinglulu
181*91f16700Schasinglulu	/* ---------------------------------------------
182*91f16700Schasinglulu	 * Disable the optional ACP.
183*91f16700Schasinglulu	 * ---------------------------------------------
184*91f16700Schasinglulu	 */
185*91f16700Schasinglulu	bl	plat_disable_acp
186*91f16700Schasinglulu
187*91f16700Schasinglulu	/* ---------------------------------------------
188*91f16700Schasinglulu	 * Flush L2 caches.
189*91f16700Schasinglulu	 * ---------------------------------------------
190*91f16700Schasinglulu	 */
191*91f16700Schasinglulu	mov	x0, #DCCISW
192*91f16700Schasinglulu	bl	dcsw_op_level2
193*91f16700Schasinglulu
194*91f16700Schasinglulu	/* ---------------------------------------------
195*91f16700Schasinglulu	 * Come out of intra cluster coherency
196*91f16700Schasinglulu	 * ---------------------------------------------
197*91f16700Schasinglulu	 */
198*91f16700Schasinglulu	mov	x30, x18
199*91f16700Schasinglulu	b	cortex_a53_disable_smp
200*91f16700Schasingluluendfunc cortex_a53_cluster_pwr_dwn
201*91f16700Schasinglulu
202*91f16700Schasingluluerrata_report_shim cortex_a53
203*91f16700Schasinglulu
204*91f16700Schasinglulu	/* ---------------------------------------------
205*91f16700Schasinglulu	 * This function provides cortex_a53 specific
206*91f16700Schasinglulu	 * register information for crash reporting.
207*91f16700Schasinglulu	 * It needs to return with x6 pointing to
208*91f16700Schasinglulu	 * a list of register names in ascii and
209*91f16700Schasinglulu	 * x8 - x15 having values of registers to be
210*91f16700Schasinglulu	 * reported.
211*91f16700Schasinglulu	 * ---------------------------------------------
212*91f16700Schasinglulu	 */
213*91f16700Schasinglulu.section .rodata.cortex_a53_regs, "aS"
214*91f16700Schasinglulucortex_a53_regs:  /* The ascii list of register names to be reported */
215*91f16700Schasinglulu	.asciz	"cpuectlr_el1", "cpumerrsr_el1", "l2merrsr_el1", \
216*91f16700Schasinglulu		"cpuactlr_el1", ""
217*91f16700Schasinglulu
218*91f16700Schasinglulufunc cortex_a53_cpu_reg_dump
219*91f16700Schasinglulu	adr	x6, cortex_a53_regs
220*91f16700Schasinglulu	mrs	x8, CORTEX_A53_ECTLR_EL1
221*91f16700Schasinglulu	mrs	x9, CORTEX_A53_MERRSR_EL1
222*91f16700Schasinglulu	mrs	x10, CORTEX_A53_L2MERRSR_EL1
223*91f16700Schasinglulu	mrs	x11, CORTEX_A53_CPUACTLR_EL1
224*91f16700Schasinglulu	ret
225*91f16700Schasingluluendfunc cortex_a53_cpu_reg_dump
226*91f16700Schasinglulu
227*91f16700Schasingluludeclare_cpu_ops cortex_a53, CORTEX_A53_MIDR, \
228*91f16700Schasinglulu	cortex_a53_reset_func, \
229*91f16700Schasinglulu	cortex_a53_core_pwr_dwn, \
230*91f16700Schasinglulu	cortex_a53_cluster_pwr_dwn
231