blob: 0fa4c863f44ebf1fa4420c5095f416128c4b0616 [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 {
36 SPM_PART_FLAG_SECURE = 0x01,
37 SPM_PART_FLAG_TRUSTED = 0x02,
38};
39
Miklos Balint386b8b52017-11-29 13:12:32 +000040/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020041 * \brief Holds the iovec parameters that are passed to a service
42 *
43 * \note The size of the structure is (and have to be) multiple of 8 bytes
44 */
45struct iovec_args_t {
46 psa_invec in_vec[PSA_MAX_IOVEC]; /*!< Array of psa_invec objects */
47 size_t in_len; /*!< Number psa_invec objects in in_vec
48 */
49 psa_outvec out_vec[PSA_MAX_IOVEC]; /*!< Array of psa_outvec objects */
50 size_t out_len; /*!< Number psa_outvec objects in out_vec
51 */
52};
53
54/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010055 * \brief Runtime context information of a partition
56 */
57struct spm_partition_runtime_data_t {
58 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010059 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020060 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010061 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010062 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020063 uint32_t lr;
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010064 int32_t iovec_api; /*!< Whether the function in the partition
65 * had been called using the iovec API.
66 * FIXME: Remove the field once this is the
67 * only option
68 */
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020069 struct iovec_args_t iovec_args;
70 psa_outvec *orig_outvec;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010071};
72
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010073
Mate Toth-Pal18b83922018-02-26 17:58:18 +010074/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010075 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000076 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010077 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000078 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010079 * \return the partition idx if partition_id is valid,
80 * \ref SPM_INVALID_PARTITION_IDX othervise
81 */
82uint32_t get_partition_idx(uint32_t partition_id);
83
Mate Toth-Pal3db437a2018-06-22 16:15:13 +020084#if TFM_LVL != 1
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085/**
86 * \brief Configure isolated sandbox for a partition
87 *
88 * \param[in] partition_idx Partition index
89 *
Miklos Balint386b8b52017-11-29 13:12:32 +000090 * \return Error code \ref spm_err_t
91 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010092 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000093 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010094enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000095
96/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010097 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000098 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010099 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000100 *
101 * \return Error code \ref spm_err_t
102 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100103 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000104 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100105enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000106
107/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100108 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000109 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100110 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000111 *
112 * \return Stack region bottom value
113 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100114 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000115 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100116uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000117
118/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100119 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000120 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100121 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000122 *
123 * \return Stack region top value
124 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100125 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000126 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100127uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
128
129/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200130 * \brief Get the start of the zero-initialised region for a partition
131 *
132 * \param[in] partition_idx Partition idx
133 *
134 * \return Start of the zero-initialised region
135 *
136 * \note This function doesn't check if partition_idx is valid.
137 */
138uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
139
140/**
141 * \brief Get the limit of the zero-initialised region for a partition
142 *
143 * \param[in] partition_idx Partition idx
144 *
145 * \return Limit of the zero-initialised region
146 *
147 * \note This function doesn't check if partition_idx is valid.
148 * \note The address returned is not part of the region.
149 */
150uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
151
152/**
153 * \brief Get the start of the read-write region for a partition
154 *
155 * \param[in] partition_idx Partition idx
156 *
157 * \return Start of the read-write region
158 *
159 * \note This function doesn't check if partition_idx is valid.
160 */
161uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
162
163/**
164 * \brief Get the limit of the read-write region for a partition
165 *
166 * \param[in] partition_idx Partition idx
167 *
168 * \return Limit of the read-write region
169 *
170 * \note This function doesn't check if partition_idx is valid.
171 * \note The address returned is not part of the region.
172 */
173uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
174
175/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200176 * \brief Save stack pointer for partition in database
177 *
178 * \param[in] partition_idx Partition index
179 * \param[in] stack_ptr Stack pointer to be stored
180 *
181 * \note This function doesn't check if partition_idx is valid.
182 */
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100183void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200184#endif
185
186/**
187 * \brief Get the flags associated with a partition
188 *
189 * \param[in] partition_idx Partition index
190 *
191 * \return Flags associated with the partition
192 *
193 * \note This function doesn't check if partition_idx is valid.
194 */
195uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
196
197/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100198 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100199 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100200 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100201 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100202 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100203 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100204 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100205 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100206const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100207 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100208
209/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100210 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100211 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100212 * \return The index of the partition with the running state, if there is any
213 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100214 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100215uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100216
217/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200218 * \brief Save stack pointer and link register for partition in database
219 *
220 * \param[in] partition_idx Partition index
221 * \param[in] stack_ptr Stack pointer to be stored
222 * \param[in] lr Link register to be stored
223 *
224 * \note This function doesn't check if partition_idx is valid.
225 */
226void tfm_spm_partition_store_context(uint32_t partition_idx,
227 uint32_t stack_ptr, uint32_t lr);
228
229/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200230 * \brief Get the id of the partition for its index from the db
231 *
232 * \param[in] partition_idx Partition index
233 *
234 * \return Partition ID for that partition
235 *
236 * \note This function doesn't check if partition_idx is valid.
237 */
238uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
239
240/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100241 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100242 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100243 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100244 * \param[in] state The state to be set
245 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100246 * \note This function doesn't check if partition_idx is valid.
Gyorgy Szing40a7af02019-02-06 14:19:47 +0100247 * \note The state has to have the value set of \ref spm_part_state_t.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100248 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100249void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100250
251/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200252 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100253 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100254 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200255 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100256 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200257 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200259void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
260 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100261
262/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200263* \brief Set the caller client ID for a given partition
264*
265* \param[in] partition_idx Partition index
266* \param[in] caller_client_id The ID of the calling client
267*
268* \note This function doesn't check if any of the partition_idxs are valid.
269*/
270void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
271 int32_t caller_client_id);
272
273/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100274 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100275 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100276 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100277 * \param[in] share The buffer share region to be set
278 *
279 * \return Error code \ref spm_err_t
280 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100281 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100282 * \note share has to have the value set of \ref tfm_buffer_share_region_e
283 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100284enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100285 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100286
287/**
Mate Toth-Pal3db437a2018-06-22 16:15:13 +0200288 * \brief Set the iovec parameters for the partition
289 *
290 * \param[in] partition_idx Partition index
291 * \param[in] args The arguments of the secure function
292 *
293 * args is expected to be of type int32_t[4] where:
294 * args[0] is in_vec
295 * args[1] is in_len
296 * args[2] is out_vec
297 * args[3] is out_len
298 *
299 * \note This function doesn't check if partition_idx is valid.
300 * \note This function assumes that the iovecs that are passed in args are
301 * valid, and does no sanity check on them at all.
302 */
303void tfm_spm_partition_set_iovec(uint32_t partition_idx, int32_t *args);
304
305/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100306 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000307 *
308 * \return Error code \ref spm_err_t
309 */
310enum spm_err_t tfm_spm_db_init(void);
311
312/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100313 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000314 *
315 * \return Error code \ref spm_err_t
316 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100317enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000318
319/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100320 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000321 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100322 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000323 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100324 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000325 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100326void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000327
328#endif /*__SPM_API_H__ */