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