Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Kevin Peng | a20b5af | 2021-01-11 11:20:52 +0800 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, 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 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 8 | #ifndef __SPM_IPC_H__ |
| 9 | #define __SPM_IPC_H__ |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 10 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 11 | #include <stdint.h> |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 12 | #include "spm_partition_defs.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 13 | #include "tfm_arch.h" |
Ken Liu | 24dffb2 | 2021-02-10 11:03:58 +0800 | [diff] [blame] | 14 | #include "lists.h" |
Edison Ai | 66fbdf1 | 2019-07-08 16:05:07 +0800 | [diff] [blame] | 15 | #include "tfm_wait.h" |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 16 | #include "tfm_secure_api.h" |
Summer Qin | b5da9cc | 2019-08-26 15:19:45 +0800 | [diff] [blame] | 17 | #include "tfm_thread.h" |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 18 | #include "psa/service.h" |
| 19 | |
| 20 | #define TFM_VERSION_POLICY_RELAXED 0 |
| 21 | #define TFM_VERSION_POLICY_STRICT 1 |
| 22 | |
| 23 | #define TFM_HANDLE_STATUS_IDLE 0 |
| 24 | #define TFM_HANDLE_STATUS_ACTIVE 1 |
| 25 | #define TFM_HANDLE_STATUS_CONNECT_ERROR 2 |
| 26 | |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 27 | #define PART_REGION_ADDR(partition, region) \ |
| 28 | (uint32_t)®ION_NAME(Image$$, partition, region) |
| 29 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 30 | #define TFM_CONN_HANDLE_MAX_NUM 16 |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 31 | |
Mingyang Sun | 3aefc36 | 2021-02-23 09:42:35 +0800 | [diff] [blame] | 32 | /* Set a minimum for client handle. Reserve small values for static handle. */ |
| 33 | #define STATIC_HANDLE_VALUE_LIMIT 32 |
| 34 | #define CLIENT_HANDLE_VALUE_MIN (STATIC_HANDLE_VALUE_LIMIT + 1) |
| 35 | |
Mate Toth-Pal | 52674ab | 2018-02-26 09:47:56 +0100 | [diff] [blame] | 36 | #define SPM_INVALID_PARTITION_IDX (~0U) |
| 37 | |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 38 | /* Privileged definitions for partition thread mode */ |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 39 | #define TFM_PARTITION_UNPRIVILEGED_MODE 0 |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 40 | #define TFM_PARTITION_PRIVILEGED_MODE 1 |
| 41 | |
| 42 | #define SPM_PART_FLAG_APP_ROT 0x01 |
| 43 | #define SPM_PART_FLAG_PSA_ROT 0x02 |
| 44 | #define SPM_PART_FLAG_IPC 0x04 |
Summer Qin | eb537e5 | 2019-03-29 09:57:10 +0800 | [diff] [blame] | 45 | |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 46 | #define TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST |
| 47 | #define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM |
| 48 | #define TFM_PRIORITY_LOW THRD_PRIOR_LOWEST |
| 49 | #define TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL |
| 50 | |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 51 | #define TFM_MSG_MAGIC 0x15154343 |
| 52 | |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 53 | /* Message struct to collect parameter from client */ |
| 54 | struct tfm_msg_body_t { |
| 55 | int32_t magic; |
| 56 | struct tfm_spm_service_t *service; /* RoT service pointer */ |
| 57 | struct tfm_event_t ack_evnt; /* Event for ack reponse */ |
| 58 | psa_msg_t msg; /* PSA message body */ |
| 59 | psa_invec invec[PSA_MAX_IOVEC]; /* Put in/out vectors in msg body */ |
| 60 | psa_outvec outvec[PSA_MAX_IOVEC]; |
| 61 | psa_outvec *caller_outvec; /* |
| 62 | * Save caller outvec pointer for |
| 63 | * write length update |
| 64 | */ |
| 65 | #ifdef TFM_MULTI_CORE_TOPOLOGY |
| 66 | const void *caller_data; /* |
| 67 | * Pointer to the private data of the |
| 68 | * caller. It identifies the NSPE PSA |
| 69 | * client calls in multi-core topology |
| 70 | */ |
| 71 | #endif |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 72 | struct bi_list_node_t msg_node; /* For list operators */ |
Mingyang Sun | 73056b6 | 2020-07-03 15:18:46 +0800 | [diff] [blame] | 73 | }; |
| 74 | |
Mate Toth-Pal | 3db437a | 2018-06-22 16:15:13 +0200 | [diff] [blame] | 75 | /** |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 76 | * Holds the fields of the partition DB used by the SPM code. The values of |
| 77 | * these fields are calculated at compile time, and set during initialisation |
| 78 | * phase. |
| 79 | */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 80 | struct partition_static_t { |
Mingyang Sun | 56c5969 | 2020-07-20 17:02:19 +0800 | [diff] [blame] | 81 | uint32_t psa_ff_ver; /* PSA-FF version */ |
| 82 | uint32_t pid; /* Partition ID */ |
| 83 | uint32_t flags; /* Flags of the partition */ |
| 84 | uint32_t priority; /* Priority of the partition thread */ |
| 85 | sp_entry_point entry; /* Entry point of the partition */ |
| 86 | uintptr_t stack_base_addr; /* Stack base of the partition */ |
| 87 | size_t stack_size; /* Stack size of the partition */ |
| 88 | uintptr_t heap_base_addr; /* Heap base of the partition */ |
| 89 | size_t heap_size; /* Heap size of the partition */ |
Ken Liu | 172f1e3 | 2021-02-05 16:31:03 +0800 | [diff] [blame] | 90 | uintptr_t platform_data; /* Platform specific data */ |
Mingyang Sun | 56c5969 | 2020-07-20 17:02:19 +0800 | [diff] [blame] | 91 | uint32_t ndeps; /* Numbers of depended services */ |
| 92 | uint32_t *deps; /* Pointer to dependency arrays */ |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * Holds the fields that define a partition for SPM. The fields are further |
| 97 | * divided to structures, to keep the related fields close to each other. |
| 98 | */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 99 | struct partition_t { |
Mingyang Sun | 56c5969 | 2020-07-20 17:02:19 +0800 | [diff] [blame] | 100 | const struct partition_static_t *p_static; |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 101 | void *p_platform; |
| 102 | void *p_interrupts; |
| 103 | void *p_metadata; |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 104 | struct tfm_core_thread_t sp_thread; |
| 105 | struct tfm_event_t event; |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 106 | struct bi_list_node_t msg_list; |
Mingyang Sun | af22ffa | 2020-07-09 17:48:37 +0800 | [diff] [blame] | 107 | uint32_t signals_allowed; |
| 108 | uint32_t signals_waiting; |
| 109 | uint32_t signals_asserted; |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 110 | /** A list of platform_data pointers */ |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 111 | const struct tfm_spm_partition_memory_data_t *memory_data; |
| 112 | }; |
| 113 | |
| 114 | struct spm_partition_db_t { |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 115 | uint32_t partition_count; |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 116 | struct partition_t *partitions; |
Mingyang Sun | 37f6ced | 2020-07-08 16:30:28 +0800 | [diff] [blame] | 117 | }; |
| 118 | |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 119 | /* Service database defined by manifest */ |
| 120 | struct tfm_spm_service_db_t { |
| 121 | char *name; /* Service name */ |
| 122 | uint32_t partition_id; /* Partition ID which service belong to */ |
| 123 | psa_signal_t signal; /* Service signal */ |
| 124 | uint32_t sid; /* Service identifier */ |
| 125 | bool non_secure_client; /* If can be called by non secure client */ |
Mingyang Sun | 973c4f4 | 2021-03-11 14:54:22 +0800 | [diff] [blame^] | 126 | bool connection_based; /* 'true' for connection-based service */ |
Shawn Shan | cc39fcb | 2019-11-13 15:38:16 +0800 | [diff] [blame] | 127 | uint32_t version; /* Service version */ |
| 128 | uint32_t version_policy; /* Service version policy */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | /* RoT Service data */ |
| 132 | struct tfm_spm_service_t { |
Summer Qin | e578c5b | 2019-08-16 16:42:16 +0800 | [diff] [blame] | 133 | const struct tfm_spm_service_db_t *service_db;/* Service database pointer */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 134 | struct partition_t *partition; /* |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 135 | * Point to secure partition |
| 136 | * data |
| 137 | */ |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 138 | struct bi_list_node_t handle_list; /* Service handle list */ |
| 139 | struct bi_list_node_t list; /* For list operation */ |
Mingyang Sun | da01a97 | 2019-07-12 17:32:59 +0800 | [diff] [blame] | 140 | }; |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 141 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 142 | /* RoT connection handle list */ |
| 143 | struct tfm_conn_handle_t { |
| 144 | void *rhandle; /* Reverse handle value */ |
| 145 | uint32_t status; /* |
| 146 | * Status of handle, three valid |
| 147 | * options: |
| 148 | * TFM_HANDLE_STATUS_ACTIVE, |
| 149 | * TFM_HANDLE_STATUS_IDLE and |
| 150 | * TFM_HANDLE_STATUS_CONNECT_ERROR |
| 151 | */ |
| 152 | int32_t client_id; /* |
| 153 | * Partition ID of the sender of the |
| 154 | * message: |
| 155 | * - secure partition id; |
| 156 | * - non secure client endpoint id. |
| 157 | */ |
| 158 | struct tfm_msg_body_t internal_msg; /* Internal message for message queue */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 159 | struct tfm_spm_service_t *service; /* RoT service pointer */ |
Ken Liu | 2c47f7f | 2021-01-22 11:06:04 +0800 | [diff] [blame] | 160 | struct bi_list_node_t list; /* list node */ |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 161 | }; |
| 162 | |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 163 | enum tfm_memory_access_e { |
| 164 | TFM_MEMORY_ACCESS_RO = 1, |
| 165 | TFM_MEMORY_ACCESS_RW = 2, |
| 166 | }; |
Summer Qin | b4a854d | 2019-05-29 15:31:22 +0800 | [diff] [blame] | 167 | |
| 168 | /** |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 169 | * \brief Get the current partition mode. |
| 170 | * |
| 171 | * \param[in] partition_flags Flags of current partition |
| 172 | * |
| 173 | * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode |
| 174 | * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode |
| 175 | */ |
| 176 | uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags); |
| 177 | |
Summer Qin | 830c554 | 2020-02-14 13:44:20 +0800 | [diff] [blame] | 178 | /** |
| 179 | * \brief Handle an SPM request by a secure service |
| 180 | * \param[in] svc_ctx The stacked SVC context |
| 181 | */ |
| 182 | void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx); |
| 183 | |
Edison Ai | 7aff9e8 | 2019-07-11 14:56:46 +0800 | [diff] [blame] | 184 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 185 | * \brief Get the running partition ID. |
| 186 | * |
| 187 | * \return Returns the partition ID |
| 188 | */ |
| 189 | uint32_t tfm_spm_partition_get_running_partition_id(void); |
| 190 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 191 | /******************** Service handle management functions ********************/ |
| 192 | |
| 193 | /** |
| 194 | * \brief Create connection handle for client connect |
| 195 | * |
| 196 | * \param[in] service Target service context pointer |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 197 | * \param[in] client_id Partition ID of the sender of the message |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 198 | * |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 199 | * \retval NULL Create failed |
| 200 | * \retval "Not NULL" Service handle created |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 201 | */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 202 | struct tfm_conn_handle_t *tfm_spm_create_conn_handle( |
| 203 | struct tfm_spm_service_t *service, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 204 | int32_t client_id); |
| 205 | |
| 206 | /** |
| 207 | * \brief Validate connection handle for client connect |
| 208 | * |
| 209 | * \param[in] conn_handle Handle to be validated |
| 210 | * \param[in] client_id Partition ID of the sender of the message |
| 211 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 212 | * \retval SPM_SUCCESS Success |
| 213 | * \retval SPM_ERROR_GENERIC Invalid handle |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 214 | */ |
Summer Qin | 630c76b | 2020-05-20 10:32:58 +0800 | [diff] [blame] | 215 | int32_t tfm_spm_validate_conn_handle( |
| 216 | const struct tfm_conn_handle_t *conn_handle, |
| 217 | int32_t client_id); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 218 | |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 219 | /** |
| 220 | * \brief Free connection handle which not used anymore. |
| 221 | * |
| 222 | * \param[in] service Target service context pointer |
| 223 | * \param[in] conn_handle Connection handle created by |
| 224 | * tfm_spm_create_conn_handle() |
| 225 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 226 | * \retval SPM_SUCCESS Success |
| 227 | * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 228 | * \retval "Does not return" Panic for not find service by handle |
| 229 | */ |
| 230 | int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service, |
| 231 | struct tfm_conn_handle_t *conn_handle); |
| 232 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 233 | /******************** Partition management functions *************************/ |
| 234 | |
| 235 | /** |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 236 | * \brief Get the msg context by signal. |
| 237 | * |
| 238 | * \param[in] partition Partition context pointer |
| 239 | * \ref partition_t structures |
| 240 | * \param[in] signal Signal associated with inputs to the Secure |
| 241 | * Partition, \ref psa_signal_t |
| 242 | * |
| 243 | * \retval NULL Failed |
| 244 | * \retval "Not NULL" Target service context pointer, |
| 245 | * \ref tfm_msg_body_t structures |
| 246 | */ |
| 247 | struct tfm_msg_body_t *tfm_spm_get_msg_by_signal(struct partition_t *partition, |
| 248 | psa_signal_t signal); |
| 249 | |
| 250 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 251 | * \brief Get current running partition context. |
| 252 | * |
| 253 | * \retval NULL Failed |
| 254 | * \retval "Not NULL" Return the parttion context pointer |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 255 | * \ref partition_t structures |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 256 | */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 257 | struct partition_t *tfm_spm_get_running_partition(void); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 258 | |
| 259 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 260 | * \brief Get the service context by service ID. |
| 261 | * |
| 262 | * \param[in] sid RoT Service identity |
| 263 | * |
| 264 | * \retval NULL Failed |
| 265 | * \retval "Not NULL" Target service context pointer, |
| 266 | * \ref tfm_spm_service_t structures |
| 267 | */ |
| 268 | struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid); |
| 269 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 270 | /************************ Message functions **********************************/ |
| 271 | |
| 272 | /** |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 273 | * \brief Get message context by message handle. |
| 274 | * |
| 275 | * \param[in] msg_handle Message handle which is a reference generated |
| 276 | * by the SPM to a specific message. |
| 277 | * |
| 278 | * \return The message body context pointer |
| 279 | * \ref tfm_msg_body_t structures |
| 280 | */ |
| 281 | struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle); |
| 282 | |
| 283 | /** |
Kevin Peng | df6aa29 | 2021-03-11 17:58:50 +0800 | [diff] [blame] | 284 | * \brief Get message context by connect handle. |
| 285 | * |
| 286 | * \param[in] conn_handle Service connect handle. |
| 287 | * |
| 288 | * \return The message body context pointer |
| 289 | * \ref msg_body_t structures |
| 290 | */ |
| 291 | struct tfm_msg_body_t * |
| 292 | tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle); |
| 293 | |
| 294 | /** |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 295 | * \brief Fill the message for PSA client call. |
| 296 | * |
| 297 | * \param[in] msg Service Message Queue buffer pointer |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 298 | * \param[in] service Target service context pointer, which can be |
| 299 | * obtained by partition management functions |
| 300 | * \prarm[in] handle Connect handle return by psa_connect(). |
| 301 | * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or |
| 302 | * PSA_IPC_DISCONNECT |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 303 | * \param[in] client_id Partition ID of the sender of the message |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 304 | * \param[in] invec Array of input \ref psa_invec structures |
| 305 | * \param[in] in_len Number of input \ref psa_invec structures |
| 306 | * \param[in] outvec Array of output \ref psa_outvec structures |
| 307 | * \param[in] out_len Number of output \ref psa_outvec structures |
| 308 | * \param[in] caller_outvec Array of caller output \ref psa_outvec structures |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 309 | */ |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 310 | void tfm_spm_fill_msg(struct tfm_msg_body_t *msg, |
| 311 | struct tfm_spm_service_t *service, |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 312 | psa_handle_t handle, |
Summer Qin | 1ce712a | 2019-10-14 18:04:05 +0800 | [diff] [blame] | 313 | int32_t type, int32_t client_id, |
Edison Ai | 9711582 | 2019-08-01 14:22:19 +0800 | [diff] [blame] | 314 | psa_invec *invec, size_t in_len, |
| 315 | psa_outvec *outvec, size_t out_len, |
| 316 | psa_outvec *caller_outvec); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 317 | |
| 318 | /** |
| 319 | * \brief Send message and wake up the SP who is waiting on |
| 320 | * message queue, block the current thread and |
| 321 | * scheduler triggered |
| 322 | * |
| 323 | * \param[in] service Target service context pointer, which can be |
| 324 | * obtained by partition management functions |
| 325 | * \param[in] msg message created by tfm_spm_create_msg() |
| 326 | * \ref tfm_msg_body_t structures |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 327 | */ |
Kevin Peng | 8dac610 | 2021-03-09 16:44:00 +0800 | [diff] [blame] | 328 | void tfm_spm_send_event(struct tfm_spm_service_t *service, |
| 329 | struct tfm_msg_body_t *msg); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 330 | |
| 331 | /** |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 332 | * \brief Check the client version according to |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 333 | * version policy |
| 334 | * |
| 335 | * \param[in] service Target service context pointer, which can be get |
| 336 | * by partition management functions |
Jaykumar Pitambarbhai Patel | 3a98602 | 2019-10-08 17:37:15 +0530 | [diff] [blame] | 337 | * \param[in] version Client support version |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 338 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 339 | * \retval SPM_SUCCESS Success |
| 340 | * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input |
| 341 | * \retval SPM_ERROR_VERSION Check failed |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 342 | */ |
| 343 | 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] | 344 | uint32_t version); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 345 | |
| 346 | /** |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 347 | * \brief Check the client access authorization |
| 348 | * |
| 349 | * \param[in] sid Target RoT Service identity |
| 350 | * \param[in] service Target service context pointer, which can be get |
| 351 | * by partition management functions |
| 352 | * \param[in] ns_caller Whether from NS caller |
| 353 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 354 | * \retval SPM_SUCCESS Success |
| 355 | * \retval SPM_ERROR_GENERIC Authorization check failed |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 356 | */ |
| 357 | int32_t tfm_spm_check_authorization(uint32_t sid, |
| 358 | struct tfm_spm_service_t *service, |
Summer Qin | 618e8c3 | 2019-12-09 10:47:20 +0800 | [diff] [blame] | 359 | bool ns_caller); |
Edison Ai | e728fbf | 2019-11-13 09:37:12 +0800 | [diff] [blame] | 360 | |
| 361 | /** |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 362 | * \brief Check the memory reference is valid. |
| 363 | * |
| 364 | * \param[in] buffer Pointer of memory reference |
| 365 | * \param[in] len Length of memory reference in bytes |
| 366 | * \param[in] ns_caller From non-secure caller |
| 367 | * \param[in] access Type of access specified by the |
| 368 | * \ref tfm_memory_access_e |
| 369 | * \param[in] privileged Privileged mode or unprivileged mode: |
| 370 | * \ref TFM_PARTITION_UNPRIVILEGED_MODE |
| 371 | * \ref TFM_PARTITION_PRIVILEGED_MODE |
| 372 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 373 | * \retval SPM_SUCCESS Success |
| 374 | * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input |
| 375 | * \retval SPM_ERROR_MEMORY_CHECK Check failed |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 376 | */ |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 377 | 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] | 378 | enum tfm_memory_access_e access, |
| 379 | uint32_t privileged); |
| 380 | |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 381 | /* |
| 382 | * PendSV specified function. |
| 383 | * |
| 384 | * Parameters : |
Summer Qin | d2ad7e7 | 2020-01-06 18:16:35 +0800 | [diff] [blame] | 385 | * p_actx - Architecture context storage pointer |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 386 | * |
| 387 | * Notes: |
| 388 | * This is a staging API. Scheduler should be called in SPM finally and |
| 389 | * this function will be obsoleted later. |
| 390 | */ |
Summer Qin | d2ad7e7 | 2020-01-06 18:16:35 +0800 | [diff] [blame] | 391 | void tfm_pendsv_do_schedule(struct tfm_arch_ctx_t *p_actx); |
Mingyang Sun | f3d2989 | 2019-07-10 17:50:23 +0800 | [diff] [blame] | 392 | |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 393 | /** |
| 394 | * \brief SPM initialization implementation |
| 395 | * |
| 396 | * \details This function must be called under handler mode. |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 397 | * \retval This function returns an EXC_RETURN value. Other |
| 398 | * faults would panic the execution and never |
| 399 | * returned. |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 400 | */ |
Ken Liu | ce2692d | 2020-02-11 12:39:36 +0800 | [diff] [blame] | 401 | uint32_t tfm_spm_init(void); |
Ken Liu | 490281d | 2019-12-30 15:55:26 +0800 | [diff] [blame] | 402 | |
Summer Qin | dea1f2c | 2021-01-11 14:46:34 +0800 | [diff] [blame] | 403 | #if !defined(__ARM_ARCH_8_1M_MAIN__) |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 404 | /** |
| 405 | * \brief Validate the whether NS caller re-enter. |
| 406 | * |
| 407 | * \param[in] p_cur_sp Pointer to current partition. |
| 408 | * \param[in] p_ctx Pointer to current stack context. |
| 409 | * \param[in] exc_return EXC_RETURN value. |
| 410 | * \param[in] ns_caller If 'true', call from non-secure client. |
| 411 | * Or from secure client. |
| 412 | * |
| 413 | * \retval void Success. |
Summer Qin | dea1f2c | 2021-01-11 14:46:34 +0800 | [diff] [blame] | 414 | * |
| 415 | * Notes: |
| 416 | * For architecture v8.1m and later, will use hardware re-entrant detection. |
| 417 | * Otherwise will use the software solution to validate the caller. |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 418 | */ |
Mingyang Sun | ae70d8d | 2020-06-30 15:56:05 +0800 | [diff] [blame] | 419 | void tfm_spm_validate_caller(struct partition_t *p_cur_sp, uint32_t *p_ctx, |
| 420 | uint32_t exc_return, bool ns_caller); |
Summer Qin | dea1f2c | 2021-01-11 14:46:34 +0800 | [diff] [blame] | 421 | #else |
| 422 | /** |
| 423 | * In v8.1 mainline, will use hardware re-entrant detection instead. |
| 424 | */ |
| 425 | __STATIC_INLINE |
| 426 | void tfm_spm_validate_caller(struct partition_t *p_cur_sp, uint32_t *p_ctx, |
| 427 | uint32_t exc_return, bool ns_caller) |
| 428 | { |
| 429 | (void)p_cur_sp; |
| 430 | (void)p_ctx; |
| 431 | (void)exc_return; |
| 432 | (void)ns_caller; |
| 433 | return; |
| 434 | } |
| 435 | #endif |
| 436 | |
Mingyang Sun | d44522a | 2020-01-16 16:48:37 +0800 | [diff] [blame] | 437 | |
| 438 | /** |
Ken Liu | 505b170 | 2020-05-29 13:19:58 +0800 | [diff] [blame] | 439 | * \brief Converts a handle instance into a corresponded user handle. |
| 440 | */ |
| 441 | psa_handle_t tfm_spm_to_user_handle(struct tfm_conn_handle_t *handle_instance); |
| 442 | |
| 443 | /** |
Summer Qin | 373feb1 | 2020-03-27 15:35:33 +0800 | [diff] [blame] | 444 | * \brief Converts a user handle into a corresponded handle instance. |
| 445 | */ |
| 446 | struct tfm_conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle); |
| 447 | |
Summer Qin | 9c1fba1 | 2020-08-12 15:49:12 +0800 | [diff] [blame] | 448 | /** |
| 449 | * \brief Move to handler mode by a SVC for specific purpose |
| 450 | */ |
| 451 | void tfm_core_handler_mode(void); |
| 452 | |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 453 | /** |
| 454 | * \brief Set reverse handle value for connection. |
| 455 | * |
| 456 | * \param[in] service Target service context pointer |
| 457 | * \param[in] conn_handle Connection handle created by |
| 458 | * tfm_spm_create_conn_handle() |
| 459 | * \param[in] rhandle rhandle need to save |
| 460 | * |
Ken Liu | bcae38b | 2021-01-20 15:47:44 +0800 | [diff] [blame] | 461 | * \retval SPM_SUCCESS Success |
| 462 | * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 463 | * \retval "Does not return" Panic for not find handle node |
| 464 | */ |
| 465 | int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service, |
| 466 | struct tfm_conn_handle_t *conn_handle, |
| 467 | void *rhandle); |
| 468 | |
| 469 | void update_caller_outvec_len(struct tfm_msg_body_t *msg); |
| 470 | |
| 471 | /** |
| 472 | * \brief notify the partition with the signal. |
| 473 | * |
| 474 | * \param[in] partition_id The ID of the partition to be notified. |
| 475 | * \param[in] signal The signal that the partition is to be notified |
| 476 | * with. |
| 477 | * |
| 478 | * \retval void Success. |
| 479 | * \retval "Does not return" If partition_id is invalid. |
| 480 | */ |
| 481 | void notify_with_signal(int32_t partition_id, psa_signal_t signal); |
| 482 | |
| 483 | /** |
| 484 | * \brief Return the IRQ line number associated with a signal |
| 485 | * |
| 486 | * \param[in] partition_id The ID of the partition in which we look for |
| 487 | * the signal. |
Kevin Peng | 410bee5 | 2021-01-13 16:27:17 +0800 | [diff] [blame] | 488 | * \param[in] signal The signal to query for. |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 489 | * |
Kevin Peng | a20b5af | 2021-01-11 11:20:52 +0800 | [diff] [blame] | 490 | * \retval None-negative value The irq line associated with signal |
Kevin Peng | 410bee5 | 2021-01-13 16:27:17 +0800 | [diff] [blame] | 491 | * \retval Negative value if one of more the following are true: |
| 492 | * - the \ref signal indicates more than one signal |
| 493 | * - the \ref signal does not belong to the |
| 494 | * partition. |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 495 | */ |
Kevin Peng | a20b5af | 2021-01-11 11:20:52 +0800 | [diff] [blame] | 496 | int32_t get_irq_line_for_signal(int32_t partition_id, psa_signal_t signal); |
Summer Qin | 02f7f07 | 2020-08-24 16:02:54 +0800 | [diff] [blame] | 497 | |
Mingyang Sun | 7397b4f | 2020-06-17 15:07:45 +0800 | [diff] [blame] | 498 | #endif /* __SPM_IPC_H__ */ |