blob: b42311aa528e5b5303678d691e0dcef91588fa2a [file] [log] [blame]
Xinyu Zhang3ea91b92021-09-22 14:54:29 +08001/*
2 * Copyright (c) 2021, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/*
9 * This is a simple implementaton for reference to manage NSID from NS side.
10 * Developers can design the management according to RTOS and usage scenarios.
11 */
12
13#ifndef __TFM_NSID_MANAGER_H__
14#define __TFM_NSID_MANAGER_H__
15
16#include <stdint.h>
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#ifndef ARRAY_SIZE
23#define ARRAY_SIZE(arr) (sizeof(arr)/sizeof(arr[0]))
24#endif
25
26#define TFM_DEFAULT_GID 0x00
27#define TFM_DEFAULT_NSID ((int32_t)-1)
28/* Non-secure client ID needs to be negative */
29#define TFM_INVALID_NSID_MIN ((int32_t)0)
30
31/* NSID Manager Error Code */
32#define NSID_MGR_ERR_SUCCESS 0x00
33#define NSID_MGR_ERR_INVALID_NSID 0x01
34#define NSID_MGR_ERR_INVALID_TOKEN 0x02
35#define NSID_MGR_ERR_NO_FREE_ENTRY 0x03
36
37/*
Xinyu Zhang21559372021-09-24 17:06:09 +080038 * Current active NSID token needs to be manually save and reload
39 * before and after calling NS client ext directly from SVC in NSID test suite.
40 */
41#ifdef TEST_NS_MANAGE_NSID
42extern uint32_t current_active_token;
43#endif
44
45/*
Xinyu Zhang3ea91b92021-09-22 14:54:29 +080046 * Initialize the table to map token and nsid.
47 * This function should be called before any other NSID manager APIs.
48 */
49uint8_t nsid_mgr_init(void);
50
51/*
52 * Add a new nsid-token map entry to the table.
53 * This function should be called once a new token
54 * has been successfully assigned by ns_client_ext.
55 */
56uint8_t nsid_mgr_add_entry(int32_t nsid, uint32_t token);
57
58/*
59 * Delete a nsid-token map entry from the table.
60 * This function should be called once an existing token
61 * has been successfully released by ns_client_ext.
62 */
63uint8_t nsid_mgr_remove_entry(uint32_t token);
64
65/*
66 * Query NSID from the map table with token.
67 * This function is to get NSID assigned by RTOS with token of a NS thread.
68 */
69int32_t nsid_mgr_query_nsid(uint32_t token);
70
71#ifdef __cplusplus
72}
73#endif
74
75#endif /* __TFM_NSID_MANAGER_H__ */