blob: aebcc5a44d166cb3e4f834b0c96926807157764a [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 */
Edison Ai66fbdf12019-07-08 16:05:07 +080091#else /* TFM_PSA_API */
Mate Toth-Pal18b83922018-02-26 17:58:18 +010092 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010093 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020094 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010095 uint32_t share;
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-Pal2a6f8c22018-12-13 16:37:17 +010098 int32_t iovec_api; /*!< Whether the function in the partition
99 * had been called using the iovec API.
100 * FIXME: Remove the field once this is the
101 * only option
102 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200103 struct iovec_args_t iovec_args;
104 psa_outvec *orig_outvec;
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200105 uint32_t *ctx_stack_ptr;
Edison Ai66fbdf12019-07-08 16:05:07 +0800106#endif /* TFM_PSA_API */
107 uint32_t signal_mask; /*
108 * Service signal mask passed by
109 * psa_wait()
110 */
Summer Qin423dbef2019-08-22 15:59:35 +0800111 uint32_t index; /* Partition index */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100112};
113
Mingyang Sunda01a972019-07-12 17:32:59 +0800114#ifdef TFM_PSA_API
115
Mingyang Sunda01a972019-07-12 17:32:59 +0800116#define TFM_VERSION_POLICY_RELAXED 0
117#define TFM_VERSION_POLICY_STRICT 1
118
Edison Ai97115822019-08-01 14:22:19 +0800119#define TFM_CONN_HANDLE_MAX_NUM 16
Mingyang Sunda01a972019-07-12 17:32:59 +0800120
121/* RoT connection handle list */
122struct tfm_conn_handle_t {
Edison Ai9cc26242019-08-06 11:28:04 +0800123 void *rhandle; /* Reverse handle value */
Edison Ai97115822019-08-01 14:22:19 +0800124 struct tfm_msg_body_t internal_msg; /* Internal message for message queue */
Edison Ai9cc26242019-08-06 11:28:04 +0800125 struct tfm_spm_service_t *service; /* RoT service pointer */
126 struct tfm_list_node_t list; /* list node */
Mingyang Sunda01a972019-07-12 17:32:59 +0800127};
128
129/* Service database defined by manifest */
130struct tfm_spm_service_db_t {
131 char *name; /* Service name */
132 uint32_t partition_id; /* Partition ID which service belong to */
133 psa_signal_t signal; /* Service signal */
134 uint32_t sid; /* Service identifier */
135 bool non_secure_client; /* If can be called by non secure client */
136 uint32_t minor_version; /* Minor version */
137 uint32_t minor_policy; /* Minor version policy */
138};
139
140/* RoT Service data */
141struct tfm_spm_service_t {
Summer Qine578c5b2019-08-16 16:42:16 +0800142 const struct tfm_spm_service_db_t *service_db;/* Service database pointer */
Mingyang Sunda01a972019-07-12 17:32:59 +0800143 struct spm_partition_desc_t *partition; /*
144 * Point to secure partition
145 * data
146 */
147 struct tfm_list_node_t handle_list; /* Service handle list */
148 struct tfm_msg_queue_t msg_queue; /* Message queue */
149 struct tfm_list_node_t list; /* For list operation */
150};
151#endif /* ifdef(TFM_PSA_API) */
152
153/*********************** common definitions ***********************/
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100154
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100155/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100156 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +0000157 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100158 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000159 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100160 * \return the partition idx if partition_id is valid,
161 * \ref SPM_INVALID_PARTITION_IDX othervise
162 */
163uint32_t get_partition_idx(uint32_t partition_id);
164
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200165/**
Summer Qinb4a854d2019-05-29 15:31:22 +0800166 * \brief Get the id of the partition for its index from the db
167 *
168 * \param[in] partition_idx Partition index
169 *
170 * \return Partition ID for that partition
171 *
172 * \note This function doesn't check if partition_idx is valid.
173 */
174uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
175
176/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200177 * \brief Get the flags associated with a partition
178 *
179 * \param[in] partition_idx Partition index
180 *
181 * \return Flags associated with the partition
182 *
183 * \note This function doesn't check if partition_idx is valid.
184 */
185uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
186
Mingyang Sunda01a972019-07-12 17:32:59 +0800187/**
188 * \brief Initialize partition database
189 *
190 * \return Error code \ref spm_err_t
191 */
192enum spm_err_t tfm_spm_db_init(void);
193
194/**
195 * \brief Change the privilege mode for partition thread mode.
196 *
197 * \param[in] privileged Privileged mode,
198 * \ref TFM_PARTITION_PRIVILEGED_MODE
199 * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
200 *
201 * \note Barrier instructions are not called by this function, and if
202 * it is called in thread mode, it might be necessary to call
Edison Ai7aff9e82019-07-11 14:56:46 +0800203 * them after this function returns.
Mingyang Sunda01a972019-07-12 17:32:59 +0800204 */
205void tfm_spm_partition_change_privilege(uint32_t privileged);
206
207/*********************** library definitions ***********************/
208
Summer Qinb4a854d2019-05-29 15:31:22 +0800209#ifndef TFM_PSA_API
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200210/**
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200211 * \brief Save interrupted partition context on ctx stack
212 *
213 * \param[in] partition_idx Partition index
214 *
215 * \note This function doesn't check if partition_idx is valid.
216 * \note This function doesn't whether the ctx stack overflows.
217 */
218void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx);
219
220/**
221 * \brief Restores interrupted partition context on ctx stack
222 *
223 * \param[in] partition_idx Partition index
224 *
225 * \note This function doesn't check if partition_idx is valid.
226 * \note This function doesn't whether the ctx stack underflows.
227 */
228void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx);
229
230/**
231 * \brief Save handler partition context on ctx stack
232 *
233 * \param[in] partition_idx Partition index
234 *
235 * \note This function doesn't check if partition_idx is valid.
236 * \note This function doesn't whether the ctx stack overflows.
237 */
238void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx);
239
240/**
241 * \brief Restores handler partition context on ctx stack
242 *
243 * \param[in] partition_idx Partition index
244 *
245 * \note This function doesn't check if partition_idx is valid.
246 * \note This function doesn't whether the ctx stack underflows.
247 */
248void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx);
249
250/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100251 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100252 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100253 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100254 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100255 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100256 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100257 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100259const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100260 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100261
262/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100263 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100264 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100265 * \return The index of the partition with the running state, if there is any
266 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100267 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100268uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100269
270/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200271 * \brief Save stack pointer and link register for partition in database
272 *
273 * \param[in] partition_idx Partition index
274 * \param[in] stack_ptr Stack pointer to be stored
275 * \param[in] lr Link register to be stored
276 *
277 * \note This function doesn't check if partition_idx is valid.
278 */
279void tfm_spm_partition_store_context(uint32_t partition_idx,
280 uint32_t stack_ptr, uint32_t lr);
281
282/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100283 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100284 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100285 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100286 * \param[in] state The state to be set
287 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100288 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100289 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100290 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100291void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100292
293/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200294 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100295 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100296 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200297 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100298 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200299 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100300 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200301void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
302 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100303
304/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200305* \brief Set the caller client ID for a given partition
306*
307* \param[in] partition_idx Partition index
308* \param[in] caller_client_id The ID of the calling client
309*
310* \note This function doesn't check if any of the partition_idxs are valid.
311*/
312void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
313 int32_t caller_client_id);
314
315/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100316 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100317 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100318 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100319 * \param[in] share The buffer share region to be set
320 *
321 * \return Error code \ref spm_err_t
322 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100323 * \note This function doesn't check if partition_idx is valid.
Hugues de Valon99578562019-06-18 16:08:51 +0100324 * \note share has to have one of the buffer share values:
325 * - TFM_BUFFER_SHARE_DISABLE
326 * - TFM_BUFFER_SHARE_NS_CODE
327 * - TFM_BUFFER_SHARE_SCRATCH
328 * - TFM_BUFFER_SHARE_PRIV
329 * - TFM_BUFFER_SHARE_DEFAULT
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100330 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100331enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100332 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100333
334/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200335 * \brief Set the iovec parameters for the partition
336 *
337 * \param[in] partition_idx Partition index
338 * \param[in] args The arguments of the secure function
339 *
340 * args is expected to be of type int32_t[4] where:
341 * args[0] is in_vec
342 * args[1] is in_len
343 * args[2] is out_vec
344 * args[3] is out_len
345 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000346 * \return Error code \ref spm_err_t
347 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200348 * \note This function doesn't check if partition_idx is valid.
349 * \note This function assumes that the iovecs that are passed in args are
350 * valid, and does no sanity check on them at all.
351 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000352enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
353 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200354
355/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100356 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000357 *
358 * \return Error code \ref spm_err_t
359 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100360enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000361
362/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100363 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000364 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100365 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000366 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100367 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000368 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100369void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200370
371/**
372 * \brief Set the signal mask for a given partition
373 *
374 * \param[in] partition_idx Partition index
375 * \param[in] signal_mask The signal mask to be set for the partition
376 *
377 * \note This function doesn't check if any of the partition_idxs are valid.
378 */
379void tfm_spm_partition_set_signal_mask(uint32_t partition_idx,
380 uint32_t signal_mask);
Summer Qinb4a854d2019-05-29 15:31:22 +0800381#endif /* !defined(TFM_PSA_API) */
382
Mingyang Sunf3d29892019-07-10 17:50:23 +0800383#ifdef TFM_PSA_API
Mingyang Sunda01a972019-07-12 17:32:59 +0800384/*************************** IPC definitions **************************/
Edison Ai7aff9e82019-07-11 14:56:46 +0800385
386/**
387 * \brief Get bottom of stack region for a partition
388 *
389 * \param[in] partition_idx Partition index
390 *
391 * \return Stack region bottom value
392 *
393 * \note This function doesn't check if partition_idx is valid.
394 */
395uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
396
397/**
398 * \brief Get top of stack region for a partition
399 *
400 * \param[in] partition_idx Partition index
401 *
402 * \return Stack region top value
403 *
404 * \note This function doesn't check if partition_idx is valid.
405 */
406uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800407
408/**
409 * \brief Get the running partition ID.
410 *
411 * \return Returns the partition ID
412 */
413uint32_t tfm_spm_partition_get_running_partition_id(void);
414
415/**
416 * \brief Get the current partition mode.
417 *
418 * \param[in] partition_idx Index of current partition
419 *
420 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
421 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
422 */
423uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx);
424
425/******************** Service handle management functions ********************/
426
427/**
428 * \brief Create connection handle for client connect
429 *
430 * \param[in] service Target service context pointer
431 *
432 * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE
433 * \retval >0 Service handle created, \ref psa_handle_t
434 */
435psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service);
436
437/**
438 * \brief Free connection handle which not used anymore.
439 *
440 * \param[in] service Target service context pointer
441 * \param[in] conn_handle Connection handle created by
442 * tfm_spm_create_conn_handle(), \ref psa_handle_t
443 *
444 * \retval IPC_SUCCESS Success
445 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
446 * \retval "Does not return" Panic for not find service by handle
447 */
448int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
449 psa_handle_t conn_handle);
450
451/**
452 * \brief Set reverse handle value for connection.
453 *
454 * \param[in] service Target service context pointer
455 * \param[in] conn_handle Connection handle created by
456 * tfm_spm_create_conn_handle(), \ref psa_handle_t
457 * \param[in] rhandle rhandle need to save
458 *
459 * \retval IPC_SUCCESS Success
460 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
461 * \retval "Does not return" Panic for not find handle node
462 */
463int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
464 psa_handle_t conn_handle,
465 void *rhandle);
466
467/**
468 * \brief Get reverse handle value from connection hanlde.
469 *
470 * \param[in] service Target service context pointer
471 * \param[in] conn_handle Connection handle created by
472 * tfm_spm_create_conn_handle(), \ref psa_handle_t
473 *
474 * \retval void * Success
475 * \retval "Does not return" Panic for those:
476 * service pointer are NULL
477 * hanlde is \ref PSA_NULL_HANDLE
478 * handle node does not be found
479 */
480void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
481 psa_handle_t conn_handle);
482
483/******************** Partition management functions *************************/
484
485/**
486 * \brief Get current running partition context.
487 *
488 * \retval NULL Failed
489 * \retval "Not NULL" Return the parttion context pointer
490 * \ref spm_partition_desc_t structures
491 */
492struct spm_partition_desc_t *tfm_spm_get_running_partition(void);
493
494/**
495 * \brief Get the service context by signal.
496 *
497 * \param[in] partition Partition context pointer
498 * \ref spm_partition_desc_t structures
499 * \param[in] signal Signal associated with inputs to the Secure
500 * Partition, \ref psa_signal_t
501 *
502 * \retval NULL Failed
503 * \retval "Not NULL" Target service context pointer,
504 * \ref tfm_spm_service_t structures
505 */
506struct tfm_spm_service_t *
507 tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition,
508 psa_signal_t signal);
509
510/**
511 * \brief Get the service context by service ID.
512 *
513 * \param[in] sid RoT Service identity
514 *
515 * \retval NULL Failed
516 * \retval "Not NULL" Target service context pointer,
517 * \ref tfm_spm_service_t structures
518 */
519struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
520
521/**
522 * \brief Get the service context by connection handle.
523 *
524 * \param[in] conn_handle Connection handle created by
525 * tfm_spm_create_conn_handle()
526 *
527 * \retval NULL Failed
528 * \retval "Not NULL" Target service context pointer,
529 * \ref tfm_spm_service_t structures
530 */
531struct tfm_spm_service_t *
532 tfm_spm_get_service_by_handle(psa_handle_t conn_handle);
533
534/**
535 * \brief Get the partition context by partition ID.
536 *
537 * \param[in] partition_id Partition identity
538 *
539 * \retval NULL Failed
540 * \retval "Not NULL" Target partition context pointer,
541 * \ref spm_partition_desc_t structures
542 */
543struct spm_partition_desc_t *
544 tfm_spm_get_partition_by_id(int32_t partition_id);
545
546/************************ Message functions **********************************/
547
548/**
549 * \brief Get message context by message handle.
550 *
551 * \param[in] msg_handle Message handle which is a reference generated
552 * by the SPM to a specific message.
553 *
554 * \return The message body context pointer
555 * \ref tfm_msg_body_t structures
556 */
557struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
558
559/**
Edison Ai97115822019-08-01 14:22:19 +0800560 * \brief Get message context by connect handle.
Mingyang Sunf3d29892019-07-10 17:50:23 +0800561 *
Edison Ai97115822019-08-01 14:22:19 +0800562 * \param[in] conn_handle Service connect handle.
563 *
564 * \return The message body context pointer
565 * \ref msg_body_t structures
566 */
567struct tfm_msg_body_t *
568 tfm_spm_get_msg_buffer_from_conn_handle(psa_handle_t conn_handle);
569
570/**
571 * \brief Fill the message for PSA client call.
572 *
573 * \param[in] msg Service Message Queue buffer pointer
Mingyang Sunf3d29892019-07-10 17:50:23 +0800574 * \param[in] service Target service context pointer, which can be
575 * obtained by partition management functions
576 * \prarm[in] handle Connect handle return by psa_connect().
577 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
578 * PSA_IPC_DISCONNECT
579 * \param[in] ns_caller Whether from NS caller
580 * \param[in] invec Array of input \ref psa_invec structures
581 * \param[in] in_len Number of input \ref psa_invec structures
582 * \param[in] outvec Array of output \ref psa_outvec structures
583 * \param[in] out_len Number of output \ref psa_outvec structures
584 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
Mingyang Sunf3d29892019-07-10 17:50:23 +0800585 */
Edison Ai97115822019-08-01 14:22:19 +0800586void tfm_spm_fill_msg(struct tfm_msg_body_t *msg,
587 struct tfm_spm_service_t *service,
588 psa_handle_t handle,
589 int32_t type, int32_t ns_caller,
590 psa_invec *invec, size_t in_len,
591 psa_outvec *outvec, size_t out_len,
592 psa_outvec *caller_outvec);
Mingyang Sunf3d29892019-07-10 17:50:23 +0800593
594/**
595 * \brief Send message and wake up the SP who is waiting on
596 * message queue, block the current thread and
597 * scheduler triggered
598 *
599 * \param[in] service Target service context pointer, which can be
600 * obtained by partition management functions
601 * \param[in] msg message created by tfm_spm_create_msg()
602 * \ref tfm_msg_body_t structures
603 *
604 * \retval IPC_SUCCESS Success
605 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
606 * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue
607 */
608int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
609 struct tfm_msg_body_t *msg);
610
611/**
612 * \brief Check the client minor version according to
613 * version policy
614 *
615 * \param[in] service Target service context pointer, which can be get
616 * by partition management functions
617 * \param[in] minor_version Client support minor version
618 *
619 * \retval IPC_SUCCESS Success
620 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
621 * \retval IPC_ERROR_VERSION Check failed
622 */
623int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
624 uint32_t minor_version);
625
626/**
627 * \brief Check the memory reference is valid.
628 *
629 * \param[in] buffer Pointer of memory reference
630 * \param[in] len Length of memory reference in bytes
631 * \param[in] ns_caller From non-secure caller
632 * \param[in] access Type of access specified by the
633 * \ref tfm_memory_access_e
634 * \param[in] privileged Privileged mode or unprivileged mode:
635 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
636 * \ref TFM_PARTITION_PRIVILEGED_MODE
637 *
638 * \retval IPC_SUCCESS Success
639 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
640 * \retval IPC_ERROR_MEMORY_CHECK Check failed
641 */
David Hucb05d972019-08-06 18:10:11 +0800642int32_t tfm_memory_check(const void *buffer, size_t len, int32_t ns_caller,
Mingyang Sunf3d29892019-07-10 17:50:23 +0800643 enum tfm_memory_access_e access,
644 uint32_t privileged);
645
646/* This function should be called before schedule function */
647void tfm_spm_init(void);
648
649/*
650 * PendSV specified function.
651 *
652 * Parameters :
653 * ctxb - State context storage pointer
654 *
655 * Notes:
656 * This is a staging API. Scheduler should be called in SPM finally and
657 * this function will be obsoleted later.
658 */
659void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
660
661#endif /* ifdef(TFM_PSA_API) */
662
Miklos Balint386b8b52017-11-29 13:12:32 +0000663#endif /*__SPM_API_H__ */