1 /*
2  * Copyright (c) 2022, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <common/debug.h>
8 #include <services/el3_spmc_logical_sp.h>
9 #include <services/ffa_svc.h>
10 #include <smccc_helpers.h>
11 
12 #define LP_PARTITION_ID 0xC001
13 #define LP_UUID {0x47a3bf57, 0xe98e43ad, 0xb7db524f, 0x1588f4e3}
14 
15 /* Our Logical SP currently only supports receipt of direct messaging. */
16 #define PARTITION_PROPERTIES FFA_PARTITION_DIRECT_REQ_RECV
17 
sp_init(void)18 static int32_t sp_init(void)
19 {
20 	INFO("LSP: Init function called.\n");
21 	return 0;
22 }
23 
handle_ffa_direct_request(uint32_t smc_fid,bool secure_origin,uint64_t x1,uint64_t x2,uint64_t x3,uint64_t x4,void * cookie,void * handle,uint64_t flags)24 static uint64_t handle_ffa_direct_request(uint32_t smc_fid,  bool secure_origin,
25 					  uint64_t x1, uint64_t x2, uint64_t x3,
26 					  uint64_t x4, void *cookie,
27 					  void *handle, uint64_t flags)
28 {
29 	uint64_t ret;
30 	uint32_t src_dst;
31 
32 	/* Determine if we have a 64 or 32 direct request. */
33 	if (smc_fid == FFA_MSG_SEND_DIRECT_REQ_SMC32) {
34 		ret = FFA_MSG_SEND_DIRECT_RESP_SMC32;
35 	} else if (smc_fid == FFA_MSG_SEND_DIRECT_REQ_SMC64) {
36 		ret = FFA_MSG_SEND_DIRECT_RESP_SMC64;
37 	} else {
38 		panic(); /* Unknown SMC. */
39 	}
40 
41 	/*
42 	 * Handle the incoming request. For testing purposes we echo the
43 	 * incoming message.
44 	 */
45 	INFO("LSP: Received Direct Request from %s world (0x%x)\n",
46 	     secure_origin ? "Secure" : "Normal", ffa_endpoint_source(x1));
47 
48 	/* Populate the source and destination IDs. */
49 	src_dst = (uint32_t) LP_PARTITION_ID << FFA_DIRECT_MSG_SOURCE_SHIFT |
50 		  ffa_endpoint_source(x1) << FFA_DIRECT_MSG_DESTINATION_SHIFT;
51 	/*
52 	 * Logical SP's must always send a direct response so we can populate
53 	 * our response directly.
54 	 */
55 	SMC_RET8(handle, ret, src_dst, 0, x4, 0, 0, 0, 0);
56 }
57 
58 /* Register logical partition  */
59 DECLARE_LOGICAL_PARTITION(
60 	my_logical_partition,
61 	sp_init,			/* Init Function */
62 	LP_PARTITION_ID,		/* FF-A Partition ID */
63 	LP_UUID,			/* UUID */
64 	PARTITION_PROPERTIES,		/* Partition Properties. */
65 	handle_ffa_direct_request	/* Callback for direct requests. */
66 );
67