Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, 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" |
David Hu | 49a28eb | 2019-08-14 18:18:15 +0800 | [diff] [blame] | 14 | #include "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" |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 21 | #include "tfm_thread.h" |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 22 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 23 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 24 | #define SPM_INVALID_PARTITION_IDX (~0U) |
| 25 | |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 26 | /* Privileged definitions for partition thread mode */ |
| 27 | #define TFM_PARTITION_PRIVILEGED_MODE 1 |
| 28 | #define TFM_PARTITION_UNPRIVILEGED_MODE 0 |
| 29 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 30 | enum spm_err_t { |
| 31 | SPM_ERR_OK = 0, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 32 | SPM_ERR_PARTITION_DB_NOT_INIT, |
| 33 | SPM_ERR_PARTITION_ALREADY_ACTIVE, |
| 34 | SPM_ERR_PARTITION_NOT_AVAILABLE, |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 35 | SPM_ERR_INVALID_PARAMETER, |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 36 | SPM_ERR_INVALID_CONFIG, |
| 37 | }; |
| 38 | |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 39 | #define SPM_PARTITION_STATE_UNINIT 0 |
| 40 | #define SPM_PARTITION_STATE_IDLE 1 |
| 41 | #define SPM_PARTITION_STATE_RUNNING 2 |
| 42 | #define SPM_PARTITION_STATE_HANDLING_IRQ 3 |
| 43 | #define SPM_PARTITION_STATE_SUSPENDED 4 |
| 44 | #define SPM_PARTITION_STATE_BLOCKED 5 |
| 45 | #define SPM_PARTITION_STATE_CLOSED 6 |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 46 | |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 47 | #define SPM_PART_FLAG_APP_ROT 0x01 |
| 48 | #define SPM_PART_FLAG_PSA_ROT 0x02 |
| 49 | #define SPM_PART_FLAG_IPC 0x04 |
Mate Toth-Pal | 5939871 | 2018-02-28 17:06:40 +0100 | [diff] [blame] | 50 | |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 51 | #define TFM_HANDLE_STATUS_IDLE 0 |
| 52 | #define TFM_HANDLE_STATUS_ACTIVE 1 |
Shawn Shan | adb0286 | 2019-12-10 11:04:33 +0800 | [diff] [blame] | 53 | #define TFM_HANDLE_STATUS_CONNECT_ERROR 2 |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 54 | |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 55 | #ifndef TFM_PSA_API |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 56 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 57 | * \brief Holds the iovec parameters that are passed to a service |
| 58 | * |
| 59 | * \note The size of the structure is (and have to be) multiple of 8 bytes |
| 60 | */ |
| 61 | struct iovec_args_t { |
| 62 | psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */ |
| 63 | size_t in_len; /*!< Number psa_invec objects in in_vec |
| 64 | */ |
| 65 | psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */ |
| 66 | size_t out_len; /*!< Number psa_outvec objects in out_vec |
| 67 | */ |
| 68 | }; |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 69 | |
| 70 | /* The size of this struct must be multiple of 4 bytes as it is stacked to an |
| 71 | * uint32_t[] array |
| 72 | */ |
| 73 | struct interrupted_ctx_stack_frame_t { |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 74 | uint32_t partition_state; |
| 75 | }; |
| 76 | |
| 77 | /* The size of this struct must be multiple of 4 bytes as it is stacked to an |
| 78 | * uint32_t[] array |
| 79 | */ |
| 80 | struct handler_ctx_stack_frame_t { |
| 81 | uint32_t partition_state; |
| 82 | uint32_t caller_partition_idx; |
| 83 | }; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 84 | #endif /* !define(TFM_PSA_API) */ |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 85 | |
| 86 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 87 | * \brief Runtime context information of a partition |
| 88 | */ |
| 89 | struct spm_partition_runtime_data_t { |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 90 | #ifdef TFM_PSA_API |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 91 | uint32_t signals; /* Service signals had been triggered*/ |
TTornblom | 83d9637 | 2019-11-19 12:53:16 +0100 | [diff] [blame] | 92 | struct tfm_event_t signal_evnt; /* Event signal */ |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 93 | struct tfm_list_node_t service_list;/* Service list */ |
Summer Qin | 66f1e03 | 2020-01-06 15:40:03 +0800 | [diff] [blame] | 94 | struct tfm_core_thread_t sp_thrd; /* Thread object */ |
Shawn Shan | 9b0e0c7 | 2019-10-22 13:43:07 +0800 | [diff] [blame] | 95 | uint32_t assigned_signals; /* All assigned signals */ |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 96 | #else /* TFM_PSA_API */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 97 | uint32_t partition_state; |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 98 | uint32_t caller_partition_idx; |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 99 | int32_t caller_client_id; |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 100 | uint32_t stack_ptr; |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 101 | uint32_t lr; |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 102 | struct iovec_args_t iovec_args; |
| 103 | psa_outvec *orig_outvec; |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 104 | uint32_t *ctx_stack_ptr; |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 105 | #endif /* TFM_PSA_API */ |
| 106 | uint32_t signal_mask; /* |
| 107 | * Service signal mask passed by |
| 108 | * psa_wait() |
| 109 | */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 110 | }; |
| 111 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 112 | #ifdef TFM_PSA_API |
| 113 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 114 | #define TFM_VERSION_POLICY_RELAXED 0 |
| 115 | #define TFM_VERSION_POLICY_STRICT 1 |
| 116 | |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 117 | #define TFM_CONN_HANDLE_MAX_NUM 16 |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 118 | |
| 119 | /* RoT connection handle list */ |
| 120 | struct tfm_conn_handle_t { |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 121 | void *rhandle; /* Reverse handle value */ |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 122 | uint32_t status; /* |
Shawn Shan | adb0286 | 2019-12-10 11:04:33 +0800 | [diff] [blame] | 123 | * Status of handle, three valid |
| 124 | * options: |
| 125 | * TFM_HANDLE_STATUS_ACTIVE, |
| 126 | * TFM_HANDLE_STATUS_IDLE and |
| 127 | * TFM_HANDLE_STATUS_CONNECT_ERROR |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 128 | */ |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 129 | int32_t client_id; /* |
| 130 | * Partition ID of the sender of the |
| 131 | * message: |
| 132 | * - secure partition id; |
| 133 | * - non secure client endpoint id. |
| 134 | */ |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 135 | struct tfm_msg_body_t internal_msg; /* Internal message for message queue */ |
Edison Ai | 9cc2624 | 2019-08-06 11:28:04 +0800 | [diff] [blame] | 136 | struct tfm_spm_service_t *service; /* RoT service pointer */ |
| 137 | struct tfm_list_node_t list; /* list node */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /* Service database defined by manifest */ |
| 141 | struct tfm_spm_service_db_t { |
| 142 | char *name; /* Service name */ |
| 143 | uint32_t partition_id; /* Partition ID which service belong to */ |
| 144 | psa_signal_t signal; /* Service signal */ |
| 145 | uint32_t sid; /* Service identifier */ |
| 146 | bool non_secure_client; /* If can be called by non secure client */ |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 147 | uint32_t version; /* Service version */ |
| 148 | uint32_t version_policy; /* Service version policy */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | /* RoT Service data */ |
| 152 | struct tfm_spm_service_t { |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 153 | const struct tfm_spm_service_db_t *service_db;/* Service database pointer */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 154 | struct spm_partition_desc_t *partition; /* |
| 155 | * Point to secure partition |
| 156 | * data |
| 157 | */ |
| 158 | struct tfm_list_node_t handle_list; /* Service handle list */ |
| 159 | struct tfm_msg_queue_t msg_queue; /* Message queue */ |
| 160 | struct tfm_list_node_t list; /* For list operation */ |
| 161 | }; |
| 162 | #endif /* ifdef(TFM_PSA_API) */ |
| 163 | |
| 164 | /*********************** common definitions ***********************/ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 165 | |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 166 | /** |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 167 | * \brief Returns the index of the partition with the given partition ID. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 168 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 169 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 170 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 171 | * \return the partition idx if partition_id is valid, |
| 172 | * \ref SPM_INVALID_PARTITION_IDX othervise |
| 173 | */ |
| 174 | uint32_t get_partition_idx(uint32_t partition_id); |
| 175 | |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 176 | /** |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 177 | * \brief Get the id of the partition for its index from the db |
| 178 | * |
| 179 | * \param[in] partition_idx Partition index |
| 180 | * |
| 181 | * \return Partition ID for that partition |
| 182 | * |
| 183 | * \note This function doesn't check if partition_idx is valid. |
| 184 | */ |
| 185 | uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx); |
| 186 | |
| 187 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 188 | * \brief Get the flags associated with a partition |
| 189 | * |
| 190 | * \param[in] partition_idx Partition index |
| 191 | * |
| 192 | * \return Flags associated with the partition |
| 193 | * |
| 194 | * \note This function doesn't check if partition_idx is valid. |
| 195 | */ |
| 196 | uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx); |
| 197 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 198 | /** |
| 199 | * \brief Initialize partition database |
| 200 | * |
| 201 | * \return Error code \ref spm_err_t |
| 202 | */ |
| 203 | enum spm_err_t tfm_spm_db_init(void); |
| 204 | |
| 205 | /** |
| 206 | * \brief Change the privilege mode for partition thread mode. |
| 207 | * |
| 208 | * \param[in] privileged Privileged mode, |
| 209 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 210 | * and \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 211 | * |
| 212 | * \note Barrier instructions are not called by this function, and if |
| 213 | * it is called in thread mode, it might be necessary to call |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 214 | * them after this function returns. |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 215 | */ |
| 216 | void tfm_spm_partition_change_privilege(uint32_t privileged); |
| 217 | |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 218 | /** |
| 219 | * \brief Get the current partition mode. |
| 220 | * |
| 221 | * \param[in] partition_flags Flags of current partition |
| 222 | * |
| 223 | * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode |
| 224 | * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode |
| 225 | */ |
| 226 | uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags); |
| 227 | |
Summer Qin | 830c554 | 2020-02-14 13:44:20 +0800 | [diff] [blame] | 228 | /** |
| 229 | * \brief Handle an SPM request by a secure service |
| 230 | * \param[in] svc_ctx The stacked SVC context |
| 231 | */ |
| 232 | void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx); |
| 233 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 234 | /*********************** library definitions ***********************/ |
| 235 | |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 236 | #ifndef TFM_PSA_API |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 237 | /** |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 238 | * \brief Save interrupted 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 overflows. |
| 244 | */ |
| 245 | void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx); |
| 246 | |
| 247 | /** |
| 248 | * \brief Restores interrupted partition context on ctx stack |
| 249 | * |
| 250 | * \param[in] partition_idx Partition index |
| 251 | * |
| 252 | * \note This function doesn't check if partition_idx is valid. |
| 253 | * \note This function doesn't whether the ctx stack underflows. |
| 254 | */ |
| 255 | void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx); |
| 256 | |
| 257 | /** |
| 258 | * \brief Save handler partition context on ctx stack |
| 259 | * |
| 260 | * \param[in] partition_idx Partition index |
| 261 | * |
| 262 | * \note This function doesn't check if partition_idx is valid. |
| 263 | * \note This function doesn't whether the ctx stack overflows. |
| 264 | */ |
| 265 | void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx); |
| 266 | |
| 267 | /** |
| 268 | * \brief Restores handler partition context on ctx stack |
| 269 | * |
| 270 | * \param[in] partition_idx Partition index |
| 271 | * |
| 272 | * \note This function doesn't check if partition_idx is valid. |
| 273 | * \note This function doesn't whether the ctx stack underflows. |
| 274 | */ |
| 275 | void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx); |
| 276 | |
| 277 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 278 | * \brief Get the current runtime data of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 279 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 280 | * \param[in] partition_idx Partition index |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 281 | * |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 282 | * \return The runtime data of the specified partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 283 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 284 | * \note This function doesn't check if partition_idx is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 285 | */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 286 | const struct spm_partition_runtime_data_t * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 287 | tfm_spm_partition_get_runtime_data(uint32_t partition_idx); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 288 | |
| 289 | /** |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 290 | * \brief Returns the index of the partition that has running state |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 291 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 292 | * \return The index of the partition with the running state, if there is any |
| 293 | * set. 0 otherwise. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 294 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 295 | uint32_t tfm_spm_partition_get_running_partition_idx(void); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 296 | |
| 297 | /** |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 298 | * \brief Save stack pointer and link register for partition in database |
| 299 | * |
| 300 | * \param[in] partition_idx Partition index |
| 301 | * \param[in] stack_ptr Stack pointer to be stored |
| 302 | * \param[in] lr Link register to be stored |
| 303 | * |
| 304 | * \note This function doesn't check if partition_idx is valid. |
| 305 | */ |
| 306 | void tfm_spm_partition_store_context(uint32_t partition_idx, |
| 307 | uint32_t stack_ptr, uint32_t lr); |
| 308 | |
| 309 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 310 | * \brief Set the current state of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 311 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 312 | * \param[in] partition_idx Partition index |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 313 | * \param[in] state The state to be set |
| 314 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 315 | * \note This function doesn't check if partition_idx is valid. |
Gyorgy Szing | 40a7af0 | 2019-02-06 14:19:47 +0100 | [diff] [blame] | 316 | * \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] | 317 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 318 | 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] | 319 | |
| 320 | /** |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 321 | * \brief Set the caller partition index for a given partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 322 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 323 | * \param[in] partition_idx Partition index |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 324 | * \param[in] caller_partition_idx The index of the caller partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 325 | * |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 326 | * \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] | 327 | */ |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 328 | void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx, |
| 329 | uint32_t caller_partition_idx); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 330 | |
| 331 | /** |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 332 | * \brief Set the caller client ID for a given partition |
| 333 | * |
| 334 | * \param[in] partition_idx Partition index |
| 335 | * \param[in] caller_client_id The ID of the calling client |
| 336 | * |
| 337 | * \note This function doesn't check if any of the partition_idxs are valid. |
| 338 | */ |
| 339 | void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx, |
| 340 | int32_t caller_client_id); |
| 341 | |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 342 | |
| 343 | /** |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 344 | * \brief Set the iovec parameters for the partition |
| 345 | * |
| 346 | * \param[in] partition_idx Partition index |
| 347 | * \param[in] args The arguments of the secure function |
| 348 | * |
| 349 | * args is expected to be of type int32_t[4] where: |
| 350 | * args[0] is in_vec |
| 351 | * args[1] is in_len |
| 352 | * args[2] is out_vec |
| 353 | * args[3] is out_len |
| 354 | * |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 355 | * \return Error code \ref spm_err_t |
| 356 | * |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 357 | * \note This function doesn't check if partition_idx is valid. |
| 358 | * \note This function assumes that the iovecs that are passed in args are |
| 359 | * valid, and does no sanity check on them at all. |
| 360 | */ |
Hugues de Valon | f704c80 | 2019-02-19 14:51:41 +0000 | [diff] [blame] | 361 | enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx, |
| 362 | const int32_t *args); |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 363 | |
| 364 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 365 | * \brief Execute partition init function |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 366 | * |
| 367 | * \return Error code \ref spm_err_t |
| 368 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 369 | enum spm_err_t tfm_spm_partition_init(void); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 370 | |
| 371 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 372 | * \brief Clears the context info from the database for a partition. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 373 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 374 | * \param[in] partition_idx Partition index |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 375 | * |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 376 | * \note This function doesn't check if partition_idx is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 377 | */ |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 378 | void tfm_spm_partition_cleanup_context(uint32_t partition_idx); |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 379 | |
| 380 | /** |
| 381 | * \brief Set the signal mask for a given partition |
| 382 | * |
| 383 | * \param[in] partition_idx Partition index |
| 384 | * \param[in] signal_mask The signal mask to be set for the partition |
| 385 | * |
| 386 | * \note This function doesn't check if any of the partition_idxs are valid. |
| 387 | */ |
| 388 | void tfm_spm_partition_set_signal_mask(uint32_t partition_idx, |
| 389 | uint32_t signal_mask); |
Mingyang Sun | abb1aab | 2020-02-18 13:49:08 +0800 | [diff] [blame] | 390 | |
| 391 | /** |
| 392 | * \brief Signal that secure partition initialisation is finished |
| 393 | */ |
| 394 | void tfm_spm_secure_api_init_done(void); |
| 395 | |
| 396 | /** |
| 397 | * \brief Called if veneer is running in thread mode |
| 398 | */ |
| 399 | uint32_t tfm_spm_partition_request_svc_handler( |
| 400 | const uint32_t *svc_args, uint32_t lr); |
| 401 | |
| 402 | /** |
| 403 | * \brief Called when secure service returns |
| 404 | */ |
| 405 | uint32_t tfm_spm_partition_return_handler(uint32_t lr); |
| 406 | |
| 407 | /** |
| 408 | * \brief Called by secure service to check if client is secure |
| 409 | */ |
| 410 | void tfm_spm_validate_secure_caller_handler(uint32_t *svc_args); |
| 411 | |
| 412 | /** |
| 413 | * \brief Stores caller's client id in state context |
| 414 | */ |
| 415 | void tfm_spm_get_caller_client_id_handler(uint32_t *svc_args); |
| 416 | |
| 417 | /** |
| 418 | * \brief Checks if a secure service's access to a memory location is permitted |
| 419 | */ |
| 420 | void tfm_spm_memory_permission_check_handler(uint32_t *svc_args); |
| 421 | |
| 422 | /** |
| 423 | * \brief Check whether a buffer is ok for writing to by the privileged API |
| 424 | * function. |
| 425 | * |
| 426 | * This function checks whether the caller partition owns the buffer, can write |
| 427 | * to it, and the buffer has proper alignment. |
| 428 | * |
| 429 | * \param[in] partition_idx Partition index |
| 430 | * \param[in] start_addr The start address of the buffer |
| 431 | * \param[in] len The length of the buffer |
| 432 | * \param[in] alignment The expected alignment (in bits) |
| 433 | * |
| 434 | * \return 1 if the check passes, 0 otherwise. |
| 435 | * |
| 436 | * \note For a 0 long buffer the check fails. |
| 437 | */ |
| 438 | int32_t tfm_spm_check_buffer_access(uint32_t partition_idx, |
| 439 | void *start_addr, |
| 440 | size_t len, |
| 441 | uint32_t alignment); |
| 442 | |
| 443 | /** |
| 444 | * \brief Handle deprivileged request |
| 445 | */ |
| 446 | extern uint32_t tfm_spm_depriv_req_handler(uint32_t *svc_args, |
| 447 | uint32_t excReturn); |
| 448 | |
| 449 | /** |
| 450 | * \brief Handle request to return to privileged |
| 451 | */ |
| 452 | uint32_t tfm_spm_depriv_return_handler(uint32_t *irq_svc_args, uint32_t lr); |
| 453 | |
| 454 | /** |
| 455 | * \brief Handle IRQ enable request |
| 456 | */ |
| 457 | void tfm_spm_enable_irq_handler(uint32_t *svc_args); |
| 458 | |
| 459 | /** |
| 460 | * \brief Handle IRQ disable request |
| 461 | */ |
| 462 | void tfm_spm_disable_irq_handler(uint32_t *svc_args); |
| 463 | |
| 464 | /** |
| 465 | * \brief Handle signal wait request |
| 466 | */ |
| 467 | void tfm_spm_psa_wait(uint32_t *svc_args); |
| 468 | |
| 469 | /** |
| 470 | * \brief Handle request to record IRQ processed |
| 471 | */ |
| 472 | void tfm_spm_psa_eoi(uint32_t *svc_args); |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 473 | #endif /* !defined(TFM_PSA_API) */ |
| 474 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 475 | #ifdef TFM_PSA_API |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 476 | /*************************** IPC definitions **************************/ |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 477 | |
| 478 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 479 | * \brief Get the running partition ID. |
| 480 | * |
| 481 | * \return Returns the partition ID |
| 482 | */ |
| 483 | uint32_t tfm_spm_partition_get_running_partition_id(void); |
| 484 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 485 | /******************** Service handle management functions ********************/ |
| 486 | |
| 487 | /** |
| 488 | * \brief Create connection handle for client connect |
| 489 | * |
| 490 | * \param[in] service Target service context pointer |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 491 | * \param[in] client_id Partition ID of the sender of the message |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 492 | * |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame^] | 493 | * \retval NULL Create failed |
| 494 | * \retval "Not NULL" Service handle created |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 495 | */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame^] | 496 | struct tfm_conn_handle_t *tfm_spm_create_conn_handle( |
| 497 | struct tfm_spm_service_t *service, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 498 | int32_t client_id); |
| 499 | |
| 500 | /** |
| 501 | * \brief Validate connection handle for client connect |
| 502 | * |
| 503 | * \param[in] conn_handle Handle to be validated |
| 504 | * \param[in] client_id Partition ID of the sender of the message |
| 505 | * |
| 506 | * \retval IPC_SUCCESS Success |
| 507 | * \retval IPC_ERROR_GENERIC Invalid handle |
| 508 | */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame^] | 509 | int32_t tfm_spm_validate_conn_handle( |
| 510 | const struct tfm_conn_handle_t *conn_handle, |
| 511 | int32_t client_id); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 512 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 513 | /******************** Partition management functions *************************/ |
| 514 | |
| 515 | /** |
| 516 | * \brief Get current running partition context. |
| 517 | * |
| 518 | * \retval NULL Failed |
| 519 | * \retval "Not NULL" Return the parttion context pointer |
| 520 | * \ref spm_partition_desc_t structures |
| 521 | */ |
| 522 | struct spm_partition_desc_t *tfm_spm_get_running_partition(void); |
| 523 | |
| 524 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 525 | * \brief Get the service context by service ID. |
| 526 | * |
| 527 | * \param[in] sid RoT Service identity |
| 528 | * |
| 529 | * \retval NULL Failed |
| 530 | * \retval "Not NULL" Target service context pointer, |
| 531 | * \ref tfm_spm_service_t structures |
| 532 | */ |
| 533 | struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid); |
| 534 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 535 | /************************ Message functions **********************************/ |
| 536 | |
| 537 | /** |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 538 | * \brief Get message context by connect handle. |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 539 | * |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 540 | * \param[in] conn_handle Service connect handle. |
| 541 | * |
| 542 | * \return The message body context pointer |
| 543 | * \ref msg_body_t structures |
| 544 | */ |
| 545 | struct tfm_msg_body_t * |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame^] | 546 | tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle); |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 547 | |
| 548 | /** |
| 549 | * \brief Fill the message for PSA client call. |
| 550 | * |
| 551 | * \param[in] msg Service Message Queue buffer pointer |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 552 | * \param[in] service Target service context pointer, which can be |
| 553 | * obtained by partition management functions |
| 554 | * \prarm[in] handle Connect handle return by psa_connect(). |
| 555 | * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or |
| 556 | * PSA_IPC_DISCONNECT |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 557 | * \param[in] client_id Partition ID of the sender of the message |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 558 | * \param[in] invec Array of input \ref psa_invec structures |
| 559 | * \param[in] in_len Number of input \ref psa_invec structures |
| 560 | * \param[in] outvec Array of output \ref psa_outvec structures |
| 561 | * \param[in] out_len Number of output \ref psa_outvec structures |
| 562 | * \param[in] caller_outvec Array of caller output \ref psa_outvec structures |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 563 | */ |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 564 | void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, |
| 565 | struct tfm_spm_service_t *service, |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame^] | 566 | struct tfm_conn_handle_t *handle, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 567 | int32_t type, int32_t client_id, |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 568 | psa_invec *invec, size_t in_len, |
| 569 | psa_outvec *outvec, size_t out_len, |
| 570 | psa_outvec *caller_outvec); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * \brief Send message and wake up the SP who is waiting on |
| 574 | * message queue, block the current thread and |
| 575 | * scheduler triggered |
| 576 | * |
| 577 | * \param[in] service Target service context pointer, which can be |
| 578 | * obtained by partition management functions |
| 579 | * \param[in] msg message created by tfm_spm_create_msg() |
| 580 | * \ref tfm_msg_body_t structures |
| 581 | * |
| 582 | * \retval IPC_SUCCESS Success |
| 583 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 584 | * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue |
| 585 | */ |
| 586 | int32_t tfm_spm_send_event(struct tfm_spm_service_t *service, |
| 587 | struct tfm_msg_body_t *msg); |
| 588 | |
| 589 | /** |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 590 | * \brief Check the client version according to |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 591 | * version policy |
| 592 | * |
| 593 | * \param[in] service Target service context pointer, which can be get |
| 594 | * by partition management functions |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 595 | * \param[in] version Client support version |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 596 | * |
| 597 | * \retval IPC_SUCCESS Success |
| 598 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 599 | * \retval IPC_ERROR_VERSION Check failed |
| 600 | */ |
| 601 | int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service, |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 602 | uint32_t version); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 603 | |
| 604 | /** |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 605 | * \brief Check the client access authorization |
| 606 | * |
| 607 | * \param[in] sid Target RoT Service identity |
| 608 | * \param[in] service Target service context pointer, which can be get |
| 609 | * by partition management functions |
| 610 | * \param[in] ns_caller Whether from NS caller |
| 611 | * |
| 612 | * \retval IPC_SUCCESS Success |
| 613 | * \retval IPC_ERROR_GENERIC Authorization check failed |
| 614 | */ |
| 615 | int32_t tfm_spm_check_authorization(uint32_t sid, |
| 616 | struct tfm_spm_service_t *service, |
Summer Qin | 618e8c3 | 2019-12-09 10:47:20 +0800 | [diff] [blame] | 617 | bool ns_caller); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 618 | |
| 619 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 620 | * \brief Check the memory reference is valid. |
| 621 | * |
| 622 | * \param[in] buffer Pointer of memory reference |
| 623 | * \param[in] len Length of memory reference in bytes |
| 624 | * \param[in] ns_caller From non-secure caller |
| 625 | * \param[in] access Type of access specified by the |
| 626 | * \ref tfm_memory_access_e |
| 627 | * \param[in] privileged Privileged mode or unprivileged mode: |
| 628 | * \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 629 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 630 | * |
| 631 | * \retval IPC_SUCCESS Success |
| 632 | * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input |
| 633 | * \retval IPC_ERROR_MEMORY_CHECK Check failed |
| 634 | */ |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 635 | int32_t tfm_memory_check(const void *buffer, size_t len, bool ns_caller, |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 636 | enum tfm_memory_access_e access, |
| 637 | uint32_t privileged); |
| 638 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 639 | /* |
| 640 | * PendSV specified function. |
| 641 | * |
| 642 | * Parameters : |
Summer Qin | d2ad7e7 | 2020-01-06 18:16:35 +0800 | [diff] [blame] | 643 | * p_actx - Architecture context storage pointer |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 644 | * |
| 645 | * Notes: |
| 646 | * This is a staging API. Scheduler should be called in SPM finally and |
| 647 | * this function will be obsoleted later. |
| 648 | */ |
Summer Qin | d2ad7e7 | 2020-01-06 18:16:35 +0800 | [diff] [blame] | 649 | void tfm_pendsv_do_schedule(struct tfm_arch_ctx_t *p_actx); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 650 | |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 651 | /** |
| 652 | * \brief SPM initialization implementation |
| 653 | * |
| 654 | * \details This function must be called under handler mode. |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 655 | * \retval This function returns an EXC_RETURN value. Other |
| 656 | * faults would panic the execution and never |
| 657 | * returned. |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 658 | */ |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 659 | uint32_t tfm_spm_init(void); |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 660 | |
Shawn Shan | 6e7be07 | 2019-11-29 17:56:29 +0800 | [diff] [blame] | 661 | /* |
| 662 | * \brief This function get the current PSA RoT lifecycle state. |
| 663 | * |
| 664 | * \return state The current security lifecycle state of the PSA |
| 665 | * RoT. The PSA state and implementation state are |
| 666 | * encoded as follows: |
| 667 | * \arg state[15:8] – PSA lifecycle state |
| 668 | * \arg state[7:0] – IMPLEMENTATION DEFINED state |
| 669 | */ |
| 670 | uint32_t tfm_spm_get_lifecycle_state(void); |
| 671 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 672 | /* Svcall for PSA Client APIs */ |
| 673 | |
| 674 | /** |
| 675 | * \brief SVC handler for \ref psa_framework_version. |
| 676 | * |
| 677 | * \return version The version of the PSA Framework implementation |
| 678 | * that is providing the runtime services to the |
| 679 | * caller. |
| 680 | */ |
| 681 | uint32_t tfm_spm_psa_framework_version(void); |
| 682 | |
| 683 | /** |
| 684 | * \brief SVC handler for \ref psa_version. |
| 685 | * |
| 686 | * \param[in] args Include all input arguments: sid. |
| 687 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 688 | * Or from secure client. |
| 689 | * |
| 690 | * \retval PSA_VERSION_NONE The RoT Service is not implemented, or the |
| 691 | * caller is not permitted to access the service. |
| 692 | * \retval > 0 The version of the implemented RoT Service. |
| 693 | */ |
| 694 | uint32_t tfm_spm_psa_version(uint32_t *args, bool ns_caller); |
| 695 | |
| 696 | /** |
| 697 | * \brief SVC handler for \ref psa_connect. |
| 698 | * |
| 699 | * \param[in] args Include all input arguments: |
| 700 | * sid, version. |
| 701 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 702 | * Or from secure client. |
| 703 | * |
| 704 | * \retval PSA_SUCCESS Success. |
| 705 | * \retval PSA_ERROR_CONNECTION_REFUSED The SPM or RoT Service has refused the |
| 706 | * connection. |
| 707 | * \retval PSA_ERROR_CONNECTION_BUSY The SPM or RoT Service cannot make the |
| 708 | * connection at the moment. |
| 709 | * \retval "Does not return" The RoT Service ID and version are not |
| 710 | * supported, or the caller is not permitted to |
| 711 | * access the service. |
| 712 | */ |
| 713 | psa_status_t tfm_spm_psa_connect(uint32_t *args, bool ns_caller); |
| 714 | |
| 715 | /** |
| 716 | * \brief SVC handler for \ref psa_call. |
| 717 | * |
| 718 | * \param[in] args Include all input arguments: |
| 719 | * handle, in_vec, in_len, out_vec, out_len. |
| 720 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 721 | * Or from secure client. |
| 722 | * \param[in] lr EXC_RETURN value of the SVC. |
| 723 | * |
| 724 | * \retval >=0 RoT Service-specific status value. |
| 725 | * \retval <0 RoT Service-specific error code. |
| 726 | * \retval PSA_ERROR_PROGRAMMER_ERROR The connection has been terminated by the |
| 727 | * RoT Service. The call is a PROGRAMMER ERROR if |
| 728 | * one or more of the following are true: |
| 729 | * \arg An invalid handle was passed. |
| 730 | * \arg The connection is already handling a request. |
| 731 | * \arg type < 0. |
| 732 | * \arg An invalid memory reference was provided. |
| 733 | * \arg in_len + out_len > PSA_MAX_IOVEC. |
| 734 | * \arg The message is unrecognized by the RoT |
| 735 | * Service or incorrectly formatted. |
| 736 | */ |
| 737 | psa_status_t tfm_spm_psa_call(uint32_t *args, bool ns_caller, uint32_t lr); |
| 738 | |
| 739 | /** |
| 740 | * \brief SVC handler for \ref psa_close. |
| 741 | * |
| 742 | * \param[in] args Include all input arguments: handle. |
| 743 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 744 | * Or from secure client. |
| 745 | * |
| 746 | * \retval void Success. |
| 747 | * \retval "Does not return" The call is invalid, one or more of the |
| 748 | * following are true: |
| 749 | * \arg An invalid handle was provided that is not |
| 750 | * the null handle. |
| 751 | * \arg The connection is handling a request. |
| 752 | */ |
| 753 | void tfm_spm_psa_close(uint32_t *args, bool ns_caller); |
| 754 | |
| 755 | /* Svcall for PSA Service APIs */ |
| 756 | |
| 757 | /** |
| 758 | * \brief SVC handler for \ref psa_wait. |
| 759 | * |
| 760 | * \param[in] args Include all input arguments: |
| 761 | * signal_mask, timeout. |
| 762 | * |
| 763 | * \retval >0 At least one signal is asserted. |
| 764 | * \retval 0 No signals are asserted. This is only seen when |
| 765 | * a polling timeout is used. |
| 766 | */ |
| 767 | psa_signal_t tfm_spm_psa_wait(uint32_t *args); |
| 768 | |
| 769 | /** |
| 770 | * \brief SVC handler for \ref psa_get. |
| 771 | * |
| 772 | * \param[in] args Include all input arguments: signal, msg. |
| 773 | * |
| 774 | * \retval PSA_SUCCESS Success, *msg will contain the delivered |
| 775 | * message. |
| 776 | * \retval PSA_ERROR_DOES_NOT_EXIST Message could not be delivered. |
| 777 | * \retval "Does not return" The call is invalid because one or more of the |
| 778 | * following are true: |
| 779 | * \arg signal has more than a single bit set. |
| 780 | * \arg signal does not correspond to an RoT Service. |
| 781 | * \arg The RoT Service signal is not currently |
| 782 | * asserted. |
| 783 | * \arg The msg pointer provided is not a valid memory |
| 784 | * reference. |
| 785 | */ |
| 786 | psa_status_t tfm_spm_psa_get(uint32_t *args); |
| 787 | |
| 788 | /** |
| 789 | * \brief SVC handler for \ref psa_set_rhandle. |
| 790 | * |
| 791 | * \param[in] args Include all input arguments: |
| 792 | * msg_handle, rhandle. |
| 793 | * |
| 794 | * \retval void Success, rhandle will be provided with all |
| 795 | * subsequent messages delivered on this |
| 796 | * connection. |
| 797 | * \retval "Does not return" msg_handle is invalid. |
| 798 | */ |
| 799 | void tfm_spm_psa_set_rhandle(uint32_t *args); |
| 800 | |
| 801 | /** |
| 802 | * \brief SVC handler for \ref psa_read. |
| 803 | * |
| 804 | * \param[in] args Include all input arguments: |
| 805 | * msg_handle, invec_idx, buffer, num_bytes. |
| 806 | * |
| 807 | * \retval >0 Number of bytes copied. |
| 808 | * \retval 0 There was no remaining data in this input |
| 809 | * vector. |
| 810 | * \retval "Does not return" The call is invalid, one or more of the |
| 811 | * following are true: |
| 812 | * \arg msg_handle is invalid. |
| 813 | * \arg msg_handle does not refer to a request |
| 814 | * message. |
| 815 | * \arg invec_idx is equal to or greater than |
| 816 | * \ref PSA_MAX_IOVEC. |
| 817 | * \arg the memory reference for buffer is invalid or |
| 818 | * not writable. |
| 819 | */ |
| 820 | size_t tfm_spm_psa_read(uint32_t *args); |
| 821 | |
| 822 | /** |
| 823 | * \brief SVC handler for \ref psa_skip. |
| 824 | * |
| 825 | * \param[in] args Include all input arguments: |
| 826 | * msg_handle, invec_idx, num_bytes. |
| 827 | * |
| 828 | * \retval >0 Number of bytes skipped. |
| 829 | * \retval 0 There was no remaining data in this input |
| 830 | * vector. |
| 831 | * \retval "Does not return" The call is invalid, one or more of the |
| 832 | * following are true: |
| 833 | * \arg msg_handle is invalid. |
| 834 | * \arg msg_handle does not refer to a request |
| 835 | * message. |
| 836 | * \arg invec_idx is equal to or greater than |
| 837 | * \ref PSA_MAX_IOVEC. |
| 838 | */ |
| 839 | size_t tfm_spm_psa_skip(uint32_t *args); |
| 840 | |
| 841 | /** |
| 842 | * \brief SVC handler for \ref psa_write. |
| 843 | * |
| 844 | * \param[in] args Include all input arguments: |
| 845 | * msg_handle, outvec_idx, buffer, num_bytes. |
| 846 | * |
| 847 | * \retval void Success |
| 848 | * \retval "Does not return" The call is invalid, one or more of the |
| 849 | * following are true: |
| 850 | * \arg msg_handle is invalid. |
| 851 | * \arg msg_handle does not refer to a request |
| 852 | * message. |
| 853 | * \arg outvec_idx is equal to or greater than |
| 854 | * \ref PSA_MAX_IOVEC. |
| 855 | * \arg The memory reference for buffer is invalid. |
| 856 | * \arg The call attempts to write data past the end |
| 857 | * of the client output vector. |
| 858 | */ |
| 859 | void tfm_spm_psa_write(uint32_t *args); |
| 860 | |
| 861 | /** |
| 862 | * \brief SVC handler for \ref psa_reply. |
| 863 | * |
| 864 | * \param[in] args Include all input arguments: |
| 865 | * msg_handle, status. |
| 866 | * |
| 867 | * \retval void Success. |
| 868 | * \retval "Does not return" The call is invalid, one or more of the |
| 869 | * following are true: |
| 870 | * \arg msg_handle is invalid. |
| 871 | * \arg An invalid status code is specified for the |
| 872 | * type of message. |
| 873 | */ |
| 874 | void tfm_spm_psa_reply(uint32_t *args); |
| 875 | |
| 876 | /** |
| 877 | * \brief SVC handler for \ref psa_notify. |
| 878 | * |
| 879 | * \param[in] args Include all input arguments: partition_id. |
| 880 | * |
| 881 | * \retval void Success. |
| 882 | * \retval "Does not return" partition_id does not correspond to a Secure |
| 883 | * Partition. |
| 884 | */ |
| 885 | void tfm_spm_psa_notify(uint32_t *args); |
| 886 | |
| 887 | /** |
| 888 | * \brief SVC handler for \ref psa_clear. |
| 889 | * |
| 890 | * \retval void Success. |
| 891 | * \retval "Does not return" The Secure Partition's doorbell signal is not |
| 892 | * currently asserted. |
| 893 | */ |
| 894 | void tfm_spm_psa_clear(void); |
| 895 | |
| 896 | /** |
| 897 | * \brief SVC handler for \ref psa_eoi. |
| 898 | * |
| 899 | * \param[in] args Include all input arguments: irq_signal. |
| 900 | * |
| 901 | * \retval void Success. |
| 902 | * \retval "Does not return" The call is invalid, one or more of the |
| 903 | * following are true: |
| 904 | * \arg irq_signal is not an interrupt signal. |
| 905 | * \arg irq_signal indicates more than one signal. |
| 906 | * \arg irq_signal is not currently asserted. |
| 907 | */ |
| 908 | void tfm_spm_psa_eoi(uint32_t *args); |
| 909 | |
| 910 | /** |
| 911 | * \brief SVC hander of enabling irq_line of the specified irq_signal. |
| 912 | * |
| 913 | * \param[in] args Include all input arguments: irq_signal. |
| 914 | * |
| 915 | * \retval void Success. |
| 916 | * \retval "Does not return" The call is invalid, one or more of the |
| 917 | * following are true: |
| 918 | * \arg irq_signal is not an interrupt signal. |
| 919 | * \arg irq_signal indicates more than one signal. |
| 920 | */ |
| 921 | void tfm_spm_enable_irq(uint32_t *args); |
| 922 | |
| 923 | /** |
| 924 | * \brief SVC hander of disabling irq_line of the specified irq_signal. |
| 925 | * |
| 926 | * \param[in] args Include all input arguments: irq_signal. |
| 927 | * |
| 928 | * \retval void Success. |
| 929 | * \retval "Does not return" The call is invalid, one or more of the |
| 930 | * following are true: |
| 931 | * \arg irq_signal is not an interrupt signal. |
| 932 | * \arg irq_signal indicates more than one signal. |
| 933 | */ |
| 934 | void tfm_spm_disable_irq(uint32_t *args); |
| 935 | |
| 936 | /** |
| 937 | * \brief Validate the whether NS caller re-enter. |
| 938 | * |
| 939 | * \param[in] p_cur_sp Pointer to current partition. |
| 940 | * \param[in] p_ctx Pointer to current stack context. |
| 941 | * \param[in] exc_return EXC_RETURN value. |
| 942 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 943 | * Or from secure client. |
| 944 | * |
| 945 | * \retval void Success. |
| 946 | */ |
| 947 | void tfm_spm_validate_caller(struct spm_partition_desc_t *p_cur_sp, |
| 948 | uint32_t *p_ctx, uint32_t exc_return, |
| 949 | bool ns_caller); |
| 950 | |
| 951 | /** |
| 952 | * \brief Terminate execution within the calling Secure Partition and will not |
| 953 | * return. |
| 954 | * |
| 955 | * \retval "Does not return" |
| 956 | */ |
| 957 | void tfm_spm_psa_panic(void); |
| 958 | |
| 959 | #endif /* defined(TFM_PSA_API) */ |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 960 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 961 | #endif /*__SPM_API_H__ */ |