blob: 67accd5e8a242018a80c37460fb93c3f9c80c707 [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"
15
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010016#define SPM_INVALID_PARTITION_IDX (~0U)
17
Miklos Balint386b8b52017-11-29 13:12:32 +000018enum spm_err_t {
19 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010020 SPM_ERR_PARTITION_DB_NOT_INIT,
21 SPM_ERR_PARTITION_ALREADY_ACTIVE,
22 SPM_ERR_PARTITION_NOT_AVAILABLE,
Hugues de Valonf704c802019-02-19 14:51:41 +000023 SPM_ERR_INVALID_PARAMETER,
Miklos Balint386b8b52017-11-29 13:12:32 +000024 SPM_ERR_INVALID_CONFIG,
25};
26
Mate Toth-Pal65291f32018-02-23 14:35:22 +010027enum spm_part_state_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010028 SPM_PARTITION_STATE_UNINIT = 0,
29 SPM_PARTITION_STATE_IDLE,
30 SPM_PARTITION_STATE_RUNNING,
31 SPM_PARTITION_STATE_SUSPENDED,
32 SPM_PARTITION_STATE_BLOCKED,
33 SPM_PARTITION_STATE_CLOSED
Mate Toth-Pal65291f32018-02-23 14:35:22 +010034};
35
Mate Toth-Pal59398712018-02-28 17:06:40 +010036enum spm_part_flag_mask_t {
Edison Aibb614aa2018-11-21 15:15:00 +080037 SPM_PART_FLAG_APP_ROT = 0x01,
38 SPM_PART_FLAG_PSA_ROT = 0x02,
39 SPM_PART_FLAG_IPC = 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010040};
41
Miklos Balint386b8b52017-11-29 13:12:32 +000042/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020043 * \brief Holds the iovec parameters that are passed to a service
44 *
45 * \note The size of the structure is (and have to be) multiple of 8 bytes
46 */
47struct iovec_args_t {
48 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
49 size_t in_len; /*!< Number psa_invec objects in in_vec
50 */
51 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
52 size_t out_len; /*!< Number psa_outvec objects in out_vec
53 */
54};
55
56/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010057 * \brief Runtime context information of a partition
58 */
59struct spm_partition_runtime_data_t {
60 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010061 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020062 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010063 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010064 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020065 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010066 int32_t iovec_api; /*!< Whether the function in the partition
67 * had been called using the iovec API.
68 * FIXME: Remove the field once this is the
69 * only option
70 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020071 struct iovec_args_t iovec_args;
72 psa_outvec *orig_outvec;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010073};
74
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010075
Mate Toth-Pal18b83922018-02-26 17:58:18 +010076/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010077 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000078 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010079 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000080 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010081 * \return the partition idx if partition_id is valid,
82 * \ref SPM_INVALID_PARTITION_IDX othervise
83 */
84uint32_t get_partition_idx(uint32_t partition_id);
85
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020086#if TFM_LVL != 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010087/**
88 * \brief Configure isolated sandbox for a partition
89 *
90 * \param[in] partition_idx Partition index
91 *
Miklos Balint386b8b52017-11-29 13:12:32 +000092 * \return Error code \ref spm_err_t
93 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010094 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000095 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010096enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000097
98/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010099 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000100 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100101 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000102 *
103 * \return Error code \ref spm_err_t
104 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100105 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000106 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100107enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000108
109/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100110 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000111 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100112 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000113 *
114 * \return Stack region bottom value
115 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100116 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000117 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100118uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000119
120/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100121 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000122 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100123 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000124 *
125 * \return Stack region top value
126 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100127 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000128 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100129uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
130
131/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200132 * \brief Get the start of the zero-initialised region for a partition
133 *
134 * \param[in] partition_idx Partition idx
135 *
136 * \return Start of the zero-initialised region
137 *
138 * \note This function doesn't check if partition_idx is valid.
139 */
140uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
141
142/**
143 * \brief Get the limit of the zero-initialised region for a partition
144 *
145 * \param[in] partition_idx Partition idx
146 *
147 * \return Limit of the zero-initialised region
148 *
149 * \note This function doesn't check if partition_idx is valid.
150 * \note The address returned is not part of the region.
151 */
152uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
153
154/**
155 * \brief Get the start of the read-write region for a partition
156 *
157 * \param[in] partition_idx Partition idx
158 *
159 * \return Start of the read-write region
160 *
161 * \note This function doesn't check if partition_idx is valid.
162 */
163uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
164
165/**
166 * \brief Get the limit of the read-write region for a partition
167 *
168 * \param[in] partition_idx Partition idx
169 *
170 * \return Limit of the read-write region
171 *
172 * \note This function doesn't check if partition_idx is valid.
173 * \note The address returned is not part of the region.
174 */
175uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
176
177/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200178 * \brief Save stack pointer for partition in database
179 *
180 * \param[in] partition_idx Partition index
181 * \param[in] stack_ptr Stack pointer to be stored
182 *
183 * \note This function doesn't check if partition_idx is valid.
184 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100185void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200186#endif
187
188/**
189 * \brief Get the flags associated with a partition
190 *
191 * \param[in] partition_idx Partition index
192 *
193 * \return Flags associated with the partition
194 *
195 * \note This function doesn't check if partition_idx is valid.
196 */
197uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
198
199/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100200 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100201 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100202 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100203 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100204 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100205 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100206 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100207 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100208const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100209 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100210
211/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100212 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100213 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100214 * \return The index of the partition with the running state, if there is any
215 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100216 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100217uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100218
219/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200220 * \brief Save stack pointer and link register for partition in database
221 *
222 * \param[in] partition_idx Partition index
223 * \param[in] stack_ptr Stack pointer to be stored
224 * \param[in] lr Link register to be stored
225 *
226 * \note This function doesn't check if partition_idx is valid.
227 */
228void tfm_spm_partition_store_context(uint32_t partition_idx,
229 uint32_t stack_ptr, uint32_t lr);
230
231/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200232 * \brief Get the id of the partition for its index from the db
233 *
234 * \param[in] partition_idx Partition index
235 *
236 * \return Partition ID for that partition
237 *
238 * \note This function doesn't check if partition_idx is valid.
239 */
240uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
241
242/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100243 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100244 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100245 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100246 * \param[in] state The state to be set
247 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100248 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100249 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100250 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100251void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100252
253/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200254 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100255 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100256 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200257 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200259 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100260 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200261void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
262 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100263
264/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200265* \brief Set the caller client ID for a given partition
266*
267* \param[in] partition_idx Partition index
268* \param[in] caller_client_id The ID of the calling client
269*
270* \note This function doesn't check if any of the partition_idxs are valid.
271*/
272void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
273 int32_t caller_client_id);
274
275/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100276 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100277 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100278 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100279 * \param[in] share The buffer share region to be set
280 *
281 * \return Error code \ref spm_err_t
282 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100283 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100284 * \note share has to have the value set of \ref tfm_buffer_share_region_e
285 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100286enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100287 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100288
289/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200290 * \brief Set the iovec parameters for the partition
291 *
292 * \param[in] partition_idx Partition index
293 * \param[in] args The arguments of the secure function
294 *
295 * args is expected to be of type int32_t[4] where:
296 * args[0] is in_vec
297 * args[1] is in_len
298 * args[2] is out_vec
299 * args[3] is out_len
300 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000301 * \return Error code \ref spm_err_t
302 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200303 * \note This function doesn't check if partition_idx is valid.
304 * \note This function assumes that the iovecs that are passed in args are
305 * valid, and does no sanity check on them at all.
306 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000307enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
308 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200309
310/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100311 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000312 *
313 * \return Error code \ref spm_err_t
314 */
315enum spm_err_t tfm_spm_db_init(void);
316
317/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100318 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000319 *
320 * \return Error code \ref spm_err_t
321 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100322enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000323
324/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100325 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000326 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100327 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000328 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100329 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000330 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100331void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000332
333#endif /*__SPM_API_H__ */