blob: a835f2d42eb1ba6e1547f266f2a30698ecbe15cd [file] [log] [blame]
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +02001/*
Jamie Fox17c30bb2019-01-10 13:39:33 +00002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +02003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +01008#include "tfm_nspm_api.h"
9
10#include <string.h>
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020011#include <stdint.h>
12
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010013#include "cmsis_os2.h"
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020014#include "tfm_ns_svc.h"
15
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010016/* Translation table pair between OS threads and client IDs */
17struct thread_test_clientid_pair {
18 const char* t_name; /*!< Task/Thread name */
19 int32_t client_id; /*!< Client ID used in assets definition */
20};
21
22static struct thread_test_clientid_pair test_ns_policy_table[] =
23{
24 {"Thread_A", -1},
25 {"Thread_B", -2},
26 {"Thread_C", -3},
27 {"Thread_D", -4},
28 {"seq_task", -5},
29 {"mid_task", -6},
30 {"pri_task", -7},
Jamie Fox17c30bb2019-01-10 13:39:33 +000031#ifdef PSA_API_TEST_NS
32 {"psa_api_test", -8}
33#endif
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010034};
35
36/**
37 * \brief Gets the client ID based on the thread name
38 *
39 * \return If the thread name is in the test_ns_policy_table, it returns the
40 * client ID. Otherwise, it returns 0 as an error code.
41 */
42static uint32_t get_client_id(void)
43{
44 uint32_t i;
45 static uint32_t test_table_size = (sizeof(test_ns_policy_table) /
46 sizeof(test_ns_policy_table[0]));
47 const char* p_thread_name;
48 osThreadId_t thread_id;
49
50 /* Get thread name */
51 thread_id = osThreadGetId();
52 p_thread_name = osThreadGetName(thread_id);
53
54 for (i = 0; i < test_table_size; i++) {
55 if (strcmp(test_ns_policy_table[i].t_name, p_thread_name) == 0) {
56 return test_ns_policy_table[i].client_id;
57 }
58 }
59
60 return 0;
61}
62
63__attribute__ ((naked))
64static uint32_t tfm_nspm_svc_register_client(uint32_t client_id)
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020065{
66 SVC(SVC_TFM_NSPM_REGISTER_CLIENT_ID);
67 __ASM("BX LR");
68}
69
Marc Moreno Berengue2b328e92018-10-10 14:18:17 +010070uint32_t tfm_nspm_register_client_id(void)
71{
72 uint32_t client_id;
73
74 client_id = get_client_id();
75 if (client_id == 0) {
76 return 0;
77 }
78
79 return tfm_nspm_svc_register_client(client_id);
80}
81
Mate Toth-Pal3956a8a2018-08-03 17:18:47 +020082