blob: 55a42cff95261ec97ef4008b03f5a01c59ae1226 [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"
Miklos Balint386b8b52017-11-29 13:12:32 +000014#include "secure_fw/core/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 {
69#if TFM_LVL != 1
70 uint32_t stack_ptr;
71#endif
72 uint32_t partition_state;
73};
74
75/* The size of this struct must be multiple of 4 bytes as it is stacked to an
76 * uint32_t[] array
77 */
78struct handler_ctx_stack_frame_t {
79 uint32_t partition_state;
80 uint32_t caller_partition_idx;
81};
Edison Ai66fbdf12019-07-08 16:05:07 +080082#endif /* !define(TFM_PSA_API) */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020083
84/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010085 * \brief Runtime context information of a partition
86 */
87struct spm_partition_runtime_data_t {
Edison Ai66fbdf12019-07-08 16:05:07 +080088#ifdef TFM_PSA_API
89 struct tfm_event_t signal_evnt; /* Event signal */
90 uint32_t signals; /* Service signals had been triggered*/
91 struct tfm_list_node_t service_list;/* Service list */
92#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 share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010097 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020098 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010099 int32_t iovec_api; /*!< Whether the function in the partition
100 * had been called using the iovec API.
101 * FIXME: Remove the field once this is the
102 * only option
103 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200104 struct iovec_args_t iovec_args;
105 psa_outvec *orig_outvec;
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200106 uint32_t *ctx_stack_ptr;
Edison Ai66fbdf12019-07-08 16:05:07 +0800107#endif /* TFM_PSA_API */
108 uint32_t signal_mask; /*
109 * Service signal mask passed by
110 * psa_wait()
111 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100112};
113
Mingyang Sunda01a972019-07-12 17:32:59 +0800114#ifdef TFM_PSA_API
115
116#define TFM_SPM_MAX_ROT_SERV_NUM 48
117#define TFM_VERSION_POLICY_RELAXED 0
118#define TFM_VERSION_POLICY_STRICT 1
119
120#define TFM_CONN_HANDLE_MAX_NUM 32
121
122/* RoT connection handle list */
123struct tfm_conn_handle_t {
124 psa_handle_t handle; /* Handle value */
125 void *rhandle; /* Reverse handle value */
126 struct tfm_list_node_t list; /* list node */
127};
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 {
142 struct tfm_spm_service_db_t *service_db; /* Service database pointer */
143 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
Miklos Balintdd02bb32019-05-26 21:13:12 +0200165#if (TFM_LVL != 1) || defined(TFM_PSA_API)
Summer Qind00e4db2019-05-09 18:03:52 +0800166/**
167 * \brief Get bottom of stack region for a partition
168 *
169 * \param[in] partition_idx Partition index
170 *
171 * \return Stack region bottom value
172 *
173 * \note This function doesn't check if partition_idx is valid.
174 */
175uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
176
177/**
178 * \brief Get top of stack region for a partition
179 *
180 * \param[in] partition_idx Partition index
181 *
182 * \return Stack region top value
183 *
184 * \note This function doesn't check if partition_idx is valid.
185 */
186uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
Miklos Balintdd02bb32019-05-26 21:13:12 +0200187#endif
Summer Qind00e4db2019-05-09 18:03:52 +0800188
Miklos Balintdd02bb32019-05-26 21:13:12 +0200189#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100190/**
191 * \brief Configure isolated sandbox for a partition
192 *
193 * \param[in] partition_idx Partition index
194 *
Miklos Balint386b8b52017-11-29 13:12:32 +0000195 * \return Error code \ref spm_err_t
196 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100197 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000198 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100199enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000200
201/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100202 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000203 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100204 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000205 *
206 * \return Error code \ref spm_err_t
207 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100208 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000209 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100210enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000211
212/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200213 * \brief Get the start of the zero-initialised region for a partition
214 *
215 * \param[in] partition_idx Partition idx
216 *
217 * \return Start of the zero-initialised region
218 *
219 * \note This function doesn't check if partition_idx is valid.
220 */
221uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
222
223/**
224 * \brief Get the limit of the zero-initialised region for a partition
225 *
226 * \param[in] partition_idx Partition idx
227 *
228 * \return Limit of the zero-initialised region
229 *
230 * \note This function doesn't check if partition_idx is valid.
231 * \note The address returned is not part of the region.
232 */
233uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
234
235/**
236 * \brief Get the start of the read-write region for a partition
237 *
238 * \param[in] partition_idx Partition idx
239 *
240 * \return Start of the read-write region
241 *
242 * \note This function doesn't check if partition_idx is valid.
243 */
244uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
245
246/**
247 * \brief Get the limit of the read-write region for a partition
248 *
249 * \param[in] partition_idx Partition idx
250 *
251 * \return Limit of the read-write region
252 *
253 * \note This function doesn't check if partition_idx is valid.
254 * \note The address returned is not part of the region.
255 */
256uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
257
258/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200259 * \brief Save stack pointer for partition in database
260 *
261 * \param[in] partition_idx Partition index
262 * \param[in] stack_ptr Stack pointer to be stored
263 *
264 * \note This function doesn't check if partition_idx is valid.
265 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100266void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
Mingyang Sunda01a972019-07-12 17:32:59 +0800267#endif /* if (TFM_LVL != 1) && !defined(TFM_PSA_API) */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200268
269/**
Summer Qinb4a854d2019-05-29 15:31:22 +0800270 * \brief Get the id of the partition for its index from the db
271 *
272 * \param[in] partition_idx Partition index
273 *
274 * \return Partition ID for that partition
275 *
276 * \note This function doesn't check if partition_idx is valid.
277 */
278uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
279
280/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200281 * \brief Get the flags associated with a partition
282 *
283 * \param[in] partition_idx Partition index
284 *
285 * \return Flags associated with the partition
286 *
287 * \note This function doesn't check if partition_idx is valid.
288 */
289uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
290
Mingyang Sunda01a972019-07-12 17:32:59 +0800291/**
292 * \brief Initialize partition database
293 *
294 * \return Error code \ref spm_err_t
295 */
296enum spm_err_t tfm_spm_db_init(void);
297
298/**
299 * \brief Change the privilege mode for partition thread mode.
300 *
301 * \param[in] privileged Privileged mode,
302 * \ref TFM_PARTITION_PRIVILEGED_MODE
303 * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
304 *
305 * \note Barrier instructions are not called by this function, and if
306 * it is called in thread mode, it might be necessary to call
307 * them after this function returns (just like it is done in
308 * jump_to_ns_code()).
309 */
310void tfm_spm_partition_change_privilege(uint32_t privileged);
311
312/*********************** library definitions ***********************/
313
Summer Qinb4a854d2019-05-29 15:31:22 +0800314#ifndef TFM_PSA_API
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200315/**
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200316 * \brief Save interrupted partition context on ctx stack
317 *
318 * \param[in] partition_idx Partition index
319 *
320 * \note This function doesn't check if partition_idx is valid.
321 * \note This function doesn't whether the ctx stack overflows.
322 */
323void tfm_spm_partition_push_interrupted_ctx(uint32_t partition_idx);
324
325/**
326 * \brief Restores interrupted partition context on ctx stack
327 *
328 * \param[in] partition_idx Partition index
329 *
330 * \note This function doesn't check if partition_idx is valid.
331 * \note This function doesn't whether the ctx stack underflows.
332 */
333void tfm_spm_partition_pop_interrupted_ctx(uint32_t partition_idx);
334
335/**
336 * \brief Save handler partition context on ctx stack
337 *
338 * \param[in] partition_idx Partition index
339 *
340 * \note This function doesn't check if partition_idx is valid.
341 * \note This function doesn't whether the ctx stack overflows.
342 */
343void tfm_spm_partition_push_handler_ctx(uint32_t partition_idx);
344
345/**
346 * \brief Restores handler partition context on ctx stack
347 *
348 * \param[in] partition_idx Partition index
349 *
350 * \note This function doesn't check if partition_idx is valid.
351 * \note This function doesn't whether the ctx stack underflows.
352 */
353void tfm_spm_partition_pop_handler_ctx(uint32_t partition_idx);
354
355/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100356 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100357 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100358 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100359 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100360 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100361 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100362 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100363 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100364const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100365 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100366
367/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100368 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100369 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100370 * \return The index of the partition with the running state, if there is any
371 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100372 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100373uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100374
375/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200376 * \brief Save stack pointer and link register for partition in database
377 *
378 * \param[in] partition_idx Partition index
379 * \param[in] stack_ptr Stack pointer to be stored
380 * \param[in] lr Link register to be stored
381 *
382 * \note This function doesn't check if partition_idx is valid.
383 */
384void tfm_spm_partition_store_context(uint32_t partition_idx,
385 uint32_t stack_ptr, uint32_t lr);
386
387/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100388 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100389 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100390 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100391 * \param[in] state The state to be set
392 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100393 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100394 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100395 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100396void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100397
398/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200399 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100400 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100401 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200402 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100403 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200404 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100405 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200406void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
407 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100408
409/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200410* \brief Set the caller client ID for a given partition
411*
412* \param[in] partition_idx Partition index
413* \param[in] caller_client_id The ID of the calling client
414*
415* \note This function doesn't check if any of the partition_idxs are valid.
416*/
417void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
418 int32_t caller_client_id);
419
420/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100421 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100422 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100423 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100424 * \param[in] share The buffer share region to be set
425 *
426 * \return Error code \ref spm_err_t
427 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100428 * \note This function doesn't check if partition_idx is valid.
Hugues de Valon99578562019-06-18 16:08:51 +0100429 * \note share has to have one of the buffer share values:
430 * - TFM_BUFFER_SHARE_DISABLE
431 * - TFM_BUFFER_SHARE_NS_CODE
432 * - TFM_BUFFER_SHARE_SCRATCH
433 * - TFM_BUFFER_SHARE_PRIV
434 * - TFM_BUFFER_SHARE_DEFAULT
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100435 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100436enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100437 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100438
439/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200440 * \brief Set the iovec parameters for the partition
441 *
442 * \param[in] partition_idx Partition index
443 * \param[in] args The arguments of the secure function
444 *
445 * args is expected to be of type int32_t[4] where:
446 * args[0] is in_vec
447 * args[1] is in_len
448 * args[2] is out_vec
449 * args[3] is out_len
450 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000451 * \return Error code \ref spm_err_t
452 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200453 * \note This function doesn't check if partition_idx is valid.
454 * \note This function assumes that the iovecs that are passed in args are
455 * valid, and does no sanity check on them at all.
456 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000457enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
458 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200459
460/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100461 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000462 *
463 * \return Error code \ref spm_err_t
464 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100465enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000466
467/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100468 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000469 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100470 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000471 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100472 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000473 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100474void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Mate Toth-Pal4341de02018-10-02 12:55:47 +0200475
476/**
477 * \brief Set the signal mask for a given partition
478 *
479 * \param[in] partition_idx Partition index
480 * \param[in] signal_mask The signal mask to be set for the partition
481 *
482 * \note This function doesn't check if any of the partition_idxs are valid.
483 */
484void tfm_spm_partition_set_signal_mask(uint32_t partition_idx,
485 uint32_t signal_mask);
Summer Qinb4a854d2019-05-29 15:31:22 +0800486#endif /* !defined(TFM_PSA_API) */
487
Mingyang Sunf3d29892019-07-10 17:50:23 +0800488#ifdef TFM_PSA_API
Mingyang Sunda01a972019-07-12 17:32:59 +0800489/*************************** IPC definitions **************************/
Mingyang Sunf3d29892019-07-10 17:50:23 +0800490/*************************** Extended SPM functions **************************/
491
492/**
493 * \brief Get the running partition ID.
494 *
495 * \return Returns the partition ID
496 */
497uint32_t tfm_spm_partition_get_running_partition_id(void);
498
499/**
500 * \brief Get the current partition mode.
501 *
502 * \param[in] partition_idx Index of current partition
503 *
504 * \retval TFM_PARTITION_PRIVILEGED_MODE Privileged mode
505 * \retval TFM_PARTITION_UNPRIVILEGED_MODE Unprivileged mode
506 */
507uint32_t tfm_spm_partition_get_privileged_mode(uint32_t partition_idx);
508
509/******************** Service handle management functions ********************/
510
511/**
512 * \brief Create connection handle for client connect
513 *
514 * \param[in] service Target service context pointer
515 *
516 * \retval PSA_NULL_HANDLE Create failed \ref PSA_NULL_HANDLE
517 * \retval >0 Service handle created, \ref psa_handle_t
518 */
519psa_handle_t tfm_spm_create_conn_handle(struct tfm_spm_service_t *service);
520
521/**
522 * \brief Free connection handle which not used anymore.
523 *
524 * \param[in] service Target service context pointer
525 * \param[in] conn_handle Connection handle created by
526 * tfm_spm_create_conn_handle(), \ref psa_handle_t
527 *
528 * \retval IPC_SUCCESS Success
529 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
530 * \retval "Does not return" Panic for not find service by handle
531 */
532int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
533 psa_handle_t conn_handle);
534
535/**
536 * \brief Set reverse handle value for connection.
537 *
538 * \param[in] service Target service context pointer
539 * \param[in] conn_handle Connection handle created by
540 * tfm_spm_create_conn_handle(), \ref psa_handle_t
541 * \param[in] rhandle rhandle need to save
542 *
543 * \retval IPC_SUCCESS Success
544 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
545 * \retval "Does not return" Panic for not find handle node
546 */
547int32_t tfm_spm_set_rhandle(struct tfm_spm_service_t *service,
548 psa_handle_t conn_handle,
549 void *rhandle);
550
551/**
552 * \brief Get reverse handle value from connection hanlde.
553 *
554 * \param[in] service Target service context pointer
555 * \param[in] conn_handle Connection handle created by
556 * tfm_spm_create_conn_handle(), \ref psa_handle_t
557 *
558 * \retval void * Success
559 * \retval "Does not return" Panic for those:
560 * service pointer are NULL
561 * hanlde is \ref PSA_NULL_HANDLE
562 * handle node does not be found
563 */
564void *tfm_spm_get_rhandle(struct tfm_spm_service_t *service,
565 psa_handle_t conn_handle);
566
567/******************** Partition management functions *************************/
568
569/**
570 * \brief Get current running partition context.
571 *
572 * \retval NULL Failed
573 * \retval "Not NULL" Return the parttion context pointer
574 * \ref spm_partition_desc_t structures
575 */
576struct spm_partition_desc_t *tfm_spm_get_running_partition(void);
577
578/**
579 * \brief Get the service context by signal.
580 *
581 * \param[in] partition Partition context pointer
582 * \ref spm_partition_desc_t structures
583 * \param[in] signal Signal associated with inputs to the Secure
584 * Partition, \ref psa_signal_t
585 *
586 * \retval NULL Failed
587 * \retval "Not NULL" Target service context pointer,
588 * \ref tfm_spm_service_t structures
589 */
590struct tfm_spm_service_t *
591 tfm_spm_get_service_by_signal(struct spm_partition_desc_t *partition,
592 psa_signal_t signal);
593
594/**
595 * \brief Get the service context by service ID.
596 *
597 * \param[in] sid RoT Service identity
598 *
599 * \retval NULL Failed
600 * \retval "Not NULL" Target service context pointer,
601 * \ref tfm_spm_service_t structures
602 */
603struct tfm_spm_service_t *tfm_spm_get_service_by_sid(uint32_t sid);
604
605/**
606 * \brief Get the service context by connection handle.
607 *
608 * \param[in] conn_handle Connection handle created by
609 * tfm_spm_create_conn_handle()
610 *
611 * \retval NULL Failed
612 * \retval "Not NULL" Target service context pointer,
613 * \ref tfm_spm_service_t structures
614 */
615struct tfm_spm_service_t *
616 tfm_spm_get_service_by_handle(psa_handle_t conn_handle);
617
618/**
619 * \brief Get the partition context by partition ID.
620 *
621 * \param[in] partition_id Partition identity
622 *
623 * \retval NULL Failed
624 * \retval "Not NULL" Target partition context pointer,
625 * \ref spm_partition_desc_t structures
626 */
627struct spm_partition_desc_t *
628 tfm_spm_get_partition_by_id(int32_t partition_id);
629
630/************************ Message functions **********************************/
631
632/**
633 * \brief Get message context by message handle.
634 *
635 * \param[in] msg_handle Message handle which is a reference generated
636 * by the SPM to a specific message.
637 *
638 * \return The message body context pointer
639 * \ref tfm_msg_body_t structures
640 */
641struct tfm_msg_body_t *tfm_spm_get_msg_from_handle(psa_handle_t msg_handle);
642
643/**
644 * \brief Create a message for PSA client call.
645 *
646 * \param[in] service Target service context pointer, which can be
647 * obtained by partition management functions
648 * \prarm[in] handle Connect handle return by psa_connect().
649 * \param[in] type Message type, PSA_IPC_CONNECT, PSA_IPC_CALL or
650 * PSA_IPC_DISCONNECT
651 * \param[in] ns_caller Whether from NS caller
652 * \param[in] invec Array of input \ref psa_invec structures
653 * \param[in] in_len Number of input \ref psa_invec structures
654 * \param[in] outvec Array of output \ref psa_outvec structures
655 * \param[in] out_len Number of output \ref psa_outvec structures
656 * \param[in] caller_outvec Array of caller output \ref psa_outvec structures
657 *
658 * \retval NULL Failed
659 * \retval "Not NULL" New message body pointer \ref tfm_msg_body_t
660 * structures
661 */
662struct tfm_msg_body_t *tfm_spm_create_msg(struct tfm_spm_service_t *service,
663 psa_handle_t handle,
664 int32_t type, int32_t ns_caller,
665 psa_invec *invec, size_t in_len,
666 psa_outvec *outvec, size_t out_len,
667 psa_outvec *caller_outvec);
668
669/**
670 * \brief Free message which unused anymore
671 *
672 * \param[in] msg Message pointer which want to free
673 * \ref tfm_msg_body_t structures
674 *
675 * \retval void Success
676 * \retval "Does not return" Failed
677 */
678void tfm_spm_free_msg(struct tfm_msg_body_t *msg);
679
680/**
681 * \brief Send message and wake up the SP who is waiting on
682 * message queue, block the current thread and
683 * scheduler triggered
684 *
685 * \param[in] service Target service context pointer, which can be
686 * obtained by partition management functions
687 * \param[in] msg message created by tfm_spm_create_msg()
688 * \ref tfm_msg_body_t structures
689 *
690 * \retval IPC_SUCCESS Success
691 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
692 * \retval IPC_ERROR_GENERIC Failed to enqueue message to service message queue
693 */
694int32_t tfm_spm_send_event(struct tfm_spm_service_t *service,
695 struct tfm_msg_body_t *msg);
696
697/**
698 * \brief Check the client minor version according to
699 * version policy
700 *
701 * \param[in] service Target service context pointer, which can be get
702 * by partition management functions
703 * \param[in] minor_version Client support minor version
704 *
705 * \retval IPC_SUCCESS Success
706 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
707 * \retval IPC_ERROR_VERSION Check failed
708 */
709int32_t tfm_spm_check_client_version(struct tfm_spm_service_t *service,
710 uint32_t minor_version);
711
712/**
713 * \brief Check the memory reference is valid.
714 *
715 * \param[in] buffer Pointer of memory reference
716 * \param[in] len Length of memory reference in bytes
717 * \param[in] ns_caller From non-secure caller
718 * \param[in] access Type of access specified by the
719 * \ref tfm_memory_access_e
720 * \param[in] privileged Privileged mode or unprivileged mode:
721 * \ref TFM_PARTITION_UNPRIVILEGED_MODE
722 * \ref TFM_PARTITION_PRIVILEGED_MODE
723 *
724 * \retval IPC_SUCCESS Success
725 * \retval IPC_ERROR_BAD_PARAMETERS Bad parameters input
726 * \retval IPC_ERROR_MEMORY_CHECK Check failed
727 */
728int32_t tfm_memory_check(void *buffer, size_t len, int32_t ns_caller,
729 enum tfm_memory_access_e access,
730 uint32_t privileged);
731
732/* This function should be called before schedule function */
733void tfm_spm_init(void);
734
735/*
736 * PendSV specified function.
737 *
738 * Parameters :
739 * ctxb - State context storage pointer
740 *
741 * Notes:
742 * This is a staging API. Scheduler should be called in SPM finally and
743 * this function will be obsoleted later.
744 */
745void tfm_pendsv_do_schedule(struct tfm_state_context_ext *ctxb);
746
747#endif /* ifdef(TFM_PSA_API) */
748
Miklos Balint386b8b52017-11-29 13:12:32 +0000749#endif /*__SPM_API_H__ */