blob: c3f7414d4aa97a082d3047f81ad2e3392ceeac01 [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Edison Aibb614aa2018-11-21 15:15:00 +08002 * 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-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 {
Edison Aibb614aa2018-11-21 15:15:00 +080035 SPM_PART_FLAG_APP_ROT = 0x01,
36 SPM_PART_FLAG_PSA_ROT = 0x02,
37 SPM_PART_FLAG_IPC = 0x04
Mate Toth-Pal59398712018-02-28 17:06:40 +010038};
39
Miklos Balint386b8b52017-11-29 13:12:32 +000040/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010041 * \brief Runtime context information of a partition
42 */
43struct spm_partition_runtime_data_t {
44 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010045 uint32_t caller_partition_idx;
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020046 int32_t caller_client_id;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010047 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010048 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020049 uint32_t lr;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010050};
51
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010052
Mate Toth-Pal18b83922018-02-26 17:58:18 +010053/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010054 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000055 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010056 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000057 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010058 * \return the partition idx if partition_id is valid,
59 * \ref SPM_INVALID_PARTITION_IDX othervise
60 */
61uint32_t get_partition_idx(uint32_t partition_id);
62
63/**
64 * \brief Configure isolated sandbox for a partition
65 *
66 * \param[in] partition_idx Partition index
67 *
Miklos Balint386b8b52017-11-29 13:12:32 +000068 * \return Error code \ref spm_err_t
69 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010070 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000071 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010072enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000073
74/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010075 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000076 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010077 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000078 *
79 * \return Error code \ref spm_err_t
80 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010081 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000082 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010083enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000084
85/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010086 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000087 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010088 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000089 *
90 * \return Stack region bottom value
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 +010094uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000095
96/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010097 * \brief Get top of stack region 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 Stack region top value
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 +0100105uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
106
107/**
108 * \brief Get the id of the partition for its index from the db
109 *
110 * \param[in] partition_idx Partition index
111 *
112 * \return Partition ID for that partition
113 *
114 * \note This function doesn't check if partition_idx is valid.
115 */
116uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000117
118/**
Mate Toth-Pal59398712018-02-28 17:06:40 +0100119 * \brief Get the flags associated with a partition
120 *
121 * \param[in] partition_idx Partition index
122 *
123 * \return Flags associated with the partition
124 *
125 * \note This function doesn't check if partition_idx is valid.
126 */
127uint32_t tfm_spm_partition_get_flags(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-Pal18b83922018-02-26 17:58:18 +0100176 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100177 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100178 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100179 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100180 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100181 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100182 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100183 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100184const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100185 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100186
187/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100188 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100189 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100190 * \return The index of the partition with the running state, if there is any
191 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100192 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100193uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100194
195/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100196 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000197 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100198 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000199 * \param[in] stack_ptr Stack pointer to be stored
200 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100201 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000202 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100203void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000204
205/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200206 * \brief Save stack pointer and link register for partition in database
207 *
208 * \param[in] partition_idx Partition index
209 * \param[in] stack_ptr Stack pointer to be stored
210 * \param[in] lr Link register to be stored
211 *
212 * \note This function doesn't check if partition_idx is valid.
213 */
214void tfm_spm_partition_store_context(uint32_t partition_idx,
215 uint32_t stack_ptr, uint32_t lr);
216
217/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100218 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100219 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100220 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100221 * \param[in] state The state to be set
222 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100223 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100224 * \note The \ref state has to have the value set of \ref spm_part_state_t.
225 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100226void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100227
228/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200229 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100230 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100231 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200232 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100233 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200234 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100235 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200236void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
237 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100238
239/**
Mate Toth-Pal21a74c92018-04-13 14:05:41 +0200240* \brief Set the caller client ID for a given partition
241*
242* \param[in] partition_idx Partition index
243* \param[in] caller_client_id The ID of the calling client
244*
245* \note This function doesn't check if any of the partition_idxs are valid.
246*/
247void tfm_spm_partition_set_caller_client_id(uint32_t partition_idx,
248 int32_t caller_client_id);
249
250/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100251 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100252 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100253 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100254 * \param[in] share The buffer share region to be set
255 *
256 * \return Error code \ref spm_err_t
257 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100258 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100259 * \note share has to have the value set of \ref tfm_buffer_share_region_e
260 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100261enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100262 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100263
264/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100265 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000266 *
267 * \return Error code \ref spm_err_t
268 */
269enum spm_err_t tfm_spm_db_init(void);
270
271/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100272 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000273 *
274 * \return Error code \ref spm_err_t
275 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100276enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000277
278/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100279 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000280 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100281 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000282 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100283 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000284 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100285void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000286
287#endif /*__SPM_API_H__ */