blob: af2b492c538b74aa496f2045ec3a2fd605493dcf [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 Qin40db9ea2019-11-20 15:28:04 +080061/********************* Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +000062
Mate Toth-Palce61afa2018-08-03 13:51:01 +020063/**
Summer Qin40db9ea2019-11-20 15:28:04 +080064 * \brief Assign client ID to the current TZ context.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020065 *
Summer Qin40db9ea2019-11-20 15:28:04 +080066 * \param[in] ns_client_id The client ID to be assigned to the current
67 * context.
68 * \retval TFM_SUCCESS The client ID assigned successfully.
69 * \retval error code The client ID assignment failed, an error code
70 * returned according to \ref tfm_status_e.
Mate Toth-Palce61afa2018-08-03 13:51:01 +020071 * \note This function have to be called from handler mode.
72 */
73enum tfm_status_e tfm_register_client_id (int32_t ns_client_id);
Ashutosh Singhf4d88672017-11-29 13:35:43 +000074
Miklos Balint87da2512018-04-19 13:45:50 +020075/**
Summer Qin40db9ea2019-11-20 15:28:04 +080076 * \brief Retrieve the version of the PSA Framework API that is implemented.
Edison Aib3e56962018-09-04 19:12:31 +080077 *
Summer Qin40db9ea2019-11-20 15:28:04 +080078 * \return The version of the PSA Framework.
Edison Aib3e56962018-09-04 19:12:31 +080079 */
80uint32_t tfm_psa_framework_version_veneer(void);
81
82/**
Summer Qin40db9ea2019-11-20 15:28:04 +080083 * \brief Return version of secure function provided by secure binary.
Miklos Balint87da2512018-04-19 13:45:50 +020084 *
Summer Qin40db9ea2019-11-20 15:28:04 +080085 * \param[in] sid ID of secure service.
Miklos Balint87da2512018-04-19 13:45:50 +020086 *
Summer Qin40db9ea2019-11-20 15:28:04 +080087 * \return Version number of secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020088 */
89uint32_t tfm_psa_version_veneer(uint32_t sid);
90
91/**
Summer Qin40db9ea2019-11-20 15:28:04 +080092 * \brief Connect to secure function.
Miklos Balint87da2512018-04-19 13:45:50 +020093 *
Summer Qin40db9ea2019-11-20 15:28:04 +080094 * \param[in] sid ID of secure service.
95 * \param[in] version Version of SF requested by client.
Miklos Balint87da2512018-04-19 13:45:50 +020096 *
Summer Qin40db9ea2019-11-20 15:28:04 +080097 * \return Returns handle to connection.
Miklos Balint87da2512018-04-19 13:45:50 +020098 */
Summer Qin4b1d03b2019-07-02 14:56:08 +080099psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version);
Miklos Balint87da2512018-04-19 13:45:50 +0200100
101/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800102 * \brief Call a secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200103 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800104 * \param[in] handle Handle to connection.
105 * \param[in] type The reuqest type. Must be zero(PSA_IPC_CALL) or
106 * positive.
107 * \param[in] in_vec Array of input \ref psa_invec structures.
108 * \param[in] out_vec Array of output \ref psa_invec structures.
Miklos Balint87da2512018-04-19 13:45:50 +0200109 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800110 * \return Returns \ref psa_status_t status code.
Miklos Balint87da2512018-04-19 13:45:50 +0200111 */
Summer Qin4b1d03b2019-07-02 14:56:08 +0800112psa_status_t tfm_psa_call_veneer(psa_handle_t handle, int32_t type,
Summer Qin40db9ea2019-11-20 15:28:04 +0800113 const psa_invec *in_vec,
114 const psa_invec *out_vec);
Miklos Balint87da2512018-04-19 13:45:50 +0200115
116/**
Summer Qin40db9ea2019-11-20 15:28:04 +0800117 * \brief Close connection to secure function referenced by a connection handle.
Miklos Balint87da2512018-04-19 13:45:50 +0200118 *
Summer Qin40db9ea2019-11-20 15:28:04 +0800119 * \param[in] handle Handle to connection
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 */
Edison Aib3e56962018-09-04 19:12:31 +0800123psa_status_t tfm_psa_close_veneer(psa_handle_t handle);
Miklos Balint87da2512018-04-19 13:45:50 +0200124
Summer Qin40db9ea2019-11-20 15:28:04 +0800125/***************** End Secure function declarations ***************************/
Ashutosh Singhf4d88672017-11-29 13:35:43 +0000126
127#ifdef __cplusplus
128}
129#endif
130
131#endif /* __TFM_API_H__ */