blob: 106b29f423bf6700cd9c2b87b9137e367da89335 [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
Summer Qineb537e52019-03-29 09:57:10 +080018/* Privileged definitions for partition thread mode */
19#define TFM_PARTITION_PRIVILEGED_MODE 1
20#define TFM_PARTITION_UNPRIVILEGED_MODE 0
21
Miklos Balint386b8b52017-11-29 13:12:32 +000022enum spm_err_t {
23 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010024 SPM_ERR_PARTITION_DB_NOT_INIT,
25 SPM_ERR_PARTITION_ALREADY_ACTIVE,
26 SPM_ERR_PARTITION_NOT_AVAILABLE,
Hugues de Valonf704c802019-02-19 14:51:41 +000027 SPM_ERR_INVALID_PARAMETER,
Miklos Balint386b8b52017-11-29 13:12:32 +000028 SPM_ERR_INVALID_CONFIG,
29};
30
Mate Toth-Pal65291f32018-02-23 14:35:22 +010031enum spm_part_state_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010032 SPM_PARTITION_STATE_UNINIT = 0,
33 SPM_PARTITION_STATE_IDLE,
34 SPM_PARTITION_STATE_RUNNING,
35 SPM_PARTITION_STATE_SUSPENDED,
36 SPM_PARTITION_STATE_BLOCKED,
37 SPM_PARTITION_STATE_CLOSED
Mate Toth-Pal65291f32018-02-23 14:35:22 +010038};
39
Mate Toth-Pal59398712018-02-28 17:06:40 +010040enum spm_part_flag_mask_t {
Edison Aibb614aa2018-11-21 15:15:00 +080041 SPM_PART_FLAG_APP_ROT = 0x01,
42 SPM_PART_FLAG_PSA_ROT = 0x02,
43 SPM_PART_FLAG_IPC = 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010044};
45
Miklos Balint386b8b52017-11-29 13:12:32 +000046/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020047 * \brief Holds the iovec parameters that are passed to a service
48 *
49 * \note The size of the structure is (and have to be) multiple of 8 bytes
50 */
51struct iovec_args_t {
52 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
53 size_t in_len; /*!< Number psa_invec objects in in_vec
54 */
55 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
56 size_t out_len; /*!< Number psa_outvec objects in out_vec
57 */
58};
59
60/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010061 * \brief Runtime context information of a partition
62 */
63struct spm_partition_runtime_data_t {
64 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010065 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020066 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010067 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010068 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020069 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010070 int32_t iovec_api; /*!< Whether the function in the partition
71 * had been called using the iovec API.
72 * FIXME: Remove the field once this is the
73 * only option
74 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020075 struct iovec_args_t iovec_args;
76 psa_outvec *orig_outvec;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010077};
78
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010079
Mate Toth-Pal18b83922018-02-26 17:58:18 +010080/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010081 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000082 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010083 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000084 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085 * \return the partition idx if partition_id is valid,
86 * \ref SPM_INVALID_PARTITION_IDX othervise
87 */
88uint32_t get_partition_idx(uint32_t partition_id);
89
Miklos Balintdd02bb32019-05-26 21:13:12 +020090#if (TFM_LVL != 1) || defined(TFM_PSA_API)
Summer Qind00e4db2019-05-09 18:03:52 +080091/**
92 * \brief Get bottom of stack region for a partition
93 *
94 * \param[in] partition_idx Partition index
95 *
96 * \return Stack region bottom value
97 *
98 * \note This function doesn't check if partition_idx is valid.
99 */
100uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
101
102/**
103 * \brief Get top of stack region for a partition
104 *
105 * \param[in] partition_idx Partition index
106 *
107 * \return Stack region top value
108 *
109 * \note This function doesn't check if partition_idx is valid.
110 */
111uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
Miklos Balintdd02bb32019-05-26 21:13:12 +0200112#endif
Summer Qind00e4db2019-05-09 18:03:52 +0800113
Miklos Balintdd02bb32019-05-26 21:13:12 +0200114#if (TFM_LVL != 1) && !defined(TFM_PSA_API)
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100115/**
116 * \brief Configure isolated sandbox for a partition
117 *
118 * \param[in] partition_idx Partition index
119 *
Miklos Balint386b8b52017-11-29 13:12:32 +0000120 * \return Error code \ref spm_err_t
121 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100122 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000123 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100124enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000125
126/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100127 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000128 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100129 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000130 *
131 * \return Error code \ref spm_err_t
132 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100133 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000134 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100135enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000136
137/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200138 * \brief Get the start of the zero-initialised region for a partition
139 *
140 * \param[in] partition_idx Partition idx
141 *
142 * \return Start of the zero-initialised region
143 *
144 * \note This function doesn't check if partition_idx is valid.
145 */
146uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
147
148/**
149 * \brief Get the limit of the zero-initialised region for a partition
150 *
151 * \param[in] partition_idx Partition idx
152 *
153 * \return Limit of the zero-initialised region
154 *
155 * \note This function doesn't check if partition_idx is valid.
156 * \note The address returned is not part of the region.
157 */
158uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
159
160/**
161 * \brief Get the start of the read-write region for a partition
162 *
163 * \param[in] partition_idx Partition idx
164 *
165 * \return Start of the read-write region
166 *
167 * \note This function doesn't check if partition_idx is valid.
168 */
169uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
170
171/**
172 * \brief Get the limit of the read-write region for a partition
173 *
174 * \param[in] partition_idx Partition idx
175 *
176 * \return Limit of the read-write region
177 *
178 * \note This function doesn't check if partition_idx is valid.
179 * \note The address returned is not part of the region.
180 */
181uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
182
183/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200184 * \brief Save stack pointer for partition in database
185 *
186 * \param[in] partition_idx Partition index
187 * \param[in] stack_ptr Stack pointer to be stored
188 *
189 * \note This function doesn't check if partition_idx is valid.
190 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100191void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200192#endif
193
194/**
195 * \brief Get the flags associated with a partition
196 *
197 * \param[in] partition_idx Partition index
198 *
199 * \return Flags associated with the partition
200 *
201 * \note This function doesn't check if partition_idx is valid.
202 */
203uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
204
205/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100206 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100207 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100208 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100209 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100210 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100211 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100212 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100213 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100214const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100215 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100216
217/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100218 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100219 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100220 * \return The index of the partition with the running state, if there is any
221 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100222 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100223uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100224
225/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200226 * \brief Save stack pointer and link register for partition in database
227 *
228 * \param[in] partition_idx Partition index
229 * \param[in] stack_ptr Stack pointer to be stored
230 * \param[in] lr Link register to be stored
231 *
232 * \note This function doesn't check if partition_idx is valid.
233 */
234void tfm_spm_partition_store_context(uint32_t partition_idx,
235 uint32_t stack_ptr, uint32_t lr);
236
237/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200238 * \brief Get the id of the partition for its index from the db
239 *
240 * \param[in] partition_idx Partition index
241 *
242 * \return Partition ID for that partition
243 *
244 * \note This function doesn't check if partition_idx is valid.
245 */
246uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
247
248/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100249 * \brief Set the current state 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 * \param[in] state The state to be set
253 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100254 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100255 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100256 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100257void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258
259/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200260 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100261 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100262 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200263 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100264 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200265 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100266 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200267void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
268 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100269
270/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200271* \brief Set the caller client ID for a given partition
272*
273* \param[in] partition_idx Partition index
274* \param[in] caller_client_id The ID of the calling client
275*
276* \note This function doesn't check if any of the partition_idxs are valid.
277*/
278void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
279 int32_t caller_client_id);
280
281/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100282 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100283 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100284 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100285 * \param[in] share The buffer share region to be set
286 *
287 * \return Error code \ref spm_err_t
288 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100289 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100290 * \note share has to have the value set of \ref tfm_buffer_share_region_e
291 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100292enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100293 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100294
295/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200296 * \brief Set the iovec parameters for the partition
297 *
298 * \param[in] partition_idx Partition index
299 * \param[in] args The arguments of the secure function
300 *
301 * args is expected to be of type int32_t[4] where:
302 * args[0] is in_vec
303 * args[1] is in_len
304 * args[2] is out_vec
305 * args[3] is out_len
306 *
Hugues de Valonf704c802019-02-19 14:51:41 +0000307 * \return Error code \ref spm_err_t
308 *
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200309 * \note This function doesn't check if partition_idx is valid.
310 * \note This function assumes that the iovecs that are passed in args are
311 * valid, and does no sanity check on them at all.
312 */
Hugues de Valonf704c802019-02-19 14:51:41 +0000313enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
314 const int32_t *args);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200315
316/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100317 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000318 *
319 * \return Error code \ref spm_err_t
320 */
321enum spm_err_t tfm_spm_db_init(void);
322
323/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100324 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000325 *
326 * \return Error code \ref spm_err_t
327 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100328enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000329
330/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100331 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000332 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100333 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000334 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100335 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000336 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100337void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000338
Edison Aib5571352019-03-22 10:49:52 +0800339/**
340 * \brief Change the privilege mode for partition thread mode.
341 *
342 * \param[in] privileged Privileged mode,
343 * \ref TFM_PARTITION_PRIVILEGED_MODE
344 * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
345 *
346 * \note Barrier instructions are not called by this function, and if
347 * it is called in thread mode, it might be necessary to call
348 * them after this function returns (just like it is done in
349 * jump_to_ns_code()).
350 */
351void tfm_spm_partition_change_privilege(uint32_t privileged);
352
Miklos Balint386b8b52017-11-29 13:12:32 +0000353#endif /*__SPM_API_H__ */