xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_a78_ae.S (revision af61b50c1077b6d936c8ed741c1d0b8e43eb2b19)
1/*
2 * Copyright (c) 2019-2025, Arm Limited. All rights reserved.
3 * Copyright (c) 2021-2023, NVIDIA Corporation. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8#include <arch.h>
9#include <asm_macros.S>
10#include <common/bl_common.h>
11#include <cortex_a78_ae.h>
12#include <cpu_macros.S>
13#include <plat_macros.S>
14#include "wa_cve_2022_23960_bhb_vector.S"
15
16/* Hardware handled coherency */
17#if HW_ASSISTED_COHERENCY == 0
18#error "cortex_a78_ae must be compiled with HW_ASSISTED_COHERENCY enabled"
19#endif
20
21#if WORKAROUND_CVE_2022_23960
22	wa_cve_2022_23960_bhb_vector_table CORTEX_A78_AE_BHB_LOOP_COUNT, cortex_a78_ae
23#endif /* WORKAROUND_CVE_2022_23960 */
24
25cpu_reset_prologue cortex_a78_ae
26
27/* Disable hardware page aggregation. Enables mitigation for `CVE-2024-5660` */
28workaround_reset_start cortex_a78_ae, CVE(2024, 5660), WORKAROUND_CVE_2024_5660
29	sysreg_bit_set CORTEX_A78_AE_CPUECTLR_EL1, BIT(46)
30workaround_reset_end cortex_a78_ae, CVE(2024, 5660)
31
32check_erratum_ls cortex_a78_ae, CVE(2024, 5660), CPU_REV(0, 3)
33
34workaround_reset_start cortex_a78_ae, ERRATUM(1941500), ERRATA_A78_AE_1941500
35	sysreg_bit_set CORTEX_A78_AE_CPUECTLR_EL1, CORTEX_A78_AE_CPUECTLR_EL1_BIT_8
36workaround_reset_end cortex_a78_ae, ERRATUM(1941500)
37
38check_erratum_ls cortex_a78_ae, ERRATUM(1941500), CPU_REV(0, 1)
39
40workaround_reset_start cortex_a78_ae, ERRATUM(1951502), ERRATA_A78_AE_1951502
41	msr	S3_6_c15_c8_0, xzr
42	ldr	x0, =0x10E3900002
43	msr	S3_6_c15_c8_2, x0
44	ldr	x0, =0x10FFF00083
45	msr	S3_6_c15_c8_3, x0
46	ldr	x0, =0x2001003FF
47	msr	S3_6_c15_c8_1, x0
48
49	mov	x0, #1
50	msr	S3_6_c15_c8_0, x0
51	ldr	x0, =0x10E3800082
52	msr	S3_6_c15_c8_2, x0
53	ldr	x0, =0x10FFF00083
54	msr	S3_6_c15_c8_3, x0
55	ldr	x0, =0x2001003FF
56	msr	S3_6_c15_c8_1, x0
57
58	mov	x0, #2
59	msr	S3_6_c15_c8_0, x0
60	ldr	x0, =0x10E3800200
61	msr	S3_6_c15_c8_2, x0
62	ldr	x0, =0x10FFF003E0
63	msr	S3_6_c15_c8_3, x0
64	ldr	x0, =0x2001003FF
65	msr	S3_6_c15_c8_1, x0
66workaround_reset_end cortex_a78_ae, ERRATUM(1951502)
67
68check_erratum_ls cortex_a78_ae, ERRATUM(1951502), CPU_REV(0, 1)
69
70workaround_reset_start cortex_a78_ae, ERRATUM(2376748), ERRATA_A78_AE_2376748
71	/* -------------------------------------------------------
72	 * Set CPUACTLR2_EL1[0] to 1 to force PLDW/PFRM ST to
73	 * behave like PLD/PRFM LD and not cause invalidations to
74	 * other PE caches. There might be a small performance
75	 * degradation to this workaround for certain workloads
76	 * that share data.
77	 * -------------------------------------------------------
78	 */
79	sysreg_bit_set CORTEX_A78_AE_ACTLR2_EL1, CORTEX_A78_AE_ACTLR2_EL1_BIT_0
80workaround_reset_end cortex_a78_ae, ERRATUM(2376748)
81
82check_erratum_ls cortex_a78_ae, ERRATUM(2376748), CPU_REV(0, 2)
83
84workaround_reset_start cortex_a78_ae, ERRATUM(2395408), ERRATA_A78_AE_2395408
85	/* --------------------------------------------------------
86	 * Disable folding of demand requests into older prefetches
87	 * with L2 miss requests outstanding by setting the
88	 * CPUACTLR2_EL1[40] to 1.
89	 * --------------------------------------------------------
90	 */
91	sysreg_bit_set CORTEX_A78_AE_ACTLR2_EL1, CORTEX_A78_AE_ACTLR2_EL1_BIT_40
92workaround_reset_end cortex_a78_ae, ERRATUM(2395408)
93
94check_erratum_ls cortex_a78_ae, ERRATUM(2395408), CPU_REV(0, 1)
95
96workaround_reset_start cortex_a78_ae, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
97#if IMAGE_BL31
98	/*
99	 * The Cortex-A78AE generic vectors are overridden to apply errata
100	 * mitigation on exception entry from lower ELs.
101	 */
102	override_vector_table wa_cve_vbar_cortex_a78_ae
103#endif /* IMAGE_BL31 */
104workaround_reset_end cortex_a78_ae, CVE(2022, 23960)
105
106check_erratum_chosen cortex_a78_ae, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
107
108cpu_reset_func_start cortex_a78_ae
109#if ENABLE_FEAT_AMU
110	/* Make sure accesses from EL0/EL1 and EL2 are not trapped to EL3 */
111	sysreg_bit_clear actlr_el3, CORTEX_A78_ACTLR_TAM_BIT
112
113	/* Make sure accesses from non-secure EL0/EL1 are not trapped to EL2 */
114	sysreg_bit_clear actlr_el2, CORTEX_A78_ACTLR_TAM_BIT
115
116	/* Enable group0 counters */
117	mov	x0, #CORTEX_A78_AMU_GROUP0_MASK
118	msr	CPUAMCNTENSET0_EL0, x0
119
120	/* Enable group1 counters */
121	mov	x0, #CORTEX_A78_AMU_GROUP1_MASK
122	msr	CPUAMCNTENSET1_EL0, x0
123#endif
124cpu_reset_func_end cortex_a78_ae
125
126	/* -------------------------------------------------------
127	 * HW will do the cache maintenance while powering down
128	 * -------------------------------------------------------
129	 */
130func cortex_a78_ae_core_pwr_dwn
131	/* -------------------------------------------------------
132	 * Enable CPU power down bit in power control register
133	 * -------------------------------------------------------
134	 */
135	sysreg_bit_set CORTEX_A78_CPUPWRCTLR_EL1, CORTEX_A78_CPUPWRCTLR_EL1_CORE_PWRDN_EN_BIT
136	isb
137	ret
138endfunc cortex_a78_ae_core_pwr_dwn
139
140	/* -------------------------------------------------------
141	 * This function provides cortex_a78_ae specific
142	 * register information for crash reporting.
143	 * It needs to return with x6 pointing to
144	 * a list of register names in ascii and
145	 * x8 - x15 having values of registers to be
146	 * reported.
147	 * -------------------------------------------------------
148	 */
149.section .rodata.cortex_a78_ae_regs, "aS"
150cortex_a78_ae_regs:  /* The ascii list of register names to be reported */
151	.asciz	"cpuectlr_el1", ""
152
153func cortex_a78_ae_cpu_reg_dump
154	adr	x6, cortex_a78_ae_regs
155	mrs	x8, CORTEX_A78_CPUECTLR_EL1
156	ret
157endfunc cortex_a78_ae_cpu_reg_dump
158
159declare_cpu_ops cortex_a78_ae, CORTEX_A78_AE_MIDR, \
160	cortex_a78_ae_reset_func, \
161	cortex_a78_ae_core_pwr_dwn
162