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 
31 	/* Determine if we have a 64 or 32 direct request. */
32 	if (smc_fid == FFA_MSG_SEND_DIRECT_REQ_SMC32) {
33 		ret = FFA_MSG_SEND_DIRECT_RESP_SMC32;
34 	} else if (smc_fid == FFA_MSG_SEND_DIRECT_REQ_SMC64) {
35 		ret = FFA_MSG_SEND_DIRECT_RESP_SMC64;
36 	} else {
37 		panic(); /* Unknown SMC. */
38 	}
39 	/*
40 	 * Handle the incoming request. For testing purposes we echo the
41 	 * incoming message.
42 	 */
43 	INFO("Logical Partition: Received Direct Request from %s world!\n",
44 	     secure_origin ? "Secure" : "Normal");
45 
46 	/*
47 	 * Logical SP's must always send a direct response so we can populate
48 	 * our response directly.
49 	 */
50 	SMC_RET8(handle, ret, 0, 0, x4, 0, 0, 0, 0);
51 }
52 
53 /* Register logical partition  */
54 DECLARE_LOGICAL_PARTITION(
55 	my_logical_partition,
56 	sp_init,			/* Init Function */
57 	LP_PARTITION_ID,		/* FF-A Partition ID */
58 	LP_UUID,			/* UUID */
59 	PARTITION_PROPERTIES,		/* Partition Properties. */
60 	handle_ffa_direct_request	/* Callback for direct requests. */
61 );
62