aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdison Ai <edison.ai@arm.com>2019-08-06 11:28:04 +0800
committerEdison Ai <edison.ai@arm.com>2019-08-16 11:32:04 +0800
commit9cc26248d1f51581a872a4c29d6ad9f7746aec66 (patch)
tree194e13a36fb5c55fe78c6019305042ad78cedb68
parent9711582d5acf1bc9b3c06be06aa2b3f39f093a22 (diff)
downloadtrusted-firmware-m-9cc26248d1f51581a872a4c29d6ad9f7746aec66.tar.gz
Core: Refine SPM APIs
- Use handler buffer address as connect handle directly. - Add RoT service pointer into connect handle structure and get service info direclty from connect handle. Change-Id: I2db775b1aa0a2e3873081d0f23e33b8e507b7290 Signed-off-by: Edison Ai <edison.ai@arm.com>
-rw-r--r--secure_fw/spm/spm_api.h6
-rw-r--r--secure_fw/spm/spm_api_ipc.c86
2 files changed, 24 insertions, 68 deletions
diff --git a/secure_fw/spm/spm_api.h b/secure_fw/spm/spm_api.h
index a3ceb26994..9097fba597 100644
--- a/secure_fw/spm/spm_api.h
+++ b/secure_fw/spm/spm_api.h
@@ -117,10 +117,10 @@ struct spm_partition_runtime_data_t {
/* RoT connection handle list */
struct tfm_conn_handle_t {
- psa_handle_t handle; /* Handle value */
- void *rhandle; /* Reverse 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 */
+ struct tfm_spm_service_t *service; /* RoT service pointer */
+ struct tfm_list_node_t list; /* list node */
};
/* Service database defined by manifest */
diff --git a/secure_fw/spm/spm_api_ipc.c b/secure_fw/spm/spm_api_ipc.c
index f03cf96e4b..1a1e8a6207 100644
--- a/secure_fw/spm/spm_api_ipc.c
+++ b/secure_fw/spm/spm_api_ipc.c
@@ -48,63 +48,51 @@ TFM_POOL_DECLARE(conn_handle_pool, sizeof(struct tfm_conn_handle_t),
/* Service handle management functions */
psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service)
{
- struct tfm_conn_handle_t *node;
+ struct tfm_conn_handle_t *p_handle;
TFM_ASSERT(service);
/* Get buffer for handle list structure from handle pool */
- node = (struct tfm_conn_handle_t *)tfm_pool_alloc(conn_handle_pool);
- if (!node) {
+ p_handle = (struct tfm_conn_handle_t *)tfm_pool_alloc(conn_handle_pool);
+ if (!p_handle) {
return PSA_NULL_HANDLE;
}
- /* Global unique handle, use handle buffer address directly */
- node->handle = (psa_handle_t)node;
+ p_handle->service = service;
/* Add handle node to list for next psa functions */
- tfm_list_add_tail(&service->handle_list, &node->list);
+ tfm_list_add_tail(&service->handle_list, &p_handle->list);
- return node->handle;
+ return (psa_handle_t)p_handle;
}
static struct tfm_conn_handle_t *
tfm_spm_find_conn_handle_node(struct tfm_spm_service_t *service,
psa_handle_t conn_handle)
{
- struct tfm_conn_handle_t *handle_node;
- struct tfm_list_node_t *node, *head;
-
TFM_ASSERT(service);
- head = &service->handle_list;
- TFM_LIST_FOR_EACH(node, head) {
- handle_node = TFM_GET_CONTAINER_PTR(node, struct tfm_conn_handle_t,
- list);
- if (handle_node->handle == conn_handle) {
- return handle_node;
- }
- }
- return NULL;
+ return (struct tfm_conn_handle_t *)conn_handle;
}
int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
psa_handle_t conn_handle)
{
- struct tfm_conn_handle_t *node;
+ struct tfm_conn_handle_t *p_handle;
TFM_ASSERT(service);
/* There are many handles for each RoT Service */
- node = tfm_spm_find_conn_handle_node(service, conn_handle);
- if (!node) {
+ p_handle = tfm_spm_find_conn_handle_node(service, conn_handle);
+ if (!p_handle) {
tfm_panic();
}
/* Remove node from handle list */
- tfm_list_del_node(&node->list);
+ tfm_list_del_node(&p_handle->list);
/* Back handle buffer to pool */
- tfm_pool_free(node);
+ tfm_pool_free(p_handle);
return IPC_SUCCESS;
}
@@ -112,38 +100,38 @@ int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
psa_handle_t conn_handle,
void *rhandle)
{
- struct tfm_conn_handle_t *node;
+ struct tfm_conn_handle_t *p_handle;
TFM_ASSERT(service);
/* Set reverse handle value only be allowed for a connected handle */
TFM_ASSERT(conn_handle != PSA_NULL_HANDLE);
/* There are many handles for each RoT Service */
- node = tfm_spm_find_conn_handle_node(service, conn_handle);
- if (!node) {
+ p_handle = tfm_spm_find_conn_handle_node(service, conn_handle);
+ if (!p_handle) {
tfm_panic();
}
- node->rhandle = rhandle;
+ p_handle->rhandle = rhandle;
return IPC_SUCCESS;
}
void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
psa_handle_t conn_handle)
{
- struct tfm_conn_handle_t *node;
+ struct tfm_conn_handle_t *p_handle;
TFM_ASSERT(service);
/* Get reverse handle value only be allowed for a connected handle */
TFM_ASSERT(conn_handle != PSA_NULL_HANDLE);
/* There are many handles for each RoT Service */
- node = tfm_spm_find_conn_handle_node(service, conn_handle);
- if (!node) {
+ p_handle = tfm_spm_find_conn_handle_node(service, conn_handle);
+ if (!p_handle) {
tfm_panic();
}
- return node->rhandle;
+ return p_handle->rhandle;
}
/* Partition management functions */
@@ -203,39 +191,7 @@ struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid)
struct tfm_spm_service_t *
tfm_spm_get_service_by_handle(psa_handle_t conn_handle)
{
- uint32_t i;
- struct tfm_conn_handle_t *handle;
- struct tfm_list_node_t *service_node, *service_head;
- struct tfm_list_node_t *handle_node, *handle_head;
- struct tfm_spm_service_t *service;
- struct spm_partition_desc_t *partition;
-
- for (i = 0; i < g_spm_partition_db.partition_count; i++) {
- partition = &g_spm_partition_db.partitions[i];
- /* Skip partition without IPC flag */
- if ((tfm_spm_partition_get_flags(i) & SPM_PART_FLAG_IPC) == 0) {
- continue;
- }
-
- if (tfm_list_is_empty(&partition->runtime_data.service_list)) {
- continue;
- }
-
- service_head = &partition->runtime_data.service_list;
- TFM_LIST_FOR_EACH(service_node, service_head) {
- service = TFM_GET_CONTAINER_PTR(service_node,
- struct tfm_spm_service_t, list);
- handle_head = &service->handle_list;
- TFM_LIST_FOR_EACH(handle_node, handle_head) {
- handle = TFM_GET_CONTAINER_PTR(handle_node,
- struct tfm_conn_handle_t, list);
- if (handle->handle == conn_handle) {
- return service;
- }
- }
- }
- }
- return NULL;
+ return ((struct tfm_conn_handle_t *)conn_handle)->service;
}
struct spm_partition_desc_t *tfm_spm_get_partition_by_id(int32_t partition_id)