Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, 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 | * |
| 23 | * \param[in] client_id Client ID to check |
| 24 | * |
| 25 | * \return Returns 1 if the client Id is secure. Otherwise, returns 0. |
| 26 | */ |
| 27 | #define TFM_CLIENT_ID_IS_S(client_id) ((client_id)>0) |
| 28 | |
| 29 | /** |
| 30 | * \brief Checks if the provided client ID is a non-secure client ID. |
| 31 | * |
| 32 | * \param[in] client_id Client ID to check |
| 33 | * |
| 34 | * \return Returns 1 if the client Id is non-secure. Otherwise, returns 0. |
| 35 | */ |
| 36 | #define TFM_CLIENT_ID_IS_NS(client_id) ((client_id)<0) |
| 37 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 38 | /* The mask used for timeout values */ |
| 39 | #define PSA_TIMEOUT_MASK PSA_BLOCK |
| 40 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 41 | /* FixMe: sort out DEBUG compile option and limit return value options |
| 42 | * on external interfaces */ |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 43 | /* For secure functions using prorietary signatures |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 44 | * TFM will only return values recognized and parsed by TFM core. |
| 45 | * Service return codes are not automatically passed on to REE. |
| 46 | * Any non-zero return value is interpreted as an error that may trigger |
| 47 | * TEE error handling flow. |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 48 | * For secure functions using the veneers in secure_fw/ns_callable/tfm_veneers.c |
| 49 | * (iovec API) this limitation does not apply. |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 50 | */ |
| 51 | enum tfm_status_e |
| 52 | { |
| 53 | TFM_SUCCESS = 0, |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 54 | TFM_PARTITION_BUSY, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 55 | TFM_ERROR_SECURE_DOMAIN_LOCKED, |
| 56 | TFM_ERROR_INVALID_PARAMETER, |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 57 | TFM_ERROR_PARTITION_NON_REENTRANT, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 58 | TFM_ERROR_NS_THREAD_MODE_CALL, |
Miklos Balint | 1fdb12f | 2018-09-11 11:30:30 +0200 | [diff] [blame] | 59 | TFM_ERROR_NOT_INITIALIZED, |
| 60 | TFM_ERROR_NO_ACTIVE_PARTITION, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 61 | TFM_ERROR_INVALID_EXC_MODE, |
| 62 | TFM_SECURE_LOCK_FAILED, |
| 63 | TFM_SECURE_UNLOCK_FAILED, |
| 64 | TFM_ERROR_GENERIC = 0x1F, |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 65 | TFM_PARTITION_SPECIFIC_ERROR_MIN, |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 66 | }; |
| 67 | |
| 68 | //==================== Secure function declarations ==========================// |
| 69 | |
Mate Toth-Pal | ce61afa | 2018-08-03 13:51:01 +0200 | [diff] [blame] | 70 | /** |
| 71 | * \brief Assign client ID to the current TZ context |
| 72 | * |
| 73 | * \param[in] ns_client_id The client ID to be assigned to the current |
| 74 | * context |
| 75 | * \return TFM_SUCCESS if the client ID assigned successfully, an error code |
| 76 | * according to \ref tfm_status_e in case of error. |
| 77 | * |
| 78 | * \note This function have to be called from handler mode. |
| 79 | */ |
| 80 | 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] | 81 | |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 82 | /** |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 83 | * \brief Retrieve the version of the PSA Framework API that is implemented |
| 84 | * |
| 85 | * \return The version of the PSA Framework |
| 86 | */ |
| 87 | uint32_t tfm_psa_framework_version_veneer(void); |
| 88 | |
| 89 | /** |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 90 | * \brief Return version of secure function provided by secure binary |
| 91 | * |
| 92 | * \param[in] sid ID of secure service |
| 93 | * |
| 94 | * \return Version number of secure function |
| 95 | */ |
| 96 | uint32_t tfm_psa_version_veneer(uint32_t sid); |
| 97 | |
| 98 | /** |
| 99 | * \brief Connect to secure function |
| 100 | * |
| 101 | * \param[in] sid ID of secure service |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame^] | 102 | * \param[in] version Version of SF requested by client |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 103 | * |
| 104 | * \return Returns handle to connection |
| 105 | */ |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame^] | 106 | 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] | 107 | |
| 108 | /** |
| 109 | * \brief Call a secure function referenced by a connection handle |
| 110 | * |
| 111 | * \param[in] handle Handle to connection |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame^] | 112 | * \param[in] type The reuqest type. Must be zero(PSA_IPC_CALL) or |
| 113 | * positive. |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 114 | * \param[in] in_vecs invec containing pointer/count of input vectors |
| 115 | * \param[in] out_vecs invec containing pointer/count of output vectors |
| 116 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 117 | * \return Returns \ref psa_status_t status code |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 118 | */ |
Summer Qin | 4b1d03b | 2019-07-02 14:56:08 +0800 | [diff] [blame^] | 119 | psa_status_t tfm_psa_call_veneer(psa_handle_t handle, int32_t type, |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 120 | const psa_invec *in_vecs, |
| 121 | const psa_invec *out_vecs); |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 122 | |
| 123 | /** |
| 124 | * \brief Close connection to secure function referenced by a connection handle |
| 125 | * |
| 126 | * \param[in] handle Handle to connection |
| 127 | * |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 128 | * \return Returns \ref psa_status_t status code |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 129 | */ |
Edison Ai | b3e5696 | 2018-09-04 19:12:31 +0800 | [diff] [blame] | 130 | psa_status_t tfm_psa_close_veneer(psa_handle_t handle); |
Miklos Balint | 87da251 | 2018-04-19 13:45:50 +0200 | [diff] [blame] | 131 | |
Ashutosh Singh | f4d8867 | 2017-11-29 13:35:43 +0000 | [diff] [blame] | 132 | //================ End Secure function declarations ==========================// |
| 133 | |
| 134 | #ifdef __cplusplus |
| 135 | } |
| 136 | #endif |
| 137 | |
| 138 | #endif /* __TFM_API_H__ */ |