1 /*
2  * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __TFM_API_H__
9 #define __TFM_API_H__
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 #include <stdint.h>
16 #include "psa/client.h"
17 
18 #define TFM_INVALID_CLIENT_ID 0
19 
20 /**
21  * \brief Checks if the provided client ID is a secure client ID.
22  *
23  * \param[in] client_id         Client ID to check.
24  *
25  * \retval 1                    Client ID is secure.
26  * \retval 0                    Client ID is non-secure.
27  */
28 #define TFM_CLIENT_ID_IS_S(client_id)  ((client_id)>0)
29 
30 /**
31  * \brief Checks if the provided client ID is a non-secure client ID.
32  *
33  * \param[in] client_id         Client ID to check.
34  *
35  * \retval 1                    Client ID is non-secure.
36  * \retval 0                    Client ID is secure.
37  */
38 #define TFM_CLIENT_ID_IS_NS(client_id) ((client_id)<0)
39 
40 /* The mask used for timeout values */
41 #define PSA_TIMEOUT_MASK        PSA_BLOCK
42 
43 /* FixMe: sort out DEBUG compile option and limit return value options
44  * on external interfaces */
45 enum tfm_status_e
46 {
47     TFM_SUCCESS = 0,
48     TFM_PARTITION_BUSY,
49     TFM_ERROR_SECURE_DOMAIN_LOCKED,
50     TFM_ERROR_INVALID_PARAMETER,
51     TFM_ERROR_PARTITION_NON_REENTRANT,
52     TFM_ERROR_NS_THREAD_MODE_CALL,
53     TFM_ERROR_NOT_INITIALIZED,
54     TFM_ERROR_NO_ACTIVE_PARTITION,
55     TFM_ERROR_INVALID_EXC_MODE,
56     TFM_ERROR_NOT_IN_RANGE,
57     TFM_SECURE_LOCK_FAILED,
58     TFM_SECURE_UNLOCK_FAILED,
59     TFM_ERROR_GENERIC = 0x1F,
60 };
61 
62 /********************* Secure function declarations ***************************/
63 
64 /**
65  * \brief Retrieve the version of the PSA Framework API that is implemented.
66  *
67  * \return The version of the PSA Framework.
68  */
69 uint32_t tfm_psa_framework_version_veneer(void);
70 
71 /**
72  * \brief Return version of secure function provided by secure binary.
73  *
74  * \param[in] sid               ID of secure service.
75  *
76  * \return Version number of secure function.
77  */
78 uint32_t tfm_psa_version_veneer(uint32_t sid);
79 
80 /**
81  * \brief Connect to secure function.
82  *
83  * \param[in] sid               ID of secure service.
84  * \param[in] version           Version of SF requested by client.
85  *
86  * \return Returns handle to connection.
87  */
88 psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version);
89 
90 /**
91  * \brief Call a secure function referenced by a connection handle.
92  *
93  * \param[in] handle            Handle to connection.
94  * \param[in] ctrl_param        Parameters combined in uint32_t,
95  *                              includes request type, in_num and out_num.
96  * \param[in] in_vec            Array of input \ref psa_invec structures.
97  * \param[in,out] out_vec       Array of output \ref psa_outvec structures.
98  *
99  * \return Returns \ref psa_status_t status code.
100  */
101 psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
102                                  uint32_t ctrl_param,
103                                  const psa_invec *in_vec,
104                                  psa_outvec *out_vec);
105 
106 /**
107  * \brief Close connection to secure function referenced by a connection handle.
108  *
109  * \param[in] handle            Handle to connection
110  */
111 void tfm_psa_close_veneer(psa_handle_t handle);
112 
113 /***************** End Secure function declarations ***************************/
114 
115 #ifdef __cplusplus
116 }
117 #endif
118 
119 #endif /* __TFM_API_H__ */
120