xref: /rk3399_ARM-atf/bl32/tsp/aarch64/tsp_entrypoint.S (revision 82cb2c1ad9897473743f08437d0a3995bed561b9)
17c88f3f6SAchin Gupta/*
2308d359bSDouglas Raillard * Copyright (c) 2013-2017, ARM Limited and Contributors. All rights reserved.
37c88f3f6SAchin Gupta *
4*82cb2c1aSdp-arm * SPDX-License-Identifier: BSD-3-Clause
57c88f3f6SAchin Gupta */
67c88f3f6SAchin Gupta
77c88f3f6SAchin Gupta#include <arch.h>
80a30cf54SAndrew Thoelke#include <asm_macros.S>
997043ac9SDan Handley#include <tsp.h>
10d50ece03SAntonio Nino Diaz#include <xlat_tables_defs.h>
11da0af78aSDan Handley#include "../tsp_private.h"
127c88f3f6SAchin Gupta
137c88f3f6SAchin Gupta
147c88f3f6SAchin Gupta	.globl	tsp_entrypoint
15399fb08fSAndrew Thoelke	.globl  tsp_vector_table
167c88f3f6SAchin Gupta
17239b04faSSoby Mathew
18239b04faSSoby Mathew
197c88f3f6SAchin Gupta	/* ---------------------------------------------
207c88f3f6SAchin Gupta	 * Populate the params in x0-x7 from the pointer
217c88f3f6SAchin Gupta	 * to the smc args structure in x0.
227c88f3f6SAchin Gupta	 * ---------------------------------------------
237c88f3f6SAchin Gupta	 */
247c88f3f6SAchin Gupta	.macro restore_args_call_smc
257c88f3f6SAchin Gupta	ldp	x6, x7, [x0, #TSP_ARG6]
267c88f3f6SAchin Gupta	ldp	x4, x5, [x0, #TSP_ARG4]
277c88f3f6SAchin Gupta	ldp	x2, x3, [x0, #TSP_ARG2]
287c88f3f6SAchin Gupta	ldp	x0, x1, [x0, #TSP_ARG0]
297c88f3f6SAchin Gupta	smc	#0
307c88f3f6SAchin Gupta	.endm
317c88f3f6SAchin Gupta
326cf89021SAchin Gupta	.macro	save_eret_context reg1 reg2
336cf89021SAchin Gupta	mrs	\reg1, elr_el1
346cf89021SAchin Gupta	mrs	\reg2, spsr_el1
356cf89021SAchin Gupta	stp	\reg1, \reg2, [sp, #-0x10]!
366cf89021SAchin Gupta	stp	x30, x18, [sp, #-0x10]!
376cf89021SAchin Gupta	.endm
386cf89021SAchin Gupta
396cf89021SAchin Gupta	.macro restore_eret_context reg1 reg2
406cf89021SAchin Gupta	ldp	x30, x18, [sp], #0x10
416cf89021SAchin Gupta	ldp	\reg1, \reg2, [sp], #0x10
426cf89021SAchin Gupta	msr	elr_el1, \reg1
436cf89021SAchin Gupta	msr	spsr_el1, \reg2
446cf89021SAchin Gupta	.endm
456cf89021SAchin Gupta
466cf89021SAchin Gupta	.section	.text, "ax"
476cf89021SAchin Gupta	.align 3
487c88f3f6SAchin Gupta
490a30cf54SAndrew Thoelkefunc tsp_entrypoint
507c88f3f6SAchin Gupta
517c88f3f6SAchin Gupta	/* ---------------------------------------------
527c88f3f6SAchin Gupta	 * Set the exception vector to something sane.
537c88f3f6SAchin Gupta	 * ---------------------------------------------
547c88f3f6SAchin Gupta	 */
5557356e90SAchin Gupta	adr	x0, tsp_exceptions
567c88f3f6SAchin Gupta	msr	vbar_el1, x0
570c8d4fefSAchin Gupta	isb
580c8d4fefSAchin Gupta
590c8d4fefSAchin Gupta	/* ---------------------------------------------
600c8d4fefSAchin Gupta	 * Enable the SError interrupt now that the
610c8d4fefSAchin Gupta	 * exception vectors have been setup.
620c8d4fefSAchin Gupta	 * ---------------------------------------------
630c8d4fefSAchin Gupta	 */
640c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
657c88f3f6SAchin Gupta
667c88f3f6SAchin Gupta	/* ---------------------------------------------
67ec3c1003SAchin Gupta	 * Enable the instruction cache, stack pointer
68ec3c1003SAchin Gupta	 * and data access alignment checks
697c88f3f6SAchin Gupta	 * ---------------------------------------------
707c88f3f6SAchin Gupta	 */
71ec3c1003SAchin Gupta	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
727c88f3f6SAchin Gupta	mrs	x0, sctlr_el1
73ec3c1003SAchin Gupta	orr	x0, x0, x1
747c88f3f6SAchin Gupta	msr	sctlr_el1, x0
757c88f3f6SAchin Gupta	isb
767c88f3f6SAchin Gupta
777c88f3f6SAchin Gupta	/* ---------------------------------------------
7854dc71e7SAchin Gupta	 * Invalidate the RW memory used by the BL32
7954dc71e7SAchin Gupta	 * image. This includes the data and NOBITS
8054dc71e7SAchin Gupta	 * sections. This is done to safeguard against
8154dc71e7SAchin Gupta	 * possible corruption of this memory by dirty
8254dc71e7SAchin Gupta	 * cache lines in a system cache as a result of
8354dc71e7SAchin Gupta	 * use by an earlier boot loader stage.
8454dc71e7SAchin Gupta	 * ---------------------------------------------
8554dc71e7SAchin Gupta	 */
8654dc71e7SAchin Gupta	adr	x0, __RW_START__
8754dc71e7SAchin Gupta	adr	x1, __RW_END__
8854dc71e7SAchin Gupta	sub	x1, x1, x0
8954dc71e7SAchin Gupta	bl	inv_dcache_range
9054dc71e7SAchin Gupta
9154dc71e7SAchin Gupta	/* ---------------------------------------------
927c88f3f6SAchin Gupta	 * Zero out NOBITS sections. There are 2 of them:
937c88f3f6SAchin Gupta	 *   - the .bss section;
947c88f3f6SAchin Gupta	 *   - the coherent memory section.
957c88f3f6SAchin Gupta	 * ---------------------------------------------
967c88f3f6SAchin Gupta	 */
977c88f3f6SAchin Gupta	ldr	x0, =__BSS_START__
987c88f3f6SAchin Gupta	ldr	x1, =__BSS_SIZE__
99308d359bSDouglas Raillard	bl	zeromem
1007c88f3f6SAchin Gupta
101ab8707e6SSoby Mathew#if USE_COHERENT_MEM
1027c88f3f6SAchin Gupta	ldr	x0, =__COHERENT_RAM_START__
1037c88f3f6SAchin Gupta	ldr	x1, =__COHERENT_RAM_UNALIGNED_SIZE__
104308d359bSDouglas Raillard	bl	zeromem
105ab8707e6SSoby Mathew#endif
1067c88f3f6SAchin Gupta
1077c88f3f6SAchin Gupta	/* --------------------------------------------
108754a2b7aSAchin Gupta	 * Allocate a stack whose memory will be marked
109754a2b7aSAchin Gupta	 * as Normal-IS-WBWA when the MMU is enabled.
110754a2b7aSAchin Gupta	 * There is no risk of reading stale stack
111754a2b7aSAchin Gupta	 * memory after enabling the MMU as only the
112754a2b7aSAchin Gupta	 * primary cpu is running at the moment.
1137c88f3f6SAchin Gupta	 * --------------------------------------------
1147c88f3f6SAchin Gupta	 */
115fd650ff6SSoby Mathew	bl	plat_set_my_stack
1167c88f3f6SAchin Gupta
1177c88f3f6SAchin Gupta	/* ---------------------------------------------
11851faada7SDouglas Raillard	 * Initialize the stack protector canary before
11951faada7SDouglas Raillard	 * any C code is called.
12051faada7SDouglas Raillard	 * ---------------------------------------------
12151faada7SDouglas Raillard	 */
12251faada7SDouglas Raillard#if STACK_PROTECTOR_ENABLED
12351faada7SDouglas Raillard	bl	update_stack_protector_canary
12451faada7SDouglas Raillard#endif
12551faada7SDouglas Raillard
12651faada7SDouglas Raillard	/* ---------------------------------------------
1277c88f3f6SAchin Gupta	 * Perform early platform setup & platform
1287c88f3f6SAchin Gupta	 * specific early arch. setup e.g. mmu setup
1297c88f3f6SAchin Gupta	 * ---------------------------------------------
1307c88f3f6SAchin Gupta	 */
1315a06bb7eSDan Handley	bl	tsp_early_platform_setup
1325a06bb7eSDan Handley	bl	tsp_plat_arch_setup
1337c88f3f6SAchin Gupta
1347c88f3f6SAchin Gupta	/* ---------------------------------------------
1357c88f3f6SAchin Gupta	 * Jump to main function.
1367c88f3f6SAchin Gupta	 * ---------------------------------------------
1377c88f3f6SAchin Gupta	 */
1387c88f3f6SAchin Gupta	bl	tsp_main
1397c88f3f6SAchin Gupta
1407c88f3f6SAchin Gupta	/* ---------------------------------------------
1417c88f3f6SAchin Gupta	 * Tell TSPD that we are done initialising
1427c88f3f6SAchin Gupta	 * ---------------------------------------------
1437c88f3f6SAchin Gupta	 */
1447c88f3f6SAchin Gupta	mov	x1, x0
1457c88f3f6SAchin Gupta	mov	x0, #TSP_ENTRY_DONE
1467c88f3f6SAchin Gupta	smc	#0
1477c88f3f6SAchin Gupta
1487c88f3f6SAchin Guptatsp_entrypoint_panic:
1497c88f3f6SAchin Gupta	b	tsp_entrypoint_panic
1508b779620SKévin Petitendfunc tsp_entrypoint
1517c88f3f6SAchin Gupta
152399fb08fSAndrew Thoelke
153399fb08fSAndrew Thoelke	/* -------------------------------------------
154399fb08fSAndrew Thoelke	 * Table of entrypoint vectors provided to the
155399fb08fSAndrew Thoelke	 * TSPD for the various entrypoints
156399fb08fSAndrew Thoelke	 * -------------------------------------------
157399fb08fSAndrew Thoelke	 */
158399fb08fSAndrew Thoelkefunc tsp_vector_table
159399fb08fSAndrew Thoelke	b	tsp_std_smc_entry
160399fb08fSAndrew Thoelke	b	tsp_fast_smc_entry
161399fb08fSAndrew Thoelke	b	tsp_cpu_on_entry
162399fb08fSAndrew Thoelke	b	tsp_cpu_off_entry
163399fb08fSAndrew Thoelke	b	tsp_cpu_resume_entry
164399fb08fSAndrew Thoelke	b	tsp_cpu_suspend_entry
16502446137SSoby Mathew	b	tsp_sel1_intr_entry
166d5f13093SJuan Castillo	b	tsp_system_off_entry
167d5f13093SJuan Castillo	b	tsp_system_reset_entry
1683df6012aSDouglas Raillard	b	tsp_abort_std_smc_entry
1698b779620SKévin Petitendfunc tsp_vector_table
170399fb08fSAndrew Thoelke
1717c88f3f6SAchin Gupta	/*---------------------------------------------
1727c88f3f6SAchin Gupta	 * This entrypoint is used by the TSPD when this
1737c88f3f6SAchin Gupta	 * cpu is to be turned off through a CPU_OFF
1747c88f3f6SAchin Gupta	 * psci call to ask the TSP to perform any
1757c88f3f6SAchin Gupta	 * bookeeping necessary. In the current
1767c88f3f6SAchin Gupta	 * implementation, the TSPD expects the TSP to
1777c88f3f6SAchin Gupta	 * re-initialise its state so nothing is done
1787c88f3f6SAchin Gupta	 * here except for acknowledging the request.
1797c88f3f6SAchin Gupta	 * ---------------------------------------------
1807c88f3f6SAchin Gupta	 */
1810a30cf54SAndrew Thoelkefunc tsp_cpu_off_entry
1827c88f3f6SAchin Gupta	bl	tsp_cpu_off_main
1837c88f3f6SAchin Gupta	restore_args_call_smc
1848b779620SKévin Petitendfunc tsp_cpu_off_entry
1857c88f3f6SAchin Gupta
1867c88f3f6SAchin Gupta	/*---------------------------------------------
187d5f13093SJuan Castillo	 * This entrypoint is used by the TSPD when the
188d5f13093SJuan Castillo	 * system is about to be switched off (through
189d5f13093SJuan Castillo	 * a SYSTEM_OFF psci call) to ask the TSP to
190d5f13093SJuan Castillo	 * perform any necessary bookkeeping.
191d5f13093SJuan Castillo	 * ---------------------------------------------
192d5f13093SJuan Castillo	 */
193d5f13093SJuan Castillofunc tsp_system_off_entry
194d5f13093SJuan Castillo	bl	tsp_system_off_main
195d5f13093SJuan Castillo	restore_args_call_smc
1968b779620SKévin Petitendfunc tsp_system_off_entry
197d5f13093SJuan Castillo
198d5f13093SJuan Castillo	/*---------------------------------------------
199d5f13093SJuan Castillo	 * This entrypoint is used by the TSPD when the
200d5f13093SJuan Castillo	 * system is about to be reset (through a
201d5f13093SJuan Castillo	 * SYSTEM_RESET psci call) to ask the TSP to
202d5f13093SJuan Castillo	 * perform any necessary bookkeeping.
203d5f13093SJuan Castillo	 * ---------------------------------------------
204d5f13093SJuan Castillo	 */
205d5f13093SJuan Castillofunc tsp_system_reset_entry
206d5f13093SJuan Castillo	bl	tsp_system_reset_main
207d5f13093SJuan Castillo	restore_args_call_smc
2088b779620SKévin Petitendfunc tsp_system_reset_entry
209d5f13093SJuan Castillo
210d5f13093SJuan Castillo	/*---------------------------------------------
2117c88f3f6SAchin Gupta	 * This entrypoint is used by the TSPD when this
2127c88f3f6SAchin Gupta	 * cpu is turned on using a CPU_ON psci call to
2137c88f3f6SAchin Gupta	 * ask the TSP to initialise itself i.e. setup
2147c88f3f6SAchin Gupta	 * the mmu, stacks etc. Minimal architectural
2157c88f3f6SAchin Gupta	 * state will be initialised by the TSPD when
2167c88f3f6SAchin Gupta	 * this function is entered i.e. Caches and MMU
2177c88f3f6SAchin Gupta	 * will be turned off, the execution state
2187c88f3f6SAchin Gupta	 * will be aarch64 and exceptions masked.
2197c88f3f6SAchin Gupta	 * ---------------------------------------------
2207c88f3f6SAchin Gupta	 */
2210a30cf54SAndrew Thoelkefunc tsp_cpu_on_entry
2227c88f3f6SAchin Gupta	/* ---------------------------------------------
2237c88f3f6SAchin Gupta	 * Set the exception vector to something sane.
2247c88f3f6SAchin Gupta	 * ---------------------------------------------
2257c88f3f6SAchin Gupta	 */
22657356e90SAchin Gupta	adr	x0, tsp_exceptions
2277c88f3f6SAchin Gupta	msr	vbar_el1, x0
2280c8d4fefSAchin Gupta	isb
2290c8d4fefSAchin Gupta
2300c8d4fefSAchin Gupta	/* Enable the SError interrupt */
2310c8d4fefSAchin Gupta	msr	daifclr, #DAIF_ABT_BIT
2327c88f3f6SAchin Gupta
2337c88f3f6SAchin Gupta	/* ---------------------------------------------
234ec3c1003SAchin Gupta	 * Enable the instruction cache, stack pointer
235ec3c1003SAchin Gupta	 * and data access alignment checks
2367c88f3f6SAchin Gupta	 * ---------------------------------------------
2377c88f3f6SAchin Gupta	 */
238ec3c1003SAchin Gupta	mov	x1, #(SCTLR_I_BIT | SCTLR_A_BIT | SCTLR_SA_BIT)
2397c88f3f6SAchin Gupta	mrs	x0, sctlr_el1
240ec3c1003SAchin Gupta	orr	x0, x0, x1
2417c88f3f6SAchin Gupta	msr	sctlr_el1, x0
2427c88f3f6SAchin Gupta	isb
2437c88f3f6SAchin Gupta
2447c88f3f6SAchin Gupta	/* --------------------------------------------
245b51da821SAchin Gupta	 * Give ourselves a stack whose memory will be
246b51da821SAchin Gupta	 * marked as Normal-IS-WBWA when the MMU is
247b51da821SAchin Gupta	 * enabled.
2487c88f3f6SAchin Gupta	 * --------------------------------------------
2497c88f3f6SAchin Gupta	 */
250fd650ff6SSoby Mathew	bl	plat_set_my_stack
2517c88f3f6SAchin Gupta
252b51da821SAchin Gupta	/* --------------------------------------------
253b51da821SAchin Gupta	 * Enable the MMU with the DCache disabled. It
254b51da821SAchin Gupta	 * is safe to use stacks allocated in normal
255b51da821SAchin Gupta	 * memory as a result. All memory accesses are
256b51da821SAchin Gupta	 * marked nGnRnE when the MMU is disabled. So
257b51da821SAchin Gupta	 * all the stack writes will make it to memory.
258b51da821SAchin Gupta	 * All memory accesses are marked Non-cacheable
259b51da821SAchin Gupta	 * when the MMU is enabled but D$ is disabled.
260b51da821SAchin Gupta	 * So used stack memory is guaranteed to be
261b51da821SAchin Gupta	 * visible immediately after the MMU is enabled
262b51da821SAchin Gupta	 * Enabling the DCache at the same time as the
263b51da821SAchin Gupta	 * MMU can lead to speculatively fetched and
264b51da821SAchin Gupta	 * possibly stale stack memory being read from
265b51da821SAchin Gupta	 * other caches. This can lead to coherency
266b51da821SAchin Gupta	 * issues.
267b51da821SAchin Gupta	 * --------------------------------------------
2687c88f3f6SAchin Gupta	 */
269b51da821SAchin Gupta	mov	x0, #DISABLE_DCACHE
270dff8e47aSDan Handley	bl	bl32_plat_enable_mmu
2717c88f3f6SAchin Gupta
2727c88f3f6SAchin Gupta	/* ---------------------------------------------
273b51da821SAchin Gupta	 * Enable the Data cache now that the MMU has
274b51da821SAchin Gupta	 * been enabled. The stack has been unwound. It
275b51da821SAchin Gupta	 * will be written first before being read. This
276b51da821SAchin Gupta	 * will invalidate any stale cache lines resi-
277b51da821SAchin Gupta	 * -dent in other caches. We assume that
278b51da821SAchin Gupta	 * interconnect coherency has been enabled for
279b51da821SAchin Gupta	 * this cluster by EL3 firmware.
2807c88f3f6SAchin Gupta	 * ---------------------------------------------
2817c88f3f6SAchin Gupta	 */
282b51da821SAchin Gupta	mrs	x0, sctlr_el1
283b51da821SAchin Gupta	orr	x0, x0, #SCTLR_C_BIT
284b51da821SAchin Gupta	msr	sctlr_el1, x0
285b51da821SAchin Gupta	isb
2867c88f3f6SAchin Gupta
2877c88f3f6SAchin Gupta	/* ---------------------------------------------
2887c88f3f6SAchin Gupta	 * Enter C runtime to perform any remaining
2897c88f3f6SAchin Gupta	 * book keeping
2907c88f3f6SAchin Gupta	 * ---------------------------------------------
2917c88f3f6SAchin Gupta	 */
2927c88f3f6SAchin Gupta	bl	tsp_cpu_on_main
2937c88f3f6SAchin Gupta	restore_args_call_smc
2947c88f3f6SAchin Gupta
2957c88f3f6SAchin Gupta	/* Should never reach here */
2967c88f3f6SAchin Guptatsp_cpu_on_entry_panic:
2977c88f3f6SAchin Gupta	b	tsp_cpu_on_entry_panic
2988b779620SKévin Petitendfunc tsp_cpu_on_entry
2997c88f3f6SAchin Gupta
3007c88f3f6SAchin Gupta	/*---------------------------------------------
3017c88f3f6SAchin Gupta	 * This entrypoint is used by the TSPD when this
3027c88f3f6SAchin Gupta	 * cpu is to be suspended through a CPU_SUSPEND
3037c88f3f6SAchin Gupta	 * psci call to ask the TSP to perform any
3047c88f3f6SAchin Gupta	 * bookeeping necessary. In the current
3057c88f3f6SAchin Gupta	 * implementation, the TSPD saves and restores
3067c88f3f6SAchin Gupta	 * the EL1 state.
3077c88f3f6SAchin Gupta	 * ---------------------------------------------
3087c88f3f6SAchin Gupta	 */
3090a30cf54SAndrew Thoelkefunc tsp_cpu_suspend_entry
3107c88f3f6SAchin Gupta	bl	tsp_cpu_suspend_main
3117c88f3f6SAchin Gupta	restore_args_call_smc
3128b779620SKévin Petitendfunc tsp_cpu_suspend_entry
3137c88f3f6SAchin Gupta
31402446137SSoby Mathew	/*-------------------------------------------------
3156cf89021SAchin Gupta	 * This entrypoint is used by the TSPD to pass
31663b8440fSSoby Mathew	 * control for `synchronously` handling a S-EL1
31763b8440fSSoby Mathew	 * Interrupt which was triggered while executing
31863b8440fSSoby Mathew	 * in normal world. 'x0' contains a magic number
31963b8440fSSoby Mathew	 * which indicates this. TSPD expects control to
32063b8440fSSoby Mathew	 * be handed back at the end of interrupt
32163b8440fSSoby Mathew	 * processing. This is done through an SMC.
32263b8440fSSoby Mathew	 * The handover agreement is:
3236cf89021SAchin Gupta	 *
3246cf89021SAchin Gupta	 * 1. PSTATE.DAIF are set upon entry. 'x1' has
3256cf89021SAchin Gupta	 *    the ELR_EL3 from the non-secure state.
3266cf89021SAchin Gupta	 * 2. TSP has to preserve the callee saved
3276cf89021SAchin Gupta	 *    general purpose registers, SP_EL1/EL0 and
3286cf89021SAchin Gupta	 *    LR.
3296cf89021SAchin Gupta	 * 3. TSP has to preserve the system and vfp
3306cf89021SAchin Gupta	 *    registers (if applicable).
3316cf89021SAchin Gupta	 * 4. TSP can use 'x0-x18' to enable its C
3326cf89021SAchin Gupta	 *    runtime.
3336cf89021SAchin Gupta	 * 5. TSP returns to TSPD using an SMC with
33402446137SSoby Mathew	 *    'x0' = TSP_HANDLED_S_EL1_INTR
33502446137SSoby Mathew	 * ------------------------------------------------
3366cf89021SAchin Gupta	 */
33702446137SSoby Mathewfunc	tsp_sel1_intr_entry
3386cf89021SAchin Gupta#if DEBUG
33963b8440fSSoby Mathew	mov_imm	x2, TSP_HANDLE_SEL1_INTR_AND_RETURN
3406cf89021SAchin Gupta	cmp	x0, x2
34102446137SSoby Mathew	b.ne	tsp_sel1_int_entry_panic
3426cf89021SAchin Gupta#endif
34302446137SSoby Mathew	/*-------------------------------------------------
3446cf89021SAchin Gupta	 * Save any previous context needed to perform
3456cf89021SAchin Gupta	 * an exception return from S-EL1 e.g. context
34602446137SSoby Mathew	 * from a previous Non secure Interrupt.
34702446137SSoby Mathew	 * Update statistics and handle the S-EL1
34802446137SSoby Mathew	 * interrupt before returning to the TSPD.
3496cf89021SAchin Gupta	 * IRQ/FIQs are not enabled since that will
3506cf89021SAchin Gupta	 * complicate the implementation. Execution
3516cf89021SAchin Gupta	 * will be transferred back to the normal world
35263b8440fSSoby Mathew	 * in any case. The handler can return 0
35363b8440fSSoby Mathew	 * if the interrupt was handled or TSP_PREEMPTED
35463b8440fSSoby Mathew	 * if the expected interrupt was preempted
35563b8440fSSoby Mathew	 * by an interrupt that should be handled in EL3
35663b8440fSSoby Mathew	 * e.g. Group 0 interrupt in GICv3. In both
35763b8440fSSoby Mathew	 * the cases switch to EL3 using SMC with id
35863b8440fSSoby Mathew	 * TSP_HANDLED_S_EL1_INTR. Any other return value
35963b8440fSSoby Mathew	 * from the handler will result in panic.
36002446137SSoby Mathew	 * ------------------------------------------------
3616cf89021SAchin Gupta	 */
3626cf89021SAchin Gupta	save_eret_context x2 x3
36302446137SSoby Mathew	bl	tsp_update_sync_sel1_intr_stats
36402446137SSoby Mathew	bl	tsp_common_int_handler
36563b8440fSSoby Mathew	/* Check if the S-EL1 interrupt has been handled */
36663b8440fSSoby Mathew	cbnz	x0, tsp_sel1_intr_check_preemption
36763b8440fSSoby Mathew	b	tsp_sel1_intr_return
36863b8440fSSoby Mathewtsp_sel1_intr_check_preemption:
36963b8440fSSoby Mathew	/* Check if the S-EL1 interrupt has been preempted */
37063b8440fSSoby Mathew	mov_imm	x1, TSP_PREEMPTED
37163b8440fSSoby Mathew	cmp	x0, x1
37263b8440fSSoby Mathew	b.ne	tsp_sel1_int_entry_panic
37363b8440fSSoby Mathewtsp_sel1_intr_return:
37463b8440fSSoby Mathew	mov_imm	x0, TSP_HANDLED_S_EL1_INTR
3756cf89021SAchin Gupta	restore_eret_context x2 x3
3766cf89021SAchin Gupta	smc	#0
3776cf89021SAchin Gupta
37863b8440fSSoby Mathew	/* Should never reach here */
37902446137SSoby Mathewtsp_sel1_int_entry_panic:
380a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
38102446137SSoby Mathewendfunc tsp_sel1_intr_entry
3826cf89021SAchin Gupta
3836cf89021SAchin Gupta	/*---------------------------------------------
3847c88f3f6SAchin Gupta	 * This entrypoint is used by the TSPD when this
3857c88f3f6SAchin Gupta	 * cpu resumes execution after an earlier
3867c88f3f6SAchin Gupta	 * CPU_SUSPEND psci call to ask the TSP to
3877c88f3f6SAchin Gupta	 * restore its saved context. In the current
3887c88f3f6SAchin Gupta	 * implementation, the TSPD saves and restores
3897c88f3f6SAchin Gupta	 * EL1 state so nothing is done here apart from
3907c88f3f6SAchin Gupta	 * acknowledging the request.
3917c88f3f6SAchin Gupta	 * ---------------------------------------------
3927c88f3f6SAchin Gupta	 */
3930a30cf54SAndrew Thoelkefunc tsp_cpu_resume_entry
3947c88f3f6SAchin Gupta	bl	tsp_cpu_resume_main
3957c88f3f6SAchin Gupta	restore_args_call_smc
3961c3ea103SAntonio Nino Diaz
3971c3ea103SAntonio Nino Diaz	/* Should never reach here */
398a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
3998b779620SKévin Petitendfunc tsp_cpu_resume_entry
4007c88f3f6SAchin Gupta
4017c88f3f6SAchin Gupta	/*---------------------------------------------
4027c88f3f6SAchin Gupta	 * This entrypoint is used by the TSPD to ask
4037c88f3f6SAchin Gupta	 * the TSP to service a fast smc request.
4047c88f3f6SAchin Gupta	 * ---------------------------------------------
4057c88f3f6SAchin Gupta	 */
4060a30cf54SAndrew Thoelkefunc tsp_fast_smc_entry
407239b04faSSoby Mathew	bl	tsp_smc_handler
4087c88f3f6SAchin Gupta	restore_args_call_smc
4091c3ea103SAntonio Nino Diaz
4101c3ea103SAntonio Nino Diaz	/* Should never reach here */
411a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
4128b779620SKévin Petitendfunc tsp_fast_smc_entry
4137c88f3f6SAchin Gupta
414239b04faSSoby Mathew	/*---------------------------------------------
415239b04faSSoby Mathew	 * This entrypoint is used by the TSPD to ask
416239b04faSSoby Mathew	 * the TSP to service a std smc request.
417239b04faSSoby Mathew	 * We will enable preemption during execution
418239b04faSSoby Mathew	 * of tsp_smc_handler.
419239b04faSSoby Mathew	 * ---------------------------------------------
420239b04faSSoby Mathew	 */
421239b04faSSoby Mathewfunc tsp_std_smc_entry
422239b04faSSoby Mathew	msr	daifclr, #DAIF_FIQ_BIT | DAIF_IRQ_BIT
423239b04faSSoby Mathew	bl	tsp_smc_handler
424239b04faSSoby Mathew	msr	daifset, #DAIF_FIQ_BIT | DAIF_IRQ_BIT
425239b04faSSoby Mathew	restore_args_call_smc
4261c3ea103SAntonio Nino Diaz
4271c3ea103SAntonio Nino Diaz	/* Should never reach here */
428a806dad5SJeenu Viswambharan	no_ret	plat_panic_handler
4298b779620SKévin Petitendfunc tsp_std_smc_entry
4303df6012aSDouglas Raillard
4313df6012aSDouglas Raillard	/*---------------------------------------------------------------------
4323df6012aSDouglas Raillard	 * This entrypoint is used by the TSPD to abort a pre-empted Standard
4333df6012aSDouglas Raillard	 * SMC. It could be on behalf of non-secure world or because a CPU
4343df6012aSDouglas Raillard	 * suspend/CPU off request needs to abort the preempted SMC.
4353df6012aSDouglas Raillard	 * --------------------------------------------------------------------
4363df6012aSDouglas Raillard	 */
4373df6012aSDouglas Raillardfunc tsp_abort_std_smc_entry
4383df6012aSDouglas Raillard
4393df6012aSDouglas Raillard	/*
4403df6012aSDouglas Raillard	 * Exceptions masking is already done by the TSPD when entering this
4413df6012aSDouglas Raillard	 * hook so there is no need to do it here.
4423df6012aSDouglas Raillard	 */
4433df6012aSDouglas Raillard
4443df6012aSDouglas Raillard	/* Reset the stack used by the pre-empted SMC */
4453df6012aSDouglas Raillard	bl	plat_set_my_stack
4463df6012aSDouglas Raillard
4473df6012aSDouglas Raillard	/*
4483df6012aSDouglas Raillard	 * Allow some cleanup such as releasing locks.
4493df6012aSDouglas Raillard	 */
4503df6012aSDouglas Raillard	bl	tsp_abort_smc_handler
4513df6012aSDouglas Raillard
4523df6012aSDouglas Raillard	restore_args_call_smc
4533df6012aSDouglas Raillard
4543df6012aSDouglas Raillard	/* Should never reach here */
4553df6012aSDouglas Raillard	bl	plat_panic_handler
4563df6012aSDouglas Raillardendfunc tsp_abort_std_smc_entry
457