1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright 2016 NXP Semiconductor, Inc.
4 */
5
6#include <config.h>
7#include <linux/linkage.h>
8#include <asm/system.h>
9#include <asm/macro.h>
10
11WEAK(_sec_firmware_entry)
12	/*
13	 * x0: Secure Firmware entry point
14	 * x1: Exception return address Low
15	 * x2: Exception return address High
16	 */
17
18	/* Save stack pointer for EL2 */
19	mov	x3, sp
20	msr	sp_el2, x3
21
22	/* Set exception return address hold pointer */
23        adr	x4, 1f
24        mov	x3, x4
25#ifdef CONFIG_ARMV8_SEC_FIRMWARE_ERET_ADDR_REVERT
26        rev	w3, w3
27#endif
28        str	w3, [x1]
29        lsr	x3, x4, #32
30#ifdef CONFIG_ARMV8_SEC_FIRMWARE_ERET_ADDR_REVERT
31        rev	w3, w3
32#endif
33        str	w3, [x2]
34
35	/* Call SEC monitor */
36        br	x0
37
381:
39        mov	x0, #0
40        ret
41ENDPROC(_sec_firmware_entry)
42
43#ifdef CONFIG_SEC_FIRMWARE_ARMV8_PSCI
44ENTRY(_sec_firmware_support_psci_version)
45	mov	x0, 0x84000000
46	mov	x1, 0x0
47	mov	x2, 0x0
48	mov	x3, 0x0
49	smc	#0
50	ret
51ENDPROC(_sec_firmware_support_psci_version)
52
53/*
54 * Switch from AArch64 EL2 to AArch32 EL2
55 * @param inputs:
56 * x0: argument, zero
57 * x1: machine nr
58 * x2: fdt address
59 * x3: input argument
60 * x4: kernel entry point
61 * @param outputs for secure firmware:
62 * x0: function id
63 * x1: kernel entry point
64 * x2: machine nr
65 * x3: fdt address
66*/
67ENTRY(armv8_el2_to_aarch32)
68	mov	x3, x2
69	mov	x2, x1
70	mov	x1, x4
71	ldr	x0, =0xc000ff04
72	smc	#0
73	ret
74ENDPROC(armv8_el2_to_aarch32)
75#endif
76