aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Peng <kevin.peng@arm.com>2021-03-09 16:44:00 +0800
committerKen Liu <ken.liu@arm.com>2021-03-19 07:26:36 +0100
commit8dac6101a5d71bbe09df49f5883c340631e57130 (patch)
tree8d3f1d21f4017b71fc6cc236bc6c841a8d5112e5
parenta1ca6118c9d840a67fbc016e36a346f932bab88b (diff)
downloadtrusted-firmware-m-8dac6101a5d71bbe09df49f5883c340631e57130.tar.gz
SPM: Wake up only when waitfing for the signal
If a Partition is not waiting for a signal, it should not be woken up. Appending the signal to its asserted_signals is enough. The next time it waits for this signal, it will get it. And the waiting signal should be cleared when waking up. Setting waiting signal for polling mode is not necessary either. Change-Id: I9929fd7a4081077eb9543ef3b95ac7278931496c Signed-off-by: Kevin Peng <kevin.peng@arm.com>
-rw-r--r--secure_fw/spm/cmsis_psa/spm_ipc.c40
-rw-r--r--secure_fw/spm/cmsis_psa/spm_ipc.h8
-rw-r--r--secure_fw/spm/ffm/psa_client_service_apis.c8
-rw-r--r--secure_fw/spm/ffm/spm_psa_client_call.c6
4 files changed, 28 insertions, 34 deletions
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index 074c88a9a6..c30f6cd90a 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -544,22 +544,31 @@ void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
}
}
-int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
- struct tfm_msg_body_t *msg)
+void tfm_spm_send_event(struct tfm_spm_service_t *service,
+ struct tfm_msg_body_t *msg)
{
- struct partition_t *partition = service->partition;
+ struct partition_t *partition = NULL;
+ psa_signal_t signal = 0;
- TFM_CORE_ASSERT(service);
- TFM_CORE_ASSERT(msg);
+ if (!msg || !service || !service->service_db || !service->partition) {
+ tfm_core_panic();
+ }
+
+ partition = service->partition;
+ signal = service->service_db->signal;
/* Add message to partition message list tail */
BI_LIST_INSERT_BEFORE(&partition->msg_list, &msg->msg_node);
/* Messages put. Update signals */
- partition->signals_asserted |= service->service_db->signal;
+ partition->signals_asserted |= signal;
- tfm_event_wake(&partition->event,
- (partition->signals_asserted & partition->signals_waiting));
+ if (partition->signals_waiting & signal) {
+ tfm_event_wake(
+ &partition->event,
+ (partition->signals_asserted & partition->signals_waiting));
+ partition->signals_waiting &= ~signal;
+ }
/*
* If it is a NS request via RPC, it is unnecessary to block current
@@ -568,8 +577,6 @@ int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
if (!is_tfm_rpc_msg(msg)) {
tfm_event_wait(&msg->ack_evnt);
}
-
- return SPM_SUCCESS;
}
uint32_t tfm_spm_partition_get_running_partition_id(void)
@@ -848,13 +855,12 @@ void notify_with_signal(int32_t partition_id, psa_signal_t signal)
partition->signals_asserted |= signal;
- /*
- * The target partition may be blocked with waiting for signals after
- * called psa_wait(). Set the return value with the available signals
- * before wake it up with tfm_event_signal().
- */
- tfm_event_wake(&partition->event,
- partition->signals_asserted & partition->signals_waiting);
+ if (partition->signals_waiting & signal) {
+ tfm_event_wake(
+ &partition->event,
+ partition->signals_asserted & partition->signals_waiting);
+ partition->signals_waiting &= ~signal;
+ }
}
/**
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.h b/secure_fw/spm/cmsis_psa/spm_ipc.h
index 1c095c5fb7..1a1c1ea909 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.h
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.h
@@ -323,13 +323,9 @@ void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
* obtained by partition management functions
* \param[in] msg message created by tfm_spm_create_msg()
* \ref tfm_msg_body_t structures
- *
- * \retval SPM_SUCCESS Success
- * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
- * \retval SPM_ERROR_GENERIC Failed to enqueue message to service message queue
*/
-int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
- struct tfm_msg_body_t *msg);
+void tfm_spm_send_event(struct tfm_spm_service_t *service,
+ struct tfm_msg_body_t *msg);
/**
* \brief Check the client version according to
diff --git a/secure_fw/spm/ffm/psa_client_service_apis.c b/secure_fw/spm/ffm/psa_client_service_apis.c
index 20ac5beeac..ff9083eb02 100644
--- a/secure_fw/spm/ffm/psa_client_service_apis.c
+++ b/secure_fw/spm/ffm/psa_client_service_apis.c
@@ -149,13 +149,6 @@ psa_signal_t tfm_spm_psa_wait(uint32_t *args)
}
/*
- * Expected signals are included in signal wait mask, ignored signals
- * should not be set and affect caller thread state. Save this mask for
- * further checking while signals are ready to be set.
- */
- partition->signals_waiting = signal_mask;
-
- /*
* tfm_event_wait() blocks the caller thread if no signals are available.
* In this case, the return value of this function is temporary set into
* runtime context. After new signal(s) are available, the return value
@@ -163,6 +156,7 @@ psa_signal_t tfm_spm_psa_wait(uint32_t *args)
*/
if (timeout == PSA_BLOCK &&
(partition->signals_asserted & signal_mask) == 0) {
+ partition->signals_waiting = signal_mask;
tfm_event_wait(&partition->event);
}
diff --git a/secure_fw/spm/ffm/spm_psa_client_call.c b/secure_fw/spm/ffm/spm_psa_client_call.c
index a0d737ad63..98a695fb94 100644
--- a/secure_fw/spm/ffm/spm_psa_client_call.c
+++ b/secure_fw/spm/ffm/spm_psa_client_call.c
@@ -249,10 +249,8 @@ psa_status_t tfm_spm_client_psa_call(psa_handle_t handle, int32_t type,
* Send message and wake up the SP who is waiting on message queue,
* and scheduler triggered
*/
- if (tfm_spm_send_event(service, msg) != SPM_SUCCESS) {
- /* FixMe: Need to refine failure process here. */
- tfm_core_panic();
- }
+ tfm_spm_send_event(service, msg);
+
return PSA_SUCCESS;
}