aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArunachalam Ganapathy <arunachalam.ganapathy@arm.com>2021-10-12 14:09:19 +0100
committerDmitriy Filchenko <dmitriyf@google.com>2023-11-14 06:57:12 +0000
commita56aab0eacc67ce11b58c71fea075daf8e9971ca (patch)
tree40869fb8fd6bde60c8681671bb30344186691288
parente4530cd3cfdc7b77a3cbe95a929ade4db363eb06 (diff)
downloadtrusted-firmware-a-a56aab0eacc67ce11b58c71fea075daf8e9971ca.tar.gz
spd: trusty: add secure partition and non secure client descriptors
This changes adds FFA endpoint descriptor for both secure and non secure endpoints. Initializes the endpoint descriptors with Trusty specific UUID, SP ID and properties. Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com> Change-Id: I10d09154b0842d6a59304ed742cb97a528278cca
-rw-r--r--services/spd/trusty/include/trusty/arm_ffa.h3
-rw-r--r--services/spd/trusty/shared-mem-smcall.c67
-rw-r--r--services/spd/trusty/trusty.c4
3 files changed, 65 insertions, 9 deletions
diff --git a/services/spd/trusty/include/trusty/arm_ffa.h b/services/spd/trusty/include/trusty/arm_ffa.h
index d7e0416a6..f94d0a403 100644
--- a/services/spd/trusty/include/trusty/arm_ffa.h
+++ b/services/spd/trusty/include/trusty/arm_ffa.h
@@ -26,6 +26,9 @@
MAKE_FFA_VERSION(TRUSTY_FFA_CURRENT_VERSION_MAJOR, \
TRUSTY_FFA_CURRENT_VERSION_MINOR)
+#define FFA_NWLD_ID_BASE 0x0
+#define FFA_SWLD_ID_BASE 0x8000
+
#define SMC_ENTITY_SHARED_MEMORY 4
#define SMC_FASTCALL_NR_SHARED_MEMORY(nr) \
diff --git a/services/spd/trusty/shared-mem-smcall.c b/services/spd/trusty/shared-mem-smcall.c
index 71cde3673..6c45adcd2 100644
--- a/services/spd/trusty/shared-mem-smcall.c
+++ b/services/spd/trusty/shared-mem-smcall.c
@@ -107,6 +107,23 @@ static struct trusty_shmem_obj_state trusty_shmem_obj_state = {
.next_handle = 0xffffffc0,
};
+typedef struct trusty_sp_desc {
+ uint16_t sp_id;
+ const uuid_t *uuid;
+ uint32_t ffa_version;
+ uint32_t properties;
+ struct trusty_shmem_client_state *client;
+} trusty_sp_desc_t;
+
+static trusty_sp_desc_t trusty_sp;
+
+typedef struct trusty_ns_client_desc {
+ uint16_t ep_id;
+ struct trusty_shmem_client_state *client;
+} trusty_ns_client_desc_t;
+
+static trusty_ns_client_desc_t trusty_ns_client;
+
static struct trusty_shmem_client_state trusty_shmem_client_state[2] = {
[true].secure = true,
[true].identity_mapped = true,
@@ -872,12 +889,11 @@ static long trusty_ffa_rxtx_unmap(struct trusty_shmem_client_state *client,
/**
* trusty_ffa_id_get - FFA_ID_GET implementation.
- * @client: Client state.
+ * @flags: State flags.
* @idp: Pointer to store id return value in.
*
* Return the ID of the caller. For the non-secure client, use ID 0 as required
- * by FF-A. For the secure side return 0x8000 as Hafnium expects the secure OS
- * to use that ID.
+ * by FF-A.
*
* Note that the sender_id check in trusty_ffa_mem_frag_tx and
* trusty_ffa_mem_frag_rx only works when there is no hypervisor because we use
@@ -885,10 +901,14 @@ static long trusty_ffa_rxtx_unmap(struct trusty_shmem_client_state *client,
*
* Return: 0 on success, error code on failure.
*/
-static int trusty_ffa_id_get(struct trusty_shmem_client_state *client,
- u_register_t *idp)
+static int trusty_ffa_id_get(u_register_t flags, u_register_t *idp)
{
- *idp = client->secure ? 0x8000 : 0;
+ if (is_caller_secure(flags)) {
+ *idp = trusty_sp.sp_id;
+ } else {
+ *idp = trusty_ns_client.ep_id;
+ }
+
return 0;
}
@@ -1033,8 +1053,7 @@ uintptr_t spmd_ffa_smc_handler(uint32_t smc_fid,
uint32_t w4 = (uint32_t)x4;
u_register_t ret_reg2 = 0;
u_register_t ret_reg3 = 0;
- struct trusty_shmem_client_state *client = &trusty_shmem_client_state[
- is_caller_secure(flags)];
+ struct trusty_shmem_client_state *client;
if (((smc_fid < SMC_FC32_FFA_MIN) || (smc_fid > SMC_FC32_FFA_MAX)) &&
((smc_fid < SMC_FC64_FFA_MIN) || (smc_fid > SMC_FC64_FFA_MAX))) {
@@ -1044,6 +1063,12 @@ uintptr_t spmd_ffa_smc_handler(uint32_t smc_fid,
spin_lock(&trusty_shmem_obj_state.lock);
+ if (is_caller_secure(flags)) {
+ client = trusty_sp.client;
+ } else {
+ client = trusty_ns_client.client;
+ }
+
switch (smc_fid) {
case FFA_VERSION:
ret = trusty_ffa_version(client, w1, handle);
@@ -1066,7 +1091,7 @@ uintptr_t spmd_ffa_smc_handler(uint32_t smc_fid,
break;
case FFA_ID_GET:
- ret = trusty_ffa_id_get(client, &ret_reg2);
+ ret = trusty_ffa_id_get(flags, &ret_reg2);
break;
case FFA_MEM_LEND_SMC32:
@@ -1140,3 +1165,27 @@ uintptr_t spmd_ffa_smc_handler(uint32_t smc_fid,
0, 0, 0);
}
}
+
+/**
+ * trusty_shared_mem_init - Initialize Trusty secure and non-secure endpoints.
+ * @trusty_uuid: Pointer to Trusty UUID
+ *
+ * Returns: none
+ */
+void trusty_shared_mem_init(const uuid_t *trusty_uuid)
+{
+ /*
+ * Initialize secure side of Trusty that implements FFA_MEM_ABIs
+ */
+ trusty_sp.sp_id = FFA_SWLD_ID_BASE;
+ trusty_sp.uuid = trusty_uuid;
+ trusty_sp.properties = 0; /* Doesn't support DIRECT MSG */
+ trusty_sp.ffa_version = MAKE_TRUSTY_FFA_CURRENT_VERSION;
+ trusty_sp.client = &trusty_shmem_client_state[true];
+
+ /*
+ * Initialize non-secure client endpoint.
+ */
+ trusty_ns_client.ep_id = FFA_NWLD_ID_BASE;
+ trusty_ns_client.client = &trusty_shmem_client_state[false];
+}
diff --git a/services/spd/trusty/trusty.c b/services/spd/trusty/trusty.c
index 14195e93b..368bf8ee1 100644
--- a/services/spd/trusty/trusty.c
+++ b/services/spd/trusty/trusty.c
@@ -27,6 +27,8 @@
#include <trusty/smcall.h>
#include <trusty/sm_err.h>
+void trusty_shared_mem_init(const uuid_t *trusty_uuid);
+
/* Trusty UID: RFC-4122 compliant UUID version 4 */
DEFINE_SVC_UUID2(trusty_uuid,
0x40ee25f0, 0xa2bc, 0x304c, 0x8c, 0x4c,
@@ -547,6 +549,8 @@ static int32_t trusty_setup(void)
VERBOSE("trusty: failed to register fiq handler, ret = %d\n", ret);
}
+ trusty_shared_mem_init(&trusty_uuid);
+
if (aarch32) {
entry_point_info_t *ns_ep_info;
uint32_t spsr;