xref: /arm-trusted-firmware/lib/cpus/aarch64/cortex_x3.S (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu/*
2*91f16700Schasinglulu * Copyright (c) 2021-2023, Arm Limited. All rights reserved.
3*91f16700Schasinglulu *
4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu */
6*91f16700Schasinglulu
7*91f16700Schasinglulu#include <arch.h>
8*91f16700Schasinglulu#include <asm_macros.S>
9*91f16700Schasinglulu#include <common/bl_common.h>
10*91f16700Schasinglulu#include <cortex_x3.h>
11*91f16700Schasinglulu#include <cpu_macros.S>
12*91f16700Schasinglulu#include <plat_macros.S>
13*91f16700Schasinglulu#include "wa_cve_2022_23960_bhb_vector.S"
14*91f16700Schasinglulu
15*91f16700Schasinglulu/* Hardware handled coherency */
16*91f16700Schasinglulu#if HW_ASSISTED_COHERENCY == 0
17*91f16700Schasinglulu#error "Cortex-X3 must be compiled with HW_ASSISTED_COHERENCY enabled"
18*91f16700Schasinglulu#endif
19*91f16700Schasinglulu
20*91f16700Schasinglulu/* 64-bit only core */
21*91f16700Schasinglulu#if CTX_INCLUDE_AARCH32_REGS == 1
22*91f16700Schasinglulu#error "Cortex-X3 supports only AArch64. Compile with CTX_INCLUDE_AARCH32_REGS=0"
23*91f16700Schasinglulu#endif
24*91f16700Schasinglulu
25*91f16700Schasinglulu#if WORKAROUND_CVE_2022_23960
26*91f16700Schasinglulu	wa_cve_2022_23960_bhb_vector_table CORTEX_X3_BHB_LOOP_COUNT, cortex_x3
27*91f16700Schasinglulu#endif /* WORKAROUND_CVE_2022_23960 */
28*91f16700Schasinglulu
29*91f16700Schasingluluworkaround_reset_start cortex_x3, ERRATUM(2070301), ERRATA_X3_2070301
30*91f16700Schasinglulu	sysreg_bitfield_insert CORTEX_X3_CPUECTLR2_EL1, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_CNSRV, \
31*91f16700Schasinglulu	CORTEX_X3_CPUECTLR2_EL1_PF_MODE_LSB, CORTEX_X3_CPUECTLR2_EL1_PF_MODE_WIDTH
32*91f16700Schasingluluworkaround_reset_end cortex_x3, ERRATUM(2070301)
33*91f16700Schasinglulu
34*91f16700Schasinglulucheck_erratum_ls cortex_x3, ERRATUM(2070301), CPU_REV(1, 2)
35*91f16700Schasinglulu
36*91f16700Schasingluluworkaround_runtime_start cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909
37*91f16700Schasinglulu	sysreg_bit_set	CORTEX_X3_CPUACTLR2_EL1, CORTEX_X3_CPUACTLR2_EL1_BIT_36
38*91f16700Schasingluluworkaround_runtime_end cortex_x3, ERRATUM(2313909), NO_ISB
39*91f16700Schasinglulu
40*91f16700Schasinglulucheck_erratum_ls cortex_x3, ERRATUM(2313909), CPU_REV(1, 0)
41*91f16700Schasinglulu
42*91f16700Schasingluluworkaround_reset_start cortex_x3, ERRATUM(2615812), ERRATA_X3_2615812
43*91f16700Schasinglulu	/* Disable retention control for WFI and WFE. */
44*91f16700Schasinglulu	mrs	x0, CORTEX_X3_CPUPWRCTLR_EL1
45*91f16700Schasinglulu	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFI_RET_CTRL_BITS_SHIFT, #3
46*91f16700Schasinglulu	bfi	x0, xzr, #CORTEX_X3_CPUPWRCTLR_EL1_WFE_RET_CTRL_BITS_SHIFT, #3
47*91f16700Schasinglulu	msr	CORTEX_X3_CPUPWRCTLR_EL1, x0
48*91f16700Schasingluluworkaround_reset_end cortex_x3, ERRATUM(2615812)
49*91f16700Schasinglulu
50*91f16700Schasinglulucheck_erratum_ls cortex_x3, ERRATUM(2615812), CPU_REV(1, 1)
51*91f16700Schasinglulu
52*91f16700Schasingluluworkaround_reset_start cortex_x3, ERRATUM(2742421), ERRATA_X3_2742421
53*91f16700Schasinglulu	/* Set CPUACTLR5_EL1[56:55] to 2'b01 */
54*91f16700Schasinglulu	sysreg_bit_set CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_55
55*91f16700Schasinglulu	sysreg_bit_clear CORTEX_X3_CPUACTLR5_EL1, CORTEX_X3_CPUACTLR5_EL1_BIT_56
56*91f16700Schasingluluworkaround_reset_end cortex_x3, ERRATUM(2742421)
57*91f16700Schasinglulu
58*91f16700Schasinglulucheck_erratum_ls cortex_x3, ERRATUM(2742421), CPU_REV(1, 1)
59*91f16700Schasinglulu
60*91f16700Schasingluluworkaround_reset_start cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
61*91f16700Schasinglulu#if IMAGE_BL31
62*91f16700Schasinglulu	override_vector_table wa_cve_vbar_cortex_x3
63*91f16700Schasinglulu#endif /* IMAGE_BL31 */
64*91f16700Schasingluluworkaround_reset_end cortex_x3, CVE(2022, 23960)
65*91f16700Schasinglulu
66*91f16700Schasinglulucheck_erratum_chosen cortex_x3, CVE(2022, 23960), WORKAROUND_CVE_2022_23960
67*91f16700Schasinglulu
68*91f16700Schasinglulucpu_reset_func_start cortex_x3
69*91f16700Schasinglulu	/* Disable speculative loads */
70*91f16700Schasinglulu	msr	SSBS, xzr
71*91f16700Schasinglulucpu_reset_func_end cortex_x3
72*91f16700Schasinglulu
73*91f16700Schasinglulu	/* ----------------------------------------------------
74*91f16700Schasinglulu	 * HW will do the cache maintenance while powering down
75*91f16700Schasinglulu	 * ----------------------------------------------------
76*91f16700Schasinglulu	 */
77*91f16700Schasinglulufunc cortex_x3_core_pwr_dwn
78*91f16700Schasingluluapply_erratum cortex_x3, ERRATUM(2313909), ERRATA_X3_2313909
79*91f16700Schasinglulu	/* ---------------------------------------------------
80*91f16700Schasinglulu	 * Enable CPU power down bit in power control register
81*91f16700Schasinglulu	 * ---------------------------------------------------
82*91f16700Schasinglulu	 */
83*91f16700Schasinglulu	sysreg_bit_set CORTEX_X3_CPUPWRCTLR_EL1, CORTEX_X3_CPUPWRCTLR_EL1_CORE_PWRDN_BIT
84*91f16700Schasinglulu	isb
85*91f16700Schasinglulu	ret
86*91f16700Schasingluluendfunc cortex_x3_core_pwr_dwn
87*91f16700Schasinglulu
88*91f16700Schasingluluerrata_report_shim cortex_x3
89*91f16700Schasinglulu
90*91f16700Schasinglulu	/* ---------------------------------------------
91*91f16700Schasinglulu	 * This function provides Cortex-X3-
92*91f16700Schasinglulu	 * specific register information for crash
93*91f16700Schasinglulu	 * reporting. It needs to return with x6
94*91f16700Schasinglulu	 * pointing to a list of register names in ascii
95*91f16700Schasinglulu	 * and x8 - x15 having values of registers to be
96*91f16700Schasinglulu	 * reported.
97*91f16700Schasinglulu	 * ---------------------------------------------
98*91f16700Schasinglulu	 */
99*91f16700Schasinglulu.section .rodata.cortex_x3_regs, "aS"
100*91f16700Schasinglulucortex_x3_regs:  /* The ascii list of register names to be reported */
101*91f16700Schasinglulu	.asciz	"cpuectlr_el1", ""
102*91f16700Schasinglulu
103*91f16700Schasinglulufunc cortex_x3_cpu_reg_dump
104*91f16700Schasinglulu	adr	x6, cortex_x3_regs
105*91f16700Schasinglulu	mrs	x8, CORTEX_X3_CPUECTLR_EL1
106*91f16700Schasinglulu	ret
107*91f16700Schasingluluendfunc cortex_x3_cpu_reg_dump
108*91f16700Schasinglulu
109*91f16700Schasingluludeclare_cpu_ops cortex_x3, CORTEX_X3_MIDR, \
110*91f16700Schasinglulu	cortex_x3_reset_func, \
111*91f16700Schasinglulu	cortex_x3_core_pwr_dwn
112