blob: 72dfa30f047c7cc5a4f3f1fdc43e13201d1b8071 [file] [log] [blame]
Marc Bonnici35248f12021-08-19 14:42:19 +01001/*
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
18static int32_t sp_init(void)
19{
20 INFO("LSP: Init function called.\n");
21 return 0;
22}
23
24static 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;
Marc Bonnici96160172022-11-15 11:20:59 +000030 uint32_t src_dst;
Marc Bonnici35248f12021-08-19 14:42:19 +010031
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 }
Marc Bonnici96160172022-11-15 11:20:59 +000040
Marc Bonnici35248f12021-08-19 14:42:19 +010041 /*
42 * Handle the incoming request. For testing purposes we echo the
43 * incoming message.
44 */
Marc Bonnici96160172022-11-15 11:20:59 +000045 INFO("LSP: Received Direct Request from %s world (0x%x)\n",
46 secure_origin ? "Secure" : "Normal", ffa_endpoint_source(x1));
Marc Bonnici35248f12021-08-19 14:42:19 +010047
Marc Bonnici96160172022-11-15 11:20:59 +000048 /* 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;
Marc Bonnici35248f12021-08-19 14:42:19 +010051 /*
52 * Logical SP's must always send a direct response so we can populate
53 * our response directly.
54 */
Marc Bonnici96160172022-11-15 11:20:59 +000055 SMC_RET8(handle, ret, src_dst, 0, x4, 0, 0, 0, 0);
Marc Bonnici35248f12021-08-19 14:42:19 +010056}
57
58/* Register logical partition */
59DECLARE_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);