Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Gyorgy Szing | 40a7af0 | 2019-02-06 14:19:47 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, Arm Limited. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __SPM_API_H__ |
| 9 | #define __SPM_API_H__ |
| 10 | |
| 11 | /* This file contains the apis exported by the SPM to tfm core */ |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 12 | #include "tfm_api.h" |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 13 | #include "spm_partition_defs.h" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 14 | #include "secure_fw/core/tfm_secure_api.h" |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 15 | #include <stdbool.h> |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 16 | #ifdef TFM_PSA_API |
| 17 | #include "tfm_list.h" |
| 18 | #include "tfm_wait.h" |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 19 | #include "tfm_message_queue.h" |
| 20 | #include "tfm_secure_api.h" |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 21 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 22 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 23 | #define SPM_INVALID_PARTITION_IDX (~0U) |
| 24 | |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 25 | /* Privileged definitions for partition thread mode */ |
| 26 | #define TFM_PARTITION_PRIVILEGED_MODE 1 |
| 27 | #define TFM_PARTITION_UNPRIVILEGED_MODE 0 |
| 28 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 29 | enum spm_err_t { |
| 30 | SPM_ERR_OK = 0, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 31 | SPM_ERR_PARTITION_DB_NOT_INIT, |
| 32 | SPM_ERR_PARTITION_ALREADY_ACTIVE, |
| 33 | SPM_ERR_PARTITION_NOT_AVAILABLE, |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 34 | SPM_ERR_INVALID_PARAMETER, |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 35 | SPM_ERR_INVALID_CONFIG, |
| 36 | }; |
| 37 | |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 38 | #define SPM_PARTITION_STATE_UNINIT 0 |
| 39 | #define SPM_PARTITION_STATE_IDLE 1 |
| 40 | #define SPM_PARTITION_STATE_RUNNING 2 |
| 41 | #define SPM_PARTITION_STATE_HANDLING_IRQ 3 |
| 42 | #define SPM_PARTITION_STATE_SUSPENDED 4 |
| 43 | #define SPM_PARTITION_STATE_BLOCKED 5 |
| 44 | #define SPM_PARTITION_STATE_CLOSED 6 |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 45 | |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 46 | #define SPM_PART_FLAG_APP_ROT 0x01 |
| 47 | #define SPM_PART_FLAG_PSA_ROT 0x02 |
| 48 | #define SPM_PART_FLAG_IPC 0x04 |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 49 | |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 50 | #ifndef TFM_PSA_API |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 51 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 52 | * \brief Holds the iovec parameters that are passed to a service |
| 53 | * |
| 54 | * \note The size of the structure is (and have to be) multiple of 8 bytes |
| 55 | */ |
| 56 | struct iovec_args_t { |
| 57 | psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */ |
| 58 | size_t in_len; /*!< Number psa_invec objects in in_vec |
| 59 | */ |
| 60 | psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */ |
| 61 | size_t out_len; /*!< Number psa_outvec objects in out_vec |
| 62 | */ |
| 63 | }; |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 64 | |
| 65 | /* The size of this struct must be multiple of 4 bytes as it is stacked to an |
| 66 | * uint32_t[] array |
| 67 | */ |
| 68 | struct interrupted_ctx_stack_frame_t { |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 69 | uint32_t partition_state; |
| 70 | }; |
| 71 | |
| 72 | /* The size of this struct must be multiple of 4 bytes as it is stacked to an |
| 73 | * uint32_t[] array |
| 74 | */ |
| 75 | struct handler_ctx_stack_frame_t { |
| 76 | uint32_t partition_state; |
| 77 | uint32_t caller_partition_idx; |
| 78 | }; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 79 | #endif /* !define(TFM_PSA_API) */ |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 80 | |
| 81 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 82 | * \brief Runtime context information of a partition |
| 83 | */ |
| 84 | struct spm_partition_runtime_data_t { |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 85 | #ifdef TFM_PSA_API |
| 86 | struct tfm_event_t signal_evnt; /* Event signal */ |
| 87 | uint32_t signals; /* Service signals had been triggered*/ |
| 88 | struct tfm_list_node_t service_list;/* Service list */ |
| 89 | #else /* TFM_PSA_API */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 90 | uint32_t partition_state; |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 91 | uint32_t caller_partition_idx; |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 92 | int32_t caller_client_id; |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 93 | uint32_t share; |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 94 | uint32_t stack_ptr; |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 95 | uint32_t lr; |
Mate Toth-Pal | 2a6f8c2 | 2018-12-13 16:37:17 +0100 | [diff] [blame] | 96 | int32_t iovec_api; /*!< Whether the function in the partition |
| 97 | * had been called using the iovec API. |
| 98 | * FIXME: Remove the field once this is the |
| 99 | * only option |
| 100 | */ |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 101 | struct iovec_args_t iovec_args; |
| 102 | psa_outvec *orig_outvec; |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 103 | uint32_t *ctx_stack_ptr; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 104 | #endif /* TFM_PSA_API */ |
| 105 | uint32_t signal_mask; /* |
| 106 | * Service signal mask passed by |
| 107 | * psa_wait() |
| 108 | */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 109 | }; |
| 110 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 111 | #ifdef TFM_PSA_API |
| 112 | |
| 113 | #define TFM_SPM_MAX_ROT_SERV_NUM 48 |
| 114 | #define TFM_VERSION_POLICY_RELAXED 0 |
| 115 | #define TFM_VERSION_POLICY_STRICT 1 |
| 116 | |
| 117 | #define TFM_CONN_HANDLE_MAX_NUM 32 |
| 118 | |
| 119 | /* RoT connection handle list */ |
| 120 | struct tfm_conn_handle_t { |
| 121 | psa_handle_t handle; /* Handle value */ |
| 122 | void *rhandle; /* Reverse handle value */ |
| 123 | struct tfm_list_node_t list; /* list node */ |
| 124 | }; |
| 125 | |
| 126 | /* Service database defined by manifest */ |
| 127 | struct tfm_spm_service_db_t { |
| 128 | char *name; /* Service name */ |
| 129 | uint32_t partition_id; /* Partition ID which service belong to */ |
| 130 | psa_signal_t signal; /* Service signal */ |
| 131 | uint32_t sid; /* Service identifier */ |
| 132 | bool non_secure_client; /* If can be called by non secure client */ |
| 133 | uint32_t minor_version; /* Minor version */ |
| 134 | uint32_t minor_policy; /* Minor version policy */ |
| 135 | }; |
| 136 | |
| 137 | /* RoT Service data */ |
| 138 | struct tfm_spm_service_t { |
| 139 | struct tfm_spm_service_db_t *service_db; /* Service database pointer */ |
| 140 | struct spm_partition_desc_t *partition; /* |
| 141 | * Point to secure partition |
| 142 | * data |
| 143 | */ |
| 144 | struct tfm_list_node_t handle_list; /* Service handle list */ |
| 145 | struct tfm_msg_queue_t msg_queue; /* Message queue */ |
| 146 | struct tfm_list_node_t list; /* For list operation */ |
| 147 | }; |
| 148 | #endif /* ifdef(TFM_PSA_API) */ |
| 149 | |
| 150 | /*********************** common definitions ***********************/ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 151 | |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 152 | /** |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 153 | * \brief Returns the index of the partition with the given partition ID. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 154 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 155 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 156 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 157 | * \return the partition idx if partition_id is valid, |
| 158 | * \ref SPM_INVALID_PARTITION_IDX othervise |
| 159 | */ |
| 160 | uint32_t get_partition_idx(uint32_t partition_id); |
| 161 | |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 162 | /** |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 163 | * \brief Get the id of the partition for its index from the db |
| 164 | * |
| 165 | * \param[in] partition_idx Partition index |
| 166 | * |
| 167 | * \return Partition ID for that partition |
| 168 | * |
| 169 | * \note This function doesn't check if partition_idx is valid. |
| 170 | */ |
| 171 | uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx); |
| 172 | |
| 173 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 174 | * \brief Get the flags associated with a partition |
| 175 | * |
| 176 | * \param[in] partition_idx Partition index |
| 177 | * |
| 178 | * \return Flags associated with the partition |
| 179 | * |
| 180 | * \note This function doesn't check if partition_idx is valid. |
| 181 | */ |
| 182 | uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx); |
| 183 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 184 | /** |
| 185 | * \brief Initialize partition database |
| 186 | * |
| 187 | * \return Error code \ref spm_err_t |
| 188 | */ |
| 189 | enum spm_err_t tfm_spm_db_init(void); |
| 190 | |
| 191 | /** |
| 192 | * \brief Change the privilege mode for partition thread mode. |
| 193 | * |
| 194 | * \param[in] privileged Privileged mode, |
| 195 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 196 | * and \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 197 | * |
| 198 | * \note Barrier instructions are not called by this function, and if |
| 199 | * it is called in thread mode, it might be necessary to call |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame^] | 200 | * them after this function returns. |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 201 | */ |
| 202 | void tfm_spm_partition_change_privilege(uint32_t privileged); |
| 203 | |
| 204 | /*********************** library definitions ***********************/ |
| 205 | |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 206 | #ifndef TFM_PSA_API |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 207 | /** |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 208 | * \brief Save interrupted partition context on ctx stack |
| 209 | * |
| 210 | * \param[in] partition_idx Partition index |
| 211 | * |
| 212 | * \note This function doesn't check if partition_idx is valid. |
| 213 | * \note This function doesn't whether the ctx stack overflows. |
| 214 | */ |
| 215 | void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx); |
| 216 | |
| 217 | /** |
| 218 | * \brief Restores interrupted partition context on ctx stack |
| 219 | * |
| 220 | * \param[in] partition_idx Partition index |
| 221 | * |
| 222 | * \note This function doesn't check if partition_idx is valid. |
| 223 | * \note This function doesn't whether the ctx stack underflows. |
| 224 | */ |
| 225 | void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx); |
| 226 | |
| 227 | /** |
| 228 | * \brief Save handler partition context on ctx stack |
| 229 | * |
| 230 | * \param[in] partition_idx Partition index |
| 231 | * |
| 232 | * \note This function doesn't check if partition_idx is valid. |
| 233 | * \note This function doesn't whether the ctx stack overflows. |
| 234 | */ |
| 235 | void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx); |
| 236 | |
| 237 | /** |
| 238 | * \brief Restores handler partition context on ctx stack |
| 239 | * |
| 240 | * \param[in] partition_idx Partition index |
| 241 | * |
| 242 | * \note This function doesn't check if partition_idx is valid. |
| 243 | * \note This function doesn't whether the ctx stack underflows. |
| 244 | */ |
| 245 | void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx); |
| 246 | |
| 247 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 248 | * \brief Get the current runtime data of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 249 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 250 | * \param[in] partition_idx Partition index |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 251 | * |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 252 | * \return The runtime data of the specified partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 253 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 254 | * \note This function doesn't check if partition_idx is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 255 | */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 256 | const struct spm_partition_runtime_data_t * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 257 | tfm_spm_partition_get_runtime_data(uint32_t partition_idx); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 258 | |
| 259 | /** |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 260 | * \brief Returns the index of the partition that has running state |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 261 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 262 | * \return The index of the partition with the running state, if there is any |
| 263 | * set. 0 otherwise. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 264 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 265 | uint32_t tfm_spm_partition_get_running_partition_idx(void); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 266 | |
| 267 | /** |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 268 | * \brief Save stack pointer and link register for partition in database |
| 269 | * |
| 270 | * \param[in] partition_idx Partition index |
| 271 | * \param[in] stack_ptr Stack pointer to be stored |
| 272 | * \param[in] lr Link register to be stored |
| 273 | * |
| 274 | * \note This function doesn't check if partition_idx is valid. |
| 275 | */ |
| 276 | void tfm_spm_partition_store_context(uint32_t partition_idx, |
| 277 | uint32_t stack_ptr, uint32_t lr); |
| 278 | |
| 279 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 280 | * \brief Set the current state of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 281 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 282 | * \param[in] partition_idx Partition index |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 283 | * \param[in] state The state to be set |
| 284 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 285 | * \note This function doesn't check if partition_idx is valid. |
Gyorgy Szing | 40a7af0 | 2019-02-06 14:19:47 +0100 | [diff] [blame] | 286 | * \note The state has to have the value set of \ref spm_part_state_t. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 287 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 288 | void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 289 | |
| 290 | /** |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 291 | * \brief Set the caller partition index for a given partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 292 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 293 | * \param[in] partition_idx Partition index |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 294 | * \param[in] caller_partition_idx The index of the caller partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 295 | * |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 296 | * \note This function doesn't check if any of the partition_idxs are valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 297 | */ |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 298 | void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx, |
| 299 | uint32_t caller_partition_idx); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 300 | |
| 301 | /** |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 302 | * \brief Set the caller client ID for a given partition |
| 303 | * |
| 304 | * \param[in] partition_idx Partition index |
| 305 | * \param[in] caller_client_id The ID of the calling client |
| 306 | * |
| 307 | * \note This function doesn't check if any of the partition_idxs are valid. |
| 308 | */ |
| 309 | void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx, |
| 310 | int32_t caller_client_id); |
| 311 | |
| 312 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 313 | * \brief Set the buffer share region of the partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 314 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 315 | * \param[in] partition_idx Partition index |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 316 | * \param[in] share The buffer share region to be set |
| 317 | * |
| 318 | * \return Error code \ref spm_err_t |
| 319 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 320 | * \note This function doesn't check if partition_idx is valid. |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 321 | * \note share has to have one of the buffer share values: |
| 322 | * - TFM_BUFFER_SHARE_DISABLE |
| 323 | * - TFM_BUFFER_SHARE_NS_CODE |
| 324 | * - TFM_BUFFER_SHARE_SCRATCH |
| 325 | * - TFM_BUFFER_SHARE_PRIV |
| 326 | * - TFM_BUFFER_SHARE_DEFAULT |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 327 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 328 | enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 329 | uint32_t share); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 330 | |
| 331 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 332 | * \brief Set the iovec parameters for the partition |
| 333 | * |
| 334 | * \param[in] partition_idx Partition index |
| 335 | * \param[in] args The arguments of the secure function |
| 336 | * |
| 337 | * args is expected to be of type int32_t[4] where: |
| 338 | * args[0] is in_vec |
| 339 | * args[1] is in_len |
| 340 | * args[2] is out_vec |
| 341 | * args[3] is out_len |
| 342 | * |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 343 | * \return Error code \ref spm_err_t |
| 344 | * |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 345 | * \note This function doesn't check if partition_idx is valid. |
| 346 | * \note This function assumes that the iovecs that are passed in args are |
| 347 | * valid, and does no sanity check on them at all. |
| 348 | */ |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 349 | enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx, |
| 350 | const int32_t *args); |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 351 | |
| 352 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 353 | * \brief Execute partition init function |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 354 | * |
| 355 | * \return Error code \ref spm_err_t |
| 356 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 357 | enum spm_err_t tfm_spm_partition_init(void); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 358 | |
| 359 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 360 | * \brief Clears the context info from the database for a partition. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 361 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 362 | * \param[in] partition_idx Partition index |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 363 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 364 | * \note This function doesn't check if partition_idx is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 365 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 366 | void tfm_spm_partition_cleanup_context(uint32_t partition_idx); |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * \brief Set the signal mask for a given partition |
| 370 | * |
| 371 | * \param[in] partition_idx Partition index |
| 372 | * \param[in] signal_mask The signal mask to be set for the partition |
| 373 | * |
| 374 | * \note This function doesn't check if any of the partition_idxs are valid. |
| 375 | */ |
| 376 | void tfm_spm_partition_set_signal_mask(uint32_t partition_idx, |
| 377 | uint32_t signal_mask); |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 378 | #endif /* !defined(TFM_PSA_API) */ |
| 379 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 380 | #ifdef TFM_PSA_API |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 381 | /*************************** IPC definitions **************************/ |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame^] | 382 | |
| 383 | /** |
| 384 | * \brief Get bottom of stack region for a partition |
| 385 | * |
| 386 | * \param[in] partition_idx Partition index |
| 387 | * |
| 388 | * \return Stack region bottom value |
| 389 | * |
| 390 | * \note This function doesn't check if partition_idx is valid. |
| 391 | */ |
| 392 | uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx); |
| 393 | |
| 394 | /** |
| 395 | * \brief Get top of stack region for a partition |
| 396 | * |
| 397 | * \param[in] partition_idx Partition index |
| 398 | * |
| 399 | * \return Stack region top value |
| 400 | * |
| 401 | * \note This function doesn't check if partition_idx is valid. |
| 402 | */ |
| 403 | uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 404 | |
| 405 | /** |
| 406 | * \brief Get the running partition ID. |
| 407 | * |
| 408 | * \return Returns the partition ID |
| 409 | */ |
| 410 | uint32_t tfm_spm_partition_get_running_partition_id(void); |
| 411 | |
| 412 | /** |
| 413 | * \brief Get the current partition mode. |
| 414 | * |
| 415 | * \param[in] partition_idx Index of current partition |
| 416 | * |
| 417 | * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode |
| 418 | * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode |
| 419 | */ |
| 420 | uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx); |
| 421 | |
| 422 | /******************** Service handle management functions ********************/ |
| 423 | |
| 424 | /** |
| 425 | * \brief Create connection handle for client connect |
| 426 | * |
| 427 | * \param[in] service Target service context pointer |
| 428 | * |
| 429 | * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE |
| 430 | * \retval >0 Service handle created, \ref psa_handle_t |
| 431 | */ |
| 432 | psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service); |
| 433 | |
| 434 | /** |
| 435 | * \brief Free connection handle which not used anymore. |
| 436 | * |
| 437 | * \param[in] service Target service context pointer |
| 438 | * \param[in] conn_handle Connection handle created by |
| 439 | * tfm_spm_create_conn_handle(), \ref psa_handle_t |
| 440 | * |
| 441 | * \retval IPC_SUCCESS Success |
| 442 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 443 | * \retval "Does not return" Panic for not find service by handle |
| 444 | */ |
| 445 | int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, |
| 446 | psa_handle_t conn_handle); |
| 447 | |
| 448 | /** |
| 449 | * \brief Set reverse handle value for connection. |
| 450 | * |
| 451 | * \param[in] service Target service context pointer |
| 452 | * \param[in] conn_handle Connection handle created by |
| 453 | * tfm_spm_create_conn_handle(), \ref psa_handle_t |
| 454 | * \param[in] rhandle rhandle need to save |
| 455 | * |
| 456 | * \retval IPC_SUCCESS Success |
| 457 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 458 | * \retval "Does not return" Panic for not find handle node |
| 459 | */ |
| 460 | int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, |
| 461 | psa_handle_t conn_handle, |
| 462 | void *rhandle); |
| 463 | |
| 464 | /** |
| 465 | * \brief Get reverse handle value from connection hanlde. |
| 466 | * |
| 467 | * \param[in] service Target service context pointer |
| 468 | * \param[in] conn_handle Connection handle created by |
| 469 | * tfm_spm_create_conn_handle(), \ref psa_handle_t |
| 470 | * |
| 471 | * \retval void * Success |
| 472 | * \retval "Does not return" Panic for those: |
| 473 | * service pointer are NULL |
| 474 | * hanlde is \ref PSA_NULL_HANDLE |
| 475 | * handle node does not be found |
| 476 | */ |
| 477 | void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service, |
| 478 | psa_handle_t conn_handle); |
| 479 | |
| 480 | /******************** Partition management functions *************************/ |
| 481 | |
| 482 | /** |
| 483 | * \brief Get current running partition context. |
| 484 | * |
| 485 | * \retval NULL Failed |
| 486 | * \retval "Not NULL" Return the parttion context pointer |
| 487 | * \ref spm_partition_desc_t structures |
| 488 | */ |
| 489 | struct spm_partition_desc_t *tfm_spm_get_running_partition(void); |
| 490 | |
| 491 | /** |
| 492 | * \brief Get the service context by signal. |
| 493 | * |
| 494 | * \param[in] partition Partition context pointer |
| 495 | * \ref spm_partition_desc_t structures |
| 496 | * \param[in] signal Signal associated with inputs to the Secure |
| 497 | * Partition, \ref psa_signal_t |
| 498 | * |
| 499 | * \retval NULL Failed |
| 500 | * \retval "Not NULL" Target service context pointer, |
| 501 | * \ref tfm_spm_service_t structures |
| 502 | */ |
| 503 | struct tfm_spm_service_t * |
| 504 | tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition, |
| 505 | psa_signal_t signal); |
| 506 | |
| 507 | /** |
| 508 | * \brief Get the service context by service ID. |
| 509 | * |
| 510 | * \param[in] sid RoT Service identity |
| 511 | * |
| 512 | * \retval NULL Failed |
| 513 | * \retval "Not NULL" Target service context pointer, |
| 514 | * \ref tfm_spm_service_t structures |
| 515 | */ |
| 516 | struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid); |
| 517 | |
| 518 | /** |
| 519 | * \brief Get the service context by connection handle. |
| 520 | * |
| 521 | * \param[in] conn_handle Connection handle created by |
| 522 | * tfm_spm_create_conn_handle() |
| 523 | * |
| 524 | * \retval NULL Failed |
| 525 | * \retval "Not NULL" Target service context pointer, |
| 526 | * \ref tfm_spm_service_t structures |
| 527 | */ |
| 528 | struct tfm_spm_service_t * |
| 529 | tfm_spm_get_service_by_handle(psa_handle_t conn_handle); |
| 530 | |
| 531 | /** |
| 532 | * \brief Get the partition context by partition ID. |
| 533 | * |
| 534 | * \param[in] partition_id Partition identity |
| 535 | * |
| 536 | * \retval NULL Failed |
| 537 | * \retval "Not NULL" Target partition context pointer, |
| 538 | * \ref spm_partition_desc_t structures |
| 539 | */ |
| 540 | struct spm_partition_desc_t * |
| 541 | tfm_spm_get_partition_by_id(int32_t partition_id); |
| 542 | |
| 543 | /************************ Message functions **********************************/ |
| 544 | |
| 545 | /** |
| 546 | * \brief Get message context by message handle. |
| 547 | * |
| 548 | * \param[in] msg_handle Message handle which is a reference generated |
| 549 | * by the SPM to a specific message. |
| 550 | * |
| 551 | * \return The message body context pointer |
| 552 | * \ref tfm_msg_body_t structures |
| 553 | */ |
| 554 | struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle); |
| 555 | |
| 556 | /** |
| 557 | * \brief Create a message for PSA client call. |
| 558 | * |
| 559 | * \param[in] service Target service context pointer, which can be |
| 560 | * obtained by partition management functions |
| 561 | * \prarm[in] handle Connect handle return by psa_connect(). |
| 562 | * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or |
| 563 | * PSA_IPC_DISCONNECT |
| 564 | * \param[in] ns_caller Whether from NS caller |
| 565 | * \param[in] invec Array of input \ref psa_invec structures |
| 566 | * \param[in] in_len Number of input \ref psa_invec structures |
| 567 | * \param[in] outvec Array of output \ref psa_outvec structures |
| 568 | * \param[in] out_len Number of output \ref psa_outvec structures |
| 569 | * \param[in] caller_outvec Array of caller output \ref psa_outvec structures |
| 570 | * |
| 571 | * \retval NULL Failed |
| 572 | * \retval "Not NULL" New message body pointer \ref tfm_msg_body_t |
| 573 | * structures |
| 574 | */ |
| 575 | struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service, |
| 576 | psa_handle_t handle, |
| 577 | int32_t type, int32_t ns_caller, |
| 578 | psa_invec *invec, size_t in_len, |
| 579 | psa_outvec *outvec, size_t out_len, |
| 580 | psa_outvec *caller_outvec); |
| 581 | |
| 582 | /** |
| 583 | * \brief Free message which unused anymore |
| 584 | * |
| 585 | * \param[in] msg Message pointer which want to free |
| 586 | * \ref tfm_msg_body_t structures |
| 587 | * |
| 588 | * \retval void Success |
| 589 | * \retval "Does not return" Failed |
| 590 | */ |
| 591 | void tfm_spm_free_msg(struct tfm_msg_body_t *msg); |
| 592 | |
| 593 | /** |
| 594 | * \brief Send message and wake up the SP who is waiting on |
| 595 | * message queue, block the current thread and |
| 596 | * scheduler triggered |
| 597 | * |
| 598 | * \param[in] service Target service context pointer, which can be |
| 599 | * obtained by partition management functions |
| 600 | * \param[in] msg message created by tfm_spm_create_msg() |
| 601 | * \ref tfm_msg_body_t structures |
| 602 | * |
| 603 | * \retval IPC_SUCCESS Success |
| 604 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 605 | * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue |
| 606 | */ |
| 607 | int32_t tfm_spm_send_event(struct tfm_spm_service_t *service, |
| 608 | struct tfm_msg_body_t *msg); |
| 609 | |
| 610 | /** |
| 611 | * \brief Check the client minor version according to |
| 612 | * version policy |
| 613 | * |
| 614 | * \param[in] service Target service context pointer, which can be get |
| 615 | * by partition management functions |
| 616 | * \param[in] minor_version Client support minor version |
| 617 | * |
| 618 | * \retval IPC_SUCCESS Success |
| 619 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 620 | * \retval IPC_ERROR_VERSION Check failed |
| 621 | */ |
| 622 | int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service, |
| 623 | uint32_t minor_version); |
| 624 | |
| 625 | /** |
| 626 | * \brief Check the memory reference is valid. |
| 627 | * |
| 628 | * \param[in] buffer Pointer of memory reference |
| 629 | * \param[in] len Length of memory reference in bytes |
| 630 | * \param[in] ns_caller From non-secure caller |
| 631 | * \param[in] access Type of access specified by the |
| 632 | * \ref tfm_memory_access_e |
| 633 | * \param[in] privileged Privileged mode or unprivileged mode: |
| 634 | * \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 635 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 636 | * |
| 637 | * \retval IPC_SUCCESS Success |
| 638 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 639 | * \retval IPC_ERROR_MEMORY_CHECK Check failed |
| 640 | */ |
| 641 | int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller, |
| 642 | enum tfm_memory_access_e access, |
| 643 | uint32_t privileged); |
| 644 | |
| 645 | /* This function should be called before schedule function */ |
| 646 | void tfm_spm_init(void); |
| 647 | |
| 648 | /* |
| 649 | * PendSV specified function. |
| 650 | * |
| 651 | * Parameters : |
| 652 | * ctxb - State context storage pointer |
| 653 | * |
| 654 | * Notes: |
| 655 | * This is a staging API. Scheduler should be called in SPM finally and |
| 656 | * this function will be obsoleted later. |
| 657 | */ |
| 658 | void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb); |
| 659 | |
| 660 | #endif /* ifdef(TFM_PSA_API) */ |
| 661 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 662 | #endif /*__SPM_API_H__ */ |