blob: ed04f05f76da1bfbc68a866d65fc5d279fe742ca [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Kevin Penga20b5af2021-01-11 11:20:52 +08002 * Copyright (c) 2020-2021, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
Mingyang Sun7397b4f2020-06-17 15:07:45 +08008#ifndef __SPM_IPC_H__
9#define __SPM_IPC_H__
Miklos Balint386b8b52017-11-29 13:12:32 +000010
Mingyang Sun7397b4f2020-06-17 15:07:45 +080011#include <stdint.h>
Mingyang Sun37f6ced2020-07-08 16:30:28 +080012#include "spm_partition_defs.h"
Mingyang Sun7397b4f2020-06-17 15:07:45 +080013#include "tfm_arch.h"
Ken Liu24dffb22021-02-10 11:03:58 +080014#include "lists.h"
Edison Ai66fbdf12019-07-08 16:05:07 +080015#include "tfm_wait.h"
Mingyang Sunf3d29892019-07-10 17:50:23 +080016#include "tfm_secure_api.h"
Summer Qinb5da9cc2019-08-26 15:19:45 +080017#include "tfm_thread.h"
Mingyang Sun7397b4f2020-06-17 15:07:45 +080018#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 Sun37f6ced2020-07-08 16:30:28 +080027#define PART_REGION_ADDR(partition, region) \
28 (uint32_t)&REGION_NAME(Image$$, partition, region)
29
Mingyang Sun7397b4f2020-06-17 15:07:45 +080030#define TFM_CONN_HANDLE_MAX_NUM 16
Miklos Balint386b8b52017-11-29 13:12:32 +000031
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010032#define SPM_INVALID_PARTITION_IDX (~0U)
33
Summer Qineb537e52019-03-29 09:57:10 +080034/* Privileged definitions for partition thread mode */
Summer Qineb537e52019-03-29 09:57:10 +080035#define TFM_PARTITION_UNPRIVILEGED_MODE 0
Mingyang Sun7397b4f2020-06-17 15:07:45 +080036#define TFM_PARTITION_PRIVILEGED_MODE 1
37
38#define SPM_PART_FLAG_APP_ROT 0x01
39#define SPM_PART_FLAG_PSA_ROT 0x02
40#define SPM_PART_FLAG_IPC 0x04
Summer Qineb537e52019-03-29 09:57:10 +080041
Mingyang Sun37f6ced2020-07-08 16:30:28 +080042#define TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST
43#define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM
44#define TFM_PRIORITY_LOW THRD_PRIOR_LOWEST
45#define TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL
46
Mingyang Sun73056b62020-07-03 15:18:46 +080047#define TFM_MSG_MAGIC 0x15154343
48
Mingyang Sun73056b62020-07-03 15:18:46 +080049/* Message struct to collect parameter from client */
50struct tfm_msg_body_t {
51 int32_t magic;
52 struct tfm_spm_service_t *service; /* RoT service pointer */
53 struct tfm_event_t ack_evnt; /* Event for ack reponse */
54 psa_msg_t msg; /* PSA message body */
55 psa_invec invec[PSA_MAX_IOVEC]; /* Put in/out vectors in msg body */
56 psa_outvec outvec[PSA_MAX_IOVEC];
57 psa_outvec *caller_outvec; /*
58 * Save caller outvec pointer for
59 * write length update
60 */
61#ifdef TFM_MULTI_CORE_TOPOLOGY
62 const void *caller_data; /*
63 * Pointer to the private data of the
64 * caller. It identifies the NSPE PSA
65 * client calls in multi-core topology
66 */
67#endif
Ken Liu2c47f7f2021-01-22 11:06:04 +080068 struct bi_list_node_t msg_node; /* For list operators */
Mingyang Sun73056b62020-07-03 15:18:46 +080069};
70
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020071/**
Mingyang Sun37f6ced2020-07-08 16:30:28 +080072 * Holds the fields of the partition DB used by the SPM code. The values of
73 * these fields are calculated at compile time, and set during initialisation
74 * phase.
75 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +080076struct partition_static_t {
Mingyang Sun56c59692020-07-20 17:02:19 +080077 uint32_t psa_ff_ver; /* PSA-FF version */
78 uint32_t pid; /* Partition ID */
79 uint32_t flags; /* Flags of the partition */
80 uint32_t priority; /* Priority of the partition thread */
81 sp_entry_point entry; /* Entry point of the partition */
82 uintptr_t stack_base_addr; /* Stack base of the partition */
83 size_t stack_size; /* Stack size of the partition */
84 uintptr_t heap_base_addr; /* Heap base of the partition */
85 size_t heap_size; /* Heap size of the partition */
Ken Liu172f1e32021-02-05 16:31:03 +080086 uintptr_t platform_data; /* Platform specific data */
Mingyang Sun56c59692020-07-20 17:02:19 +080087 uint32_t ndeps; /* Numbers of depended services */
88 uint32_t *deps; /* Pointer to dependency arrays */
Mingyang Sun37f6ced2020-07-08 16:30:28 +080089};
90
91/**
92 * Holds the fields that define a partition for SPM. The fields are further
93 * divided to structures, to keep the related fields close to each other.
94 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +080095struct partition_t {
Mingyang Sun56c59692020-07-20 17:02:19 +080096 const struct partition_static_t *p_static;
Mingyang Sunae70d8d2020-06-30 15:56:05 +080097 void *p_platform;
98 void *p_interrupts;
99 void *p_metadata;
Mingyang Sunaf22ffa2020-07-09 17:48:37 +0800100 struct tfm_core_thread_t sp_thread;
101 struct tfm_event_t event;
Ken Liu2c47f7f2021-01-22 11:06:04 +0800102 struct bi_list_node_t msg_list;
Mingyang Sunaf22ffa2020-07-09 17:48:37 +0800103 uint32_t signals_allowed;
104 uint32_t signals_waiting;
105 uint32_t signals_asserted;
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800106 /** A list of platform_data pointers */
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800107 const struct tfm_spm_partition_memory_data_t *memory_data;
108};
109
110struct spm_partition_db_t {
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800111 uint32_t partition_count;
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800112 struct partition_t *partitions;
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800113};
114
Mingyang Sunda01a972019-07-12 17:32:59 +0800115/* Service database defined by manifest */
116struct tfm_spm_service_db_t {
117 char *name; /* Service name */
118 uint32_t partition_id; /* Partition ID which service belong to */
119 psa_signal_t signal; /* Service signal */
120 uint32_t sid; /* Service identifier */
121 bool non_secure_client; /* If can be called by non secure client */
Shawn Shancc39fcb2019-11-13 15:38:16 +0800122 uint32_t version; /* Service version */
123 uint32_t version_policy; /* Service version policy */
Mingyang Sunda01a972019-07-12 17:32:59 +0800124};
125
126/* RoT Service data */
127struct tfm_spm_service_t {
Summer Qine578c5b2019-08-16 16:42:16 +0800128 const struct tfm_spm_service_db_t *service_db;/* Service database pointer */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800129 struct partition_t *partition; /*
Mingyang Sunda01a972019-07-12 17:32:59 +0800130 * Point to secure partition
131 * data
132 */
Ken Liu2c47f7f2021-01-22 11:06:04 +0800133 struct bi_list_node_t handle_list; /* Service handle list */
134 struct bi_list_node_t list; /* For list operation */
Mingyang Sunda01a972019-07-12 17:32:59 +0800135};
Summer Qin5fdcf632020-06-22 16:49:24 +0800136
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800137/* RoT connection handle list */
138struct tfm_conn_handle_t {
139 void *rhandle; /* Reverse handle value */
140 uint32_t status; /*
141 * Status of handle, three valid
142 * options:
143 * TFM_HANDLE_STATUS_ACTIVE,
144 * TFM_HANDLE_STATUS_IDLE and
145 * TFM_HANDLE_STATUS_CONNECT_ERROR
146 */
147 int32_t client_id; /*
148 * Partition ID of the sender of the
149 * message:
150 * - secure partition id;
151 * - non secure client endpoint id.
152 */
153 struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800154 struct tfm_spm_service_t *service; /* RoT service pointer */
Ken Liu2c47f7f2021-01-22 11:06:04 +0800155 struct bi_list_node_t list; /* list node */
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800156};
157
Summer Qin5fdcf632020-06-22 16:49:24 +0800158enum tfm_memory_access_e {
159 TFM_MEMORY_ACCESS_RO = 1,
160 TFM_MEMORY_ACCESS_RW = 2,
161};
Summer Qinb4a854d2019-05-29 15:31:22 +0800162
163/**
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100164 * \brief Get the current partition mode.
165 *
166 * \param[in] partition_flags Flags of current partition
167 *
168 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
169 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
170 */
171uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags);
172
Summer Qin830c5542020-02-14 13:44:20 +0800173/**
174 * \brief Handle an SPM request by a secure service
175 * \param[in] svc_ctx The stacked SVC context
176 */
177void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx);
178
Edison Ai7aff9e82019-07-11 14:56:46 +0800179/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800180 * \brief Get the running partition ID.
181 *
182 * \return Returns the partition ID
183 */
184uint32_t tfm_spm_partition_get_running_partition_id(void);
185
Mingyang Sunf3d29892019-07-10 17:50:23 +0800186/******************** Service handle management functions ********************/
187
188/**
189 * \brief Create connection handle for client connect
190 *
191 * \param[in] service Target service context pointer
Summer Qin1ce712a2019-10-14 18:04:05 +0800192 * \param[in] client_id Partition ID of the sender of the message
Mingyang Sunf3d29892019-07-10 17:50:23 +0800193 *
Summer Qin630c76b2020-05-20 10:32:58 +0800194 * \retval NULL Create failed
195 * \retval "Not NULL" Service handle created
Mingyang Sunf3d29892019-07-10 17:50:23 +0800196 */
Summer Qin630c76b2020-05-20 10:32:58 +0800197struct tfm_conn_handle_t *tfm_spm_create_conn_handle(
198 struct tfm_spm_service_t *service,
Summer Qin1ce712a2019-10-14 18:04:05 +0800199 int32_t client_id);
200
201/**
202 * \brief Validate connection handle for client connect
203 *
204 * \param[in] conn_handle Handle to be validated
205 * \param[in] client_id Partition ID of the sender of the message
206 *
Ken Liubcae38b2021-01-20 15:47:44 +0800207 * \retval SPM_SUCCESS Success
208 * \retval SPM_ERROR_GENERIC Invalid handle
Summer Qin1ce712a2019-10-14 18:04:05 +0800209 */
Summer Qin630c76b2020-05-20 10:32:58 +0800210int32_t tfm_spm_validate_conn_handle(
211 const struct tfm_conn_handle_t *conn_handle,
212 int32_t client_id);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800213
Summer Qin02f7f072020-08-24 16:02:54 +0800214/**
215 * \brief Free connection handle which not used anymore.
216 *
217 * \param[in] service Target service context pointer
218 * \param[in] conn_handle Connection handle created by
219 * tfm_spm_create_conn_handle()
220 *
Ken Liubcae38b2021-01-20 15:47:44 +0800221 * \retval SPM_SUCCESS Success
222 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
Summer Qin02f7f072020-08-24 16:02:54 +0800223 * \retval "Does not return" Panic for not find service by handle
224 */
225int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
226 struct tfm_conn_handle_t *conn_handle);
227
Mingyang Sunf3d29892019-07-10 17:50:23 +0800228/******************** Partition management functions *************************/
229
230/**
Summer Qin02f7f072020-08-24 16:02:54 +0800231 * \brief Get the msg context by signal.
232 *
233 * \param[in] partition Partition context pointer
234 * \ref partition_t structures
235 * \param[in] signal Signal associated with inputs to the Secure
236 * Partition, \ref psa_signal_t
237 *
238 * \retval NULL Failed
239 * \retval "Not NULL" Target service context pointer,
240 * \ref tfm_msg_body_t structures
241 */
242struct tfm_msg_body_t *tfm_spm_get_msg_by_signal(struct partition_t *partition,
243 psa_signal_t signal);
244
245/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800246 * \brief Get current running partition context.
247 *
248 * \retval NULL Failed
249 * \retval "Not NULL" Return the parttion context pointer
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800250 * \ref partition_t structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800251 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800252struct partition_t *tfm_spm_get_running_partition(void);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800253
254/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800255 * \brief Get the service context by service ID.
256 *
257 * \param[in] sid RoT Service identity
258 *
259 * \retval NULL Failed
260 * \retval "Not NULL" Target service context pointer,
261 * \ref tfm_spm_service_t structures
262 */
263struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
264
Mingyang Sunf3d29892019-07-10 17:50:23 +0800265/************************ Message functions **********************************/
266
267/**
Summer Qin02f7f072020-08-24 16:02:54 +0800268 * \brief Get message context by message handle.
269 *
270 * \param[in] msg_handle Message handle which is a reference generated
271 * by the SPM to a specific message.
272 *
273 * \return The message body context pointer
274 * \ref tfm_msg_body_t structures
275 */
276struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
277
278/**
Edison Ai97115822019-08-01 14:22:19 +0800279 * \brief Get message context by connect handle.
Mingyang Sunf3d29892019-07-10 17:50:23 +0800280 *
Edison Ai97115822019-08-01 14:22:19 +0800281 * \param[in] conn_handle Service connect handle.
282 *
283 * \return The message body context pointer
284 * \ref msg_body_t structures
285 */
286struct tfm_msg_body_t *
Summer Qin630c76b2020-05-20 10:32:58 +0800287 tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle);
Edison Ai97115822019-08-01 14:22:19 +0800288
289/**
290 * \brief Fill the message for PSA client call.
291 *
292 * \param[in] msg Service Message Queue buffer pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800293 * \param[in] service Target service context pointer, which can be
294 * obtained by partition management functions
295 * \prarm[in] handle Connect handle return by psa_connect().
296 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
297 * PSA_IPC_DISCONNECT
Summer Qin1ce712a2019-10-14 18:04:05 +0800298 * \param[in] client_id Partition ID of the sender of the message
Mingyang Sunf3d29892019-07-10 17:50:23 +0800299 * \param[in] invec Array of input \ref psa_invec structures
300 * \param[in] in_len Number of input \ref psa_invec structures
301 * \param[in] outvec Array of output \ref psa_outvec structures
302 * \param[in] out_len Number of output \ref psa_outvec structures
303 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800304 */
Edison Ai97115822019-08-01 14:22:19 +0800305void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
306 struct tfm_spm_service_t *service,
Ken Liu505b1702020-05-29 13:19:58 +0800307 psa_handle_t handle,
Summer Qin1ce712a2019-10-14 18:04:05 +0800308 int32_t type, int32_t client_id,
Edison Ai97115822019-08-01 14:22:19 +0800309 psa_invec *invec, size_t in_len,
310 psa_outvec *outvec, size_t out_len,
311 psa_outvec *caller_outvec);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800312
313/**
314 * \brief Send message and wake up the SP who is waiting on
315 * message queue, block the current thread and
316 * scheduler triggered
317 *
318 * \param[in] service Target service context pointer, which can be
319 * obtained by partition management functions
320 * \param[in] msg message created by tfm_spm_create_msg()
321 * \ref tfm_msg_body_t structures
322 *
Ken Liubcae38b2021-01-20 15:47:44 +0800323 * \retval SPM_SUCCESS Success
324 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
325 * \retval SPM_ERROR_GENERIC Failed to enqueue message to service message queue
Mingyang Sunf3d29892019-07-10 17:50:23 +0800326 */
327int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
328 struct tfm_msg_body_t *msg);
329
330/**
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530331 * \brief Check the client version according to
Mingyang Sunf3d29892019-07-10 17:50:23 +0800332 * version policy
333 *
334 * \param[in] service Target service context pointer, which can be get
335 * by partition management functions
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530336 * \param[in] version Client support version
Mingyang Sunf3d29892019-07-10 17:50:23 +0800337 *
Ken Liubcae38b2021-01-20 15:47:44 +0800338 * \retval SPM_SUCCESS Success
339 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
340 * \retval SPM_ERROR_VERSION Check failed
Mingyang Sunf3d29892019-07-10 17:50:23 +0800341 */
342int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530343 uint32_t version);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800344
345/**
Edison Aie728fbf2019-11-13 09:37:12 +0800346 * \brief Check the client access authorization
347 *
348 * \param[in] sid Target RoT Service identity
349 * \param[in] service Target service context pointer, which can be get
350 * by partition management functions
351 * \param[in] ns_caller Whether from NS caller
352 *
Ken Liubcae38b2021-01-20 15:47:44 +0800353 * \retval SPM_SUCCESS Success
354 * \retval SPM_ERROR_GENERIC Authorization check failed
Edison Aie728fbf2019-11-13 09:37:12 +0800355 */
356int32_t tfm_spm_check_authorization(uint32_t sid,
357 struct tfm_spm_service_t *service,
Summer Qin618e8c32019-12-09 10:47:20 +0800358 bool ns_caller);
Edison Aie728fbf2019-11-13 09:37:12 +0800359
360/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800361 * \brief Check the memory reference is valid.
362 *
363 * \param[in] buffer Pointer of memory reference
364 * \param[in] len Length of memory reference in bytes
365 * \param[in] ns_caller From non-secure caller
366 * \param[in] access Type of access specified by the
367 * \ref tfm_memory_access_e
368 * \param[in] privileged Privileged mode or unprivileged mode:
369 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
370 * \ref TFM_PARTITION_PRIVILEGED_MODE
371 *
Ken Liubcae38b2021-01-20 15:47:44 +0800372 * \retval SPM_SUCCESS Success
373 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
374 * \retval SPM_ERROR_MEMORY_CHECK Check failed
Mingyang Sunf3d29892019-07-10 17:50:23 +0800375 */
Summer Qin43c185d2019-10-10 15:44:42 +0800376int32_t tfm_memory_check(const void *buffer, size_t len, bool ns_caller,
Mingyang Sunf3d29892019-07-10 17:50:23 +0800377 enum tfm_memory_access_e access,
378 uint32_t privileged);
379
Mingyang Sunf3d29892019-07-10 17:50:23 +0800380/*
381 * PendSV specified function.
382 *
383 * Parameters :
Summer Qind2ad7e72020-01-06 18:16:35 +0800384 * p_actx - Architecture context storage pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800385 *
386 * Notes:
387 * This is a staging API. Scheduler should be called in SPM finally and
388 * this function will be obsoleted later.
389 */
Summer Qind2ad7e72020-01-06 18:16:35 +0800390void tfm_pendsv_do_schedule(struct tfm_arch_ctx_t *p_actx);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800391
Ken Liu490281d2019-12-30 15:55:26 +0800392/**
393 * \brief SPM initialization implementation
394 *
395 * \details This function must be called under handler mode.
Ken Liuce2692d2020-02-11 12:39:36 +0800396 * \retval This function returns an EXC_RETURN value. Other
397 * faults would panic the execution and never
398 * returned.
Ken Liu490281d2019-12-30 15:55:26 +0800399 */
Ken Liuce2692d2020-02-11 12:39:36 +0800400uint32_t tfm_spm_init(void);
Ken Liu490281d2019-12-30 15:55:26 +0800401
Mingyang Sund44522a2020-01-16 16:48:37 +0800402/**
Mingyang Sunc3123ec2020-06-11 17:43:58 +0800403 * \brief SVC handler of enabling irq_line of the specified irq_signal.
Mingyang Sund44522a2020-01-16 16:48:37 +0800404 *
405 * \param[in] args Include all input arguments: irq_signal.
406 *
407 * \retval void Success.
408 * \retval "Does not return" The call is invalid, one or more of the
409 * following are true:
410 * \arg irq_signal is not an interrupt signal.
411 * \arg irq_signal indicates more than one signal.
412 */
413void tfm_spm_enable_irq(uint32_t *args);
414
415/**
Mingyang Sunc3123ec2020-06-11 17:43:58 +0800416 * \brief SVC handler of disabling irq_line of the specified irq_signal.
Mingyang Sund44522a2020-01-16 16:48:37 +0800417 *
418 * \param[in] args Include all input arguments: irq_signal.
419 *
420 * \retval void Success.
421 * \retval "Does not return" The call is invalid, one or more of the
422 * following are true:
423 * \arg irq_signal is not an interrupt signal.
424 * \arg irq_signal indicates more than one signal.
425 */
426void tfm_spm_disable_irq(uint32_t *args);
427
428/**
429 * \brief Validate the whether NS caller re-enter.
430 *
431 * \param[in] p_cur_sp Pointer to current partition.
432 * \param[in] p_ctx Pointer to current stack context.
433 * \param[in] exc_return EXC_RETURN value.
434 * \param[in] ns_caller If 'true', call from non-secure client.
435 * Or from secure client.
436 *
437 * \retval void Success.
438 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800439void tfm_spm_validate_caller(struct partition_t *p_cur_sp, uint32_t *p_ctx,
440 uint32_t exc_return, bool ns_caller);
Mingyang Sund44522a2020-01-16 16:48:37 +0800441
442/**
Ken Liu505b1702020-05-29 13:19:58 +0800443 * \brief Converts a handle instance into a corresponded user handle.
444 */
445psa_handle_t tfm_spm_to_user_handle(struct tfm_conn_handle_t *handle_instance);
446
447/**
Summer Qin373feb12020-03-27 15:35:33 +0800448 * \brief Converts a user handle into a corresponded handle instance.
449 */
450struct tfm_conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle);
451
Summer Qin9c1fba12020-08-12 15:49:12 +0800452/**
453 * \brief Move to handler mode by a SVC for specific purpose
454 */
455void tfm_core_handler_mode(void);
456
Summer Qin02f7f072020-08-24 16:02:54 +0800457/**
458 * \brief Set reverse handle value for connection.
459 *
460 * \param[in] service Target service context pointer
461 * \param[in] conn_handle Connection handle created by
462 * tfm_spm_create_conn_handle()
463 * \param[in] rhandle rhandle need to save
464 *
Ken Liubcae38b2021-01-20 15:47:44 +0800465 * \retval SPM_SUCCESS Success
466 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
Summer Qin02f7f072020-08-24 16:02:54 +0800467 * \retval "Does not return" Panic for not find handle node
468 */
469int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
470 struct tfm_conn_handle_t *conn_handle,
471 void *rhandle);
472
473void update_caller_outvec_len(struct tfm_msg_body_t *msg);
474
475/**
476 * \brief notify the partition with the signal.
477 *
478 * \param[in] partition_id The ID of the partition to be notified.
479 * \param[in] signal The signal that the partition is to be notified
480 * with.
481 *
482 * \retval void Success.
483 * \retval "Does not return" If partition_id is invalid.
484 */
485void notify_with_signal(int32_t partition_id, psa_signal_t signal);
486
487/**
488 * \brief Return the IRQ line number associated with a signal
489 *
490 * \param[in] partition_id The ID of the partition in which we look for
491 * the signal.
Kevin Peng410bee52021-01-13 16:27:17 +0800492 * \param[in] signal The signal to query for.
Summer Qin02f7f072020-08-24 16:02:54 +0800493 *
Kevin Penga20b5af2021-01-11 11:20:52 +0800494 * \retval None-negative value The irq line associated with signal
Kevin Peng410bee52021-01-13 16:27:17 +0800495 * \retval Negative value if one of more the following are true:
496 * - the \ref signal indicates more than one signal
497 * - the \ref signal does not belong to the
498 * partition.
Summer Qin02f7f072020-08-24 16:02:54 +0800499 */
Kevin Penga20b5af2021-01-11 11:20:52 +0800500int32_t get_irq_line_for_signal(int32_t partition_id, psa_signal_t signal);
Summer Qin02f7f072020-08-24 16:02:54 +0800501
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800502#endif /* __SPM_IPC_H__ */