blob: 1d4c9ee5a7bc4d4deb7853a370063c3c45cebd50 [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Shawn Shan7ef79ec2021-01-21 10:28:18 +08002 * Copyright (c) 2017-2021, 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 *
Summer Qin40db9ea2019-11-20 15:28:04 +080023 * \param[in] client_id Client ID to check.
Mate Toth-Pal261df462018-08-07 12:02:42 +020024 *
Summer Qin40db9ea2019-11-20 15:28:04 +080025 * \retval 1 Client ID is secure.
26 * \retval 0 Client ID is non-secure.
Mate Toth-Pal261df462018-08-07 12:02:42 +020027 */
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 *
Summer Qin40db9ea2019-11-20 15:28:04 +080033 * \param[in] client_id Client ID to check.
Mate Toth-Pal261df462018-08-07 12:02:42 +020034 *
Summer Qin40db9ea2019-11-20 15:28:04 +080035 * \retval 1 Client ID is non-secure.
36 * \retval 0 Client ID is secure.
Mate Toth-Pal261df462018-08-07 12:02:42 +020037 */
38#define TFM_CLIENT_ID_IS_NS(client_id) ((client_id)<0)
39
Mate Toth-Pal4341de02018-10-02 12:55:47 +020040/* The mask used for timeout values */
41#define PSA_TIMEOUT_MASK PSA_BLOCK
42
Ashutosh Singhf4d88672017-11-29 13:35:43 +000043/* FixMe: sort out DEBUG compile option and limit return value options
44 * on external interfaces */
Ashutosh Singhf4d88672017-11-29 13:35:43 +000045enum tfm_status_e
46{
47 TFM_SUCCESS = 0,
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010048 TFM_PARTITION_BUSY,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000049 TFM_ERROR_SECURE_DOMAIN_LOCKED,
50 TFM_ERROR_INVALID_PARAMETER,
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010051 TFM_ERROR_PARTITION_NON_REENTRANT,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000052 TFM_ERROR_NS_THREAD_MODE_CALL,
Miklos Balint1fdb12f2018-09-11 11:30:30 +020053 TFM_ERROR_NOT_INITIALIZED,
54 TFM_ERROR_NO_ACTIVE_PARTITION,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000055 TFM_ERROR_INVALID_EXC_MODE,
Antonio de Angelisf8564cb2021-04-28 13:52:13 +010056 TFM_ERROR_NOT_IN_RANGE,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000057 TFM_SECURE_LOCK_FAILED,
58 TFM_SECURE_UNLOCK_FAILED,
59 TFM_ERROR_GENERIC = 0x1F,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000060};
61
Summer Qin83ac1ca2019-09-29 18:33:28 +080062/*
63 * Structure to package type, in_len and out_len, it is mainly used for
64 * psa_call.
65 */
66struct tfm_control_parameter_t {
67 int32_t type;
68 size_t in_len;
69 size_t out_len;
70};
71
Summer Qin40db9ea2019-11-20 15:28:04 +080072/********************* Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +000073
Mate Toth-Palce61afa2018-08-03 13:51:01 +020074/**
Summer Qin40db9ea2019-11-20 15:28:04 +080075 * \brief Assign client ID to the current TZ context.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020076 *
Summer Qin40db9ea2019-11-20 15:28:04 +080077 * \param[in] ns_client_id The client ID to be assigned to the current
78 * context.
79 * \retval TFM_SUCCESS The client ID assigned successfully.
80 * \retval error code The client ID assignment failed, an error code
81 * returned according to \ref tfm_status_e.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020082 * \note This function have to be called from handler mode.
83 */
84enum tfm_status_e tfm_register_client_id (int32_t ns_client_id);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000085
Miklos Balint87da2512018-04-19 13:45:50 +020086/**
Summer Qin40db9ea2019-11-20 15:28:04 +080087 * \brief Retrieve the version of the PSA Framework API that is implemented.
Edison Aib3e56962018-09-04 19:12:31 +080088 *
Summer Qin40db9ea2019-11-20 15:28:04 +080089 * \return The version of the PSA Framework.
Edison Aib3e56962018-09-04 19:12:31 +080090 */
91uint32_t tfm_psa_framework_version_veneer(void);
92
93/**
Summer Qin40db9ea2019-11-20 15:28:04 +080094 * \brief Return version of secure function provided by secure binary.
Miklos Balint87da2512018-04-19 13:45:50 +020095 *
Summer Qin40db9ea2019-11-20 15:28:04 +080096 * \param[in] sid ID of secure service.
Miklos Balint87da2512018-04-19 13:45:50 +020097 *
Summer Qin40db9ea2019-11-20 15:28:04 +080098 * \return Version number of secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020099 */
100uint32_t tfm_psa_version_veneer(uint32_t sid);
101
102/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800103 * \brief Connect to secure function.
Miklos Balint87da2512018-04-19 13:45:50 +0200104 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800105 * \param[in] sid ID of secure service.
106 * \param[in] version Version of SF requested by client.
Miklos Balint87da2512018-04-19 13:45:50 +0200107 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800108 * \return Returns handle to connection.
Miklos Balint87da2512018-04-19 13:45:50 +0200109 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800110psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version);
Miklos Balint87da2512018-04-19 13:45:50 +0200111
112/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800113 * \brief Call a secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200114 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800115 * \param[in] handle Handle to connection.
Xinyu Zhang99b069f2021-04-09 14:36:42 +0800116 * \param[in] ctrl_param Parameters combined in uint32_t,
117 * includes request type, in_num and out_num.
Summer Qin40db9ea2019-11-20 15:28:04 +0800118 * \param[in] in_vec Array of input \ref psa_invec structures.
Shawn Shan7ef79ec2021-01-21 10:28:18 +0800119 * \param[in,out] out_vec Array of output \ref psa_outvec structures.
Miklos Balint87da2512018-04-19 13:45:50 +0200120 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800121 * \return Returns \ref psa_status_t status code.
Miklos Balint87da2512018-04-19 13:45:50 +0200122 */
Summer Qin83ac1ca2019-09-29 18:33:28 +0800123psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
Xinyu Zhang99b069f2021-04-09 14:36:42 +0800124 uint32_t ctrl_param,
125 const psa_invec *in_vec,
126 psa_outvec *out_vec);
Miklos Balint87da2512018-04-19 13:45:50 +0200127
128/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800129 * \brief Close connection to secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200130 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800131 * \param[in] handle Handle to connection
Miklos Balint87da2512018-04-19 13:45:50 +0200132 */
Summer Qin483da642019-09-25 17:57:41 +0800133void tfm_psa_close_veneer(psa_handle_t handle);
Miklos Balint87da2512018-04-19 13:45:50 +0200134
Summer Qin40db9ea2019-11-20 15:28:04 +0800135/***************** End Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000136
137#ifdef __cplusplus
138}
139#endif
140
141#endif /* __TFM_API_H__ */