blob: 89d4564e16fd7c15462ccb50fad5f4d43e8d8c43 [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,
Miklos Balint386b8b52017-11-29 13:12:32 +000023 SPM_ERR_INVALID_CONFIG,
24};
25
Mate Toth-Pal65291f32018-02-23 14:35:22 +010026enum spm_part_state_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010027 SPM_PARTITION_STATE_UNINIT = 0,
28 SPM_PARTITION_STATE_IDLE,
29 SPM_PARTITION_STATE_RUNNING,
30 SPM_PARTITION_STATE_SUSPENDED,
31 SPM_PARTITION_STATE_BLOCKED,
32 SPM_PARTITION_STATE_CLOSED
Mate Toth-Pal65291f32018-02-23 14:35:22 +010033};
34
Mate Toth-Pal59398712018-02-28 17:06:40 +010035enum spm_part_flag_mask_t {
Edison Aibb614aa2018-11-21 15:15:00 +080036 SPM_PART_FLAG_APP_ROT = 0x01,
37 SPM_PART_FLAG_PSA_ROT = 0x02,
38 SPM_PART_FLAG_IPC = 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010039};
40
Miklos Balint386b8b52017-11-29 13:12:32 +000041/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020042 * \brief Holds the iovec parameters that are passed to a service
43 *
44 * \note The size of the structure is (and have to be) multiple of 8 bytes
45 */
46struct iovec_args_t {
47 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
48 size_t in_len; /*!< Number psa_invec objects in in_vec
49 */
50 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
51 size_t out_len; /*!< Number psa_outvec objects in out_vec
52 */
53};
54
55/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010056 * \brief Runtime context information of a partition
57 */
58struct spm_partition_runtime_data_t {
59 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010060 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020061 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010062 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010063 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020064 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010065 int32_t iovec_api; /*!< Whether the function in the partition
66 * had been called using the iovec API.
67 * FIXME: Remove the field once this is the
68 * only option
69 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020070 struct iovec_args_t iovec_args;
71 psa_outvec *orig_outvec;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010072};
73
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010074
Mate Toth-Pal18b83922018-02-26 17:58:18 +010075/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010076 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000077 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010078 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000079 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010080 * \return the partition idx if partition_id is valid,
81 * \ref SPM_INVALID_PARTITION_IDX othervise
82 */
83uint32_t get_partition_idx(uint32_t partition_id);
84
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020085#if TFM_LVL != 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010086/**
87 * \brief Configure isolated sandbox for a partition
88 *
89 * \param[in] partition_idx Partition index
90 *
Miklos Balint386b8b52017-11-29 13:12:32 +000091 * \return Error code \ref spm_err_t
92 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010093 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000094 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010095enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000096
97/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010098 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000099 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100100 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000101 *
102 * \return Error code \ref spm_err_t
103 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100104 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000105 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100106enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000107
108/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100109 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000110 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100111 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000112 *
113 * \return Stack region bottom value
114 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100115 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000116 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100117uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000118
119/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100120 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000121 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100122 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000123 *
124 * \return Stack region top value
125 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100126 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000127 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100128uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
129
130/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200131 * \brief Get the start of the zero-initialised region for a partition
132 *
133 * \param[in] partition_idx Partition idx
134 *
135 * \return Start of the zero-initialised region
136 *
137 * \note This function doesn't check if partition_idx is valid.
138 */
139uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
140
141/**
142 * \brief Get the limit of the zero-initialised region for a partition
143 *
144 * \param[in] partition_idx Partition idx
145 *
146 * \return Limit of the zero-initialised region
147 *
148 * \note This function doesn't check if partition_idx is valid.
149 * \note The address returned is not part of the region.
150 */
151uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
152
153/**
154 * \brief Get the start of the read-write region for a partition
155 *
156 * \param[in] partition_idx Partition idx
157 *
158 * \return Start of the read-write region
159 *
160 * \note This function doesn't check if partition_idx is valid.
161 */
162uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
163
164/**
165 * \brief Get the limit of the read-write region for a partition
166 *
167 * \param[in] partition_idx Partition idx
168 *
169 * \return Limit of the read-write region
170 *
171 * \note This function doesn't check if partition_idx is valid.
172 * \note The address returned is not part of the region.
173 */
174uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
175
176/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200177 * \brief Save stack pointer for partition in database
178 *
179 * \param[in] partition_idx Partition index
180 * \param[in] stack_ptr Stack pointer to be stored
181 *
182 * \note This function doesn't check if partition_idx is valid.
183 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100184void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200185#endif
186
187/**
188 * \brief Get the flags associated with a partition
189 *
190 * \param[in] partition_idx Partition index
191 *
192 * \return Flags associated with the partition
193 *
194 * \note This function doesn't check if partition_idx is valid.
195 */
196uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
197
198/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100199 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100200 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100201 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100202 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100203 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100204 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100205 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100206 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100207const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100208 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100209
210/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100211 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100212 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100213 * \return The index of the partition with the running state, if there is any
214 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100215 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100216uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100217
218/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200219 * \brief Save stack pointer and link register for partition in database
220 *
221 * \param[in] partition_idx Partition index
222 * \param[in] stack_ptr Stack pointer to be stored
223 * \param[in] lr Link register to be stored
224 *
225 * \note This function doesn't check if partition_idx is valid.
226 */
227void tfm_spm_partition_store_context(uint32_t partition_idx,
228 uint32_t stack_ptr, uint32_t lr);
229
230/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200231 * \brief Get the id of the partition for its index from the db
232 *
233 * \param[in] partition_idx Partition index
234 *
235 * \return Partition ID for that partition
236 *
237 * \note This function doesn't check if partition_idx is valid.
238 */
239uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
240
241/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100242 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100243 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100244 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100245 * \param[in] state The state to be set
246 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100247 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100248 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100249 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100250void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100251
252/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200253 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100254 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100255 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200256 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100257 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200258 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100259 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200260void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
261 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100262
263/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200264* \brief Set the caller client ID for a given partition
265*
266* \param[in] partition_idx Partition index
267* \param[in] caller_client_id The ID of the calling client
268*
269* \note This function doesn't check if any of the partition_idxs are valid.
270*/
271void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
272 int32_t caller_client_id);
273
274/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100275 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100276 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100277 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100278 * \param[in] share The buffer share region to be set
279 *
280 * \return Error code \ref spm_err_t
281 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100282 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100283 * \note share has to have the value set of \ref tfm_buffer_share_region_e
284 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100285enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100286 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100287
288/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200289 * \brief Set the iovec parameters for the partition
290 *
291 * \param[in] partition_idx Partition index
292 * \param[in] args The arguments of the secure function
293 *
294 * args is expected to be of type int32_t[4] where:
295 * args[0] is in_vec
296 * args[1] is in_len
297 * args[2] is out_vec
298 * args[3] is out_len
299 *
300 * \note This function doesn't check if partition_idx is valid.
301 * \note This function assumes that the iovecs that are passed in args are
302 * valid, and does no sanity check on them at all.
303 */
304void tfm_spm_partition_set_iovec(uint32_t partition_idx, int32_t *args);
305
306/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100307 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000308 *
309 * \return Error code \ref spm_err_t
310 */
311enum spm_err_t tfm_spm_db_init(void);
312
313/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100314 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000315 *
316 * \return Error code \ref spm_err_t
317 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100318enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000319
320/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100321 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000322 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100323 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000324 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100325 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000326 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100327void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000328
329#endif /*__SPM_API_H__ */