Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 1 | /* |
Shawn Shan | 7ef79ec | 2021-01-21 10:28:18 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2021, Arm Limited. All rights reserved. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_API_H__ |
| 9 | #define __TFM_API_H__ |
| 10 | |
| 11 | #ifdef __cplusplus |
| 12 | extern "C" { |
| 13 | #endif |
| 14 | |
Mate Toth-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 15 | #include <stdint.h> |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 16 | #include "psa/client.h" |
Miklos Balint | bf25a40 | 2018-06-14 17:43:54 +0200 | [diff] [blame] | 17 | |
Mate Toth-Pal | 261df46 | 2018-08-07 12:02:42 +0200 | [diff] [blame] | 18 | #define TFM_INVALID_CLIENT_ID 0 |
| 19 | |
| 20 | /** |
| 21 | * \brief Checks if the provided client ID is a secure client ID. |
| 22 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 23 | * \param[in] client_id Client ID to check. |
Mate Toth-Pal | 261df46 | 2018-08-07 12:02:42 +0200 | [diff] [blame] | 24 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 25 | * \retval 1 Client ID is secure. |
| 26 | * \retval 0 Client ID is non-secure. |
Mate Toth-Pal | 261df46 | 2018-08-07 12:02:42 +0200 | [diff] [blame] | 27 | */ |
| 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 Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 33 | * \param[in] client_id Client ID to check. |
Mate Toth-Pal | 261df46 | 2018-08-07 12:02:42 +0200 | [diff] [blame] | 34 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 35 | * \retval 1 Client ID is non-secure. |
| 36 | * \retval 0 Client ID is secure. |
Mate Toth-Pal | 261df46 | 2018-08-07 12:02:42 +0200 | [diff] [blame] | 37 | */ |
| 38 | #define TFM_CLIENT_ID_IS_NS(client_id) ((client_id)<0) |
| 39 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 40 | /* The mask used for timeout values */ |
| 41 | #define PSA_TIMEOUT_MASK PSA_BLOCK |
| 42 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 43 | /* FixMe: sort out DEBUG compile option and limit return value options |
| 44 | * on external interfaces */ |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 45 | enum tfm_status_e |
| 46 | { |
| 47 | TFM_SUCCESS = 0, |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 48 | TFM_PARTITION_BUSY, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 49 | TFM_ERROR_SECURE_DOMAIN_LOCKED, |
| 50 | TFM_ERROR_INVALID_PARAMETER, |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 51 | TFM_ERROR_PARTITION_NON_REENTRANT, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 52 | TFM_ERROR_NS_THREAD_MODE_CALL, |
Miklos Balint | 1fdb12f | 2018-09-11 11:30:30 +0200 | [diff] [blame] | 53 | TFM_ERROR_NOT_INITIALIZED, |
| 54 | TFM_ERROR_NO_ACTIVE_PARTITION, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 55 | TFM_ERROR_INVALID_EXC_MODE, |
Antonio de Angelis | f8564cb | 2021-04-28 13:52:13 +0100 | [diff] [blame] | 56 | TFM_ERROR_NOT_IN_RANGE, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 57 | TFM_SECURE_LOCK_FAILED, |
| 58 | TFM_SECURE_UNLOCK_FAILED, |
| 59 | TFM_ERROR_GENERIC = 0x1F, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
Summer Qin | 83ac1ca | 2019-09-29 18:33:28 +0800 | [diff] [blame] | 62 | /* |
| 63 | * Structure to package type, in_len and out_len, it is mainly used for |
| 64 | * psa_call. |
| 65 | */ |
| 66 | struct tfm_control_parameter_t { |
| 67 | int32_t type; |
| 68 | size_t in_len; |
| 69 | size_t out_len; |
| 70 | }; |
| 71 | |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 72 | /********************* Secure function declarations ***************************/ |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 73 | |
Mate Toth-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 74 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 75 | * \brief Assign client ID to the current TZ context. |
Mate Toth-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 76 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 77 | * \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-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 82 | * \note This function have to be called from handler mode. |
| 83 | */ |
| 84 | enum tfm_status_e tfm_register_client_id (int32_t ns_client_id); |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 85 | |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 86 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 87 | * \brief Retrieve the version of the PSA Framework API that is implemented. |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 88 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 89 | * \return The version of the PSA Framework. |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 90 | */ |
| 91 | uint32_t tfm_psa_framework_version_veneer(void); |
| 92 | |
| 93 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 94 | * \brief Return version of secure function provided by secure binary. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 95 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 96 | * \param[in] sid ID of secure service. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 97 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 98 | * \return Version number of secure function. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 99 | */ |
| 100 | uint32_t tfm_psa_version_veneer(uint32_t sid); |
| 101 | |
| 102 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 103 | * \brief Connect to secure function. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 104 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 105 | * \param[in] sid ID of secure service. |
| 106 | * \param[in] version Version of SF requested by client. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 107 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 108 | * \return Returns handle to connection. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 109 | */ |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame] | 110 | psa_handle_t tfm_psa_connect_veneer(uint32_t sid, uint32_t version); |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 111 | |
| 112 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 113 | * \brief Call a secure function referenced by a connection handle. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 114 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 115 | * \param[in] handle Handle to connection. |
Xinyu Zhang | 99b069f | 2021-04-09 14:36:42 +0800 | [diff] [blame] | 116 | * \param[in] ctrl_param Parameters combined in uint32_t, |
| 117 | * includes request type, in_num and out_num. |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 118 | * \param[in] in_vec Array of input \ref psa_invec structures. |
Shawn Shan | 7ef79ec | 2021-01-21 10:28:18 +0800 | [diff] [blame] | 119 | * \param[in,out] out_vec Array of output \ref psa_outvec structures. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 120 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 121 | * \return Returns \ref psa_status_t status code. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 122 | */ |
Summer Qin | 83ac1ca | 2019-09-29 18:33:28 +0800 | [diff] [blame] | 123 | psa_status_t tfm_psa_call_veneer(psa_handle_t handle, |
Xinyu Zhang | 99b069f | 2021-04-09 14:36:42 +0800 | [diff] [blame] | 124 | uint32_t ctrl_param, |
| 125 | const psa_invec *in_vec, |
| 126 | psa_outvec *out_vec); |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 127 | |
| 128 | /** |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 129 | * \brief Close connection to secure function referenced by a connection handle. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 130 | * |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 131 | * \param[in] handle Handle to connection |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 132 | */ |
Summer Qin | 483da64 | 2019-09-25 17:57:41 +0800 | [diff] [blame] | 133 | void tfm_psa_close_veneer(psa_handle_t handle); |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 134 | |
Summer Qin | 40db9ea | 2019-11-20 15:28:04 +0800 | [diff] [blame] | 135 | /***************** End Secure function declarations ***************************/ |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 136 | |
| 137 | #ifdef __cplusplus |
| 138 | } |
| 139 | #endif |
| 140 | |
| 141 | #endif /* __TFM_API_H__ */ |