Mistake on this page?
Report an issue in GitHub or email us
components/TARGET_PSA/TARGET_TFM/COMPONENT_SPE/secure_fw/spm/spm_api.h
1 /*
2  * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
3  *
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 */
12 #include "tfm_api.h"
13 #include "spm_partition_defs.h"
14 #include "secure_fw/core/tfm_secure_api.h"
15 
16 #define SPM_INVALID_PARTITION_IDX (~0U)
17 
18 /* Privileged definitions for partition thread mode */
19 #define TFM_PARTITION_PRIVILEGED_MODE 1
20 #define TFM_PARTITION_UNPRIVILEGED_MODE 0
21 
22 enum spm_err_t {
23  SPM_ERR_OK = 0,
24  SPM_ERR_PARTITION_DB_NOT_INIT,
25  SPM_ERR_PARTITION_ALREADY_ACTIVE,
26  SPM_ERR_PARTITION_NOT_AVAILABLE,
27  SPM_ERR_INVALID_PARAMETER,
28  SPM_ERR_INVALID_CONFIG,
29 };
30 
31 enum spm_part_state_t {
32  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
38 };
39 
40 enum spm_part_flag_mask_t {
41  SPM_PART_FLAG_APP_ROT = 0x01,
42  SPM_PART_FLAG_PSA_ROT = 0x02,
43  SPM_PART_FLAG_IPC = 0x04
44 };
45 
46 /**
47  * \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  */
51 struct 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 /**
61  * \brief Runtime context information of a partition
62  */
64  uint32_t partition_state;
65  uint32_t caller_partition_idx;
66  int32_t caller_client_id;
67  uint32_t share;
68  uint32_t stack_ptr;
69  uint32_t lr;
70  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  */
75  struct iovec_args_t iovec_args;
76  psa_outvec *orig_outvec;
77 };
78 
79 
80 /**
81  * \brief Returns the index of the partition with the given partition ID.
82  *
83  * \param[in] partition_id Partition id
84  *
85  * \return the partition idx if partition_id is valid,
86  * \ref SPM_INVALID_PARTITION_IDX othervise
87  */
88 uint32_t get_partition_idx(uint32_t partition_id);
89 
90 #if (TFM_LVL != 1) || defined(TFM_PSA_API)
91 /**
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  */
100 uint32_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  */
111 uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
112 #endif
113 
114 #if (TFM_LVL != 1) && !defined(TFM_PSA_API)
115 /**
116  * \brief Configure isolated sandbox for a partition
117  *
118  * \param[in] partition_idx Partition index
119  *
120  * \return Error code \ref spm_err_t
121  *
122  * \note This function doesn't check if partition_idx is valid.
123  */
124 enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
125 
126 /**
127  * \brief Deconfigure sandbox for a partition
128  *
129  * \param[in] partition_idx Partition index
130  *
131  * \return Error code \ref spm_err_t
132  *
133  * \note This function doesn't check if partition_idx is valid.
134  */
135 enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
136 
137 /**
138  * \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  */
146 uint32_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  */
158 uint32_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  */
169 uint32_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  */
181 uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
182 
183 /**
184  * \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  */
191 void tfm_spm_partition_set_stack(uint32_t partition_idx, uint32_t stack_ptr);
192 #endif
193 
194 /**
195  * \brief Get the id of the partition for its index from the db
196  *
197  * \param[in] partition_idx Partition index
198  *
199  * \return Partition ID for that partition
200  *
201  * \note This function doesn't check if partition_idx is valid.
202  */
203 uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
204 
205 /**
206  * \brief Get the flags associated with a partition
207  *
208  * \param[in] partition_idx Partition index
209  *
210  * \return Flags associated with the partition
211  *
212  * \note This function doesn't check if partition_idx is valid.
213  */
214 uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
215 
216 #ifndef TFM_PSA_API
217 /**
218  * \brief Get the current runtime data of a partition
219  *
220  * \param[in] partition_idx Partition index
221  *
222  * \return The runtime data of the specified partition
223  *
224  * \note This function doesn't check if partition_idx is valid.
225  */
226 const struct spm_partition_runtime_data_t *
227  tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
228 
229 /**
230  * \brief Returns the index of the partition that has running state
231  *
232  * \return The index of the partition with the running state, if there is any
233  * set. 0 otherwise.
234  */
235 uint32_t tfm_spm_partition_get_running_partition_idx(void);
236 
237 /**
238  * \brief Save stack pointer and link register for partition in database
239  *
240  * \param[in] partition_idx Partition index
241  * \param[in] stack_ptr Stack pointer to be stored
242  * \param[in] lr Link register to be stored
243  *
244  * \note This function doesn't check if partition_idx is valid.
245  */
246 void tfm_spm_partition_store_context(uint32_t partition_idx,
247  uint32_t stack_ptr, uint32_t lr);
248 
249 /**
250  * \brief Set the current state of a partition
251  *
252  * \param[in] partition_idx Partition index
253  * \param[in] state The state to be set
254  *
255  * \note This function doesn't check if partition_idx is valid.
256  * \note The state has to have the value set of \ref spm_part_state_t.
257  */
258 void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
259 
260 /**
261  * \brief Set the caller partition index for a given partition
262  *
263  * \param[in] partition_idx Partition index
264  * \param[in] caller_partition_idx The index of the caller partition
265  *
266  * \note This function doesn't check if any of the partition_idxs are valid.
267  */
268 void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
269  uint32_t caller_partition_idx);
270 
271 /**
272 * \brief Set the caller client ID for a given partition
273 *
274 * \param[in] partition_idx Partition index
275 * \param[in] caller_client_id The ID of the calling client
276 *
277 * \note This function doesn't check if any of the partition_idxs are valid.
278 */
279 void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
280  int32_t caller_client_id);
281 
282 /**
283  * \brief Set the buffer share region of the partition
284  *
285  * \param[in] partition_idx Partition index
286  * \param[in] share The buffer share region to be set
287  *
288  * \return Error code \ref spm_err_t
289  *
290  * \note This function doesn't check if partition_idx is valid.
291  * \note share has to have the value set of \ref tfm_buffer_share_region_e
292  */
293 enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
294  uint32_t share);
295 
296 /**
297  * \brief Set the iovec parameters for the partition
298  *
299  * \param[in] partition_idx Partition index
300  * \param[in] args The arguments of the secure function
301  *
302  * args is expected to be of type int32_t[4] where:
303  * args[0] is in_vec
304  * args[1] is in_len
305  * args[2] is out_vec
306  * args[3] is out_len
307  *
308  * \return Error code \ref spm_err_t
309  *
310  * \note This function doesn't check if partition_idx is valid.
311  * \note This function assumes that the iovecs that are passed in args are
312  * valid, and does no sanity check on them at all.
313  */
314 enum spm_err_t tfm_spm_partition_set_iovec(uint32_t partition_idx,
315  const int32_t *args);
316 
317 /**
318  * \brief Execute partition init function
319  *
320  * \return Error code \ref spm_err_t
321  */
322 enum spm_err_t tfm_spm_partition_init(void);
323 
324 /**
325  * \brief Clears the context info from the database for a partition.
326  *
327  * \param[in] partition_idx Partition index
328  *
329  * \note This function doesn't check if partition_idx is valid.
330  */
331 void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
332 #endif /* !defined(TFM_PSA_API) */
333 
334 /**
335  * \brief Initialize partition database
336  *
337  * \return Error code \ref spm_err_t
338  */
339 enum spm_err_t tfm_spm_db_init(void);
340 
341 /**
342  * \brief Change the privilege mode for partition thread mode.
343  *
344  * \param[in] privileged Privileged mode,
345  * \ref TFM_PARTITION_PRIVILEGED_MODE
346  * and \ref TFM_PARTITION_UNPRIVILEGED_MODE
347  *
348  * \note Barrier instructions are not called by this function, and if
349  * it is called in thread mode, it might be necessary to call
350  * them after this function returns (just like it is done in
351  * jump_to_ns_code()).
352  */
353 void tfm_spm_partition_change_privilege(uint32_t privileged);
354 
355 #endif /*__SPM_API_H__ */
Structure which describes a scatter-gather output buffer.
Definition: client.h:54
Structure that describes a scatter-gather input buffer.
Definition: client.h:48
#define PSA_MAX_IOVEC
Maximum number of psa_invec and psa_outvec structures allowed for psa_call().
Definition: psa_defs.h:54
Holds the iovec parameters that are passed to a service.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.