diff options
author | Summer Qin <summer.qin@arm.com> | 2020-05-20 10:32:58 +0800 |
---|---|---|
committer | Summer Qin <summer.qin@arm.com> | 2020-05-29 20:42:20 +0800 |
commit | 630c76b90301dd342947fd183b9b8cb6236aabab (patch) | |
tree | ab34bafe07619f8a138ecf3602dbb39f337164e3 /secure_fw | |
parent | 3650297e1cc7373dd5e21dde2b05444c0840f57f (diff) | |
download | trusted-firmware-m-630c76b90301dd342947fd183b9b8cb6236aabab.tar.gz |
Core: Distinguish connection handle types
SPM function direct accesses internal handle type instance,
and expose 'psa_handle_t' to external. Distinguish the internal
and the external connection handle types.
Remove 'tfm_spm_get_service_by_handle' function since we can
directly get service with connection handle.
Remove 'tfm_spm_find_conn_handle_node' function.
Change-Id: I60b481e409f4165ec1bbde97c498ee17d74c5a29
Signed-off-by: Summer Qin <summer.qin@arm.com>
Diffstat (limited to 'secure_fw')
-rw-r--r-- | secure_fw/core/ipc/include/tfm_message_queue.h | 30 | ||||
-rw-r--r-- | secure_fw/spm/spm_api.h | 29 | ||||
-rw-r--r-- | secure_fw/spm/spm_ipc.c | 92 | ||||
-rw-r--r-- | secure_fw/spm/spm_psa_client_call.c | 36 |
4 files changed, 71 insertions, 116 deletions
diff --git a/secure_fw/core/ipc/include/tfm_message_queue.h b/secure_fw/core/ipc/include/tfm_message_queue.h index ca33cd8c77..a11fb3b69a 100644 --- a/secure_fw/core/ipc/include/tfm_message_queue.h +++ b/secure_fw/core/ipc/include/tfm_message_queue.h @@ -14,24 +14,24 @@ /* Message struct to collect parameter from client */ struct tfm_msg_body_t { int32_t magic; - struct tfm_spm_service_t *service; /* RoT service pointer */ - psa_handle_t handle; /* Connected Service handle */ - struct tfm_event_t ack_evnt; /* Event for ack reponse */ - psa_msg_t msg; /* PSA message body */ - psa_invec invec[PSA_MAX_IOVEC]; /* Put in/out vectors in msg body */ + struct tfm_spm_service_t *service; /* RoT service pointer */ + struct tfm_conn_handle_t *handle; /* Connected Service handle */ + struct tfm_event_t ack_evnt; /* Event for ack reponse */ + psa_msg_t msg; /* PSA message body */ + psa_invec invec[PSA_MAX_IOVEC]; /* Put in/out vectors in msg body */ psa_outvec outvec[PSA_MAX_IOVEC]; - psa_outvec *caller_outvec; /* - * Save caller outvec pointer for - * write length update - */ + psa_outvec *caller_outvec; /* + * Save caller outvec pointer for + * write length update + */ #ifdef TFM_MULTI_CORE_TOPOLOGY - const void *caller_data; /* - * Pointer to the private data of the caller - * It identifies the NSPE PSA client calls - * in multi-core topology - */ + const void *caller_data; /* + * Pointer to the private data of the + * caller. It identifies the NSPE PSA + * client calls in multi-core topology + */ #endif - struct tfm_msg_body_t *next; /* List operators */ + struct tfm_msg_body_t *next; /* List operators */ }; struct tfm_msg_queue_t { diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h index 6dbd12f521..6162b2e66a 100644 --- a/secure_fw/spm/spm_api.h +++ b/secure_fw/spm/spm_api.h @@ -490,10 +490,11 @@ uint32_t tfm_spm_partition_get_running_partition_id(void); * \param[in] service Target service context pointer * \param[in] client_id Partition ID of the sender of the message * - * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE - * \retval >0 Service handle created, \ref psa_handle_t + * \retval NULL Create failed + * \retval "Not NULL" Service handle created */ -psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service, +struct tfm_conn_handle_t *tfm_spm_create_conn_handle( + struct tfm_spm_service_t *service, int32_t client_id); /** @@ -505,8 +506,9 @@ psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service, * \retval IPC_SUCCESS Success * \retval IPC_ERROR_GENERIC Invalid handle */ -int32_t tfm_spm_validate_conn_handle(psa_handle_t conn_handle, - int32_t client_id); +int32_t tfm_spm_validate_conn_handle( + const struct tfm_conn_handle_t *conn_handle, + int32_t client_id); /******************** Partition management functions *************************/ @@ -530,19 +532,6 @@ struct spm_partition_desc_t *tfm_spm_get_running_partition(void); */ struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid); -/** - * \brief Get the service context by connection handle. - * - * \param[in] conn_handle Connection handle created by - * tfm_spm_create_conn_handle() - * - * \retval NULL Failed - * \retval "Not NULL" Target service context pointer, - * \ref tfm_spm_service_t structures - */ -struct tfm_spm_service_t * - tfm_spm_get_service_by_handle(psa_handle_t conn_handle); - /************************ Message functions **********************************/ /** @@ -554,7 +543,7 @@ struct tfm_spm_service_t * * \ref msg_body_t structures */ struct tfm_msg_body_t * - tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle); + tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle); /** * \brief Fill the message for PSA client call. @@ -574,7 +563,7 @@ struct tfm_msg_body_t * */ void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, struct tfm_spm_service_t *service, - psa_handle_t handle, + struct tfm_conn_handle_t *handle, int32_t type, int32_t client_id, psa_invec *invec, size_t in_len, psa_outvec *outvec, size_t out_len, diff --git a/secure_fw/spm/spm_ipc.c b/secure_fw/spm/spm_ipc.c index ea3fa36ad2..3188280e3b 100644 --- a/secure_fw/spm/spm_ipc.c +++ b/secure_fw/spm/spm_ipc.c @@ -53,7 +53,8 @@ void tfm_irq_handler(uint32_t partition_id, psa_signal_t signal, #include "tfm_secure_irq_handlers_ipc.inc" /* Service handle management functions */ -psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service, +struct tfm_conn_handle_t *tfm_spm_create_conn_handle( + struct tfm_spm_service_t *service, int32_t client_id) { struct tfm_conn_handle_t *p_handle; @@ -63,7 +64,7 @@ psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service, /* Get buffer for handle list structure from handle pool */ p_handle = (struct tfm_conn_handle_t *)tfm_pool_alloc(conn_handle_pool); if (!p_handle) { - return PSA_NULL_HANDLE; + return NULL; } p_handle->service = service; @@ -73,11 +74,12 @@ psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service, /* Add handle node to list for next psa functions */ tfm_list_add_tail(&service->handle_list, &p_handle->list); - return (psa_handle_t)p_handle; + return p_handle; } -int32_t tfm_spm_validate_conn_handle(psa_handle_t conn_handle, - int32_t client_id) +int32_t tfm_spm_validate_conn_handle( + const struct tfm_conn_handle_t *conn_handle, + int32_t client_id) { /* Check the handle address is validated */ if (is_valid_chunk_data_in_pool(conn_handle_pool, @@ -86,54 +88,38 @@ int32_t tfm_spm_validate_conn_handle(psa_handle_t conn_handle, } /* Check the handle caller is correct */ - if (((struct tfm_conn_handle_t *)conn_handle)->client_id != client_id) { + if (conn_handle->client_id != client_id) { return IPC_ERROR_GENERIC; } return IPC_SUCCESS; } -static struct tfm_conn_handle_t * - tfm_spm_find_conn_handle_node(struct tfm_spm_service_t *service, - psa_handle_t conn_handle) -{ - TFM_CORE_ASSERT(service); - - return (struct tfm_conn_handle_t *)conn_handle; -} - /** * \brief Free connection handle which not used anymore. * * \param[in] service Target service context pointer * \param[in] conn_handle Connection handle created by - * tfm_spm_create_conn_handle(), \ref psa_handle_t + * tfm_spm_create_conn_handle() * * \retval IPC_SUCCESS Success * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input * \retval "Does not return" Panic for not find service by handle */ static int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, - psa_handle_t conn_handle) + struct tfm_conn_handle_t *conn_handle) { - struct tfm_conn_handle_t *p_handle; - TFM_CORE_ASSERT(service); - - /* There are many handles for each RoT Service */ - p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); - if (!p_handle) { - tfm_core_panic(); - } + TFM_CORE_ASSERT(conn_handle != NULL); /* Clear magic as the handler is not used anymore */ - p_handle->internal_msg.magic = 0; + conn_handle->internal_msg.magic = 0; /* Remove node from handle list */ - tfm_list_del_node(&p_handle->list); + tfm_list_del_node(&conn_handle->list); /* Back handle buffer to pool */ - tfm_pool_free(p_handle); + tfm_pool_free(conn_handle); return IPC_SUCCESS; } @@ -142,7 +128,7 @@ static int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, * * \param[in] service Target service context pointer * \param[in] conn_handle Connection handle created by - * tfm_spm_create_conn_handle(), \ref psa_handle_t + * tfm_spm_create_conn_handle() * \param[in] rhandle rhandle need to save * * \retval IPC_SUCCESS Success @@ -150,22 +136,14 @@ static int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, * \retval "Does not return" Panic for not find handle node */ static int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, - psa_handle_t conn_handle, + struct tfm_conn_handle_t *conn_handle, void *rhandle) { - struct tfm_conn_handle_t *p_handle; - TFM_CORE_ASSERT(service); /* Set reverse handle value only be allowed for a connected handle */ - TFM_CORE_ASSERT(conn_handle != PSA_NULL_HANDLE); + TFM_CORE_ASSERT(conn_handle != NULL); - /* There are many handles for each RoT Service */ - p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); - if (!p_handle) { - tfm_core_panic(); - } - - p_handle->rhandle = rhandle; + conn_handle->rhandle = rhandle; return IPC_SUCCESS; } @@ -174,7 +152,7 @@ static int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, * * \param[in] service Target service context pointer * \param[in] conn_handle Connection handle created by - * tfm_spm_create_conn_handle(), \ref psa_handle_t + * tfm_spm_create_conn_handle() * * \retval void * Success * \retval "Does not return" Panic for those: @@ -183,21 +161,13 @@ static int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, * handle node does not be found */ static void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service, - psa_handle_t conn_handle) + struct tfm_conn_handle_t *conn_handle) { - struct tfm_conn_handle_t *p_handle; - TFM_CORE_ASSERT(service); /* Get reverse handle value only be allowed for a connected handle */ - TFM_CORE_ASSERT(conn_handle != PSA_NULL_HANDLE); + TFM_CORE_ASSERT(conn_handle != NULL); - /* There are many handles for each RoT Service */ - p_handle = tfm_spm_find_conn_handle_node(service, conn_handle); - if (!p_handle) { - tfm_core_panic(); - } - - return p_handle->rhandle; + return conn_handle->rhandle; } /* Partition management functions */ @@ -267,12 +237,6 @@ struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid) return NULL; } -struct tfm_spm_service_t * - tfm_spm_get_service_by_handle(psa_handle_t conn_handle) -{ - return ((struct tfm_conn_handle_t *)conn_handle)->service; -} - /** * \brief Get the partition context by partition ID. * @@ -418,16 +382,16 @@ static struct tfm_msg_body_t * } struct tfm_msg_body_t * - tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle) + tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle) { - TFM_CORE_ASSERT(conn_handle != PSA_NULL_HANDLE); + TFM_CORE_ASSERT(conn_handle != NULL); - return &(((struct tfm_conn_handle_t *)conn_handle)->internal_msg); + return &(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, + struct tfm_conn_handle_t *handle, int32_t type, int32_t client_id, psa_invec *invec, size_t in_len, psa_outvec *outvec, size_t out_len, @@ -472,7 +436,7 @@ void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, msg->msg.handle = (psa_handle_t)msg; /* For connected handle, set rhandle to every message */ - if (handle != PSA_NULL_HANDLE) { + if (handle) { msg->msg.rhandle = tfm_spm_get_rhandle(service, handle); } @@ -1268,7 +1232,7 @@ void tfm_spm_psa_reply(uint32_t *args) * input status. */ if (status == PSA_SUCCESS) { - ret = msg->handle; + ret = (psa_handle_t)msg->handle; } else if (status == PSA_ERROR_CONNECTION_REFUSED) { /* Refuse the client connection, indicating a permanent error. */ tfm_spm_free_conn_handle(service, msg->handle); diff --git a/secure_fw/spm/spm_psa_client_call.c b/secure_fw/spm/spm_psa_client_call.c index ab29cb7c92..6e705bb472 100644 --- a/secure_fw/spm/spm_psa_client_call.c +++ b/secure_fw/spm/spm_psa_client_call.c @@ -50,7 +50,7 @@ psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version, { struct tfm_spm_service_t *service; struct tfm_msg_body_t *msg; - psa_handle_t connect_handle; + struct tfm_conn_handle_t *connect_handle; int32_t client_id; /* It is a fatal error if the RoT Service does not exist on the platform */ @@ -78,7 +78,7 @@ psa_status_t tfm_spm_client_psa_connect(uint32_t sid, uint32_t version, * code to client when creation fails. */ connect_handle = tfm_spm_create_conn_handle(service, client_id); - if (connect_handle == PSA_NULL_HANDLE) { + if (!connect_handle) { return PSA_ERROR_CONNECTION_BUSY; } @@ -116,6 +116,7 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, { psa_invec invecs[PSA_MAX_IOVEC]; psa_outvec outvecs[PSA_MAX_IOVEC]; + struct tfm_conn_handle_t *conn_handle; struct tfm_spm_service_t *service; struct tfm_msg_body_t *msg; int i, j; @@ -134,19 +135,19 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, client_id = tfm_spm_partition_get_running_partition_id(); } + conn_handle = (struct tfm_conn_handle_t *)handle; /* It is a fatal error if an invalid handle was passed. */ - if (tfm_spm_validate_conn_handle(handle, client_id) != IPC_SUCCESS) { + if (tfm_spm_validate_conn_handle(conn_handle, client_id) != IPC_SUCCESS) { tfm_core_panic(); } - service = tfm_spm_get_service_by_handle(handle); + service = conn_handle->service; if (!service) { /* FixMe: Need to implement one mechanism to resolve this failure. */ tfm_core_panic(); } /* It is a fatal error if the connection is currently handling a request. */ - if (((struct tfm_conn_handle_t *)handle)->status == - TFM_HANDLE_STATUS_ACTIVE) { + if (conn_handle->status == TFM_HANDLE_STATUS_ACTIVE) { tfm_core_panic(); } @@ -154,8 +155,7 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, * Return PSA_ERROR_PROGRAMMER_ERROR immediately for the connection * has been terminated by the RoT Service. */ - if (((struct tfm_conn_handle_t *)handle)->status == - TFM_HANDLE_STATUS_CONNECT_ERROR) { + if (conn_handle->status == TFM_HANDLE_STATUS_CONNECT_ERROR) { return PSA_ERROR_PROGRAMMER_ERROR; } @@ -228,14 +228,14 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type, * FixMe: Need to check if the message is unrecognized by the RoT * Service or incorrectly formatted. */ - msg = tfm_spm_get_msg_buffer_from_conn_handle(handle); + msg = tfm_spm_get_msg_buffer_from_conn_handle(conn_handle); if (!msg) { /* FixMe: Need to implement one mechanism to resolve this failure. */ tfm_core_panic(); } - tfm_spm_fill_msg(msg, service, handle, type, client_id, invecs, - in_num, outvecs, out_num, outptr); + tfm_spm_fill_msg(msg, service, conn_handle, type, client_id, + invecs, in_num, outvecs, out_num, outptr); /* * Send message and wake up the SP who is waiting on message queue, @@ -252,6 +252,7 @@ void tfm_spm_client_psa_close(psa_handle_t handle, bool ns_caller) { struct tfm_spm_service_t *service; struct tfm_msg_body_t *msg; + struct tfm_conn_handle_t *conn_handle; int32_t client_id; /* It will have no effect if called with the NULL handle */ @@ -265,33 +266,34 @@ void tfm_spm_client_psa_close(psa_handle_t handle, bool ns_caller) client_id = tfm_spm_partition_get_running_partition_id(); } + conn_handle = (struct tfm_conn_handle_t *)handle; + /* * It is a fatal error if an invalid handle was provided that is not the * null handle. */ - if (tfm_spm_validate_conn_handle(handle, client_id) != IPC_SUCCESS) { + if (tfm_spm_validate_conn_handle(conn_handle, client_id) != IPC_SUCCESS) { tfm_core_panic(); } - service = tfm_spm_get_service_by_handle(handle); + service = conn_handle->service; if (!service) { /* FixMe: Need to implement one mechanism to resolve this failure. */ tfm_core_panic(); } - msg = tfm_spm_get_msg_buffer_from_conn_handle(handle); + msg = tfm_spm_get_msg_buffer_from_conn_handle(conn_handle); if (!msg) { /* FixMe: Need to implement one mechanism to resolve this failure. */ tfm_core_panic(); } /* It is a fatal error if the connection is currently handling a request. */ - if (((struct tfm_conn_handle_t *)handle)->status == - TFM_HANDLE_STATUS_ACTIVE) { + if (conn_handle->status == TFM_HANDLE_STATUS_ACTIVE) { tfm_core_panic(); } /* No input or output needed for close message */ - tfm_spm_fill_msg(msg, service, handle, PSA_IPC_DISCONNECT, client_id, + tfm_spm_fill_msg(msg, service, conn_handle, PSA_IPC_DISCONNECT, client_id, NULL, 0, NULL, 0, NULL); /* |