xref: /rk3399_ARM-atf/lib/cpus/aarch64/cortex_x3.S (revision 3f9df2c6ad053172c5dab74cd12d82a5b2c93c34)
1/*
2 * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <asm_macros.S>
9#include <common/bl_common.h>
10#include <cortex_x3.h>
11#include <cpu_macros.S>
12#include <plat_macros.S>
13#include "wa_cve_2022_23960_bhb_vector.S"
14
15/* Hardware handled coherency */
16#if HW_ASSISTED_COHERENCY == 0
17#error "Cortex-X3 must be compiled with HW_ASSISTED_COHERENCY enabled"
18#endif
19
20/* 64-bit only core */
21#if CTX_INCLUDE_AARCH32_REGS == 1
22#error "Cortex-X3 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
23#endif
24
25#if WORKAROUND_CVE_2022_23960
26	wa_cve_2022_23960_bhb_vector_table CORTEX_X3_BHB_LOOP_COUNT, cortex_x3
27#endif /* WORKAROUND_CVE_2022_23960 */
28
29workaround_reset_start cortex_x3, ERRATUM(2070301), ERRATA_X3_2070301
30	sysreg_bitfield_insert CORTEX_X3_CPUECTLR2_EL1, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_CNSRV, \
31	CORTEX_X3_CPUECTLR2_EL1_PF_MODE_LSB, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_WIDTH
32workaround_reset_end cortex_x3, ERRATUM(2070301)
33
34check_erratum_ls cortex_x3, ERRATUM(2070301), CPU_REV(1, 2)
35
36workaround_runtime_start cortex_x3, ERRATUM(2302506), ERRATA_X3_2302506
37	sysreg_bit_set	CORTEX_X3_CPUACTLR2_EL1, BIT(0)
38workaround_runtime_end cortex_x3, ERRATUM(2302506), NO_ISB
39
40check_erratum_ls cortex_x3, ERRATUM(2302506), CPU_REV(1, 1)
41
42workaround_runtime_start cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909
43	sysreg_bit_set	CORTEX_X3_CPUACTLR2_EL1, CORTEX_X3_CPUACTLR2_EL1_BIT_36
44workaround_runtime_end cortex_x3, ERRATUM(2313909), NO_ISB
45
46check_erratum_ls cortex_x3, ERRATUM(2313909), CPU_REV(1, 0)
47
48workaround_reset_start cortex_x3, ERRATUM(2615812), ERRATA_X3_2615812
49	/* Disable retention control for WFI and WFE. */
50	mrs	x0, CORTEX_X3_CPUPWRCTLR_EL1
51	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFI_RET_CTRL_BITS_SHIFT, #3
52	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFE_RET_CTRL_BITS_SHIFT, #3
53	msr	CORTEX_X3_CPUPWRCTLR_EL1, x0
54workaround_reset_end cortex_x3, ERRATUM(2615812)
55
56check_erratum_ls cortex_x3, ERRATUM(2615812), CPU_REV(1, 1)
57
58workaround_reset_start cortex_x3, ERRATUM(2742421), ERRATA_X3_2742421
59	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
60	sysreg_bit_set CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_55
61	sysreg_bit_clear CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_56
62workaround_reset_end cortex_x3, ERRATUM(2742421)
63
64check_erratum_ls cortex_x3, ERRATUM(2742421), CPU_REV(1, 1)
65
66workaround_runtime_start cortex_x3, ERRATUM(2743088), ERRATA_X3_2743088
67	/* dsb before isb of power down sequence */
68	dsb sy
69workaround_runtime_end cortex_x3, ERRATUM(2743088), NO_ISB
70
71check_erratum_ls cortex_x3, ERRATUM(2743088), CPU_REV(1, 1)
72
73workaround_reset_start cortex_x3, ERRATUM(2779509), ERRATA_X3_2779509
74	/* Set CPUACTLR3_EL1 bit 47 */
75	sysreg_bit_set CORTEX_X3_CPUACTLR3_EL1, CORTEX_X3_CPUACTLR3_EL1_BIT_47
76workaround_reset_end cortex_x3, ERRATUM(2779509)
77
78check_erratum_ls cortex_x3, ERRATUM(2779509), CPU_REV(1, 1)
79
80workaround_reset_start cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
81#if IMAGE_BL31
82	override_vector_table wa_cve_vbar_cortex_x3
83#endif /* IMAGE_BL31 */
84workaround_reset_end cortex_x3, CVE(2022, 23960)
85
86check_erratum_chosen cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
87
88cpu_reset_func_start cortex_x3
89	/* Disable speculative loads */
90	msr	SSBS, xzr
91cpu_reset_func_end cortex_x3
92
93	/* ----------------------------------------------------
94	 * HW will do the cache maintenance while powering down
95	 * ----------------------------------------------------
96	 */
97func cortex_x3_core_pwr_dwn
98	apply_erratum cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909
99	/* ---------------------------------------------------
100	 * Enable CPU power down bit in power control register
101	 * ---------------------------------------------------
102	 */
103	sysreg_bit_set CORTEX_X3_CPUPWRCTLR_EL1, CORTEX_X3_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
104	apply_erratum cortex_x3, ERRATUM(2743088), ERRATA_X3_2743088
105	isb
106	ret
107endfunc cortex_x3_core_pwr_dwn
108
109errata_report_shim cortex_x3
110
111	/* ---------------------------------------------
112	 * This function provides Cortex-X3-
113	 * specific register information for crash
114	 * reporting. It needs to return with x6
115	 * pointing to a list of register names in ascii
116	 * and x8 - x15 having values of registers to be
117	 * reported.
118	 * ---------------------------------------------
119	 */
120.section .rodata.cortex_x3_regs, "aS"
121cortex_x3_regs:  /* The ascii list of register names to be reported */
122	.asciz	"cpuectlr_el1", ""
123
124func cortex_x3_cpu_reg_dump
125	adr	x6, cortex_x3_regs
126	mrs	x8, CORTEX_X3_CPUECTLR_EL1
127	ret
128endfunc cortex_x3_cpu_reg_dump
129
130declare_cpu_ops cortex_x3, CORTEX_X3_MIDR, \
131	cortex_x3_reset_func, \
132	cortex_x3_core_pwr_dwn
133