blob: 5a56ec79b502480053e637b3d2d5103286ec59b0 [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +01002 * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
Ashutosh Singhf4d88672017-11-29 13:35:43 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __TFM_API_H__
9#define __TFM_API_H__
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
Mate Toth-Palce61afa2018-08-03 13:51:01 +020015#include <stdint.h>
Jamie Foxcc31d402019-01-28 17:13:52 +000016#include "psa/client.h"
Miklos Balintbf25a402018-06-14 17:43:54 +020017
Mate Toth-Pal261df462018-08-07 12:02:42 +020018#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 * \return Returns 1 if the client Id is secure. Otherwise, returns 0.
26 */
27#define TFM_CLIENT_ID_IS_S(client_id) ((client_id)>0)
28
29/**
30 * \brief Checks if the provided client ID is a non-secure client ID.
31 *
32 * \param[in] client_id Client ID to check
33 *
34 * \return Returns 1 if the client Id is non-secure. Otherwise, returns 0.
35 */
36#define TFM_CLIENT_ID_IS_NS(client_id) ((client_id)<0)
37
Mate Toth-Palb8ce0dd2018-07-25 10:18:34 +020038/* Maximum number of input and output vectors */
39#define PSA_MAX_IOVEC (4)
40
Mate Toth-Pal4341de02018-10-02 12:55:47 +020041/* The mask used for timeout values */
42#define PSA_TIMEOUT_MASK PSA_BLOCK
43
Ashutosh Singhf4d88672017-11-29 13:35:43 +000044/* FixMe: sort out DEBUG compile option and limit return value options
45 * on external interfaces */
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010046/* For secure functions using prorietary signatures
Ashutosh Singhf4d88672017-11-29 13:35:43 +000047 * TFM will only return values recognized and parsed by TFM core.
48 * Service return codes are not automatically passed on to REE.
49 * Any non-zero return value is interpreted as an error that may trigger
50 * TEE error handling flow.
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010051 * For secure functions using the veneers in secure_fw/ns_callable/tfm_veneers.c
52 * (iovec API) this limitation does not apply.
Ashutosh Singhf4d88672017-11-29 13:35:43 +000053 */
54enum tfm_status_e
55{
56 TFM_SUCCESS = 0,
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010057 TFM_PARTITION_BUSY,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000058 TFM_ERROR_SECURE_DOMAIN_LOCKED,
59 TFM_ERROR_INVALID_PARAMETER,
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010060 TFM_ERROR_PARTITION_NON_REENTRANT,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000061 TFM_ERROR_NS_THREAD_MODE_CALL,
Miklos Balint1fdb12f2018-09-11 11:30:30 +020062 TFM_ERROR_NOT_INITIALIZED,
63 TFM_ERROR_NO_ACTIVE_PARTITION,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000064 TFM_ERROR_INVALID_EXC_MODE,
65 TFM_SECURE_LOCK_FAILED,
66 TFM_SECURE_UNLOCK_FAILED,
67 TFM_ERROR_GENERIC = 0x1F,
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010068 TFM_PARTITION_SPECIFIC_ERROR_MIN,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000069};
70
71//==================== Secure function declarations ==========================//
72
Mate Toth-Palce61afa2018-08-03 13:51:01 +020073/**
74 * \brief Assign client ID to the current TZ context
75 *
76 * \param[in] ns_client_id The client ID to be assigned to the current
77 * context
78 * \return TFM_SUCCESS if the client ID assigned successfully, an error code
79 * according to \ref tfm_status_e in case of error.
80 *
81 * \note This function have to be called from handler mode.
82 */
83enum tfm_status_e tfm_register_client_id (int32_t ns_client_id);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000084
Miklos Balint87da2512018-04-19 13:45:50 +020085/**
Edison Aib3e56962018-09-04 19:12:31 +080086 * \brief Retrieve the version of the PSA Framework API that is implemented
87 *
88 * \return The version of the PSA Framework
89 */
90uint32_t tfm_psa_framework_version_veneer(void);
91
92/**
Miklos Balint87da2512018-04-19 13:45:50 +020093 * \brief Return version of secure function provided by secure binary
94 *
95 * \param[in] sid ID of secure service
96 *
97 * \return Version number of secure function
98 */
99uint32_t tfm_psa_version_veneer(uint32_t sid);
100
101/**
102 * \brief Connect to secure function
103 *
104 * \param[in] sid ID of secure service
105 * \param[in] minor_version Minor version of SF requested by client
106 *
107 * \return Returns handle to connection
108 */
109psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t minor_version);
110
111/**
112 * \brief Call a secure function referenced by a connection handle
113 *
114 * \param[in] handle Handle to connection
115 * \param[in] in_vecs invec containing pointer/count of input vectors
116 * \param[in] out_vecs invec containing pointer/count of output vectors
117 *
Edison Aib3e56962018-09-04 19:12:31 +0800118 * \return Returns \ref psa_status_t status code
Miklos Balint87da2512018-04-19 13:45:50 +0200119 */
Edison Aib3e56962018-09-04 19:12:31 +0800120psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
121 const psa_invec *in_vecs,
122 const psa_invec *out_vecs);
Miklos Balint87da2512018-04-19 13:45:50 +0200123
124/**
125 * \brief Close connection to secure function referenced by a connection handle
126 *
127 * \param[in] handle Handle to connection
128 *
Edison Aib3e56962018-09-04 19:12:31 +0800129 * \return Returns \ref psa_status_t status code
Miklos Balint87da2512018-04-19 13:45:50 +0200130 */
Edison Aib3e56962018-09-04 19:12:31 +0800131psa_status_t tfm_psa_close_veneer(psa_handle_t handle);
Miklos Balint87da2512018-04-19 13:45:50 +0200132
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000133//================ End Secure function declarations ==========================//
134
135#ifdef __cplusplus
136}
137#endif
138
139#endif /* __TFM_API_H__ */