blob: f0034afa346a30a121e5ba077fe701a7cc93e194 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Mate Toth-Pal65291f32018-02-23 14:35:22 +01002 * Copyright (c) 2017-2018, 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-Pal52674ab2018-02-26 09:47:56 +010012#include "spm_partition_defs.h"
Miklos Balint386b8b52017-11-29 13:12:32 +000013#include "secure_fw/core/tfm_secure_api.h"
14
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010015#define SPM_INVALID_PARTITION_IDX (~0U)
16
Miklos Balint386b8b52017-11-29 13:12:32 +000017enum spm_err_t {
18 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010019 SPM_ERR_PARTITION_DB_NOT_INIT,
20 SPM_ERR_PARTITION_ALREADY_ACTIVE,
21 SPM_ERR_PARTITION_NOT_AVAILABLE,
Miklos Balint386b8b52017-11-29 13:12:32 +000022 SPM_ERR_INVALID_CONFIG,
23};
24
Mate Toth-Pal65291f32018-02-23 14:35:22 +010025enum spm_part_state_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010026 SPM_PARTITION_STATE_UNINIT = 0,
27 SPM_PARTITION_STATE_IDLE,
28 SPM_PARTITION_STATE_RUNNING,
29 SPM_PARTITION_STATE_SUSPENDED,
30 SPM_PARTITION_STATE_BLOCKED,
31 SPM_PARTITION_STATE_CLOSED
Mate Toth-Pal65291f32018-02-23 14:35:22 +010032};
33
Mate Toth-Pal59398712018-02-28 17:06:40 +010034enum spm_part_flag_mask_t {
35 SPM_PART_FLAG_SECURE = 0x01,
36 SPM_PART_FLAG_TRUSTED = 0x02,
37};
38
Miklos Balint386b8b52017-11-29 13:12:32 +000039/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010040 * \brief Runtime context information of a partition
41 */
42struct spm_partition_runtime_data_t {
43 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010044 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020045 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010046 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010047 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020048 uint32_t lr;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010049};
50
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010051
Mate Toth-Pal18b83922018-02-26 17:58:18 +010052/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010053 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000054 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010055 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000056 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010057 * \return the partition idx if partition_id is valid,
58 * \ref SPM_INVALID_PARTITION_IDX othervise
59 */
60uint32_t get_partition_idx(uint32_t partition_id);
61
62/**
63 * \brief Configure isolated sandbox for a partition
64 *
65 * \param[in] partition_idx Partition index
66 *
Miklos Balint386b8b52017-11-29 13:12:32 +000067 * \return Error code \ref spm_err_t
68 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010069 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000070 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010071enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000072
73/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010074 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000075 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010076 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000077 *
78 * \return Error code \ref spm_err_t
79 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010080 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000081 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010082enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000083
84/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010085 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000086 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010087 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000088 *
89 * \return Stack region bottom value
90 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010091 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000092 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010093uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000094
95/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010096 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000097 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010098 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000099 *
100 * \return Stack region top value
101 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100102 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000103 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100104uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
105
106/**
107 * \brief Get the id of the partition for its index from the db
108 *
109 * \param[in] partition_idx Partition index
110 *
111 * \return Partition ID for that partition
112 *
113 * \note This function doesn't check if partition_idx is valid.
114 */
115uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000116
117/**
Mate Toth-Pal59398712018-02-28 17:06:40 +0100118 * \brief Get the flags associated with a partition
119 *
120 * \param[in] partition_idx Partition index
121 *
122 * \return Flags associated with the partition
123 *
124 * \note This function doesn't check if partition_idx is valid.
125 */
126uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
127
128/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200129 * \brief Get the start of the zero-initialised region for a partition
130 *
131 * \param[in] partition_idx Partition idx
132 *
133 * \return Start of the zero-initialised region
134 *
135 * \note This function doesn't check if partition_idx is valid.
136 */
137uint32_t tfm_spm_partition_get_zi_start(uint32_t partition_idx);
138
139/**
140 * \brief Get the limit of the zero-initialised region for a partition
141 *
142 * \param[in] partition_idx Partition idx
143 *
144 * \return Limit of the zero-initialised region
145 *
146 * \note This function doesn't check if partition_idx is valid.
147 * \note The address returned is not part of the region.
148 */
149uint32_t tfm_spm_partition_get_zi_limit(uint32_t partition_idx);
150
151/**
152 * \brief Get the start of the read-write region for a partition
153 *
154 * \param[in] partition_idx Partition idx
155 *
156 * \return Start of the read-write region
157 *
158 * \note This function doesn't check if partition_idx is valid.
159 */
160uint32_t tfm_spm_partition_get_rw_start(uint32_t partition_idx);
161
162/**
163 * \brief Get the limit of the read-write region for a partition
164 *
165 * \param[in] partition_idx Partition idx
166 *
167 * \return Limit of the read-write region
168 *
169 * \note This function doesn't check if partition_idx is valid.
170 * \note The address returned is not part of the region.
171 */
172uint32_t tfm_spm_partition_get_rw_limit(uint32_t partition_idx);
173
174/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100175 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100176 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100177 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100178 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100179 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100180 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100181 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100182 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100183const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100184 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100185
186/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100187 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100188 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100189 * \return The index of the partition with the running state, if there is any
190 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100191 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100192uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100193
194/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100195 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000196 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100197 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000198 * \param[in] stack_ptr Stack pointer to be stored
199 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100200 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000201 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100202void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000203
204/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200205 * \brief Save stack pointer and link register for partition in database
206 *
207 * \param[in] partition_idx Partition index
208 * \param[in] stack_ptr Stack pointer to be stored
209 * \param[in] lr Link register to be stored
210 *
211 * \note This function doesn't check if partition_idx is valid.
212 */
213void tfm_spm_partition_store_context(uint32_t partition_idx,
214 uint32_t stack_ptr, uint32_t lr);
215
216/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100217 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100218 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100219 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100220 * \param[in] state The state to be set
221 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100222 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100223 * \note The \ref state has to have the value set of \ref spm_part_state_t.
224 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100225void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100226
227/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200228 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100229 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100230 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200231 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100232 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200233 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100234 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200235void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
236 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100237
238/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200239* \brief Set the caller client ID for a given partition
240*
241* \param[in] partition_idx Partition index
242* \param[in] caller_client_id The ID of the calling client
243*
244* \note This function doesn't check if any of the partition_idxs are valid.
245*/
246void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
247 int32_t caller_client_id);
248
249/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100250 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100251 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100252 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100253 * \param[in] share The buffer share region to be set
254 *
255 * \return Error code \ref spm_err_t
256 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100257 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100258 * \note share has to have the value set of \ref tfm_buffer_share_region_e
259 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100260enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100261 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100262
263/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100264 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000265 *
266 * \return Error code \ref spm_err_t
267 */
268enum spm_err_t tfm_spm_db_init(void);
269
270/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100271 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000272 *
273 * \return Error code \ref spm_err_t
274 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100275enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000276
277/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100278 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000279 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100280 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000281 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100282 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000283 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100284void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000285
286#endif /*__SPM_API_H__ */