blob: ca4994c8ee3d1239498c3175e49382a6e6bf9264 [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 */
12#include "service_defs.h"
13#include "secure_fw/core/tfm_secure_api.h"
14
15enum spm_err_t {
16 SPM_ERR_OK = 0,
Mate Toth-Pal349714a2018-02-23 15:30:24 +010017 SPM_ERR_PARTITION_DB_NOT_INIT,
18 SPM_ERR_PARTITION_ALREADY_ACTIVE,
19 SPM_ERR_PARTITION_NOT_AVAILABLE,
Miklos Balint386b8b52017-11-29 13:12:32 +000020 SPM_ERR_INVALID_CONFIG,
21};
22
Mate Toth-Pal65291f32018-02-23 14:35:22 +010023enum spm_part_state_t {
Mate Toth-Pal349714a2018-02-23 15:30:24 +010024 SPM_PARTITION_STATE_UNINIT = 0,
25 SPM_PARTITION_STATE_IDLE,
26 SPM_PARTITION_STATE_RUNNING,
27 SPM_PARTITION_STATE_SUSPENDED,
28 SPM_PARTITION_STATE_BLOCKED,
29 SPM_PARTITION_STATE_CLOSED
Mate Toth-Pal65291f32018-02-23 14:35:22 +010030};
31
Miklos Balint386b8b52017-11-29 13:12:32 +000032/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010033 * \brief Configure isolated sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000034 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010035 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000036 *
37 * \return Error code \ref spm_err_t
38 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010039 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000040 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010041enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000042
43/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010044 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000045 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010046 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000047 *
48 * \return Error code \ref spm_err_t
49 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010050 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000051 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010052enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000053
54/**
55 * \brief Get saved stack pointer for a partition
56 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010057 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000058 *
59 * \return Stack pointer value
60 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010061 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000062 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010063uint32_t tfm_spm_partition_get_stack(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000064
65/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010066 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000067 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010068 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000069 *
70 * \return Stack region bottom value
71 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010072 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000073 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010074uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000075
76/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010077 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000078 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010079 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000080 *
81 * \return Stack region top value
82 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010083 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000084 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010085uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000086
87/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010088 * \brief Get the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +010089 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010090 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +010091 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010092 * \return The state of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +010093 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010094 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +010095 * \note The returned value has the value set of \ref spm_part_state_t.
96 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010097uint32_t tfm_spm_partition_get_state(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +010098
99/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100100 * \brief Get the Id of the caller of the partition given
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100101 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100102 * \param[in] partition_id Partition id to get the caller of
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100103 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100104 * \return The Id of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100105 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100106 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100107 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100108uint32_t tfm_spm_partition_get_caller_partition_id(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100109
110/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100111 * \brief Get the original PSP of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100112 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100113 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100114 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100115 * \return The original PSP of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100116 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100117 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100118 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100119uint32_t tfm_spm_partition_get_orig_psp(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100120
121/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100122 * \brief Get the original PSP limit of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100123 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100124 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100125 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100126 * \return The original PSP limit of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100127 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100128 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100129 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100130uint32_t tfm_spm_partition_get_orig_psplim(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100131
132/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100133 * \brief Get the original link register value of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100134 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100135 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100136 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100137 * \return The original link register value of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100138 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100139 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100140 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100141uint32_t tfm_spm_partition_get_orig_lr(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100142
143/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100144 * \brief Get the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100145 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100146 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100147 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100148 * \return The buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100149 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100150 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100151 * \note The returned value has the value set of \ref tfm_buffer_share_region_e
152 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100153uint32_t tfm_spm_partition_get_share(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100154
155/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100156 * \brief Returns the id of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100157 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100158 * \return The Id of the partition with the running state, if there is any set.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100159 * 0 otherwise.
160 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100161uint32_t tfm_spm_partition_get_running_partition_id(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100162
163/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100164 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000165 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100166 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000167 * \param[in] stack_ptr Stack pointer to be stored
168 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100169 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000170 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100171void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000172
173/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100174 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100175 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100176 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100177 * \param[in] state The state to be set
178 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100179 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100180 * \note The \ref state has to have the value set of \ref spm_part_state_t.
181 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100182void tfm_spm_partition_set_state(uint32_t partition_id, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100183
184/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100185 * \brief Set the caller partition Id for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100186 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100187 * \param[in] partition_id Partition id
188 * \param[in] caller_partition_id The Id of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100189 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100190 * \note This function doesn't check if any of the partition_ids is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100191 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100192void tfm_spm_partition_set_caller_partition_id(uint32_t partition_id,
193 uint32_t caller_partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100194
195/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100196 * \brief Set the original PSP value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100197 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100198 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100199 * \param[in] orig_psp The PSP value to set
200 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100201 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100202 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100203void tfm_spm_partition_set_orig_psp(uint32_t partition_id, uint32_t orig_psp);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100204
205/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100206 * \brief Set the original PSP limit value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100207 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100208 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100209 * \param[in] orig_psplim The PSP limit value to set
210 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100211 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100212 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100213void tfm_spm_partition_set_orig_psplim(uint32_t partition_id,
214 uint32_t orig_psplim);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100215
216/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100217 * \brief Set the original link register value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100218 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100219 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100220 * \param[in] orig_lr The link register value to set
221 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100222 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100223 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100224void tfm_spm_partition_set_orig_lr(uint32_t partition_id, uint32_t orig_lr);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100225
226/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100227 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100228 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100229 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100230 * \param[in] share The buffer share region to be set
231 *
232 * \return Error code \ref spm_err_t
233 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100234 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100235 * \note share has to have the value set of \ref tfm_buffer_share_region_e
236 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100237enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_id,
238 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100239
240/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100241 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000242 *
243 * \return Error code \ref spm_err_t
244 */
245enum spm_err_t tfm_spm_db_init(void);
246
247/**
248 * \brief Apply default MPU configuration for execution
249 *
250 * \return Error code \ref spm_err_t
251 */
252enum spm_err_t tfm_spm_mpu_init(void);
253
254/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100255 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000256 *
257 * \return Error code \ref spm_err_t
258 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100259enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000260
261/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100262 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000263 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100264 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000265 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100266 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000267 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100268void tfm_spm_partition_cleanup_context(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +0000269
270#endif /*__SPM_API_H__ */