blob: 3e1d8c9d4cde91b4a62def99c076e021b740d38d [file] [log] [blame]
Zelalem Awekec8bc23e2021-07-09 15:32:21 -05001/*
Soby Mathew68ea9542022-03-22 13:58:52 +00002 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
Zelalem Awekec8bc23e2021-07-09 15:32:21 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <asm_macros.S>
Soby Mathew68ea9542022-03-22 13:58:52 +00008#include <services/rmmd_svc.h>
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +00009
10#include <platform_def.h>
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050011#include "trp_private.h"
12
13.global trp_head
14.global trp_smc
15
16.section ".head.text", "ax"
17
18 /* ---------------------------------------------
19 * Populate the params in x0-x7 from the pointer
20 * to the smc args structure in x0.
21 * ---------------------------------------------
22 */
23 .macro restore_args_call_smc
24 ldp x6, x7, [x0, #TRP_ARG6]
25 ldp x4, x5, [x0, #TRP_ARG4]
26 ldp x2, x3, [x0, #TRP_ARG2]
27 ldp x0, x1, [x0, #TRP_ARG0]
28 smc #0
29 .endm
30
31 /* ---------------------------------------------
32 * Entry point for TRP
33 * ---------------------------------------------
34 */
35trp_head:
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000036 /*
37 * Stash arguments from previous boot stage
38 */
39 mov x20, x0
40 mov x21, x1
41 mov x22, x2
42 mov x23, x3
43
44 /*
45 * Validate CPUId before allocating a stack.
46 */
47 cmp x20, #PLATFORM_CORE_COUNT
48 b.lo 1f
49
50 mov_imm x0, RMM_BOOT_COMPLETE
51 mov_imm x1, E_RMM_BOOT_CPU_ID_OUT_OF_RANGE
52 smc #0
53
54 /* EL3 should never return back here, so panic if it does */
55 b trp_panic
56
571:
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050058 bl plat_set_my_stack
Mark Dykes50746c82021-12-01 15:08:02 -060059
60 /*
61 * Find out whether this is a cold or warm boot
62 */
63 ldr x1, cold_boot_flag
64 cbz x1, warm_boot
65
66 /*
67 * Update cold boot flag to indicate cold boot is done
68 */
69 adr x2, cold_boot_flag
70 str xzr, [x2]
71
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050072 /* ---------------------------------------------
73 * Zero out BSS section
74 * ---------------------------------------------
75 */
76 ldr x0, =__BSS_START__
77 ldr x1, =__BSS_SIZE__
78 bl zeromem
79
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000080 mov x0, x20
81 mov x1, x21
82 mov x2, x22
83 mov x3, x23
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050084 bl trp_setup
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050085 bl trp_main
Javier Almansa Sobrino04a6f2f2022-12-01 17:20:45 +000086 b 1f
87
Mark Dykes50746c82021-12-01 15:08:02 -060088warm_boot:
Javier Almansa Sobrino04a6f2f2022-12-01 17:20:45 +000089 mov x0, x20
90 mov x1, x21
91 mov x2, x22
92 mov x3, x23
93 bl trp_validate_warmboot_args
94 cbnz x0, trp_panic /* Failed to validate warmboot args */
95
961:
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000097 mov_imm x0, RMM_BOOT_COMPLETE
98 mov x1, xzr /* RMM_BOOT_SUCCESS */
Zelalem Awekec8bc23e2021-07-09 15:32:21 -050099 smc #0
100 b trp_handler
101
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000102trp_panic:
103 no_ret plat_panic_handler
104
Mark Dykes50746c82021-12-01 15:08:02 -0600105 /*
106 * Flag to mark if it is a cold boot.
107 * 1: cold boot, 0: warmboot.
108 */
109.align 3
110cold_boot_flag:
111 .dword 1
112
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500113 /* ---------------------------------------------
114 * Direct SMC call to BL31 service provided by
115 * RMM Dispatcher
116 * ---------------------------------------------
117 */
118func trp_smc
119 restore_args_call_smc
120 ret
121endfunc trp_smc
122
123 /* ---------------------------------------------
124 * RMI call handler
125 * ---------------------------------------------
126 */
127func trp_handler
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000128 /*
129 * Save Link Register and X4, as per SMCCC v1.2 its value
130 * must be preserved unless it contains result, as specified
131 * in the function definition.
132 */
133 stp x4, lr, [sp, #-16]!
134
135 /*
136 * Zero the space for X0-X3 in trp_smc_result structure
137 * and pass its address as the last argument.
138 */
139 stp xzr, xzr, [sp, #-16]!
140 stp xzr, xzr, [sp, #-16]!
141 mov x7, sp
142
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500143 bl trp_rmi_handler
AlexeiFedorovf9044ab2022-11-24 13:42:44 +0000144
145 ldp x1, x2, [sp], #16
146 ldp x3, x4, [sp], #16
147 ldp x5, lr, [sp], #16
148
149 ldr x0, =RMM_RMI_REQ_COMPLETE
150 smc #0
151
Zelalem Awekec8bc23e2021-07-09 15:32:21 -0500152 b trp_handler
153endfunc trp_handler