blob: 75b921c2848de5b01cd89b962c9949f1e49c7383 [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"
Edison Ai66fbdf12019-07-08 16:05:07 +080021#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000022
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010023#define SPM_INVALID_PARTITION_IDX (~0U)
24
Summer Qineb537e52019-03-29 09:57:10 +080025/* Privileged definitions for partition thread mode */
26#define TFM_PARTITION_PRIVILEGED_MODE 1
27#define TFM_PARTITION_UNPRIVILEGED_MODE 0
28
Miklos Balint386b8b52017-11-29 13:12:32 +000029enum spm_err_t {
30 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010031 SPM_ERR_PARTITION_DB_NOT_INIT,
32 SPM_ERR_PARTITION_ALREADY_ACTIVE,
33 SPM_ERR_PARTITION_NOT_AVAILABLE,
Hugues de Valonf704c802019-02-19 14:51:41 +000034 SPM_ERR_INVALID_PARAMETER,
Miklos Balint386b8b52017-11-29 13:12:32 +000035 SPM_ERR_INVALID_CONFIG,
36};
37
Hugues de Valon99578562019-06-18 16:08:51 +010038#define SPM_PARTITION_STATE_UNINIT 0
39#define SPM_PARTITION_STATE_IDLE 1
40#define SPM_PARTITION_STATE_RUNNING 2
41#define SPM_PARTITION_STATE_HANDLING_IRQ 3
42#define SPM_PARTITION_STATE_SUSPENDED 4
43#define SPM_PARTITION_STATE_BLOCKED 5
44#define SPM_PARTITION_STATE_CLOSED 6
Mate Toth-Pal65291f32018-02-23 14:35:22 +010045
Hugues de Valon99578562019-06-18 16:08:51 +010046#define SPM_PART_FLAG_APP_ROT 0x01
47#define SPM_PART_FLAG_PSA_ROT 0x02
48#define SPM_PART_FLAG_IPC 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010049
Edison Ai66fbdf12019-07-08 16:05:07 +080050#ifndef TFM_PSA_API
Miklos Balint386b8b52017-11-29 13:12:32 +000051/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020052 * \brief Holds the iovec parameters that are passed to a service
53 *
54 * \note The size of the structure is (and have to be) multiple of 8 bytes
55 */
56struct iovec_args_t {
57 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
58 size_t in_len; /*!< Number psa_invec objects in in_vec
59 */
60 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
61 size_t out_len; /*!< Number psa_outvec objects in out_vec
62 */
63};
Mingyang Sunda01a972019-07-12 17:32:59 +080064
65/* The size of this struct must be multiple of 4 bytes as it is stacked to an
66 * uint32_t[] array
67 */
68struct interrupted_ctx_stack_frame_t {
Mingyang Sunda01a972019-07-12 17:32:59 +080069 uint32_t partition_state;
70};
71
72/* The size of this struct must be multiple of 4 bytes as it is stacked to an
73 * uint32_t[] array
74 */
75struct handler_ctx_stack_frame_t {
76 uint32_t partition_state;
77 uint32_t caller_partition_idx;
78};
Edison Ai66fbdf12019-07-08 16:05:07 +080079#endif /* !define(TFM_PSA_API) */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020080
81/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010082 * \brief Runtime context information of a partition
83 */
84struct spm_partition_runtime_data_t {
Edison Ai66fbdf12019-07-08 16:05:07 +080085#ifdef TFM_PSA_API
86 struct tfm_event_t signal_evnt; /* Event signal */
87 uint32_t signals; /* Service signals had been triggered*/
88 struct tfm_list_node_t service_list;/* Service list */
89#else /* TFM_PSA_API */
Mate Toth-Pal18b83922018-02-26 17:58:18 +010090 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010091 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020092 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010093 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010094 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020095 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010096 int32_t iovec_api; /*!< Whether the function in the partition
97 * had been called using the iovec API.
98 * FIXME: Remove the field once this is the
99 * only option
100 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200101 struct iovec_args_t iovec_args;
102 psa_outvec *orig_outvec;
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200103 uint32_t *ctx_stack_ptr;
Edison Ai66fbdf12019-07-08 16:05:07 +0800104#endif /* TFM_PSA_API */
105 uint32_t signal_mask; /*
106 * Service signal mask passed by
107 * psa_wait()
108 */
Summer Qin423dbef2019-08-22 15:59:35 +0800109 uint32_t index; /* Partition index */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100110};
111
Mingyang Sunda01a972019-07-12 17:32:59 +0800112#ifdef TFM_PSA_API
113
Mingyang Sunda01a972019-07-12 17:32:59 +0800114#define TFM_VERSION_POLICY_RELAXED 0
115#define TFM_VERSION_POLICY_STRICT 1
116
Edison Ai97115822019-08-01 14:22:19 +0800117#define TFM_CONN_HANDLE_MAX_NUM 16
Mingyang Sunda01a972019-07-12 17:32:59 +0800118
119/* RoT connection handle list */
120struct tfm_conn_handle_t {
Edison Ai9cc26242019-08-06 11:28:04 +0800121 void *rhandle; /* Reverse handle value */
Edison Ai97115822019-08-01 14:22:19 +0800122 struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
Edison Ai9cc26242019-08-06 11:28:04 +0800123 struct tfm_spm_service_t *service; /* RoT service pointer */
124 struct tfm_list_node_t list; /* list node */
Mingyang Sunda01a972019-07-12 17:32:59 +0800125};
126
127/* Service database defined by manifest */
128struct tfm_spm_service_db_t {
129 char *name; /* Service name */
130 uint32_t partition_id; /* Partition ID which service belong to */
131 psa_signal_t signal; /* Service signal */
132 uint32_t sid; /* Service identifier */
133 bool non_secure_client; /* If can be called by non secure client */
134 uint32_t minor_version; /* Minor version */
135 uint32_t minor_policy; /* Minor version policy */
136};
137
138/* RoT Service data */
139struct tfm_spm_service_t {
Summer Qine578c5b2019-08-16 16:42:16 +0800140 const struct tfm_spm_service_db_t *service_db;/* Service database pointer */
Mingyang Sunda01a972019-07-12 17:32:59 +0800141 struct spm_partition_desc_t *partition; /*
142 * Point to secure partition
143 * data
144 */
145 struct tfm_list_node_t handle_list; /* Service handle list */
146 struct tfm_msg_queue_t msg_queue; /* Message queue */
147 struct tfm_list_node_t list; /* For list operation */
148};
149#endif /* ifdef(TFM_PSA_API) */
150
151/*********************** common definitions ***********************/
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100152
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100153/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100154 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +0000155 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100156 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000157 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100158 * \return the partition idx if partition_id is valid,
159 * \ref SPM_INVALID_PARTITION_IDX othervise
160 */
161uint32_t get_partition_idx(uint32_t partition_id);
162
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200163/**
Summer Qinb4a854d2019-05-29 15:31:22 +0800164 * \brief Get the id of the partition for its index from the db
165 *
166 * \param[in] partition_idx Partition index
167 *
168 * \return Partition ID for that partition
169 *
170 * \note This function doesn't check if partition_idx is valid.
171 */
172uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
173
174/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200175 * \brief Get the flags associated with a partition
176 *
177 * \param[in] partition_idx Partition index
178 *
179 * \return Flags associated with the partition
180 *
181 * \note This function doesn't check if partition_idx is valid.
182 */
183uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
184
Mingyang Sunda01a972019-07-12 17:32:59 +0800185/**
186 * \brief Initialize partition database
187 *
188 * \return Error code \ref spm_err_t
189 */
190enum spm_err_t tfm_spm_db_init(void);
191
192/**
193 * \brief Change the privilege mode for partition thread mode.
194 *
195 * \param[in] privileged Privileged mode,
196 * \ref TFM_PARTITION_PRIVILEGED_MODE
197 * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
198 *
199 * \note Barrier instructions are not called by this function, and if
200 * it is called in thread mode, it might be necessary to call
Edison Ai7aff9e82019-07-11 14:56:46 +0800201 * them after this function returns.
Mingyang Sunda01a972019-07-12 17:32:59 +0800202 */
203void tfm_spm_partition_change_privilege(uint32_t privileged);
204
205/*********************** library definitions ***********************/
206
Summer Qinb4a854d2019-05-29 15:31:22 +0800207#ifndef TFM_PSA_API
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200208/**
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200209 * \brief Save interrupted partition context on ctx stack
210 *
211 * \param[in] partition_idx Partition index
212 *
213 * \note This function doesn't check if partition_idx is valid.
214 * \note This function doesn't whether the ctx stack overflows.
215 */
216void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx);
217
218/**
219 * \brief Restores interrupted partition context on ctx stack
220 *
221 * \param[in] partition_idx Partition index
222 *
223 * \note This function doesn't check if partition_idx is valid.
224 * \note This function doesn't whether the ctx stack underflows.
225 */
226void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx);
227
228/**
229 * \brief Save handler partition context on ctx stack
230 *
231 * \param[in] partition_idx Partition index
232 *
233 * \note This function doesn't check if partition_idx is valid.
234 * \note This function doesn't whether the ctx stack overflows.
235 */
236void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx);
237
238/**
239 * \brief Restores handler partition context on ctx stack
240 *
241 * \param[in] partition_idx Partition index
242 *
243 * \note This function doesn't check if partition_idx is valid.
244 * \note This function doesn't whether the ctx stack underflows.
245 */
246void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx);
247
248/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100249 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100250 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100251 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100252 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100253 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100254 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100255 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100256 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100257const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100258 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100259
260/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100261 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100262 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100263 * \return The index of the partition with the running state, if there is any
264 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100265 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100266uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100267
268/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200269 * \brief Save stack pointer and link register for partition in database
270 *
271 * \param[in] partition_idx Partition index
272 * \param[in] stack_ptr Stack pointer to be stored
273 * \param[in] lr Link register to be stored
274 *
275 * \note This function doesn't check if partition_idx is valid.
276 */
277void tfm_spm_partition_store_context(uint32_t partition_idx,
278 uint32_t stack_ptr, uint32_t lr);
279
280/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100281 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100282 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100283 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100284 * \param[in] state The state to be set
285 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100286 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100287 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100288 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100289void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100290
291/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200292 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100293 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100294 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200295 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100296 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200297 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100298 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200299void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
300 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100301
302/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200303* \brief Set the caller client ID for a given partition
304*
305* \param[in] partition_idx Partition index
306* \param[in] caller_client_id The ID of the calling client
307*
308* \note This function doesn't check if any of the partition_idxs are valid.
309*/
310void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
311 int32_t caller_client_id);
312
313/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100314 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100315 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100316 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100317 * \param[in] share The buffer share region to be set
318 *
319 * \return Error code \ref spm_err_t
320 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100321 * \note This function doesn't check if partition_idx is valid.
Hugues de Valon99578562019-06-18 16:08:51 +0100322 * \note share has to have one of the buffer share values:
323 * - TFM_BUFFER_SHARE_DISABLE
324 * - TFM_BUFFER_SHARE_NS_CODE
325 * - TFM_BUFFER_SHARE_SCRATCH
326 * - TFM_BUFFER_SHARE_PRIV
327 * - TFM_BUFFER_SHARE_DEFAULT
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100328 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100329enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100330 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100331
332/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200333 * \brief Set the iovec parameters for the partition
334 *
335 * \param[in] partition_idx Partition index
336 * \param[in] args The arguments of the secure function
337 *
338 * args is expected to be of type int32_t[4] where:
339 * args[0] is in_vec
340 * args[1] is in_len
341 * args[2] is out_vec
342 * args[3] is out_len
343 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000344 * \return Error code \ref spm_err_t
345 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200346 * \note This function doesn't check if partition_idx is valid.
347 * \note This function assumes that the iovecs that are passed in args are
348 * valid, and does no sanity check on them at all.
349 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000350enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
351 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200352
353/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100354 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000355 *
356 * \return Error code \ref spm_err_t
357 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100358enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000359
360/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100361 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000362 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100363 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000364 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100365 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000366 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100367void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200368
369/**
370 * \brief Set the signal mask for a given partition
371 *
372 * \param[in] partition_idx Partition index
373 * \param[in] signal_mask The signal mask to be set for the partition
374 *
375 * \note This function doesn't check if any of the partition_idxs are valid.
376 */
377void tfm_spm_partition_set_signal_mask(uint32_t partition_idx,
378 uint32_t signal_mask);
Summer Qinb4a854d2019-05-29 15:31:22 +0800379#endif /* !defined(TFM_PSA_API) */
380
Mingyang Sunf3d29892019-07-10 17:50:23 +0800381#ifdef TFM_PSA_API
Mingyang Sunda01a972019-07-12 17:32:59 +0800382/*************************** IPC definitions **************************/
Edison Ai7aff9e82019-07-11 14:56:46 +0800383
384/**
385 * \brief Get bottom of stack region for a partition
386 *
387 * \param[in] partition_idx Partition index
388 *
389 * \return Stack region bottom value
390 *
391 * \note This function doesn't check if partition_idx is valid.
392 */
393uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
394
395/**
396 * \brief Get top of stack region for a partition
397 *
398 * \param[in] partition_idx Partition index
399 *
400 * \return Stack region top value
401 *
402 * \note This function doesn't check if partition_idx is valid.
403 */
404uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800405
406/**
407 * \brief Get the running partition ID.
408 *
409 * \return Returns the partition ID
410 */
411uint32_t tfm_spm_partition_get_running_partition_id(void);
412
413/**
414 * \brief Get the current partition mode.
415 *
416 * \param[in] partition_idx Index of current partition
417 *
418 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
419 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
420 */
421uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx);
422
423/******************** Service handle management functions ********************/
424
425/**
426 * \brief Create connection handle for client connect
427 *
428 * \param[in] service Target service context pointer
429 *
430 * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE
431 * \retval >0 Service handle created, \ref psa_handle_t
432 */
433psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service);
434
435/**
436 * \brief Free connection handle which not used anymore.
437 *
438 * \param[in] service Target service context pointer
439 * \param[in] conn_handle Connection handle created by
440 * tfm_spm_create_conn_handle(), \ref psa_handle_t
441 *
442 * \retval IPC_SUCCESS Success
443 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
444 * \retval "Does not return" Panic for not find service by handle
445 */
446int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
447 psa_handle_t conn_handle);
448
449/**
450 * \brief Set reverse handle value for connection.
451 *
452 * \param[in] service Target service context pointer
453 * \param[in] conn_handle Connection handle created by
454 * tfm_spm_create_conn_handle(), \ref psa_handle_t
455 * \param[in] rhandle rhandle need to save
456 *
457 * \retval IPC_SUCCESS Success
458 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
459 * \retval "Does not return" Panic for not find handle node
460 */
461int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
462 psa_handle_t conn_handle,
463 void *rhandle);
464
465/**
466 * \brief Get reverse handle value from connection hanlde.
467 *
468 * \param[in] service Target service context pointer
469 * \param[in] conn_handle Connection handle created by
470 * tfm_spm_create_conn_handle(), \ref psa_handle_t
471 *
472 * \retval void * Success
473 * \retval "Does not return" Panic for those:
474 * service pointer are NULL
475 * hanlde is \ref PSA_NULL_HANDLE
476 * handle node does not be found
477 */
478void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
479 psa_handle_t conn_handle);
480
481/******************** Partition management functions *************************/
482
483/**
484 * \brief Get current running partition context.
485 *
486 * \retval NULL Failed
487 * \retval "Not NULL" Return the parttion context pointer
488 * \ref spm_partition_desc_t structures
489 */
490struct spm_partition_desc_t *tfm_spm_get_running_partition(void);
491
492/**
493 * \brief Get the service context by signal.
494 *
495 * \param[in] partition Partition context pointer
496 * \ref spm_partition_desc_t structures
497 * \param[in] signal Signal associated with inputs to the Secure
498 * Partition, \ref psa_signal_t
499 *
500 * \retval NULL Failed
501 * \retval "Not NULL" Target service context pointer,
502 * \ref tfm_spm_service_t structures
503 */
504struct tfm_spm_service_t *
505 tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition,
506 psa_signal_t signal);
507
508/**
509 * \brief Get the service context by service ID.
510 *
511 * \param[in] sid RoT Service identity
512 *
513 * \retval NULL Failed
514 * \retval "Not NULL" Target service context pointer,
515 * \ref tfm_spm_service_t structures
516 */
517struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
518
519/**
520 * \brief Get the service context by connection handle.
521 *
522 * \param[in] conn_handle Connection handle created by
523 * tfm_spm_create_conn_handle()
524 *
525 * \retval NULL Failed
526 * \retval "Not NULL" Target service context pointer,
527 * \ref tfm_spm_service_t structures
528 */
529struct tfm_spm_service_t *
530 tfm_spm_get_service_by_handle(psa_handle_t conn_handle);
531
532/**
533 * \brief Get the partition context by partition ID.
534 *
535 * \param[in] partition_id Partition identity
536 *
537 * \retval NULL Failed
538 * \retval "Not NULL" Target partition context pointer,
539 * \ref spm_partition_desc_t structures
540 */
541struct spm_partition_desc_t *
542 tfm_spm_get_partition_by_id(int32_t partition_id);
543
544/************************ Message functions **********************************/
545
546/**
547 * \brief Get message context by message handle.
548 *
549 * \param[in] msg_handle Message handle which is a reference generated
550 * by the SPM to a specific message.
551 *
552 * \return The message body context pointer
553 * \ref tfm_msg_body_t structures
554 */
555struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
556
557/**
Edison Ai97115822019-08-01 14:22:19 +0800558 * \brief Get message context by connect handle.
Mingyang Sunf3d29892019-07-10 17:50:23 +0800559 *
Edison Ai97115822019-08-01 14:22:19 +0800560 * \param[in] conn_handle Service connect handle.
561 *
562 * \return The message body context pointer
563 * \ref msg_body_t structures
564 */
565struct tfm_msg_body_t *
566 tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle);
567
568/**
569 * \brief Fill the message for PSA client call.
570 *
571 * \param[in] msg Service Message Queue buffer pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800572 * \param[in] service Target service context pointer, which can be
573 * obtained by partition management functions
574 * \prarm[in] handle Connect handle return by psa_connect().
575 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
576 * PSA_IPC_DISCONNECT
577 * \param[in] ns_caller Whether from NS caller
578 * \param[in] invec Array of input \ref psa_invec structures
579 * \param[in] in_len Number of input \ref psa_invec structures
580 * \param[in] outvec Array of output \ref psa_outvec structures
581 * \param[in] out_len Number of output \ref psa_outvec structures
582 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800583 */
Edison Ai97115822019-08-01 14:22:19 +0800584void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
585 struct tfm_spm_service_t *service,
586 psa_handle_t handle,
587 int32_t type, int32_t ns_caller,
588 psa_invec *invec, size_t in_len,
589 psa_outvec *outvec, size_t out_len,
590 psa_outvec *caller_outvec);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800591
592/**
593 * \brief Send message and wake up the SP who is waiting on
594 * message queue, block the current thread and
595 * scheduler triggered
596 *
597 * \param[in] service Target service context pointer, which can be
598 * obtained by partition management functions
599 * \param[in] msg message created by tfm_spm_create_msg()
600 * \ref tfm_msg_body_t structures
601 *
602 * \retval IPC_SUCCESS Success
603 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
604 * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue
605 */
606int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
607 struct tfm_msg_body_t *msg);
608
609/**
610 * \brief Check the client minor version according to
611 * version policy
612 *
613 * \param[in] service Target service context pointer, which can be get
614 * by partition management functions
615 * \param[in] minor_version Client support minor version
616 *
617 * \retval IPC_SUCCESS Success
618 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
619 * \retval IPC_ERROR_VERSION Check failed
620 */
621int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
622 uint32_t minor_version);
623
624/**
625 * \brief Check the memory reference is valid.
626 *
627 * \param[in] buffer Pointer of memory reference
628 * \param[in] len Length of memory reference in bytes
629 * \param[in] ns_caller From non-secure caller
630 * \param[in] access Type of access specified by the
631 * \ref tfm_memory_access_e
632 * \param[in] privileged Privileged mode or unprivileged mode:
633 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
634 * \ref TFM_PARTITION_PRIVILEGED_MODE
635 *
636 * \retval IPC_SUCCESS Success
637 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
638 * \retval IPC_ERROR_MEMORY_CHECK Check failed
639 */
David Hucb05d972019-08-06 18:10:11 +0800640int32_t tfm_memory_check(const void *buffer, size_t len, int32_t ns_caller,
Mingyang Sunf3d29892019-07-10 17:50:23 +0800641 enum tfm_memory_access_e access,
642 uint32_t privileged);
643
644/* This function should be called before schedule function */
645void tfm_spm_init(void);
646
647/*
648 * PendSV specified function.
649 *
650 * Parameters :
651 * ctxb - State context storage pointer
652 *
653 * Notes:
654 * This is a staging API. Scheduler should be called in SPM finally and
655 * this function will be obsoleted later.
656 */
657void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
658
659#endif /* ifdef(TFM_PSA_API) */
660
Miklos Balint386b8b52017-11-29 13:12:32 +0000661#endif /*__SPM_API_H__ */