blob: e1de88d311129c2ea2b9c456e3fbe891b27ad9ed [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Gyorgy Szing40a7af02019-02-06 14:19:47 +01002 * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00003 *
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-Pal3db437a2018-06-22 16:15:13 +020012#include "tfm_api.h"
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010013#include "spm_partition_defs.h"
David Hu49a28eb2019-08-14 18:18:15 +080014#include "tfm_secure_api.h"
Mingyang Sunf3d29892019-07-10 17:50:23 +080015#include <stdbool.h>
Edison Ai66fbdf12019-07-08 16:05:07 +080016#ifdef TFM_PSA_API
17#include "tfm_list.h"
18#include "tfm_wait.h"
Mingyang Sunf3d29892019-07-10 17:50:23 +080019#include "tfm_message_queue.h"
20#include "tfm_secure_api.h"
Summer Qinb5da9cc2019-08-26 15:19:45 +080021#include "tfm_thread.h"
Edison Ai66fbdf12019-07-08 16:05:07 +080022#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000023
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010024#define SPM_INVALID_PARTITION_IDX (~0U)
25
Summer Qineb537e52019-03-29 09:57:10 +080026/* Privileged definitions for partition thread mode */
27#define TFM_PARTITION_PRIVILEGED_MODE 1
28#define TFM_PARTITION_UNPRIVILEGED_MODE 0
29
Miklos Balint386b8b52017-11-29 13:12:32 +000030enum spm_err_t {
31 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010032 SPM_ERR_PARTITION_DB_NOT_INIT,
33 SPM_ERR_PARTITION_ALREADY_ACTIVE,
34 SPM_ERR_PARTITION_NOT_AVAILABLE,
Hugues de Valonf704c802019-02-19 14:51:41 +000035 SPM_ERR_INVALID_PARAMETER,
Miklos Balint386b8b52017-11-29 13:12:32 +000036 SPM_ERR_INVALID_CONFIG,
37};
38
Hugues de Valon99578562019-06-18 16:08:51 +010039#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-Pal65291f32018-02-23 14:35:22 +010046
Hugues de Valon99578562019-06-18 16:08:51 +010047#define SPM_PART_FLAG_APP_ROT 0x01
48#define SPM_PART_FLAG_PSA_ROT 0x02
49#define SPM_PART_FLAG_IPC 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010050
Edison Ai66fbdf12019-07-08 16:05:07 +080051#ifndef TFM_PSA_API
Miklos Balint386b8b52017-11-29 13:12:32 +000052/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020053 * \brief Holds the iovec parameters that are passed to a service
54 *
55 * \note The size of the structure is (and have to be) multiple of 8 bytes
56 */
57struct iovec_args_t {
58 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
59 size_t in_len; /*!< Number psa_invec objects in in_vec
60 */
61 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
62 size_t out_len; /*!< Number psa_outvec objects in out_vec
63 */
64};
Mingyang Sunda01a972019-07-12 17:32:59 +080065
66/* The size of this struct must be multiple of 4 bytes as it is stacked to an
67 * uint32_t[] array
68 */
69struct interrupted_ctx_stack_frame_t {
Mingyang Sunda01a972019-07-12 17:32:59 +080070 uint32_t partition_state;
71};
72
73/* The size of this struct must be multiple of 4 bytes as it is stacked to an
74 * uint32_t[] array
75 */
76struct handler_ctx_stack_frame_t {
77 uint32_t partition_state;
78 uint32_t caller_partition_idx;
79};
Edison Ai66fbdf12019-07-08 16:05:07 +080080#endif /* !define(TFM_PSA_API) */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020081
82/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010083 * \brief Runtime context information of a partition
84 */
85struct spm_partition_runtime_data_t {
Edison Ai66fbdf12019-07-08 16:05:07 +080086#ifdef TFM_PSA_API
87 struct tfm_event_t signal_evnt; /* Event signal */
88 uint32_t signals; /* Service signals had been triggered*/
89 struct tfm_list_node_t service_list;/* Service list */
Summer Qinb5da9cc2019-08-26 15:19:45 +080090 struct tfm_thrd_ctx sp_thrd; /* Thread context */
Shawn Shan9b0e0c72019-10-22 13:43:07 +080091 uint32_t assigned_signals; /* All assigned signals */
Edison Ai66fbdf12019-07-08 16:05:07 +080092#else /* TFM_PSA_API */
Mate Toth-Pal18b83922018-02-26 17:58:18 +010093 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010094 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020095 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010096 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020097 uint32_t lr;
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020098 struct iovec_args_t iovec_args;
99 psa_outvec *orig_outvec;
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200100 uint32_t *ctx_stack_ptr;
Edison Ai66fbdf12019-07-08 16:05:07 +0800101#endif /* TFM_PSA_API */
102 uint32_t signal_mask; /*
103 * Service signal mask passed by
104 * psa_wait()
105 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100106};
107
Mingyang Sunda01a972019-07-12 17:32:59 +0800108#ifdef TFM_PSA_API
109
Mingyang Sunda01a972019-07-12 17:32:59 +0800110#define TFM_VERSION_POLICY_RELAXED 0
111#define TFM_VERSION_POLICY_STRICT 1
112
Edison Ai97115822019-08-01 14:22:19 +0800113#define TFM_CONN_HANDLE_MAX_NUM 16
Mingyang Sunda01a972019-07-12 17:32:59 +0800114
115/* RoT connection handle list */
116struct tfm_conn_handle_t {
Edison Ai9cc26242019-08-06 11:28:04 +0800117 void *rhandle; /* Reverse handle value */
Edison Ai97115822019-08-01 14:22:19 +0800118 struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
Edison Ai9cc26242019-08-06 11:28:04 +0800119 struct tfm_spm_service_t *service; /* RoT service pointer */
120 struct tfm_list_node_t list; /* list node */
Mingyang Sunda01a972019-07-12 17:32:59 +0800121};
122
123/* Service database defined by manifest */
124struct tfm_spm_service_db_t {
125 char *name; /* Service name */
126 uint32_t partition_id; /* Partition ID which service belong to */
127 psa_signal_t signal; /* Service signal */
128 uint32_t sid; /* Service identifier */
129 bool non_secure_client; /* If can be called by non secure client */
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530130 uint32_t version; /* Service version */
131 uint32_t version_policy; /* Service version policy */
Mingyang Sunda01a972019-07-12 17:32:59 +0800132};
133
134/* RoT Service data */
135struct tfm_spm_service_t {
Summer Qine578c5b2019-08-16 16:42:16 +0800136 const struct tfm_spm_service_db_t *service_db;/* Service database pointer */
Mingyang Sunda01a972019-07-12 17:32:59 +0800137 struct spm_partition_desc_t *partition; /*
138 * Point to secure partition
139 * data
140 */
141 struct tfm_list_node_t handle_list; /* Service handle list */
142 struct tfm_msg_queue_t msg_queue; /* Message queue */
143 struct tfm_list_node_t list; /* For list operation */
144};
145#endif /* ifdef(TFM_PSA_API) */
146
147/*********************** common definitions ***********************/
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100148
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100149/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100150 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +0000151 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100152 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000153 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100154 * \return the partition idx if partition_id is valid,
155 * \ref SPM_INVALID_PARTITION_IDX othervise
156 */
157uint32_t get_partition_idx(uint32_t partition_id);
158
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200159/**
Summer Qinb4a854d2019-05-29 15:31:22 +0800160 * \brief Get the id of the partition for its index from the db
161 *
162 * \param[in] partition_idx Partition index
163 *
164 * \return Partition ID for that partition
165 *
166 * \note This function doesn't check if partition_idx is valid.
167 */
168uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
169
170/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200171 * \brief Get the flags associated with a partition
172 *
173 * \param[in] partition_idx Partition index
174 *
175 * \return Flags associated with the partition
176 *
177 * \note This function doesn't check if partition_idx is valid.
178 */
179uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
180
Mingyang Sunda01a972019-07-12 17:32:59 +0800181/**
182 * \brief Initialize partition database
183 *
184 * \return Error code \ref spm_err_t
185 */
186enum spm_err_t tfm_spm_db_init(void);
187
188/**
189 * \brief Change the privilege mode for partition thread mode.
190 *
191 * \param[in] privileged Privileged mode,
192 * \ref TFM_PARTITION_PRIVILEGED_MODE
193 * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
194 *
195 * \note Barrier instructions are not called by this function, and if
196 * it is called in thread mode, it might be necessary to call
Edison Ai7aff9e82019-07-11 14:56:46 +0800197 * them after this function returns.
Mingyang Sunda01a972019-07-12 17:32:59 +0800198 */
199void tfm_spm_partition_change_privilege(uint32_t privileged);
200
201/*********************** library definitions ***********************/
202
Summer Qinb4a854d2019-05-29 15:31:22 +0800203#ifndef TFM_PSA_API
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200204/**
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200205 * \brief Save interrupted partition context on ctx stack
206 *
207 * \param[in] partition_idx Partition index
208 *
209 * \note This function doesn't check if partition_idx is valid.
210 * \note This function doesn't whether the ctx stack overflows.
211 */
212void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx);
213
214/**
215 * \brief Restores interrupted partition context on ctx stack
216 *
217 * \param[in] partition_idx Partition index
218 *
219 * \note This function doesn't check if partition_idx is valid.
220 * \note This function doesn't whether the ctx stack underflows.
221 */
222void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx);
223
224/**
225 * \brief Save handler partition context on ctx stack
226 *
227 * \param[in] partition_idx Partition index
228 *
229 * \note This function doesn't check if partition_idx is valid.
230 * \note This function doesn't whether the ctx stack overflows.
231 */
232void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx);
233
234/**
235 * \brief Restores handler partition context on ctx stack
236 *
237 * \param[in] partition_idx Partition index
238 *
239 * \note This function doesn't check if partition_idx is valid.
240 * \note This function doesn't whether the ctx stack underflows.
241 */
242void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx);
243
244/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100245 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100246 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100247 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100248 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100249 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100250 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100251 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100252 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100253const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100254 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100255
256/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100257 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100259 * \return The index of the partition with the running state, if there is any
260 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100261 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100262uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100263
264/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200265 * \brief Save stack pointer and link register for partition in database
266 *
267 * \param[in] partition_idx Partition index
268 * \param[in] stack_ptr Stack pointer to be stored
269 * \param[in] lr Link register to be stored
270 *
271 * \note This function doesn't check if partition_idx is valid.
272 */
273void tfm_spm_partition_store_context(uint32_t partition_idx,
274 uint32_t stack_ptr, uint32_t lr);
275
276/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100277 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100278 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100279 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100280 * \param[in] state The state to be set
281 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100282 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100283 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100284 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100285void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100286
287/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200288 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100289 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100290 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200291 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100292 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200293 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100294 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200295void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
296 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100297
298/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200299* \brief Set the caller client ID for a given partition
300*
301* \param[in] partition_idx Partition index
302* \param[in] caller_client_id The ID of the calling client
303*
304* \note This function doesn't check if any of the partition_idxs are valid.
305*/
306void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
307 int32_t caller_client_id);
308
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100309
310/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200311 * \brief Set the iovec parameters for the partition
312 *
313 * \param[in] partition_idx Partition index
314 * \param[in] args The arguments of the secure function
315 *
316 * args is expected to be of type int32_t[4] where:
317 * args[0] is in_vec
318 * args[1] is in_len
319 * args[2] is out_vec
320 * args[3] is out_len
321 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000322 * \return Error code \ref spm_err_t
323 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200324 * \note This function doesn't check if partition_idx is valid.
325 * \note This function assumes that the iovecs that are passed in args are
326 * valid, and does no sanity check on them at all.
327 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000328enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
329 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200330
331/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100332 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000333 *
334 * \return Error code \ref spm_err_t
335 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100336enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000337
338/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100339 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000340 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100341 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000342 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100343 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000344 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100345void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200346
347/**
348 * \brief Set the signal mask for a given partition
349 *
350 * \param[in] partition_idx Partition index
351 * \param[in] signal_mask The signal mask to be set for the partition
352 *
353 * \note This function doesn't check if any of the partition_idxs are valid.
354 */
355void tfm_spm_partition_set_signal_mask(uint32_t partition_idx,
356 uint32_t signal_mask);
Summer Qinb4a854d2019-05-29 15:31:22 +0800357#endif /* !defined(TFM_PSA_API) */
358
Mingyang Sunf3d29892019-07-10 17:50:23 +0800359#ifdef TFM_PSA_API
Mingyang Sunda01a972019-07-12 17:32:59 +0800360/*************************** IPC definitions **************************/
Edison Ai7aff9e82019-07-11 14:56:46 +0800361
362/**
363 * \brief Get bottom of stack region for a partition
364 *
365 * \param[in] partition_idx Partition index
366 *
367 * \return Stack region bottom value
368 *
369 * \note This function doesn't check if partition_idx is valid.
370 */
371uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
372
373/**
374 * \brief Get top of stack region for a partition
375 *
376 * \param[in] partition_idx Partition index
377 *
378 * \return Stack region top value
379 *
380 * \note This function doesn't check if partition_idx is valid.
381 */
382uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800383
384/**
385 * \brief Get the running partition ID.
386 *
387 * \return Returns the partition ID
388 */
389uint32_t tfm_spm_partition_get_running_partition_id(void);
390
391/**
392 * \brief Get the current partition mode.
393 *
Summer Qin75f0d752019-08-27 14:38:20 +0800394 * \param[in] partition_flags Flags of current partition
Mingyang Sunf3d29892019-07-10 17:50:23 +0800395 *
396 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
397 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
398 */
Summer Qin75f0d752019-08-27 14:38:20 +0800399uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_flags);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800400
401/******************** Service handle management functions ********************/
402
403/**
404 * \brief Create connection handle for client connect
405 *
406 * \param[in] service Target service context pointer
407 *
408 * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE
409 * \retval >0 Service handle created, \ref psa_handle_t
410 */
411psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service);
412
413/**
414 * \brief Free connection handle which not used anymore.
415 *
416 * \param[in] service Target service context pointer
417 * \param[in] conn_handle Connection handle created by
418 * tfm_spm_create_conn_handle(), \ref psa_handle_t
419 *
420 * \retval IPC_SUCCESS Success
421 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
422 * \retval "Does not return" Panic for not find service by handle
423 */
424int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
425 psa_handle_t conn_handle);
426
427/**
428 * \brief Set reverse handle value for connection.
429 *
430 * \param[in] service Target service context pointer
431 * \param[in] conn_handle Connection handle created by
432 * tfm_spm_create_conn_handle(), \ref psa_handle_t
433 * \param[in] rhandle rhandle need to save
434 *
435 * \retval IPC_SUCCESS Success
436 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
437 * \retval "Does not return" Panic for not find handle node
438 */
439int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
440 psa_handle_t conn_handle,
441 void *rhandle);
442
443/**
444 * \brief Get reverse handle value from connection hanlde.
445 *
446 * \param[in] service Target service context pointer
447 * \param[in] conn_handle Connection handle created by
448 * tfm_spm_create_conn_handle(), \ref psa_handle_t
449 *
450 * \retval void * Success
451 * \retval "Does not return" Panic for those:
452 * service pointer are NULL
453 * hanlde is \ref PSA_NULL_HANDLE
454 * handle node does not be found
455 */
456void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
457 psa_handle_t conn_handle);
458
459/******************** Partition management functions *************************/
460
461/**
462 * \brief Get current running partition context.
463 *
464 * \retval NULL Failed
465 * \retval "Not NULL" Return the parttion context pointer
466 * \ref spm_partition_desc_t structures
467 */
468struct spm_partition_desc_t *tfm_spm_get_running_partition(void);
469
470/**
471 * \brief Get the service context by signal.
472 *
473 * \param[in] partition Partition context pointer
474 * \ref spm_partition_desc_t structures
475 * \param[in] signal Signal associated with inputs to the Secure
476 * Partition, \ref psa_signal_t
477 *
478 * \retval NULL Failed
479 * \retval "Not NULL" Target service context pointer,
480 * \ref tfm_spm_service_t structures
481 */
482struct tfm_spm_service_t *
483 tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition,
484 psa_signal_t signal);
485
486/**
487 * \brief Get the service context by service ID.
488 *
489 * \param[in] sid RoT Service identity
490 *
491 * \retval NULL Failed
492 * \retval "Not NULL" Target service context pointer,
493 * \ref tfm_spm_service_t structures
494 */
495struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
496
497/**
498 * \brief Get the service context by connection handle.
499 *
500 * \param[in] conn_handle Connection handle created by
501 * tfm_spm_create_conn_handle()
502 *
503 * \retval NULL Failed
504 * \retval "Not NULL" Target service context pointer,
505 * \ref tfm_spm_service_t structures
506 */
507struct tfm_spm_service_t *
508 tfm_spm_get_service_by_handle(psa_handle_t conn_handle);
509
510/**
511 * \brief Get the partition context by partition ID.
512 *
513 * \param[in] partition_id Partition identity
514 *
515 * \retval NULL Failed
516 * \retval "Not NULL" Target partition context pointer,
517 * \ref spm_partition_desc_t structures
518 */
519struct spm_partition_desc_t *
520 tfm_spm_get_partition_by_id(int32_t partition_id);
521
522/************************ Message functions **********************************/
523
524/**
525 * \brief Get message context by message handle.
526 *
527 * \param[in] msg_handle Message handle which is a reference generated
528 * by the SPM to a specific message.
529 *
530 * \return The message body context pointer
531 * \ref tfm_msg_body_t structures
532 */
533struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
534
535/**
Edison Ai97115822019-08-01 14:22:19 +0800536 * \brief Get message context by connect handle.
Mingyang Sunf3d29892019-07-10 17:50:23 +0800537 *
Edison Ai97115822019-08-01 14:22:19 +0800538 * \param[in] conn_handle Service connect handle.
539 *
540 * \return The message body context pointer
541 * \ref msg_body_t structures
542 */
543struct tfm_msg_body_t *
544 tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle);
545
546/**
547 * \brief Fill the message for PSA client call.
548 *
549 * \param[in] msg Service Message Queue buffer pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800550 * \param[in] service Target service context pointer, which can be
551 * obtained by partition management functions
552 * \prarm[in] handle Connect handle return by psa_connect().
553 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
554 * PSA_IPC_DISCONNECT
555 * \param[in] ns_caller Whether from NS caller
556 * \param[in] invec Array of input \ref psa_invec structures
557 * \param[in] in_len Number of input \ref psa_invec structures
558 * \param[in] outvec Array of output \ref psa_outvec structures
559 * \param[in] out_len Number of output \ref psa_outvec structures
560 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800561 */
Edison Ai97115822019-08-01 14:22:19 +0800562void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
563 struct tfm_spm_service_t *service,
564 psa_handle_t handle,
565 int32_t type, int32_t ns_caller,
566 psa_invec *invec, size_t in_len,
567 psa_outvec *outvec, size_t out_len,
568 psa_outvec *caller_outvec);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800569
570/**
571 * \brief Send message and wake up the SP who is waiting on
572 * message queue, block the current thread and
573 * scheduler triggered
574 *
575 * \param[in] service Target service context pointer, which can be
576 * obtained by partition management functions
577 * \param[in] msg message created by tfm_spm_create_msg()
578 * \ref tfm_msg_body_t structures
579 *
580 * \retval IPC_SUCCESS Success
581 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
582 * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue
583 */
584int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
585 struct tfm_msg_body_t *msg);
586
587/**
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530588 * \brief Check the client version according to
Mingyang Sunf3d29892019-07-10 17:50:23 +0800589 * version policy
590 *
591 * \param[in] service Target service context pointer, which can be get
592 * by partition management functions
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530593 * \param[in] version Client support version
Mingyang Sunf3d29892019-07-10 17:50:23 +0800594 *
595 * \retval IPC_SUCCESS Success
596 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
597 * \retval IPC_ERROR_VERSION Check failed
598 */
599int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
Jaykumar Pitambarbhai Patel3a986022019-10-08 17:37:15 +0530600 uint32_t version);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800601
602/**
603 * \brief Check the memory reference is valid.
604 *
605 * \param[in] buffer Pointer of memory reference
606 * \param[in] len Length of memory reference in bytes
607 * \param[in] ns_caller From non-secure caller
608 * \param[in] access Type of access specified by the
609 * \ref tfm_memory_access_e
610 * \param[in] privileged Privileged mode or unprivileged mode:
611 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
612 * \ref TFM_PARTITION_PRIVILEGED_MODE
613 *
614 * \retval IPC_SUCCESS Success
615 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
616 * \retval IPC_ERROR_MEMORY_CHECK Check failed
617 */
David Hucb05d972019-08-06 18:10:11 +0800618int32_t tfm_memory_check(const void *buffer, size_t len, int32_t ns_caller,
Mingyang Sunf3d29892019-07-10 17:50:23 +0800619 enum tfm_memory_access_e access,
620 uint32_t privileged);
621
622/* This function should be called before schedule function */
623void tfm_spm_init(void);
624
625/*
626 * PendSV specified function.
627 *
628 * Parameters :
629 * ctxb - State context storage pointer
630 *
631 * Notes:
632 * This is a staging API. Scheduler should be called in SPM finally and
633 * this function will be obsoleted later.
634 */
635void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
636
637#endif /* ifdef(TFM_PSA_API) */
638
Miklos Balint386b8b52017-11-29 13:12:32 +0000639#endif /*__SPM_API_H__ */