blob: 09abc399b176a2c988e64f94891e41de2c0623db [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 *
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,
56 TFM_SECURE_LOCK_FAILED,
57 TFM_SECURE_UNLOCK_FAILED,
58 TFM_ERROR_GENERIC = 0x1F,
Ashutosh Singhf4d88672017-11-29 13:35:43 +000059};
60
Summer Qin83ac1ca2019-09-29 18:33:28 +080061/*
62 * Structure to package type, in_len and out_len, it is mainly used for
63 * psa_call.
64 */
65struct tfm_control_parameter_t {
66 int32_t type;
67 size_t in_len;
68 size_t out_len;
69};
70
Summer Qin40db9ea2019-11-20 15:28:04 +080071/********************* Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +000072
Mate Toth-Palce61afa2018-08-03 13:51:01 +020073/**
Summer Qin40db9ea2019-11-20 15:28:04 +080074 * \brief Assign client ID to the current TZ context.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020075 *
Summer Qin40db9ea2019-11-20 15:28:04 +080076 * \param[in] ns_client_id The client ID to be assigned to the current
77 * context.
78 * \retval TFM_SUCCESS The client ID assigned successfully.
79 * \retval error code The client ID assignment failed, an error code
80 * returned according to \ref tfm_status_e.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020081 * \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/**
Summer Qin40db9ea2019-11-20 15:28:04 +080086 * \brief Retrieve the version of the PSA Framework API that is implemented.
Edison Aib3e56962018-09-04 19:12:31 +080087 *
Summer Qin40db9ea2019-11-20 15:28:04 +080088 * \return The version of the PSA Framework.
Edison Aib3e56962018-09-04 19:12:31 +080089 */
90uint32_t tfm_psa_framework_version_veneer(void);
91
92/**
Summer Qin40db9ea2019-11-20 15:28:04 +080093 * \brief Return version of secure function provided by secure binary.
Miklos Balint87da2512018-04-19 13:45:50 +020094 *
Summer Qin40db9ea2019-11-20 15:28:04 +080095 * \param[in] sid ID of secure service.
Miklos Balint87da2512018-04-19 13:45:50 +020096 *
Summer Qin40db9ea2019-11-20 15:28:04 +080097 * \return Version number of secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020098 */
99uint32_t tfm_psa_version_veneer(uint32_t sid);
100
101/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800102 * \brief Connect to secure function.
Miklos Balint87da2512018-04-19 13:45:50 +0200103 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800104 * \param[in] sid ID of secure service.
105 * \param[in] version Version of SF requested by client.
Miklos Balint87da2512018-04-19 13:45:50 +0200106 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800107 * \return Returns handle to connection.
Miklos Balint87da2512018-04-19 13:45:50 +0200108 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800109psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version);
Miklos Balint87da2512018-04-19 13:45:50 +0200110
111/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800112 * \brief Call a secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200113 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800114 * \param[in] handle Handle to connection.
Summer Qin83ac1ca2019-09-29 18:33:28 +0800115 * \param[in] ctrl_param Parameter structure, includes reuqest type,
116 * in_num and out_num.
Summer Qin40db9ea2019-11-20 15:28:04 +0800117 * \param[in] in_vec Array of input \ref psa_invec structures.
Summer Qin83ac1ca2019-09-29 18:33:28 +0800118 * \param[in/out] out_vec Array of output \ref psa_outvec structures.
Miklos Balint87da2512018-04-19 13:45:50 +0200119 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800120 * \return Returns \ref psa_status_t status code.
Miklos Balint87da2512018-04-19 13:45:50 +0200121 */
Summer Qin83ac1ca2019-09-29 18:33:28 +0800122psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
123 const struct tfm_control_parameter_t *ctrl_param,
124 const psa_invec *in_vec,
125 psa_outvec *out_vec);
Miklos Balint87da2512018-04-19 13:45:50 +0200126
127/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800128 * \brief Close connection to secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200129 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800130 * \param[in] handle Handle to connection
Miklos Balint87da2512018-04-19 13:45:50 +0200131 *
Summer Qin483da642019-09-25 17:57:41 +0800132 * \return void
Miklos Balint87da2512018-04-19 13:45:50 +0200133 */
Summer Qin483da642019-09-25 17:57:41 +0800134void tfm_psa_close_veneer(psa_handle_t handle);
Miklos Balint87da2512018-04-19 13:45:50 +0200135
Summer Qin40db9ea2019-11-20 15:28:04 +0800136/***************** End Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000137
138#ifdef __cplusplus
139}
140#endif
141
142#endif /* __TFM_API_H__ */