blob: 1a1384fda0033c3a6ff6155da0f40d1589e3054a [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
Mingyang Sun453ad402021-03-17 17:58:33 +080032/*
33 * Set a number limit for stateless handle.
34 * Valid handle must be positive, set client handle minimum value to 1.
35 */
36#define STATIC_HANDLE_NUM_LIMIT 32
37#define CLIENT_HANDLE_VALUE_MIN 1
38
39#define STAIC_HANDLE_IDX_BIT_WIDTH 8
40#define STAIC_HANDLE_IDX_MASK \
41 (uint32_t)((1UL << STAIC_HANDLE_IDX_BIT_WIDTH) - 1)
42#define GET_INDEX_FROM_STATIC_HANDLE(handle) \
Mingyang Sun4ecea992021-03-30 17:56:26 +080043 (uint32_t)((handle) & STAIC_HANDLE_IDX_MASK)
Mingyang Sun453ad402021-03-17 17:58:33 +080044
45#define STAIC_HANDLE_VER_BIT_WIDTH 8
46#define STAIC_HANDLE_VER_OFFSET 8
47#define STAIC_HANDLE_VER_MASK \
48 (uint32_t)((1UL << STAIC_HANDLE_VER_BIT_WIDTH) - 1)
49#define GET_VERSION_FROM_STATIC_HANDLE(handle) \
50 (uint32_t)(((handle) >> STAIC_HANDLE_VER_OFFSET) & STAIC_HANDLE_VER_MASK)
51
Mingyang Sune8d38082021-03-30 18:34:40 +080052/* Validate the static handle indicator bit */
Mingyang Sun453ad402021-03-17 17:58:33 +080053#define STAIC_HANDLE_INDICATOR_OFFSET 30
Mingyang Sune8d38082021-03-30 18:34:40 +080054#define IS_STATIC_HANDLE(handle) \
55 ((handle) & (1UL << STAIC_HANDLE_INDICATOR_OFFSET))
56
57/* Valid index should be [0, STATIC_HANDLE_NUM_LIMIT-1] */
58#define IS_VALID_STATIC_HANDLE_IDX(index) \
59 (((index) >= 0) && ((index) < STATIC_HANDLE_NUM_LIMIT))
Mingyang Sun3aefc362021-02-23 09:42:35 +080060
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010061#define SPM_INVALID_PARTITION_IDX (~0U)
62
Summer Qineb537e52019-03-29 09:57:10 +080063/* Privileged definitions for partition thread mode */
Summer Qineb537e52019-03-29 09:57:10 +080064#define TFM_PARTITION_UNPRIVILEGED_MODE 0
Mingyang Sun7397b4f2020-06-17 15:07:45 +080065#define TFM_PARTITION_PRIVILEGED_MODE 1
66
67#define SPM_PART_FLAG_APP_ROT 0x01
68#define SPM_PART_FLAG_PSA_ROT 0x02
69#define SPM_PART_FLAG_IPC 0x04
Summer Qineb537e52019-03-29 09:57:10 +080070
Mingyang Sun37f6ced2020-07-08 16:30:28 +080071#define TFM_PRIORITY_HIGH THRD_PRIOR_HIGHEST
72#define TFM_PRIORITY_NORMAL THRD_PRIOR_MEDIUM
73#define TFM_PRIORITY_LOW THRD_PRIOR_LOWEST
74#define TFM_PRIORITY(LEVEL) TFM_PRIORITY_##LEVEL
75
Mingyang Sun73056b62020-07-03 15:18:46 +080076#define TFM_MSG_MAGIC 0x15154343
77
Mingyang Sun73056b62020-07-03 15:18:46 +080078/* Message struct to collect parameter from client */
79struct tfm_msg_body_t {
80 int32_t magic;
81 struct tfm_spm_service_t *service; /* RoT service pointer */
82 struct tfm_event_t ack_evnt; /* Event for ack reponse */
83 psa_msg_t msg; /* PSA message body */
84 psa_invec invec[PSA_MAX_IOVEC]; /* Put in/out vectors in msg body */
85 psa_outvec outvec[PSA_MAX_IOVEC];
86 psa_outvec *caller_outvec; /*
87 * Save caller outvec pointer for
88 * write length update
89 */
90#ifdef TFM_MULTI_CORE_TOPOLOGY
91 const void *caller_data; /*
92 * Pointer to the private data of the
93 * caller. It identifies the NSPE PSA
94 * client calls in multi-core topology
95 */
96#endif
Ken Liu2c47f7f2021-01-22 11:06:04 +080097 struct bi_list_node_t msg_node; /* For list operators */
Mingyang Sun73056b62020-07-03 15:18:46 +080098};
99
Ken Liucdaec9c2021-04-17 11:04:23 +0800100struct partition_memory_t {
101 uintptr_t start;
102 uintptr_t limit;
103};
104
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200105/**
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800106 * Holds the fields of the partition DB used by the SPM code. The values of
107 * these fields are calculated at compile time, and set during initialisation
108 * phase.
109 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800110struct partition_static_t {
Mingyang Sun56c59692020-07-20 17:02:19 +0800111 uint32_t psa_ff_ver; /* PSA-FF version */
112 uint32_t pid; /* Partition ID */
113 uint32_t flags; /* Flags of the partition */
114 uint32_t priority; /* Priority of the partition thread */
115 sp_entry_point entry; /* Entry point of the partition */
116 uintptr_t stack_base_addr; /* Stack base of the partition */
117 size_t stack_size; /* Stack size of the partition */
118 uintptr_t heap_base_addr; /* Heap base of the partition */
119 size_t heap_size; /* Heap size of the partition */
Ken Liu172f1e32021-02-05 16:31:03 +0800120 uintptr_t platform_data; /* Platform specific data */
Mingyang Sun56c59692020-07-20 17:02:19 +0800121 uint32_t ndeps; /* Numbers of depended services */
122 uint32_t *deps; /* Pointer to dependency arrays */
Ken Liucdaec9c2021-04-17 11:04:23 +0800123#if TFM_LVL == 3
124 struct partition_memory_t mems; /* Partition memories */
125#endif
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800126};
127
128/**
129 * Holds the fields that define a partition for SPM. The fields are further
130 * divided to structures, to keep the related fields close to each other.
131 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800132struct partition_t {
Mingyang Sun56c59692020-07-20 17:02:19 +0800133 const struct partition_static_t *p_static;
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800134 void *p_platform;
135 void *p_interrupts;
136 void *p_metadata;
Mingyang Sunaf22ffa2020-07-09 17:48:37 +0800137 struct tfm_core_thread_t sp_thread;
138 struct tfm_event_t event;
Ken Liu2c47f7f2021-01-22 11:06:04 +0800139 struct bi_list_node_t msg_list;
Mingyang Sunaf22ffa2020-07-09 17:48:37 +0800140 uint32_t signals_allowed;
141 uint32_t signals_waiting;
142 uint32_t signals_asserted;
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800143};
144
145struct spm_partition_db_t {
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800146 uint32_t partition_count;
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800147 struct partition_t *partitions;
Mingyang Sun37f6ced2020-07-08 16:30:28 +0800148};
149
Mingyang Sunda01a972019-07-12 17:32:59 +0800150/* Service database defined by manifest */
151struct tfm_spm_service_db_t {
152 char *name; /* Service name */
153 uint32_t partition_id; /* Partition ID which service belong to */
154 psa_signal_t signal; /* Service signal */
155 uint32_t sid; /* Service identifier */
156 bool non_secure_client; /* If can be called by non secure client */
Mingyang Sun973c4f42021-03-11 14:54:22 +0800157 bool connection_based; /* 'true' for connection-based service */
Shawn Shancc39fcb2019-11-13 15:38:16 +0800158 uint32_t version; /* Service version */
159 uint32_t version_policy; /* Service version policy */
Mingyang Sunda01a972019-07-12 17:32:59 +0800160};
161
162/* RoT Service data */
163struct tfm_spm_service_t {
Summer Qine578c5b2019-08-16 16:42:16 +0800164 const struct tfm_spm_service_db_t *service_db;/* Service database pointer */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800165 struct partition_t *partition; /*
Mingyang Sunda01a972019-07-12 17:32:59 +0800166 * Point to secure partition
167 * data
168 */
Ken Liu2c47f7f2021-01-22 11:06:04 +0800169 struct bi_list_node_t handle_list; /* Service handle list */
170 struct bi_list_node_t list; /* For list operation */
Mingyang Sunda01a972019-07-12 17:32:59 +0800171};
Summer Qin5fdcf632020-06-22 16:49:24 +0800172
Mingyang Suneceda862021-02-25 15:09:48 +0800173/* Stateless RoT service tracking array item type. Indexed by static handle */
174struct stateless_service_tracking_t {
175 uint32_t sid; /* Service ID */
176 struct tfm_spm_service_t *p_service; /* Service instance */
177};
178
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800179/* RoT connection handle list */
180struct tfm_conn_handle_t {
181 void *rhandle; /* Reverse handle value */
182 uint32_t status; /*
183 * Status of handle, three valid
184 * options:
185 * TFM_HANDLE_STATUS_ACTIVE,
186 * TFM_HANDLE_STATUS_IDLE and
187 * TFM_HANDLE_STATUS_CONNECT_ERROR
188 */
189 int32_t client_id; /*
190 * Partition ID of the sender of the
191 * message:
192 * - secure partition id;
193 * - non secure client endpoint id.
194 */
195 struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800196 struct tfm_spm_service_t *service; /* RoT service pointer */
Ken Liu2c47f7f2021-01-22 11:06:04 +0800197 struct bi_list_node_t list; /* list node */
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800198};
199
Summer Qin5fdcf632020-06-22 16:49:24 +0800200enum tfm_memory_access_e {
201 TFM_MEMORY_ACCESS_RO = 1,
202 TFM_MEMORY_ACCESS_RW = 2,
203};
Summer Qinb4a854d2019-05-29 15:31:22 +0800204
205/**
Mate Toth-Pal5e6d0342019-11-22 11:43:20 +0100206 * \brief Get the current partition mode.
207 *
208 * \param[in] partition_flags Flags of current partition
209 *
210 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
211 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
212 */
213uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags);
214
Summer Qin830c5542020-02-14 13:44:20 +0800215/**
216 * \brief Handle an SPM request by a secure service
217 * \param[in] svc_ctx The stacked SVC context
218 */
219void tfm_spm_request_handler(const struct tfm_state_context_t *svc_ctx);
220
Edison Ai7aff9e82019-07-11 14:56:46 +0800221/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800222 * \brief Get the running partition ID.
223 *
224 * \return Returns the partition ID
225 */
226uint32_t tfm_spm_partition_get_running_partition_id(void);
227
Mingyang Sunf3d29892019-07-10 17:50:23 +0800228/******************** Service handle management functions ********************/
229
230/**
231 * \brief Create connection handle for client connect
232 *
233 * \param[in] service Target service context pointer
Summer Qin1ce712a2019-10-14 18:04:05 +0800234 * \param[in] client_id Partition ID of the sender of the message
Mingyang Sunf3d29892019-07-10 17:50:23 +0800235 *
Summer Qin630c76b2020-05-20 10:32:58 +0800236 * \retval NULL Create failed
237 * \retval "Not NULL" Service handle created
Mingyang Sunf3d29892019-07-10 17:50:23 +0800238 */
Summer Qin630c76b2020-05-20 10:32:58 +0800239struct tfm_conn_handle_t *tfm_spm_create_conn_handle(
240 struct tfm_spm_service_t *service,
Summer Qin1ce712a2019-10-14 18:04:05 +0800241 int32_t client_id);
242
243/**
244 * \brief Validate connection handle for client connect
245 *
246 * \param[in] conn_handle Handle to be validated
247 * \param[in] client_id Partition ID of the sender of the message
248 *
Ken Liubcae38b2021-01-20 15:47:44 +0800249 * \retval SPM_SUCCESS Success
250 * \retval SPM_ERROR_GENERIC Invalid handle
Summer Qin1ce712a2019-10-14 18:04:05 +0800251 */
Summer Qin630c76b2020-05-20 10:32:58 +0800252int32_t tfm_spm_validate_conn_handle(
253 const struct tfm_conn_handle_t *conn_handle,
254 int32_t client_id);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800255
Summer Qin02f7f072020-08-24 16:02:54 +0800256/**
257 * \brief Free connection handle which not used anymore.
258 *
259 * \param[in] service Target service context pointer
260 * \param[in] conn_handle Connection handle created by
261 * tfm_spm_create_conn_handle()
262 *
Ken Liubcae38b2021-01-20 15:47:44 +0800263 * \retval SPM_SUCCESS Success
264 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
Summer Qin02f7f072020-08-24 16:02:54 +0800265 * \retval "Does not return" Panic for not find service by handle
266 */
267int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
268 struct tfm_conn_handle_t *conn_handle);
269
Mingyang Sunf3d29892019-07-10 17:50:23 +0800270/******************** Partition management functions *************************/
271
272/**
Summer Qin02f7f072020-08-24 16:02:54 +0800273 * \brief Get the msg context by signal.
274 *
275 * \param[in] partition Partition context pointer
276 * \ref partition_t structures
277 * \param[in] signal Signal associated with inputs to the Secure
278 * Partition, \ref psa_signal_t
279 *
280 * \retval NULL Failed
281 * \retval "Not NULL" Target service context pointer,
282 * \ref tfm_msg_body_t structures
283 */
284struct tfm_msg_body_t *tfm_spm_get_msg_by_signal(struct partition_t *partition,
285 psa_signal_t signal);
286
287/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800288 * \brief Get current running partition context.
289 *
290 * \retval NULL Failed
291 * \retval "Not NULL" Return the parttion context pointer
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800292 * \ref partition_t structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800293 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800294struct partition_t *tfm_spm_get_running_partition(void);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800295
296/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800297 * \brief Get the service context by service ID.
298 *
299 * \param[in] sid RoT Service identity
300 *
301 * \retval NULL Failed
302 * \retval "Not NULL" Target service context pointer,
303 * \ref tfm_spm_service_t structures
304 */
305struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
306
Mingyang Sunf3d29892019-07-10 17:50:23 +0800307/************************ Message functions **********************************/
308
309/**
Summer Qin02f7f072020-08-24 16:02:54 +0800310 * \brief Get message context by message handle.
311 *
312 * \param[in] msg_handle Message handle which is a reference generated
313 * by the SPM to a specific message.
314 *
315 * \return The message body context pointer
316 * \ref tfm_msg_body_t structures
317 */
318struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
319
320/**
Kevin Pengdf6aa292021-03-11 17:58:50 +0800321 * \brief Get message context by connect handle.
322 *
323 * \param[in] conn_handle Service connect handle.
324 *
325 * \return The message body context pointer
326 * \ref msg_body_t structures
327 */
328struct tfm_msg_body_t *
329 tfm_spm_get_msg_buffer_from_conn_handle(struct tfm_conn_handle_t *conn_handle);
330
331/**
Edison Ai97115822019-08-01 14:22:19 +0800332 * \brief Fill the message for PSA client call.
333 *
334 * \param[in] msg Service Message Queue buffer pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800335 * \param[in] service Target service context pointer, which can be
336 * obtained by partition management functions
337 * \prarm[in] handle Connect handle return by psa_connect().
338 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
339 * PSA_IPC_DISCONNECT
Summer Qin1ce712a2019-10-14 18:04:05 +0800340 * \param[in] client_id Partition ID of the sender of the message
Mingyang Sunf3d29892019-07-10 17:50:23 +0800341 * \param[in] invec Array of input \ref psa_invec structures
342 * \param[in] in_len Number of input \ref psa_invec structures
343 * \param[in] outvec Array of output \ref psa_outvec structures
344 * \param[in] out_len Number of output \ref psa_outvec structures
345 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800346 */
Edison Ai97115822019-08-01 14:22:19 +0800347void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
348 struct tfm_spm_service_t *service,
Ken Liu505b1702020-05-29 13:19:58 +0800349 psa_handle_t handle,
Summer Qin1ce712a2019-10-14 18:04:05 +0800350 int32_t type, int32_t client_id,
Edison Ai97115822019-08-01 14:22:19 +0800351 psa_invec *invec, size_t in_len,
352 psa_outvec *outvec, size_t out_len,
353 psa_outvec *caller_outvec);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800354
355/**
356 * \brief Send message and wake up the SP who is waiting on
357 * message queue, block the current thread and
358 * scheduler triggered
359 *
360 * \param[in] service Target service context pointer, which can be
361 * obtained by partition management functions
362 * \param[in] msg message created by tfm_spm_create_msg()
363 * \ref tfm_msg_body_t structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800364 */
Kevin Peng8dac6102021-03-09 16:44:00 +0800365void tfm_spm_send_event(struct tfm_spm_service_t *service,
366 struct tfm_msg_body_t *msg);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800367
368/**
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530369 * \brief Check the client version according to
Mingyang Sunf3d29892019-07-10 17:50:23 +0800370 * version policy
371 *
372 * \param[in] service Target service context pointer, which can be get
373 * by partition management functions
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530374 * \param[in] version Client support version
Mingyang Sunf3d29892019-07-10 17:50:23 +0800375 *
Ken Liubcae38b2021-01-20 15:47:44 +0800376 * \retval SPM_SUCCESS Success
377 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
378 * \retval SPM_ERROR_VERSION Check failed
Mingyang Sunf3d29892019-07-10 17:50:23 +0800379 */
380int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530381 uint32_t version);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800382
383/**
Edison Aie728fbf2019-11-13 09:37:12 +0800384 * \brief Check the client access authorization
385 *
386 * \param[in] sid Target RoT Service identity
387 * \param[in] service Target service context pointer, which can be get
388 * by partition management functions
389 * \param[in] ns_caller Whether from NS caller
390 *
Ken Liubcae38b2021-01-20 15:47:44 +0800391 * \retval SPM_SUCCESS Success
392 * \retval SPM_ERROR_GENERIC Authorization check failed
Edison Aie728fbf2019-11-13 09:37:12 +0800393 */
394int32_t tfm_spm_check_authorization(uint32_t sid,
395 struct tfm_spm_service_t *service,
Summer Qin618e8c32019-12-09 10:47:20 +0800396 bool ns_caller);
Edison Aie728fbf2019-11-13 09:37:12 +0800397
398/**
Mingyang Sunf3d29892019-07-10 17:50:23 +0800399 * \brief Check the memory reference is valid.
400 *
401 * \param[in] buffer Pointer of memory reference
402 * \param[in] len Length of memory reference in bytes
403 * \param[in] ns_caller From non-secure caller
404 * \param[in] access Type of access specified by the
405 * \ref tfm_memory_access_e
406 * \param[in] privileged Privileged mode or unprivileged mode:
407 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
408 * \ref TFM_PARTITION_PRIVILEGED_MODE
409 *
Ken Liubcae38b2021-01-20 15:47:44 +0800410 * \retval SPM_SUCCESS Success
411 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
412 * \retval SPM_ERROR_MEMORY_CHECK Check failed
Mingyang Sunf3d29892019-07-10 17:50:23 +0800413 */
Summer Qin43c185d2019-10-10 15:44:42 +0800414int32_t tfm_memory_check(const void *buffer, size_t len, bool ns_caller,
Mingyang Sunf3d29892019-07-10 17:50:23 +0800415 enum tfm_memory_access_e access,
416 uint32_t privileged);
417
Mingyang Sunf3d29892019-07-10 17:50:23 +0800418/*
419 * PendSV specified function.
420 *
421 * Parameters :
Summer Qind2ad7e72020-01-06 18:16:35 +0800422 * p_actx - Architecture context storage pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800423 *
424 * Notes:
425 * This is a staging API. Scheduler should be called in SPM finally and
426 * this function will be obsoleted later.
427 */
Summer Qind2ad7e72020-01-06 18:16:35 +0800428void tfm_pendsv_do_schedule(struct tfm_arch_ctx_t *p_actx);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800429
Ken Liu490281d2019-12-30 15:55:26 +0800430/**
431 * \brief SPM initialization implementation
432 *
433 * \details This function must be called under handler mode.
Ken Liuce2692d2020-02-11 12:39:36 +0800434 * \retval This function returns an EXC_RETURN value. Other
435 * faults would panic the execution and never
436 * returned.
Ken Liu490281d2019-12-30 15:55:26 +0800437 */
Ken Liuce2692d2020-02-11 12:39:36 +0800438uint32_t tfm_spm_init(void);
Ken Liu490281d2019-12-30 15:55:26 +0800439
Summer Qindea1f2c2021-01-11 14:46:34 +0800440#if !defined(__ARM_ARCH_8_1M_MAIN__)
Mingyang Sund44522a2020-01-16 16:48:37 +0800441/**
442 * \brief Validate the whether NS caller re-enter.
443 *
444 * \param[in] p_cur_sp Pointer to current partition.
445 * \param[in] p_ctx Pointer to current stack context.
446 * \param[in] exc_return EXC_RETURN value.
447 * \param[in] ns_caller If 'true', call from non-secure client.
448 * Or from secure client.
449 *
450 * \retval void Success.
Summer Qindea1f2c2021-01-11 14:46:34 +0800451 *
452 * Notes:
453 * For architecture v8.1m and later, will use hardware re-entrant detection.
454 * Otherwise will use the software solution to validate the caller.
Mingyang Sund44522a2020-01-16 16:48:37 +0800455 */
Mingyang Sunae70d8d2020-06-30 15:56:05 +0800456void tfm_spm_validate_caller(struct partition_t *p_cur_sp, uint32_t *p_ctx,
457 uint32_t exc_return, bool ns_caller);
Summer Qindea1f2c2021-01-11 14:46:34 +0800458#else
459/**
460 * In v8.1 mainline, will use hardware re-entrant detection instead.
461 */
462__STATIC_INLINE
463void tfm_spm_validate_caller(struct partition_t *p_cur_sp, uint32_t *p_ctx,
464 uint32_t exc_return, bool ns_caller)
465{
466 (void)p_cur_sp;
467 (void)p_ctx;
468 (void)exc_return;
469 (void)ns_caller;
470 return;
471}
472#endif
473
Mingyang Sund44522a2020-01-16 16:48:37 +0800474
475/**
Ken Liu505b1702020-05-29 13:19:58 +0800476 * \brief Converts a handle instance into a corresponded user handle.
477 */
478psa_handle_t tfm_spm_to_user_handle(struct tfm_conn_handle_t *handle_instance);
479
480/**
Summer Qin373feb12020-03-27 15:35:33 +0800481 * \brief Converts a user handle into a corresponded handle instance.
482 */
483struct tfm_conn_handle_t *tfm_spm_to_handle_instance(psa_handle_t user_handle);
484
Summer Qin9c1fba12020-08-12 15:49:12 +0800485/**
486 * \brief Move to handler mode by a SVC for specific purpose
487 */
488void tfm_core_handler_mode(void);
489
Summer Qin02f7f072020-08-24 16:02:54 +0800490/**
491 * \brief Set reverse handle value for connection.
492 *
493 * \param[in] service Target service context pointer
494 * \param[in] conn_handle Connection handle created by
495 * tfm_spm_create_conn_handle()
496 * \param[in] rhandle rhandle need to save
497 *
Ken Liubcae38b2021-01-20 15:47:44 +0800498 * \retval SPM_SUCCESS Success
499 * \retval SPM_ERROR_BAD_PARAMETERS Bad parameters input
Summer Qin02f7f072020-08-24 16:02:54 +0800500 * \retval "Does not return" Panic for not find handle node
501 */
502int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
503 struct tfm_conn_handle_t *conn_handle,
504 void *rhandle);
505
506void update_caller_outvec_len(struct tfm_msg_body_t *msg);
507
508/**
509 * \brief notify the partition with the signal.
510 *
511 * \param[in] partition_id The ID of the partition to be notified.
512 * \param[in] signal The signal that the partition is to be notified
513 * with.
514 *
515 * \retval void Success.
516 * \retval "Does not return" If partition_id is invalid.
517 */
518void notify_with_signal(int32_t partition_id, psa_signal_t signal);
519
520/**
521 * \brief Return the IRQ line number associated with a signal
522 *
523 * \param[in] partition_id The ID of the partition in which we look for
524 * the signal.
Kevin Peng410bee52021-01-13 16:27:17 +0800525 * \param[in] signal The signal to query for.
Summer Qin02f7f072020-08-24 16:02:54 +0800526 *
Kevin Penga20b5af2021-01-11 11:20:52 +0800527 * \retval None-negative value The irq line associated with signal
Kevin Peng410bee52021-01-13 16:27:17 +0800528 * \retval Negative value if one of more the following are true:
529 * - the \ref signal indicates more than one signal
530 * - the \ref signal does not belong to the
531 * partition.
Summer Qin02f7f072020-08-24 16:02:54 +0800532 */
Kevin Penga20b5af2021-01-11 11:20:52 +0800533int32_t get_irq_line_for_signal(int32_t partition_id, psa_signal_t signal);
Summer Qin02f7f072020-08-24 16:02:54 +0800534
Mingyang Sun7397b4f2020-06-17 15:07:45 +0800535#endif /* __SPM_IPC_H__ */