aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdison Ai <edison.ai@arm.com>2019-08-01 14:22:19 +0800
committerEdison Ai <edison.ai@arm.com>2019-08-16 11:31:52 +0800
commit9711582d5acf1bc9b3c06be06aa2b3f39f093a22 (patch)
tree853f5760406a6dbeceb4c974afc577b14a9441dc
parentd99509f4690f7d6cff23e00056dfd301bb50a48d (diff)
downloadtrusted-firmware-m-9711582d5acf1bc9b3c06be06aa2b3f39f093a22.tar.gz
Core: Merge message buffer into connect handle
Only one message buffer is enough for one connect process. So merge the message buffer into connect handle structure. Change-Id: Id529d29d5a630e2726b3c0667bd17e9c42a2d10f Signed-off-by: Edison Ai <edison.ai@arm.com>
-rw-r--r--secure_fw/core/ipc/include/tfm_message_queue.h1
-rw-r--r--secure_fw/core/ipc/tfm_svcalls.c29
-rw-r--r--secure_fw/spm/spm_api.h46
-rw-r--r--secure_fw/spm/spm_api_ipc.c41
4 files changed, 54 insertions, 63 deletions
diff --git a/secure_fw/core/ipc/include/tfm_message_queue.h b/secure_fw/core/ipc/include/tfm_message_queue.h
index 231dc3f78..2cf3d3355 100644
--- a/secure_fw/core/ipc/include/tfm_message_queue.h
+++ b/secure_fw/core/ipc/include/tfm_message_queue.h
@@ -10,7 +10,6 @@
#include "psa/service.h"
#include "tfm_wait.h"
-#define TFM_MSG_QUEUE_MAX_MSG_NUM 16
#define TFM_MSG_MAGIC 0x15154343
/* Message struct to collect parameter from client */
struct tfm_msg_body_t {
diff --git a/secure_fw/core/ipc/tfm_svcalls.c b/secure_fw/core/ipc/tfm_svcalls.c
index cee5c7e49..c2f50e0c1 100644
--- a/secure_fw/core/ipc/tfm_svcalls.c
+++ b/secure_fw/core/ipc/tfm_svcalls.c
@@ -107,21 +107,23 @@ psa_handle_t tfm_svcall_psa_connect(uint32_t *args, int32_t ns_caller)
tfm_panic();
}
- /* No input or output needed for connect message */
- msg = tfm_spm_create_msg(service, connect_handle, PSA_IPC_CONNECT,
- ns_caller, NULL, 0, NULL, 0, NULL);
+ msg = tfm_spm_get_msg_buffer_from_conn_handle(connect_handle);
if (!msg) {
/* Have no enough resource to create message */
return PSA_ERROR_CONNECTION_BUSY;
}
+ /* No input or output needed for connect message */
+ tfm_spm_fill_msg(msg, service, connect_handle, PSA_IPC_CONNECT,
+ ns_caller, NULL, 0, NULL, 0, NULL);
+
/*
* Send message and wake up the SP who is waiting on message queue,
* and scheduler triggered
*/
tfm_spm_send_event(service, msg);
- return PSA_ERROR_CONNECTION_BUSY;
+ return PSA_SUCCESS;
}
psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr)
@@ -264,13 +266,15 @@ psa_status_t tfm_svcall_psa_call(uint32_t *args, int32_t ns_caller, uint32_t lr)
* FixMe: Need to check if the message is unrecognized by the RoT
* Service or incorrectly formatted.
*/
- msg = tfm_spm_create_msg(service, handle, type, ns_caller, invecs,
- in_num, outvecs, out_num, outptr);
+ msg = tfm_spm_get_msg_buffer_from_conn_handle(handle);
if (!msg) {
/* FixMe: Need to implement one mechanism to resolve this failure. */
tfm_panic();
}
+ tfm_spm_fill_msg(msg, service, handle, type, ns_caller, invecs,
+ in_num, outvecs, out_num, outptr);
+
/*
* Send message and wake up the SP who is waiting on message queue,
* and scheduler triggered
@@ -305,14 +309,16 @@ void tfm_svcall_psa_close(uint32_t *args, int32_t ns_caller)
tfm_panic();
}
- /* No input or output needed for close message */
- msg = tfm_spm_create_msg(service, handle, PSA_IPC_DISCONNECT, ns_caller,
- NULL, 0, NULL, 0, NULL);
+ msg = tfm_spm_get_msg_buffer_from_conn_handle(handle);
if (!msg) {
/* FixMe: Need to implement one mechanism to resolve this failure. */
- return;
+ tfm_panic();
}
+ /* No input or output needed for close message */
+ tfm_spm_fill_msg(msg, service, handle, PSA_IPC_DISCONNECT, ns_caller,
+ NULL, 0, NULL, 0, NULL);
+
/*
* Send message and wake up the SP who is waiting on message queue,
* and scheduler triggered
@@ -875,9 +881,6 @@ static void tfm_svcall_psa_reply(uint32_t *args)
}
tfm_event_wake(&msg->ack_evnt, ret);
-
- /* Message should not be unsed anymore */
- tfm_spm_free_msg(msg);
}
/**
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index eb2d1078c..a3ceb2699 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -110,16 +110,16 @@ struct spm_partition_runtime_data_t {
#ifdef TFM_PSA_API
-#define TFM_SPM_MAX_ROT_SERV_NUM 48
#define TFM_VERSION_POLICY_RELAXED 0
#define TFM_VERSION_POLICY_STRICT 1
-#define TFM_CONN_HANDLE_MAX_NUM 32
+#define TFM_CONN_HANDLE_MAX_NUM 16
/* RoT connection handle list */
struct tfm_conn_handle_t {
psa_handle_t handle; /* Handle value */
void *rhandle; /* Reverse handle value */
+ struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
struct tfm_list_node_t list; /* list node */
};
@@ -554,8 +554,20 @@ struct spm_partition_desc_t *
struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
/**
- * \brief Create a message for PSA client call.
+ * \brief Get message context by connect handle.
*
+ * \param[in] conn_handle Service connect handle.
+ *
+ * \return The message body context pointer
+ * \ref msg_body_t structures
+ */
+struct tfm_msg_body_t *
+ tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle);
+
+/**
+ * \brief Fill the message for PSA client call.
+ *
+ * \param[in] msg Service Message Queue buffer pointer
* \param[in] service Target service context pointer, which can be
* obtained by partition management functions
* \prarm[in] handle Connect handle return by psa_connect().
@@ -567,28 +579,14 @@ struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
* \param[in] outvec Array of output \ref psa_outvec structures
* \param[in] out_len Number of output \ref psa_outvec structures
* \param[in] caller_outvec Array of caller output \ref psa_outvec structures
- *
- * \retval NULL Failed
- * \retval "Not NULL" New message body pointer \ref tfm_msg_body_t
- * structures
- */
-struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
- psa_handle_t handle,
- int32_t type, int32_t ns_caller,
- psa_invec *invec, size_t in_len,
- psa_outvec *outvec, size_t out_len,
- psa_outvec *caller_outvec);
-
-/**
- * \brief Free message which unused anymore
- *
- * \param[in] msg Message pointer which want to free
- * \ref tfm_msg_body_t structures
- *
- * \retval void Success
- * \retval "Does not return" Failed
*/
-void tfm_spm_free_msg(struct tfm_msg_body_t *msg);
+void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
+ struct tfm_spm_service_t *service,
+ psa_handle_t handle,
+ int32_t type, int32_t ns_caller,
+ psa_invec *invec, size_t in_len,
+ psa_outvec *outvec, size_t out_len,
+ psa_outvec *caller_outvec);
/**
* \brief Send message and wake up the SP who is waiting on
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index 60fd82d17..f03cf96e4 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -42,8 +42,6 @@ extern int32_t tfm_secure_lock;
/* Pools */
TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t),
TFM_CONN_HANDLE_MAX_NUM);
-TFM_POOL_DECLARE(msg_db_pool, sizeof(struct tfm_msg_body_t),
- TFM_MSG_QUEUE_MAX_MSG_NUM);
/********************** SPM functions for handler mode ***********************/
@@ -316,16 +314,25 @@ struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle)
return msg;
}
-struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
- psa_handle_t handle,
- int32_t type, int32_t ns_caller,
- psa_invec *invec, size_t in_len,
- psa_outvec *outvec, size_t out_len,
- psa_outvec *caller_outvec)
+struct tfm_msg_body_t *
+ tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle)
+{
+ TFM_ASSERT(conn_handle != PSA_NULL_HANDLE);
+
+ return &(((struct tfm_conn_handle_t *)conn_handle)->internal_msg);
+}
+
+void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
+ struct tfm_spm_service_t *service,
+ psa_handle_t handle,
+ int32_t type, int32_t ns_caller,
+ psa_invec *invec, size_t in_len,
+ psa_outvec *outvec, size_t out_len,
+ psa_outvec *caller_outvec)
{
- struct tfm_msg_body_t *msg = NULL;
uint32_t i;
+ TFM_ASSERT(msg);
TFM_ASSERT(service);
TFM_ASSERT(!(invec == NULL && in_len != 0));
TFM_ASSERT(!(outvec == NULL && out_len != 0));
@@ -333,12 +340,6 @@ struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
TFM_ASSERT(out_len <= PSA_MAX_IOVEC);
TFM_ASSERT(in_len + out_len <= PSA_MAX_IOVEC);
- /* Get message buffer from message pool */
- msg = (struct tfm_msg_body_t *)tfm_pool_alloc(msg_db_pool);
- if (!msg) {
- return NULL;
- }
-
/* Clear message buffer before using it */
tfm_memset(msg, 0, sizeof(struct tfm_msg_body_t));
@@ -376,13 +377,6 @@ struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
if (handle != PSA_NULL_HANDLE) {
msg->msg.rhandle = tfm_spm_get_rhandle(service, handle);
}
-
- return msg;
-}
-
-void tfm_spm_free_msg(struct tfm_msg_body_t *msg)
-{
- tfm_pool_free(msg);
}
int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
@@ -505,9 +499,6 @@ void tfm_spm_init(void)
POOL_BUFFER_SIZE(conn_handle_pool),
sizeof(struct tfm_conn_handle_t),
TFM_CONN_HANDLE_MAX_NUM);
- tfm_pool_init(msg_db_pool, POOL_BUFFER_SIZE(msg_db_pool),
- sizeof(struct tfm_msg_body_t),
- TFM_MSG_QUEUE_MAX_MSG_NUM);
/* Init partition first for it will be used when init service */
for (i = 0; i < g_spm_partition_db.partition_count; i++) {