NSPM: Update NSPM mechanism to get thread name
This patch updates the non-secure partition management (NSPM) to
use the public RTX osThreadGetName function to get the thread name
rather than use internal RTX functions.
It also gets the client ID from the thread name and passes it into the
SVC function to register the client ID to be assigned to the current
TZ context.
Change-Id: I269d2d09f21615e1fa9fc57d5c0239923a5f9fca
Signed-off-by: Marc Moreno <marc.morenoberengue@arm.com>
diff --git a/interface/include/tfm_nspm_svc_handler.h b/interface/include/tfm_nspm_svc_handler.h
index 785fda6..73f75a9 100644
--- a/interface/include/tfm_nspm_svc_handler.h
+++ b/interface/include/tfm_nspm_svc_handler.h
@@ -17,9 +17,11 @@
/**
* \brief Reports the client ID of this task to TF-M (SVC function)
*
+ * \param [in] client_id Client ID to register.
+ *
* \return Returns 1 if the client ID was successfully reported 0 otherwise
*/
-uint32_t tfm_nspm_svc_register_client_id(void);
+uint32_t tfm_nspm_svc_register_client_id(uint32_t client_id);
#ifdef __cplusplus
}
diff --git a/interface/src/tfm_nspm_api.c b/interface/src/tfm_nspm_api.c
index c95ecae..dc5e645 100644
--- a/interface/src/tfm_nspm_api.c
+++ b/interface/src/tfm_nspm_api.c
@@ -5,14 +5,75 @@
*
*/
+#include "tfm_nspm_api.h"
+
+#include <string.h>
#include <stdint.h>
+#include "cmsis_os2.h"
#include "tfm_ns_svc.h"
-__attribute__ ((naked)) uint32_t tfm_nspm_register_client_id(void)
+/* Translation table pair between OS threads and client IDs */
+struct thread_test_clientid_pair {
+ const char* t_name; /*!< Task/Thread name */
+ int32_t client_id; /*!< Client ID used in assets definition */
+};
+
+static struct thread_test_clientid_pair test_ns_policy_table[] =
+{
+ {"Thread_A", -1},
+ {"Thread_B", -2},
+ {"Thread_C", -3},
+ {"Thread_D", -4},
+ {"seq_task", -5},
+ {"mid_task", -6},
+ {"pri_task", -7},
+};
+
+/**
+ * \brief Gets the client ID based on the thread name
+ *
+ * \return If the thread name is in the test_ns_policy_table, it returns the
+ * client ID. Otherwise, it returns 0 as an error code.
+ */
+static uint32_t get_client_id(void)
+{
+ uint32_t i;
+ static uint32_t test_table_size = (sizeof(test_ns_policy_table) /
+ sizeof(test_ns_policy_table[0]));
+ const char* p_thread_name;
+ osThreadId_t thread_id;
+
+ /* Get thread name */
+ thread_id = osThreadGetId();
+ p_thread_name = osThreadGetName(thread_id);
+
+ for (i = 0; i < test_table_size; i++) {
+ if (strcmp(test_ns_policy_table[i].t_name, p_thread_name) == 0) {
+ return test_ns_policy_table[i].client_id;
+ }
+ }
+
+ return 0;
+}
+
+__attribute__ ((naked))
+static uint32_t tfm_nspm_svc_register_client(uint32_t client_id)
{
SVC(SVC_TFM_NSPM_REGISTER_CLIENT_ID);
__ASM("BX LR");
}
+uint32_t tfm_nspm_register_client_id(void)
+{
+ uint32_t client_id;
+
+ client_id = get_client_id();
+ if (client_id == 0) {
+ return 0;
+ }
+
+ return tfm_nspm_svc_register_client(client_id);
+}
+
diff --git a/interface/src/tfm_nspm_svc_handler.c b/interface/src/tfm_nspm_svc_handler.c
index 5361df4..3ec2cb0 100644
--- a/interface/src/tfm_nspm_svc_handler.c
+++ b/interface/src/tfm_nspm_svc_handler.c
@@ -4,70 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*
*/
-#include <string.h>
#include "tfm_nspm_svc_handler.h"
-#include "cmsis_os2.h"
#include "tfm_api.h"
#include "tfm_ns_svc.h"
-/* FIXME: following two functions are meant to be internally
- * available to RTX. The header file containing prototype of
- * these functions has complex header inclusion which leads
- * to compiler specific paths in CMSIS, which currently doesn't have
- * clang variant. To simplify this, following functions are directly
- * declared here (as opposed to header inclusion). After clear
- * separation of S and NS builds this will require to be revisited
- */
-extern osThreadId_t svcRtxThreadGetId(void);
-extern const char *svcRtxThreadGetName(osThreadId_t thread_id);
-
-/* Translation table pair between OS threads and SST client IDs */
-struct thread_sst_clientid_pair {
- const char* t_name; /*!< Task/Thread name */
- int32_t client_id; /*!< Client ID used in assets definition */
-};
-
-static struct thread_sst_clientid_pair sst_ns_policy_table[] =
-{
- {"Thread_A", -1},
- {"Thread_B", -2},
- {"Thread_C", -3},
- {"Thread_D", -4},
- {"seq_task", -5},
- {"mid_task", -6},
- {"pri_task", -7},
-};
-
-static const char* get_active_task_name(void)
-{
- const char* thread_name;
-
- thread_name = svcRtxThreadGetName(svcRtxThreadGetId());
-
- return thread_name;
-}
-
/* SVC function implementations */
-uint32_t tfm_nspm_svc_register_client_id()
+uint32_t tfm_nspm_svc_register_client_id(uint32_t client_id)
{
- int32_t client_id_ns;
- uint32_t i;
- static uint32_t sst_table_size = (sizeof(sst_ns_policy_table) /
- sizeof(sst_ns_policy_table[0]));
- const char* p_thread_name;
-
- p_thread_name = get_active_task_name();
-
- for (i = 0; i < sst_table_size; i++) {
- if (strcmp(sst_ns_policy_table[i].t_name, p_thread_name) == 0) {
- client_id_ns = sst_ns_policy_table[i].client_id;
- if (tfm_register_client_id(client_id_ns) == TFM_SUCCESS) {
- return 1;
- } else {
- return 0;
- }
- }
+ if (tfm_register_client_id(client_id) == TFM_SUCCESS) {
+ return 1;
}
+
return 0;
}