blob: 7e7974605dd4e7fa4e2b8af82ddcc94666ec783f [file] [log] [blame]
Ashutosh Singhf4d88672017-11-29 13:35:43 +00001/*
Summer Qin484513b2022-10-09 17:40:24 +08002 * Copyright (c) 2017-2022, 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 Qin40db9ea2019-11-20 15:28:04 +080062/********************* Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +000063
Mate Toth-Palce61afa2018-08-03 13:51:01 +020064/**
Summer Qin40db9ea2019-11-20 15:28:04 +080065 * \brief Retrieve the version of the PSA Framework API that is implemented.
Edison Aib3e56962018-09-04 19:12:31 +080066 *
Summer Qin40db9ea2019-11-20 15:28:04 +080067 * \return The version of the PSA Framework.
Edison Aib3e56962018-09-04 19:12:31 +080068 */
69uint32_t tfm_psa_framework_version_veneer(void);
70
71/**
Summer Qin40db9ea2019-11-20 15:28:04 +080072 * \brief Return version of secure function provided by secure binary.
Miklos Balint87da2512018-04-19 13:45:50 +020073 *
Summer Qin40db9ea2019-11-20 15:28:04 +080074 * \param[in] sid ID of secure service.
Miklos Balint87da2512018-04-19 13:45:50 +020075 *
Summer Qin40db9ea2019-11-20 15:28:04 +080076 * \return Version number of secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020077 */
78uint32_t tfm_psa_version_veneer(uint32_t sid);
79
80/**
Summer Qin40db9ea2019-11-20 15:28:04 +080081 * \brief Connect to secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020082 *
Summer Qin40db9ea2019-11-20 15:28:04 +080083 * \param[in] sid ID of secure service.
84 * \param[in] version Version of SF requested by client.
Miklos Balint87da2512018-04-19 13:45:50 +020085 *
Summer Qin40db9ea2019-11-20 15:28:04 +080086 * \return Returns handle to connection.
Miklos Balint87da2512018-04-19 13:45:50 +020087 */
Summer Qin4b1d03b2019-07-02 14:56:08 +080088psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version);
Miklos Balint87da2512018-04-19 13:45:50 +020089
90/**
Summer Qin40db9ea2019-11-20 15:28:04 +080091 * \brief Call a secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +020092 *
Summer Qin40db9ea2019-11-20 15:28:04 +080093 * \param[in] handle Handle to connection.
Xinyu Zhang99b069f2021-04-09 14:36:42 +080094 * \param[in] ctrl_param Parameters combined in uint32_t,
95 * includes request type, in_num and out_num.
Summer Qin40db9ea2019-11-20 15:28:04 +080096 * \param[in] in_vec Array of input \ref psa_invec structures.
Shawn Shan7ef79ec2021-01-21 10:28:18 +080097 * \param[in,out] out_vec Array of output \ref psa_outvec structures.
Miklos Balint87da2512018-04-19 13:45:50 +020098 *
Summer Qin40db9ea2019-11-20 15:28:04 +080099 * \return Returns \ref psa_status_t status code.
Miklos Balint87da2512018-04-19 13:45:50 +0200100 */
Summer Qin83ac1ca2019-09-29 18:33:28 +0800101psa_status_t tfm_psa_call_veneer(psa_handle_t handle,
Xinyu Zhang99b069f2021-04-09 14:36:42 +0800102 uint32_t ctrl_param,
103 const psa_invec *in_vec,
104 psa_outvec *out_vec);
Miklos Balint87da2512018-04-19 13:45:50 +0200105
106/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800107 * \brief Close connection to secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200108 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800109 * \param[in] handle Handle to connection
Miklos Balint87da2512018-04-19 13:45:50 +0200110 */
Summer Qin483da642019-09-25 17:57:41 +0800111void tfm_psa_close_veneer(psa_handle_t handle);
Miklos Balint87da2512018-04-19 13:45:50 +0200112
Summer Qin40db9ea2019-11-20 15:28:04 +0800113/***************** End Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000114
115#ifdef __cplusplus
116}
117#endif
118
119#endif /* __TFM_API_H__ */