Mate Toth-Pal | 3956a8a | 2018-08-03 17:18:47 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2018, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | #include <string.h> |
| 8 | |
| 9 | #include "tfm_nspm_svc_handler.h" |
| 10 | #include "cmsis_os2.h" |
| 11 | #include "tfm_api.h" |
| 12 | #include "tfm_ns_svc.h" |
| 13 | |
| 14 | /* FIXME: following two functions are meant to be internally |
| 15 | * available to RTX. The header file containing prototype of |
| 16 | * these functions has complex header inclusion which leads |
| 17 | * to compiler specific paths in CMSIS, which currently doesn't have |
| 18 | * clang variant. To simplify this, following functions are directly |
| 19 | * declared here (as opposed to header inclusion). After clear |
| 20 | * separation of S and NS builds this will require to be revisited |
| 21 | */ |
| 22 | extern osThreadId_t svcRtxThreadGetId(void); |
| 23 | extern const char *svcRtxThreadGetName(osThreadId_t thread_id); |
| 24 | |
| 25 | /* Translation table pair between OS threads and SST client IDs */ |
| 26 | struct thread_sst_clientid_pair { |
| 27 | const char* t_name; /*!< Task/Thread name */ |
| 28 | int32_t client_id; /*!< Client ID used in assets definition */ |
| 29 | }; |
| 30 | |
| 31 | static struct thread_sst_clientid_pair sst_ns_policy_table[] = |
| 32 | { |
| 33 | {"Thread_A", -9}, |
| 34 | {"Thread_B", -10}, |
| 35 | {"Thread_C", -11}, |
| 36 | {"Thread_D", -12}, |
| 37 | {"seq_task", -13}, |
| 38 | {"mid_task", -14}, |
| 39 | {"pri_task", -15}, |
| 40 | }; |
| 41 | |
| 42 | static const char* get_active_task_name(void) |
| 43 | { |
| 44 | const char* thread_name; |
| 45 | |
| 46 | thread_name = svcRtxThreadGetName(svcRtxThreadGetId()); |
| 47 | |
| 48 | return thread_name; |
| 49 | } |
| 50 | |
| 51 | /* SVC function implementations */ |
| 52 | uint32_t tfm_nspm_svc_register_client_id() |
| 53 | { |
| 54 | int32_t client_id_ns; |
| 55 | uint32_t i; |
| 56 | static uint32_t sst_table_size = (sizeof(sst_ns_policy_table) / |
| 57 | sizeof(sst_ns_policy_table[0])); |
| 58 | const char* p_thread_name; |
| 59 | |
| 60 | p_thread_name = get_active_task_name(); |
| 61 | |
| 62 | for (i = 0; i < sst_table_size; i++) { |
| 63 | if (strcmp(sst_ns_policy_table[i].t_name, p_thread_name) == 0) { |
| 64 | client_id_ns = sst_ns_policy_table[i].client_id; |
| 65 | if (tfm_register_client_id(client_id_ns) == TFM_SUCCESS) { |
| 66 | return 1; |
| 67 | } else { |
| 68 | return 0; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | return 0; |
| 73 | } |