blob: 5330025e798499b551f1c7f036ad8c6b16614ac1 [file] [log] [blame]
Antonio Nino Diazf939a6a2018-11-08 14:12:40 +00001/*
2 * Copyright (c) 2018, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <assert.h>
9#include <context_mgmt.h>
10#include <debug.h>
11#include <smccc.h>
12#include <smccc_helpers.h>
13#include <sprt_svc.h>
14#include <utils.h>
15
16#include "spm_private.h"
17
18/*******************************************************************************
19 * This function handles all SMCs in the range reserved for SPRT.
20 ******************************************************************************/
21uint64_t sprt_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2,
22 uint64_t x3, uint64_t x4, void *cookie, void *handle,
23 uint64_t flags)
24{
25 /* SPRT only supported from the Secure world */
26 if (is_caller_non_secure(flags) == SMC_FROM_NON_SECURE) {
27 SMC_RET1(handle, SMC_UNK);
28 }
29
30 assert(handle == cm_get_context(SECURE));
31
32 /*
33 * Only S-EL0 partitions are supported for now. Make the next ERET into
34 * the partition jump directly to S-EL0 instead of S-EL1.
35 */
36 cm_set_elr_spsr_el3(SECURE, read_elr_el1(), read_spsr_el1());
37
38 switch (smc_fid) {
39 case SPRT_VERSION:
40 SMC_RET1(handle, SPRT_VERSION_COMPILED);
41
Antonio Nino Diaz8c83ad82018-11-08 14:21:19 +000042 case SPRT_PUT_RESPONSE_AARCH64:
43 /*
44 * Registers x1-x3 aren't saved by default to the context,
45 * but they are needed after spm_sp_synchronous_exit() because
46 * they hold return values.
47 */
48 SMC_SET_GP(handle, CTX_GPREG_X1, x1);
49 SMC_SET_GP(handle, CTX_GPREG_X2, x2);
50 SMC_SET_GP(handle, CTX_GPREG_X3, x3);
51 spm_sp_synchronous_exit(SPRT_PUT_RESPONSE_AARCH64);
52
53 case SPRT_YIELD_AARCH64:
54 spm_sp_synchronous_exit(SPRT_YIELD_AARCH64);
55
Antonio Nino Diazf939a6a2018-11-08 14:12:40 +000056 default:
57 break;
58 }
59
60 WARN("SPRT: Unsupported call 0x%08x\n", smc_fid);
61 SMC_RET1(handle, SPRT_NOT_SUPPORTED);
62}