xref: /rk3399_ARM-atf/lib/cpus/aarch64/cpu_helpers.S (revision 42d4d3baacb3b11c68163ec85de1bf2e34e0c882)
19b476841SSoby Mathew/*
2*42d4d3baSArvind Ram Prakash * Copyright (c) 2014-2023, Arm Limited and Contributors. All rights reserved.
39b476841SSoby Mathew *
482cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
59b476841SSoby Mathew */
69b476841SSoby Mathew
79b476841SSoby Mathew#include <arch.h>
89b476841SSoby Mathew#include <asm_macros.S>
99b476841SSoby Mathew#include <assert_macros.S>
10c2ad38ceSVarun Wadekar#include <common/bl_common.h>
1109d40e0eSAntonio Nino Diaz#include <common/debug.h>
1255c70cb7SDavid Cunado#include <cpu_macros.S>
1309d40e0eSAntonio Nino Diaz#include <lib/cpus/errata_report.h>
1409d40e0eSAntonio Nino Diaz#include <lib/el3_runtime/cpu_data.h>
159b476841SSoby Mathew
169b476841SSoby Mathew /* Reset fn is needed in BL at reset vector */
17*42d4d3baSArvind Ram Prakash#if defined(IMAGE_BL1) || defined(IMAGE_BL31) ||	\
18*42d4d3baSArvind Ram Prakash	(defined(IMAGE_BL2) && RESET_TO_BL2)
199b476841SSoby Mathew	/*
209b476841SSoby Mathew	 * The reset handler common to all platforms.  After a matching
219b476841SSoby Mathew	 * cpu_ops structure entry is found, the correponding reset_handler
229b476841SSoby Mathew	 * in the cpu_ops is invoked.
23683f788fSSoby Mathew	 * Clobbers: x0 - x19, x30
249b476841SSoby Mathew	 */
259b476841SSoby Mathew	.globl	reset_handler
269b476841SSoby Mathewfunc reset_handler
277395a725SSoby Mathew	mov	x19, x30
289b476841SSoby Mathew
29683f788fSSoby Mathew	/* The plat_reset_handler can clobber x0 - x18, x30 */
3024fb838fSSoby Mathew	bl	plat_reset_handler
3124fb838fSSoby Mathew
329b476841SSoby Mathew	/* Get the matching cpu_ops pointer */
339b476841SSoby Mathew	bl	get_cpu_ops_ptr
34044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS
359b476841SSoby Mathew	cmp	x0, #0
369b476841SSoby Mathew	ASM_ASSERT(ne)
379b476841SSoby Mathew#endif
389b476841SSoby Mathew
399b476841SSoby Mathew	/* Get the cpu_ops reset handler */
409b476841SSoby Mathew	ldr	x2, [x0, #CPU_RESET_FUNC]
417395a725SSoby Mathew	mov	x30, x19
429b476841SSoby Mathew	cbz	x2, 1f
43683f788fSSoby Mathew
44683f788fSSoby Mathew	/* The cpu_ops reset handler can clobber x0 - x19, x30 */
457395a725SSoby Mathew	br	x2
469b476841SSoby Mathew1:
477395a725SSoby Mathew	ret
488b779620SKévin Petitendfunc reset_handler
4924fb838fSSoby Mathew
50b1d27b48SRoberto Vargas#endif
519b476841SSoby Mathew
523d8256b2SMasahiro Yamada#ifdef IMAGE_BL31 /* The power down core and cluster is needed only in  BL31 */
53add40351SSoby Mathew	/*
545dd9dbb5SJeenu Viswambharan	 * void prepare_cpu_pwr_dwn(unsigned int power_level)
555dd9dbb5SJeenu Viswambharan	 *
565dd9dbb5SJeenu Viswambharan	 * Prepare CPU power down function for all platforms. The function takes
575dd9dbb5SJeenu Viswambharan	 * a domain level to be powered down as its parameter. After the cpu_ops
585dd9dbb5SJeenu Viswambharan	 * pointer is retrieved from cpu_data, the handler for requested power
595dd9dbb5SJeenu Viswambharan	 * level is called.
60add40351SSoby Mathew	 */
615dd9dbb5SJeenu Viswambharan	.globl	prepare_cpu_pwr_dwn
625dd9dbb5SJeenu Viswambharanfunc prepare_cpu_pwr_dwn
63add40351SSoby Mathew	/*
645dd9dbb5SJeenu Viswambharan	 * If the given power level exceeds CPU_MAX_PWR_DWN_OPS, we call the
655dd9dbb5SJeenu Viswambharan	 * power down handler for the last power level
66add40351SSoby Mathew	 */
675dd9dbb5SJeenu Viswambharan	mov_imm	x2, (CPU_MAX_PWR_DWN_OPS - 1)
685dd9dbb5SJeenu Viswambharan	cmp	x0, x2
695dd9dbb5SJeenu Viswambharan	csel	x2, x2, x0, hi
705dd9dbb5SJeenu Viswambharan
71add40351SSoby Mathew	mrs	x1, tpidr_el3
72add40351SSoby Mathew	ldr	x0, [x1, #CPU_DATA_CPU_OPS_PTR]
73044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS
74add40351SSoby Mathew	cmp	x0, #0
75add40351SSoby Mathew	ASM_ASSERT(ne)
76add40351SSoby Mathew#endif
77add40351SSoby Mathew
785dd9dbb5SJeenu Viswambharan	/* Get the appropriate power down handler */
795dd9dbb5SJeenu Viswambharan	mov	x1, #CPU_PWR_DWN_OPS
805dd9dbb5SJeenu Viswambharan	add	x1, x1, x2, lsl #3
815dd9dbb5SJeenu Viswambharan	ldr	x1, [x0, x1]
82601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
83601e3ed2SVarun Wadekar	cmp	x1, #0
84601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
85601e3ed2SVarun Wadekar#endif
86add40351SSoby Mathew	br	x1
875dd9dbb5SJeenu Viswambharanendfunc prepare_cpu_pwr_dwn
88add40351SSoby Mathew
89add40351SSoby Mathew
90add40351SSoby Mathew	/*
91add40351SSoby Mathew	 * Initializes the cpu_ops_ptr if not already initialized
9212e7c4abSVikram Kanigiri	 * in cpu_data. This can be called without a runtime stack, but may
9312e7c4abSVikram Kanigiri	 * only be called after the MMU is enabled.
94add40351SSoby Mathew	 * clobbers: x0 - x6, x10
95add40351SSoby Mathew	 */
96add40351SSoby Mathew	.globl	init_cpu_ops
97add40351SSoby Mathewfunc init_cpu_ops
98add40351SSoby Mathew	mrs	x6, tpidr_el3
99add40351SSoby Mathew	ldr	x0, [x6, #CPU_DATA_CPU_OPS_PTR]
100add40351SSoby Mathew	cbnz	x0, 1f
101add40351SSoby Mathew	mov	x10, x30
102add40351SSoby Mathew	bl	get_cpu_ops_ptr
103044bb2faSAntonio Nino Diaz#if ENABLE_ASSERTIONS
104add40351SSoby Mathew	cmp	x0, #0
105add40351SSoby Mathew	ASM_ASSERT(ne)
106add40351SSoby Mathew#endif
10709997346SSoby Mathew	str	x0, [x6, #CPU_DATA_CPU_OPS_PTR]!
108add40351SSoby Mathew	mov x30, x10
109add40351SSoby Mathew1:
110add40351SSoby Mathew	ret
1118b779620SKévin Petitendfunc init_cpu_ops
112add40351SSoby Mathew#endif /* IMAGE_BL31 */
113add40351SSoby Mathew
1143d8256b2SMasahiro Yamada#if defined(IMAGE_BL31) && CRASH_REPORTING
115d3f70af6SSoby Mathew	/*
116d3f70af6SSoby Mathew	 * The cpu specific registers which need to be reported in a crash
117d3f70af6SSoby Mathew	 * are reported via cpu_ops cpu_reg_dump function. After a matching
118d3f70af6SSoby Mathew	 * cpu_ops structure entry is found, the correponding cpu_reg_dump
119d3f70af6SSoby Mathew	 * in the cpu_ops is invoked.
120d3f70af6SSoby Mathew	 */
121d3f70af6SSoby Mathew	.globl	do_cpu_reg_dump
122d3f70af6SSoby Mathewfunc do_cpu_reg_dump
123d3f70af6SSoby Mathew	mov	x16, x30
124d3f70af6SSoby Mathew
125d3f70af6SSoby Mathew	/* Get the matching cpu_ops pointer */
126d3f70af6SSoby Mathew	bl	get_cpu_ops_ptr
127d3f70af6SSoby Mathew	cbz	x0, 1f
128d3f70af6SSoby Mathew
129d3f70af6SSoby Mathew	/* Get the cpu_ops cpu_reg_dump */
130d3f70af6SSoby Mathew	ldr	x2, [x0, #CPU_REG_DUMP]
131d3f70af6SSoby Mathew	cbz	x2, 1f
132d3f70af6SSoby Mathew	blr	x2
133d3f70af6SSoby Mathew1:
134d3f70af6SSoby Mathew	mov	x30, x16
135d3f70af6SSoby Mathew	ret
1368b779620SKévin Petitendfunc do_cpu_reg_dump
137d3f70af6SSoby Mathew#endif
138d3f70af6SSoby Mathew
1399b476841SSoby Mathew	/*
1409b476841SSoby Mathew	 * The below function returns the cpu_ops structure matching the
1419b476841SSoby Mathew	 * midr of the core. It reads the MIDR_EL1 and finds the matching
1429b476841SSoby Mathew	 * entry in cpu_ops entries. Only the implementation and part number
1439b476841SSoby Mathew	 * are used to match the entries.
1441994e562SJavier Almansa Sobrino	 *
1451994e562SJavier Almansa Sobrino	 * If cpu_ops for the MIDR_EL1 cannot be found and
1461994e562SJavier Almansa Sobrino	 * SUPPORT_UNKNOWN_MPID is enabled, it will try to look for a
1471994e562SJavier Almansa Sobrino	 * default cpu_ops with an MIDR value of 0.
1482e61d687SOlivier Deprez	 * (Implementation number 0x0 should be reserved for software use
1491994e562SJavier Almansa Sobrino	 * and therefore no clashes should happen with that default value).
1501994e562SJavier Almansa Sobrino	 *
1519b476841SSoby Mathew	 * Return :
1529b476841SSoby Mathew	 *     x0 - The matching cpu_ops pointer on Success
1539b476841SSoby Mathew	 *     x0 - 0 on failure.
1549b476841SSoby Mathew	 * Clobbers : x0 - x5
1559b476841SSoby Mathew	 */
1569b476841SSoby Mathew	.globl	get_cpu_ops_ptr
1579b476841SSoby Mathewfunc get_cpu_ops_ptr
1589b476841SSoby Mathew	/* Read the MIDR_EL1 */
1599b476841SSoby Mathew	mrs	x2, midr_el1
1609b476841SSoby Mathew	mov_imm	x3, CPU_IMPL_PN_MASK
1619b476841SSoby Mathew
1629b476841SSoby Mathew	/* Retain only the implementation and part number using mask */
1639b476841SSoby Mathew	and	w2, w2, w3
1641994e562SJavier Almansa Sobrino
1651994e562SJavier Almansa Sobrino	/* Get the cpu_ops end location */
1661994e562SJavier Almansa Sobrino	adr	x5, (__CPU_OPS_END__ + CPU_MIDR)
1671994e562SJavier Almansa Sobrino
1681994e562SJavier Almansa Sobrino	/* Initialize the return parameter */
1691994e562SJavier Almansa Sobrino	mov	x0, #0
1709b476841SSoby Mathew1:
1711994e562SJavier Almansa Sobrino	/* Get the cpu_ops start location */
1721994e562SJavier Almansa Sobrino	adr	x4, (__CPU_OPS_START__ + CPU_MIDR)
1731994e562SJavier Almansa Sobrino
1741994e562SJavier Almansa Sobrino2:
1759b476841SSoby Mathew	/* Check if we have reached end of list */
1769b476841SSoby Mathew	cmp	x4, x5
1771994e562SJavier Almansa Sobrino	b.eq	search_def_ptr
1789b476841SSoby Mathew
1799b476841SSoby Mathew	/* load the midr from the cpu_ops */
1809b476841SSoby Mathew	ldr	x1, [x4], #CPU_OPS_SIZE
1819b476841SSoby Mathew	and	w1, w1, w3
1829b476841SSoby Mathew
1839b476841SSoby Mathew	/* Check if midr matches to midr of this core */
1849b476841SSoby Mathew	cmp	w1, w2
1851994e562SJavier Almansa Sobrino	b.ne	2b
1869b476841SSoby Mathew
1879b476841SSoby Mathew	/* Subtract the increment and offset to get the cpu-ops pointer */
1889b476841SSoby Mathew	sub	x0, x4, #(CPU_OPS_SIZE + CPU_MIDR)
189601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
190601e3ed2SVarun Wadekar	cmp	x0, #0
191601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
192601e3ed2SVarun Wadekar#endif
1931994e562SJavier Almansa Sobrino#ifdef SUPPORT_UNKNOWN_MPID
1941994e562SJavier Almansa Sobrino	cbnz	x2, exit_mpid_found
1951994e562SJavier Almansa Sobrino	/* Mark the unsupported MPID flag */
1961994e562SJavier Almansa Sobrino	adrp	x1, unsupported_mpid_flag
1971994e562SJavier Almansa Sobrino	add	x1, x1, :lo12:unsupported_mpid_flag
1981994e562SJavier Almansa Sobrino	str	w2, [x1]
1991994e562SJavier Almansa Sobrinoexit_mpid_found:
2001994e562SJavier Almansa Sobrino#endif
2011994e562SJavier Almansa Sobrino	ret
2021994e562SJavier Almansa Sobrino
2031994e562SJavier Almansa Sobrino	/*
2041994e562SJavier Almansa Sobrino	 * Search again for a default pointer (MIDR = 0x0)
2051994e562SJavier Almansa Sobrino	 * or return error if already searched.
2061994e562SJavier Almansa Sobrino	 */
2071994e562SJavier Almansa Sobrinosearch_def_ptr:
2081994e562SJavier Almansa Sobrino#ifdef SUPPORT_UNKNOWN_MPID
2091994e562SJavier Almansa Sobrino	cbz	x2, error_exit
2101994e562SJavier Almansa Sobrino	mov	x2, #0
2111994e562SJavier Almansa Sobrino	b	1b
2129b476841SSoby Mathewerror_exit:
2131994e562SJavier Almansa Sobrino#endif
2149b476841SSoby Mathew	ret
2158b779620SKévin Petitendfunc get_cpu_ops_ptr
2167395a725SSoby Mathew
21710bcd761SJeenu Viswambharan/*
21810bcd761SJeenu Viswambharan * Extract CPU revision and variant, and combine them into a single numeric for
21910bcd761SJeenu Viswambharan * easier comparison.
22010bcd761SJeenu Viswambharan */
22110bcd761SJeenu Viswambharan	.globl	cpu_get_rev_var
22210bcd761SJeenu Viswambharanfunc cpu_get_rev_var
22310bcd761SJeenu Viswambharan	mrs	x1, midr_el1
2247395a725SSoby Mathew
22554035fc4SSandrine Bailleux	/*
22610bcd761SJeenu Viswambharan	 * Extract the variant[23:20] and revision[3:0] from MIDR, and pack them
22710bcd761SJeenu Viswambharan	 * as variant[7:4] and revision[3:0] of x0.
22854035fc4SSandrine Bailleux	 *
22910bcd761SJeenu Viswambharan	 * First extract x1[23:16] to x0[7:0] and zero fill the rest. Then
23010bcd761SJeenu Viswambharan	 * extract x1[3:0] into x0[3:0] retaining other bits.
23154035fc4SSandrine Bailleux	 */
23210bcd761SJeenu Viswambharan	ubfx	x0, x1, #(MIDR_VAR_SHIFT - MIDR_REV_BITS), #(MIDR_REV_BITS + MIDR_VAR_BITS)
23310bcd761SJeenu Viswambharan	bfxil	x0, x1, #MIDR_REV_SHIFT, #MIDR_REV_BITS
23410bcd761SJeenu Viswambharan	ret
23510bcd761SJeenu Viswambharanendfunc cpu_get_rev_var
2367395a725SSoby Mathew
23710bcd761SJeenu Viswambharan/*
23810bcd761SJeenu Viswambharan * Compare the CPU's revision-variant (x0) with a given value (x1), for errata
23910bcd761SJeenu Viswambharan * application purposes. If the revision-variant is less than or same as a given
24010bcd761SJeenu Viswambharan * value, indicates that errata applies; otherwise not.
2419ec3921cSJonathan Wright *
2429ec3921cSJonathan Wright * Shall clobber: x0-x3
24310bcd761SJeenu Viswambharan */
24410bcd761SJeenu Viswambharan	.globl	cpu_rev_var_ls
24510bcd761SJeenu Viswambharanfunc cpu_rev_var_ls
24610bcd761SJeenu Viswambharan	mov	x2, #ERRATA_APPLIES
24710bcd761SJeenu Viswambharan	mov	x3, #ERRATA_NOT_APPLIES
24810bcd761SJeenu Viswambharan	cmp	x0, x1
24910bcd761SJeenu Viswambharan	csel	x0, x2, x3, ls
25010bcd761SJeenu Viswambharan	ret
25110bcd761SJeenu Viswambharanendfunc cpu_rev_var_ls
25210bcd761SJeenu Viswambharan
253b75dc0e4SAndre Przywara/*
254b75dc0e4SAndre Przywara * Compare the CPU's revision-variant (x0) with a given value (x1), for errata
255b75dc0e4SAndre Przywara * application purposes. If the revision-variant is higher than or same as a
256b75dc0e4SAndre Przywara * given value, indicates that errata applies; otherwise not.
2579ec3921cSJonathan Wright *
2589ec3921cSJonathan Wright * Shall clobber: x0-x3
259b75dc0e4SAndre Przywara */
260b75dc0e4SAndre Przywara	.globl	cpu_rev_var_hs
261b75dc0e4SAndre Przywarafunc cpu_rev_var_hs
262b75dc0e4SAndre Przywara	mov	x2, #ERRATA_APPLIES
263b75dc0e4SAndre Przywara	mov	x3, #ERRATA_NOT_APPLIES
264b75dc0e4SAndre Przywara	cmp	x0, x1
265b75dc0e4SAndre Przywara	csel	x0, x2, x3, hs
266b75dc0e4SAndre Przywara	ret
267b75dc0e4SAndre Przywaraendfunc cpu_rev_var_hs
268b75dc0e4SAndre Przywara
26980942622Slaurenw-arm/*
27080942622Slaurenw-arm * Compare the CPU's revision-variant (x0) with a given range (x1 - x2), for errata
27180942622Slaurenw-arm * application purposes. If the revision-variant is between or includes the given
27280942622Slaurenw-arm * values, this indicates that errata applies; otherwise not.
27380942622Slaurenw-arm *
27480942622Slaurenw-arm * Shall clobber: x0-x4
27580942622Slaurenw-arm */
27680942622Slaurenw-arm	.globl	cpu_rev_var_range
27780942622Slaurenw-armfunc cpu_rev_var_range
27880942622Slaurenw-arm	mov	x3, #ERRATA_APPLIES
27980942622Slaurenw-arm	mov	x4, #ERRATA_NOT_APPLIES
28080942622Slaurenw-arm	cmp	x0, x1
28180942622Slaurenw-arm	csel	x1, x3, x4, hs
28280942622Slaurenw-arm	cbz	x1, 1f
28380942622Slaurenw-arm	cmp	x0, x2
28480942622Slaurenw-arm	csel	x1, x3, x4, ls
28580942622Slaurenw-arm1:
28680942622Slaurenw-arm	mov	x0, x1
28780942622Slaurenw-arm	ret
28880942622Slaurenw-armendfunc cpu_rev_var_range
28980942622Slaurenw-arm
29010bcd761SJeenu Viswambharan#if REPORT_ERRATA
29110bcd761SJeenu Viswambharan/*
29210bcd761SJeenu Viswambharan * void print_errata_status(void);
29310bcd761SJeenu Viswambharan *
29410bcd761SJeenu Viswambharan * Function to print errata status for CPUs of its class. Must be called only:
29510bcd761SJeenu Viswambharan *
29610bcd761SJeenu Viswambharan *   - with MMU and data caches are enabled;
29710bcd761SJeenu Viswambharan *   - after cpu_ops have been initialized in per-CPU data.
29810bcd761SJeenu Viswambharan */
29910bcd761SJeenu Viswambharan	.globl print_errata_status
30010bcd761SJeenu Viswambharanfunc print_errata_status
30110bcd761SJeenu Viswambharan#ifdef IMAGE_BL1
30210bcd761SJeenu Viswambharan	/*
30310bcd761SJeenu Viswambharan	 * BL1 doesn't have per-CPU data. So retrieve the CPU operations
30410bcd761SJeenu Viswambharan	 * directly.
30510bcd761SJeenu Viswambharan	 */
30610bcd761SJeenu Viswambharan	stp	xzr, x30, [sp, #-16]!
30710bcd761SJeenu Viswambharan	bl	get_cpu_ops_ptr
30810bcd761SJeenu Viswambharan	ldp	xzr, x30, [sp], #16
30910bcd761SJeenu Viswambharan	ldr	x1, [x0, #CPU_ERRATA_FUNC]
31010bcd761SJeenu Viswambharan	cbnz	x1, .Lprint
31110bcd761SJeenu Viswambharan#else
31210bcd761SJeenu Viswambharan	/*
31310bcd761SJeenu Viswambharan	 * Retrieve pointer to cpu_ops from per-CPU data, and further, the
31410bcd761SJeenu Viswambharan	 * errata printing function. If it's non-NULL, jump to the function in
31510bcd761SJeenu Viswambharan	 * turn.
31610bcd761SJeenu Viswambharan	 */
31710bcd761SJeenu Viswambharan	mrs	x0, tpidr_el3
318601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
319601e3ed2SVarun Wadekar	cmp	x0, #0
320601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
321601e3ed2SVarun Wadekar#endif
32210bcd761SJeenu Viswambharan	ldr	x1, [x0, #CPU_DATA_CPU_OPS_PTR]
323601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
324601e3ed2SVarun Wadekar	cmp	x1, #0
325601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
326601e3ed2SVarun Wadekar#endif
32710bcd761SJeenu Viswambharan	ldr	x0, [x1, #CPU_ERRATA_FUNC]
32810bcd761SJeenu Viswambharan	cbz	x0, .Lnoprint
32910bcd761SJeenu Viswambharan
33010bcd761SJeenu Viswambharan	/*
33110bcd761SJeenu Viswambharan	 * Printing errata status requires atomically testing the printed flag.
33210bcd761SJeenu Viswambharan	 */
33322fa58cbSdp-arm	stp	x19, x30, [sp, #-16]!
33422fa58cbSdp-arm	mov	x19, x0
33510bcd761SJeenu Viswambharan
33610bcd761SJeenu Viswambharan	/*
33710bcd761SJeenu Viswambharan	 * Load pointers to errata lock and printed flag. Call
33810bcd761SJeenu Viswambharan	 * errata_needs_reporting to check whether this CPU needs to report
33910bcd761SJeenu Viswambharan	 * errata status pertaining to its class.
34010bcd761SJeenu Viswambharan	 */
34110bcd761SJeenu Viswambharan	ldr	x0, [x1, #CPU_ERRATA_LOCK]
34210bcd761SJeenu Viswambharan	ldr	x1, [x1, #CPU_ERRATA_PRINTED]
34310bcd761SJeenu Viswambharan	bl	errata_needs_reporting
34422fa58cbSdp-arm	mov	x1, x19
34522fa58cbSdp-arm	ldp	x19, x30, [sp], #16
34610bcd761SJeenu Viswambharan	cbnz	x0, .Lprint
34710bcd761SJeenu Viswambharan#endif
34810bcd761SJeenu Viswambharan.Lnoprint:
34910bcd761SJeenu Viswambharan	ret
35010bcd761SJeenu Viswambharan.Lprint:
35110bcd761SJeenu Viswambharan	/* Jump to errata reporting function for this CPU */
35210bcd761SJeenu Viswambharan	br	x1
35310bcd761SJeenu Viswambharanendfunc print_errata_status
35410bcd761SJeenu Viswambharan#endif
355a205a56eSDimitris Papastamos
356a205a56eSDimitris Papastamos/*
3572c3a1078SDimitris Papastamos * int check_wa_cve_2017_5715(void);
358a205a56eSDimitris Papastamos *
359a205a56eSDimitris Papastamos * This function returns:
360a205a56eSDimitris Papastamos *  - ERRATA_APPLIES when firmware mitigation is required.
361a205a56eSDimitris Papastamos *  - ERRATA_NOT_APPLIES when firmware mitigation is _not_ required.
362a205a56eSDimitris Papastamos *  - ERRATA_MISSING when firmware mitigation would be required but
363a205a56eSDimitris Papastamos *    is not compiled in.
364a205a56eSDimitris Papastamos *
365a205a56eSDimitris Papastamos * NOTE: Must be called only after cpu_ops have been initialized
366a205a56eSDimitris Papastamos *       in per-CPU data.
367a205a56eSDimitris Papastamos */
3682c3a1078SDimitris Papastamos	.globl	check_wa_cve_2017_5715
3692c3a1078SDimitris Papastamosfunc check_wa_cve_2017_5715
370a205a56eSDimitris Papastamos	mrs	x0, tpidr_el3
371a205a56eSDimitris Papastamos#if ENABLE_ASSERTIONS
372a205a56eSDimitris Papastamos	cmp	x0, #0
373a205a56eSDimitris Papastamos	ASM_ASSERT(ne)
374a205a56eSDimitris Papastamos#endif
375a205a56eSDimitris Papastamos	ldr	x0, [x0, #CPU_DATA_CPU_OPS_PTR]
376601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
377601e3ed2SVarun Wadekar	cmp	x0, #0
378601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
379601e3ed2SVarun Wadekar#endif
380a205a56eSDimitris Papastamos	ldr	x0, [x0, #CPU_EXTRA1_FUNC]
381a205a56eSDimitris Papastamos	/*
382a205a56eSDimitris Papastamos	 * If the reserved function pointer is NULL, this CPU
383a205a56eSDimitris Papastamos	 * is unaffected by CVE-2017-5715 so bail out.
384a205a56eSDimitris Papastamos	 */
3859b2510b6SBipin Ravi	cmp	x0, #CPU_NO_EXTRA1_FUNC
386a205a56eSDimitris Papastamos	beq	1f
387a205a56eSDimitris Papastamos	br	x0
388a205a56eSDimitris Papastamos1:
389a205a56eSDimitris Papastamos	mov	x0, #ERRATA_NOT_APPLIES
390a205a56eSDimitris Papastamos	ret
3912c3a1078SDimitris Papastamosendfunc check_wa_cve_2017_5715
392fe007b2eSDimitris Papastamos
393fe007b2eSDimitris Papastamos/*
394fe007b2eSDimitris Papastamos * void *wa_cve_2018_3639_get_disable_ptr(void);
395fe007b2eSDimitris Papastamos *
396fe007b2eSDimitris Papastamos * Returns a function pointer which is used to disable mitigation
397fe007b2eSDimitris Papastamos * for CVE-2018-3639.
398fe007b2eSDimitris Papastamos * The function pointer is only returned on cores that employ
399fe007b2eSDimitris Papastamos * dynamic mitigation.  If the core uses static mitigation or is
400fe007b2eSDimitris Papastamos * unaffected by CVE-2018-3639 this function returns NULL.
401fe007b2eSDimitris Papastamos *
402fe007b2eSDimitris Papastamos * NOTE: Must be called only after cpu_ops have been initialized
403fe007b2eSDimitris Papastamos *       in per-CPU data.
404fe007b2eSDimitris Papastamos */
405fe007b2eSDimitris Papastamos	.globl	wa_cve_2018_3639_get_disable_ptr
406fe007b2eSDimitris Papastamosfunc wa_cve_2018_3639_get_disable_ptr
407fe007b2eSDimitris Papastamos	mrs	x0, tpidr_el3
408fe007b2eSDimitris Papastamos#if ENABLE_ASSERTIONS
409fe007b2eSDimitris Papastamos	cmp	x0, #0
410fe007b2eSDimitris Papastamos	ASM_ASSERT(ne)
411fe007b2eSDimitris Papastamos#endif
412fe007b2eSDimitris Papastamos	ldr	x0, [x0, #CPU_DATA_CPU_OPS_PTR]
413601e3ed2SVarun Wadekar#if ENABLE_ASSERTIONS
414601e3ed2SVarun Wadekar	cmp	x0, #0
415601e3ed2SVarun Wadekar	ASM_ASSERT(ne)
416601e3ed2SVarun Wadekar#endif
417fe007b2eSDimitris Papastamos	ldr	x0, [x0, #CPU_EXTRA2_FUNC]
418fe007b2eSDimitris Papastamos	ret
419fe007b2eSDimitris Papastamosendfunc wa_cve_2018_3639_get_disable_ptr
4209b2510b6SBipin Ravi
4219b2510b6SBipin Ravi/*
4229b2510b6SBipin Ravi * int check_smccc_arch_wa3_applies(void);
4239b2510b6SBipin Ravi *
4249b2510b6SBipin Ravi * This function checks whether SMCCC_ARCH_WORKAROUND_3 is enabled to mitigate
4259b2510b6SBipin Ravi * CVE-2022-23960 for this CPU. It returns:
4269b2510b6SBipin Ravi *  - ERRATA_APPLIES when SMCCC_ARCH_WORKAROUND_3 can be invoked to mitigate
4279b2510b6SBipin Ravi *    the CVE.
4289b2510b6SBipin Ravi *  - ERRATA_NOT_APPLIES when SMCCC_ARCH_WORKAROUND_3 should not be invoked to
4299b2510b6SBipin Ravi *    mitigate the CVE.
4309b2510b6SBipin Ravi *
4319b2510b6SBipin Ravi * NOTE: Must be called only after cpu_ops have been initialized
4329b2510b6SBipin Ravi *       in per-CPU data.
4339b2510b6SBipin Ravi */
4349b2510b6SBipin Ravi	.globl	check_smccc_arch_wa3_applies
4359b2510b6SBipin Ravifunc check_smccc_arch_wa3_applies
4369b2510b6SBipin Ravi	mrs	x0, tpidr_el3
4379b2510b6SBipin Ravi#if ENABLE_ASSERTIONS
4389b2510b6SBipin Ravi	cmp	x0, #0
4399b2510b6SBipin Ravi	ASM_ASSERT(ne)
4409b2510b6SBipin Ravi#endif
4419b2510b6SBipin Ravi	ldr	x0, [x0, #CPU_DATA_CPU_OPS_PTR]
4429b2510b6SBipin Ravi#if ENABLE_ASSERTIONS
4439b2510b6SBipin Ravi	cmp	x0, #0
4449b2510b6SBipin Ravi	ASM_ASSERT(ne)
4459b2510b6SBipin Ravi#endif
4469b2510b6SBipin Ravi	ldr	x0, [x0, #CPU_EXTRA3_FUNC]
4479b2510b6SBipin Ravi	/*
4489b2510b6SBipin Ravi	 * If the reserved function pointer is NULL, this CPU
4499b2510b6SBipin Ravi	 * is unaffected by CVE-2022-23960 so bail out.
4509b2510b6SBipin Ravi	 */
4519b2510b6SBipin Ravi	cmp	x0, #CPU_NO_EXTRA3_FUNC
4529b2510b6SBipin Ravi	beq	1f
4539b2510b6SBipin Ravi	br	x0
4549b2510b6SBipin Ravi1:
4559b2510b6SBipin Ravi	mov	x0, #ERRATA_NOT_APPLIES
4569b2510b6SBipin Ravi	ret
4579b2510b6SBipin Raviendfunc check_smccc_arch_wa3_applies
458