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/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);
+}
+