blob: ecac43522a2711a4cb1add32857c81af74f0833b [file] [log] [blame]
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05301/*
Varun Wadekar079e20e2018-08-10 09:55:25 -07002 * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
Varun Wadekarf09264a2018-11-05 15:12:55 -08003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05304 *
dp-armfa3cf0b2017-05-03 09:38:09 +01005 * SPDX-License-Identifier: BSD-3-Clause
Varun Wadekar3d4e6a52015-03-13 14:01:03 +05306 */
7
8/*******************************************************************************
9 * This is the Secure Payload Dispatcher (SPD). The dispatcher is meant to be a
10 * plug-in component to the Secure Monitor, registered as a runtime service. The
11 * SPD is expected to be a functional extension of the Secure Payload (SP) that
12 * executes in Secure EL1. The Secure Monitor will delegate all SMCs targeting
13 * the Trusted OS/Applications range to the dispatcher. The SPD will either
14 * handle the request locally or delegate it to the Secure Payload. It is also
15 * responsible for initialising and maintaining communication with the SP.
16 ******************************************************************************/
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053017#include <assert.h>
Varun Wadekar079e20e2018-08-10 09:55:25 -070018#include <bl31/interrupt_mgmt.h>
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053019#include <errno.h>
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053020#include <stddef.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000021
Antonio Nino Diaz31a157f2019-02-11 11:57:57 +000022#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000023#include <bl31/bl31.h>
Antonio Nino Diaz31a157f2019-02-11 11:57:57 +000024#include <bl32/payloads/tlk.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include <common/bl_common.h>
26#include <common/debug.h>
27#include <common/runtime_svc.h>
28#include <lib/el3_runtime/context_mgmt.h>
29#include <plat/common/platform.h>
30#include <tools_share/uuid.h>
31
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053032#include "tlkd_private.h"
33
34extern const spd_pm_ops_t tlkd_pm_ops;
35
36/*******************************************************************************
Varun Wadekara70dec32015-08-26 12:49:03 +053037 * Per-cpu Secure Payload state
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053038 ******************************************************************************/
Varun Wadekara70dec32015-08-26 12:49:03 +053039tlk_context_t tlk_ctx;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053040
Varun Wadekar0bbe8a62016-06-07 21:21:59 -070041/*******************************************************************************
42 * CPU number on which TLK booted up
43 ******************************************************************************/
Varun Wadekar66231d12017-06-07 09:57:42 -070044static uint32_t boot_cpu;
Varun Wadekar0bbe8a62016-06-07 21:21:59 -070045
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053046/* TLK UID: RFC-4122 compliant UUID (version-5, sha-1) */
Roberto Vargaseace8f12018-04-26 13:36:53 +010047DEFINE_SVC_UUID2(tlk_uuid,
48 0xc9e911bd, 0xba2b, 0xee52, 0xb1, 0x72,
49 0x46, 0x1f, 0xba, 0x97, 0x7f, 0x63);
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053050
Masahiro Yamada56212752018-04-19 01:14:42 +090051static int32_t tlkd_init(void);
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053052
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053053/*******************************************************************************
Varun Wadekar079e20e2018-08-10 09:55:25 -070054 * Secure Payload Dispatcher's timer interrupt handler
55 ******************************************************************************/
56static uint64_t tlkd_interrupt_handler(uint32_t id,
57 uint32_t flags,
58 void *handle,
59 void *cookie)
60{
61 cpu_context_t *s_cpu_context;
62 int irq = plat_ic_get_pending_interrupt_id();
63
64 /* acknowledge the interrupt and mark it complete */
65 (void)plat_ic_acknowledge_interrupt();
66 plat_ic_end_of_interrupt(irq);
67
68 /*
69 * Disable the routing of NS interrupts from secure world to
70 * EL3 while interrupted on this core.
71 */
72 disable_intr_rm_local(INTR_TYPE_S_EL1, SECURE);
73
74 /* Check the security state when the exception was generated */
75 assert(get_interrupt_src_ss(flags) == NON_SECURE);
76 assert(handle == cm_get_context(NON_SECURE));
77
78 /* Save non-secure state */
79 cm_el1_sysregs_context_save(NON_SECURE);
80
81 /* Get a reference to the secure context */
82 s_cpu_context = cm_get_context(SECURE);
83 assert(s_cpu_context);
84
85 /*
86 * Restore non-secure state. There is no need to save the
87 * secure system register context since the SP was supposed
88 * to preserve it during S-EL1 interrupt handling.
89 */
90 cm_el1_sysregs_context_restore(SECURE);
91 cm_set_next_eret_context(SECURE);
92
93 /* Provide the IRQ number to the SPD */
94 SMC_RET4(s_cpu_context, (uint32_t)TLK_IRQ_FIRED, 0, (uint32_t)irq, 0);
95}
96
97/*******************************************************************************
Varun Wadekar3d4e6a52015-03-13 14:01:03 +053098 * Secure Payload Dispatcher setup. The SPD finds out the SP entrypoint and type
99 * (aarch32/aarch64) if not already known and initialises the context for entry
100 * into the SP for its initialisation.
101 ******************************************************************************/
Masahiro Yamada56212752018-04-19 01:14:42 +0900102static int32_t tlkd_setup(void)
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530103{
104 entry_point_info_t *tlk_ep_info;
Varun Wadekar079e20e2018-08-10 09:55:25 -0700105 uint32_t flags;
106 int32_t ret;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530107
108 /*
109 * Get information about the Secure Payload (BL32) image. Its
110 * absence is a critical failure.
111 */
112 tlk_ep_info = bl31_plat_get_next_image_ep_info(SECURE);
113 if (!tlk_ep_info) {
114 WARN("No SP provided. Booting device without SP"
115 " initialization. SMC`s destined for SP"
116 " will return SMC_UNK\n");
117 return 1;
118 }
119
120 /*
121 * If there's no valid entry point for SP, we return a non-zero value
122 * signalling failure initializing the service. We bail out without
123 * registering any handlers
124 */
125 if (!tlk_ep_info->pc)
126 return 1;
127
128 /*
129 * Inspect the SP image's SPSR and determine it's execution state
130 * i.e whether AArch32 or AArch64.
131 */
132 tlkd_init_tlk_ep_state(tlk_ep_info,
133 (tlk_ep_info->spsr >> MODE_RW_SHIFT) & MODE_RW_MASK,
134 tlk_ep_info->pc,
135 &tlk_ctx);
136
Varun Wadekar079e20e2018-08-10 09:55:25 -0700137 /* get a list of all S-EL1 IRQs from the platform */
138
139 /* register interrupt handler */
140 flags = 0;
141 set_interrupt_rm_flag(flags, NON_SECURE);
142 ret = register_interrupt_type_handler(INTR_TYPE_S_EL1,
143 tlkd_interrupt_handler,
144 flags);
145 if (ret != 0) {
146 ERROR("failed to register tlkd interrupt handler (%d)\n", ret);
147 }
148
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530149 /*
150 * All TLK SPD initialization done. Now register our init function
151 * with BL31 for deferred invocation
152 */
153 bl31_register_bl32_init(&tlkd_init);
154
155 return 0;
156}
157
158/*******************************************************************************
159 * This function passes control to the Secure Payload image (BL32) for the first
160 * time on the primary cpu after a cold boot. It assumes that a valid secure
161 * context has already been created by tlkd_setup() which can be directly
162 * used. This function performs a synchronous entry into the Secure payload.
163 * The SP passes control back to this routine through a SMC.
164 ******************************************************************************/
Masahiro Yamada56212752018-04-19 01:14:42 +0900165static int32_t tlkd_init(void)
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530166{
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530167 entry_point_info_t *tlk_entry_point;
168
169 /*
170 * Get information about the Secure Payload (BL32) image. Its
171 * absence is a critical failure.
172 */
173 tlk_entry_point = bl31_plat_get_next_image_ep_info(SECURE);
174 assert(tlk_entry_point);
175
Soby Mathewda43b662015-07-08 21:45:46 +0100176 cm_init_my_context(tlk_entry_point);
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530177
178 /*
Varun Wadekar0bbe8a62016-06-07 21:21:59 -0700179 * TLK runs only on a single CPU. Store the value of the boot
180 * CPU for sanity checking later.
181 */
182 boot_cpu = plat_my_core_pos();
183
184 /*
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530185 * Arrange for an entry into the test secure payload.
186 */
187 return tlkd_synchronous_sp_entry(&tlk_ctx);
188}
189
190/*******************************************************************************
191 * This function is responsible for handling all SMCs in the Trusted OS/App
192 * range from the non-secure state as defined in the SMC Calling Convention
193 * Document. It is also responsible for communicating with the Secure payload
194 * to delegate work and return results back to the non-secure state. Lastly it
195 * will also return any information that the secure payload needs to do the
196 * work assigned to it.
197 ******************************************************************************/
Masahiro Yamada5ac9d962018-04-19 01:18:48 +0900198static uintptr_t tlkd_smc_handler(uint32_t smc_fid,
199 u_register_t x1,
200 u_register_t x2,
201 u_register_t x3,
202 u_register_t x4,
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530203 void *cookie,
204 void *handle,
Masahiro Yamada5ac9d962018-04-19 01:18:48 +0900205 u_register_t flags)
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530206{
Varun Wadekara97535f2015-03-13 14:19:11 +0530207 cpu_context_t *ns_cpu_context;
Varun Wadekarebfeae92015-04-02 14:57:47 +0530208 gp_regs_t *gp_regs;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530209 uint32_t ns;
Varun Wadekarebfeae92015-04-02 14:57:47 +0530210 uint64_t par;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530211
212 /* Passing a NULL context is a critical programming error */
213 assert(handle);
214
Varun Wadekar0bbe8a62016-06-07 21:21:59 -0700215 /* These SMCs are only supported by a single CPU */
216 if (boot_cpu != plat_my_core_pos())
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530217 SMC_RET1(handle, SMC_UNK);
218
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530219 /* Determine which security state this SMC originated from */
220 ns = is_caller_non_secure(flags);
221
222 switch (smc_fid) {
223
224 /*
Varun Wadekar968c0292015-03-13 15:10:54 +0530225 * This function ID is used by SP to indicate that it was
226 * preempted by a non-secure world IRQ.
227 */
228 case TLK_PREEMPTED:
229
230 if (ns)
231 SMC_RET1(handle, SMC_UNK);
232
233 assert(handle == cm_get_context(SECURE));
234 cm_el1_sysregs_context_save(SECURE);
235
236 /* Get a reference to the non-secure context */
237 ns_cpu_context = cm_get_context(NON_SECURE);
238 assert(ns_cpu_context);
239
240 /*
241 * Restore non-secure state. There is no need to save the
242 * secure system register context since the SP was supposed
243 * to preserve it during S-EL1 interrupt handling.
244 */
245 cm_el1_sysregs_context_restore(NON_SECURE);
246 cm_set_next_eret_context(NON_SECURE);
247
Varun Wadekarebfeae92015-04-02 14:57:47 +0530248 SMC_RET1(ns_cpu_context, x1);
Varun Wadekar968c0292015-03-13 15:10:54 +0530249
250 /*
Varun Wadekara97535f2015-03-13 14:19:11 +0530251 * This is a request from the non-secure context to:
252 *
253 * a. register shared memory with the SP for storing it's
254 * activity logs.
255 * b. register shared memory with the SP for passing args
256 * required for maintaining sessions with the Trusted
257 * Applications.
Mihir Joshi518230c2018-01-22 14:02:16 -0800258 * c. register shared persistent buffers for secure storage
259 * d. register NS DRAM ranges passed by Cboot
260 * e. register Root of Trust parameters from Cboot for Verified Boot
261 * f. open/close sessions
262 * g. issue commands to the Trusted Apps
263 * h. resume the preempted yielding SMC call.
Varun Wadekara97535f2015-03-13 14:19:11 +0530264 */
265 case TLK_REGISTER_LOGBUF:
266 case TLK_REGISTER_REQBUF:
Mihir Joshi518230c2018-01-22 14:02:16 -0800267 case TLK_SS_REGISTER_HANDLER:
268 case TLK_REGISTER_NS_DRAM_RANGES:
269 case TLK_SET_ROOT_OF_TRUST:
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530270 case TLK_OPEN_TA_SESSION:
271 case TLK_CLOSE_TA_SESSION:
272 case TLK_TA_LAUNCH_OP:
273 case TLK_TA_SEND_EVENT:
Varun Wadekar5e1fa052015-10-07 17:15:41 +0530274 case TLK_RESUME_FID:
Mustafa Yigit Bilgen95867b12018-12-03 15:53:38 -0800275 case TLK_SET_BL_VERSION:
276 case TLK_LOCK_BL_INTERFACE:
277 case TLK_BL_RPMB_SERVICE:
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530278
Varun Wadekarebfeae92015-04-02 14:57:47 +0530279 if (!ns)
Varun Wadekara97535f2015-03-13 14:19:11 +0530280 SMC_RET1(handle, SMC_UNK);
281
282 /*
283 * This is a fresh request from the non-secure client.
284 * The parameters are in x1 and x2. Figure out which
285 * registers need to be preserved, save the non-secure
286 * state and send the request to the secure payload.
287 */
288 assert(handle == cm_get_context(NON_SECURE));
289
Varun Wadekar5e1fa052015-10-07 17:15:41 +0530290 /*
David Cunadoc8833ea2017-04-16 17:15:08 +0100291 * Check if we are already processing a yielding SMC
Varun Wadekar5e1fa052015-10-07 17:15:41 +0530292 * call. Of all the supported fids, only the "resume"
293 * fid expects the flag to be set.
294 */
295 if (smc_fid == TLK_RESUME_FID) {
David Cunadoc8833ea2017-04-16 17:15:08 +0100296 if (!get_yield_smc_active_flag(tlk_ctx.state))
Varun Wadekar5e1fa052015-10-07 17:15:41 +0530297 SMC_RET1(handle, SMC_UNK);
298 } else {
David Cunadoc8833ea2017-04-16 17:15:08 +0100299 if (get_yield_smc_active_flag(tlk_ctx.state))
Varun Wadekar5e1fa052015-10-07 17:15:41 +0530300 SMC_RET1(handle, SMC_UNK);
301 }
Varun Wadekara97535f2015-03-13 14:19:11 +0530302
303 cm_el1_sysregs_context_save(NON_SECURE);
304
305 /*
306 * Verify if there is a valid context to use.
307 */
308 assert(&tlk_ctx.cpu_ctx == cm_get_context(SECURE));
309
310 /*
311 * Mark the SP state as active.
312 */
David Cunadoc8833ea2017-04-16 17:15:08 +0100313 set_yield_smc_active_flag(tlk_ctx.state);
Varun Wadekara97535f2015-03-13 14:19:11 +0530314
Varun Wadekara97535f2015-03-13 14:19:11 +0530315 /*
316 * We are done stashing the non-secure context. Ask the
317 * secure payload to do the work now.
318 */
319 cm_el1_sysregs_context_restore(SECURE);
320 cm_set_next_eret_context(SECURE);
Varun Wadekarebfeae92015-04-02 14:57:47 +0530321
322 /*
323 * TLK is a 32-bit Trusted OS and so expects the SMC
324 * arguments via r0-r7. TLK expects the monitor frame
325 * registers to be 64-bits long. Hence, we pass x0 in
326 * r0-r1, x1 in r2-r3, x3 in r4-r5 and x4 in r6-r7.
327 *
328 * As smc_fid is a uint32 value, r1 contains 0.
329 */
330 gp_regs = get_gpregs_ctx(&tlk_ctx.cpu_ctx);
331 write_ctx_reg(gp_regs, CTX_GPREG_X4, (uint32_t)x2);
332 write_ctx_reg(gp_regs, CTX_GPREG_X5, (uint32_t)(x2 >> 32));
333 write_ctx_reg(gp_regs, CTX_GPREG_X6, (uint32_t)x3);
334 write_ctx_reg(gp_regs, CTX_GPREG_X7, (uint32_t)(x3 >> 32));
335 SMC_RET4(&tlk_ctx.cpu_ctx, smc_fid, 0, (uint32_t)x1,
336 (uint32_t)(x1 >> 32));
Varun Wadekara97535f2015-03-13 14:19:11 +0530337
338 /*
Varun Wadekarebfeae92015-04-02 14:57:47 +0530339 * Translate NS/EL1-S virtual addresses.
340 *
341 * x1 = virtual address
342 * x3 = type (NS/S)
343 *
344 * Returns PA:lo in r0, PA:hi in r1.
Varun Wadekar97625e32015-03-13 14:59:03 +0530345 */
346 case TLK_VA_TRANSLATE:
Varun Wadekarebfeae92015-04-02 14:57:47 +0530347
348 /* Should be invoked only by secure world */
349 if (ns)
Varun Wadekar97625e32015-03-13 14:59:03 +0530350 SMC_RET1(handle, SMC_UNK);
351
Varun Wadekarebfeae92015-04-02 14:57:47 +0530352 /* NS virtual addresses are 64-bit long */
353 if (x3 & TLK_TRANSLATE_NS_VADDR)
354 x1 = (uint32_t)x1 | (x2 << 32);
Varun Wadekar97625e32015-03-13 14:59:03 +0530355
Varun Wadekarebfeae92015-04-02 14:57:47 +0530356 if (!x1)
357 SMC_RET1(handle, SMC_UNK);
Varun Wadekar97625e32015-03-13 14:59:03 +0530358
Varun Wadekarebfeae92015-04-02 14:57:47 +0530359 /*
360 * TODO: Sanity check x1. This would require platform
361 * support.
362 */
Varun Wadekar97625e32015-03-13 14:59:03 +0530363
Varun Wadekarebfeae92015-04-02 14:57:47 +0530364 /* virtual address and type: ns/s */
365 par = tlkd_va_translate(x1, x3);
366
367 /* return physical address in r0-r1 */
368 SMC_RET4(handle, (uint32_t)par, (uint32_t)(par >> 32), 0, 0);
Varun Wadekar97625e32015-03-13 14:59:03 +0530369
370 /*
Varun Wadekara97535f2015-03-13 14:19:11 +0530371 * This is a request from the SP to mark completion of
David Cunadoc8833ea2017-04-16 17:15:08 +0100372 * a yielding function ID.
Varun Wadekara97535f2015-03-13 14:19:11 +0530373 */
374 case TLK_REQUEST_DONE:
Varun Wadekarebfeae92015-04-02 14:57:47 +0530375 if (ns)
Varun Wadekara97535f2015-03-13 14:19:11 +0530376 SMC_RET1(handle, SMC_UNK);
377
378 /*
379 * Mark the SP state as inactive.
380 */
David Cunadoc8833ea2017-04-16 17:15:08 +0100381 clr_yield_smc_active_flag(tlk_ctx.state);
Varun Wadekara97535f2015-03-13 14:19:11 +0530382
383 /* Get a reference to the non-secure context */
384 ns_cpu_context = cm_get_context(NON_SECURE);
385 assert(ns_cpu_context);
386
387 /*
388 * This is a request completion SMC and we must switch to
389 * the non-secure world to pass the result.
390 */
391 cm_el1_sysregs_context_save(SECURE);
392
393 /*
394 * We are done stashing the secure context. Switch to the
395 * non-secure context and return the result.
396 */
397 cm_el1_sysregs_context_restore(NON_SECURE);
398 cm_set_next_eret_context(NON_SECURE);
Varun Wadekarebfeae92015-04-02 14:57:47 +0530399 SMC_RET1(ns_cpu_context, x1);
Varun Wadekara97535f2015-03-13 14:19:11 +0530400
401 /*
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530402 * This function ID is used only by the SP to indicate it has
403 * finished initialising itself after a cold boot
404 */
405 case TLK_ENTRY_DONE:
Varun Wadekarebfeae92015-04-02 14:57:47 +0530406 if (ns)
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530407 SMC_RET1(handle, SMC_UNK);
408
409 /*
410 * SP has been successfully initialized. Register power
Paul Beesley1fbc97b2019-01-11 18:26:51 +0000411 * management hooks with PSCI
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530412 */
413 psci_register_spd_pm_hook(&tlkd_pm_ops);
414
415 /*
416 * TLK reports completion. The SPD must have initiated
417 * the original request through a synchronous entry
418 * into the SP. Jump back to the original C runtime
419 * context.
420 */
Varun Wadekarebfeae92015-04-02 14:57:47 +0530421 tlkd_synchronous_sp_exit(&tlk_ctx, x1);
Jonathan Wright75a5d8b2018-03-14 15:56:21 +0000422 break;
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530423
424 /*
Varun Wadekara70dec32015-08-26 12:49:03 +0530425 * These function IDs are used only by TLK to indicate it has
426 * finished:
427 * 1. suspending itself after an earlier psci cpu_suspend
428 * request.
429 * 2. resuming itself after an earlier psci cpu_suspend
430 * request.
431 * 3. powering down after an earlier psci system_off/system_reset
432 * request.
433 */
434 case TLK_SUSPEND_DONE:
435 case TLK_RESUME_DONE:
Varun Wadekara70dec32015-08-26 12:49:03 +0530436
437 if (ns)
438 SMC_RET1(handle, SMC_UNK);
439
440 /*
441 * TLK reports completion. TLKD must have initiated the
442 * original request through a synchronous entry into the SP.
443 * Jump back to the original C runtime context, and pass x1 as
444 * return value to the caller
445 */
446 tlkd_synchronous_sp_exit(&tlk_ctx, x1);
Jonathan Wright75a5d8b2018-03-14 15:56:21 +0000447 break;
Varun Wadekara70dec32015-08-26 12:49:03 +0530448
449 /*
Varun Wadekar079e20e2018-08-10 09:55:25 -0700450 * This function ID is used by SP to indicate that it has completed
451 * handling the secure interrupt.
452 */
453 case TLK_IRQ_DONE:
454
455 if (ns)
456 SMC_RET1(handle, SMC_UNK);
457
458 assert(handle == cm_get_context(SECURE));
459
460 /* save secure world context */
461 cm_el1_sysregs_context_save(SECURE);
462
463 /* Get a reference to the non-secure context */
464 ns_cpu_context = cm_get_context(NON_SECURE);
465 assert(ns_cpu_context);
466
467 /*
468 * Restore non-secure state. There is no need to save the
469 * secure system register context since the SP was supposed
470 * to preserve it during S-EL1 interrupt handling.
471 */
472 cm_el1_sysregs_context_restore(NON_SECURE);
473 cm_set_next_eret_context(NON_SECURE);
474
475 SMC_RET0(ns_cpu_context);
476
477 /*
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530478 * Return the number of service function IDs implemented to
479 * provide service to non-secure
480 */
481 case TOS_CALL_COUNT:
482 SMC_RET1(handle, TLK_NUM_FID);
483
484 /*
485 * Return TLK's UID to the caller
486 */
487 case TOS_UID:
488 SMC_UUID_RET(handle, tlk_uuid);
489
490 /*
491 * Return the version of current implementation
492 */
493 case TOS_CALL_VERSION:
494 SMC_RET2(handle, TLK_VERSION_MAJOR, TLK_VERSION_MINOR);
495
496 default:
Mihir Joshi518230c2018-01-22 14:02:16 -0800497 WARN("%s: Unhandled SMC: 0x%x\n", __func__, smc_fid);
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530498 break;
499 }
500
501 SMC_RET1(handle, SMC_UNK);
502}
503
504/* Define a SPD runtime service descriptor for fast SMC calls */
505DECLARE_RT_SVC(
506 tlkd_tos_fast,
507
508 OEN_TOS_START,
509 OEN_TOS_END,
510 SMC_TYPE_FAST,
511 tlkd_setup,
512 tlkd_smc_handler
513);
514
David Cunadoc8833ea2017-04-16 17:15:08 +0100515/* Define a SPD runtime service descriptor for yielding SMC calls */
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530516DECLARE_RT_SVC(
517 tlkd_tos_std,
518
519 OEN_TOS_START,
520 OEN_TOS_END,
David Cunadoc8833ea2017-04-16 17:15:08 +0100521 SMC_TYPE_YIELD,
Varun Wadekar3d4e6a52015-03-13 14:01:03 +0530522 NULL,
523 tlkd_smc_handler
524);
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530525
526/* Define a SPD runtime service descriptor for fast SMC calls */
527DECLARE_RT_SVC(
528 tlkd_tap_fast,
529
530 OEN_TAP_START,
531 OEN_TAP_END,
532 SMC_TYPE_FAST,
533 NULL,
534 tlkd_smc_handler
535);
536
David Cunadoc8833ea2017-04-16 17:15:08 +0100537/* Define a SPD runtime service descriptor for yielding SMC calls */
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530538DECLARE_RT_SVC(
539 tlkd_tap_std,
540
541 OEN_TAP_START,
542 OEN_TAP_END,
David Cunadoc8833ea2017-04-16 17:15:08 +0100543 SMC_TYPE_YIELD,
Varun Wadekarb539b6c2015-03-13 15:18:20 +0530544 NULL,
545 tlkd_smc_handler
546);