blob: fced5d1b486f1f98a65991143d830ae630fd384c [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
Miklos Balint386b8b52017-11-29 13:12:32 +000034/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010035 * \brief Runtime context information of a partition
36 */
37struct spm_partition_runtime_data_t {
38 uint32_t partition_state;
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010039 uint32_t caller_partition_idx;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010040 uint32_t orig_psp;
41 uint32_t orig_psplim;
42 uint32_t orig_lr;
43 uint32_t share;
44#if TFM_LVL != 1
45 uint32_t stack_ptr;
46#endif
47};
48
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010049
Mate Toth-Pal18b83922018-02-26 17:58:18 +010050/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010051 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000052 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010053 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000054 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010055 * \return the partition idx if partition_id is valid,
56 * \ref SPM_INVALID_PARTITION_IDX othervise
57 */
58uint32_t get_partition_idx(uint32_t partition_id);
59
60/**
61 * \brief Configure isolated sandbox for a partition
62 *
63 * \param[in] partition_idx Partition index
64 *
Miklos Balint386b8b52017-11-29 13:12:32 +000065 * \return Error code \ref spm_err_t
66 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010067 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000068 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010069enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000070
71/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010072 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000073 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010074 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000075 *
76 * \return Error code \ref spm_err_t
77 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010078 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000079 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010080enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000081
82/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010083 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000084 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000086 *
87 * \return Stack region bottom value
88 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010089 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000090 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010091uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000092
93/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010094 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000095 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010096 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000097 *
98 * \return Stack region top value
99 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100100 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000101 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100102uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
103
104/**
105 * \brief Get the id of the partition for its index from the db
106 *
107 * \param[in] partition_idx Partition index
108 *
109 * \return Partition ID for that partition
110 *
111 * \note This function doesn't check if partition_idx is valid.
112 */
113uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000114
115/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100116 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100117 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100118 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100119 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100120 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100121 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100122 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100123 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100124const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100125 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100126
127/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100128 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100129 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100130 * \return The index of the partition with the running state, if there is any
131 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100132 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100133uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100134
135/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100136 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000137 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100138 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000139 * \param[in] stack_ptr Stack pointer to be stored
140 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100141 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000142 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100143void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000144
145/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100146 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100147 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100148 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100149 * \param[in] state The state to be set
150 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100151 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100152 * \note The \ref state has to have the value set of \ref spm_part_state_t.
153 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100154void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100155
156/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100157 * \brief Set the caller partition Id for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100158 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100159 * \param[in] partition_idx Partition index
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100160 * \param[in] caller_partition_id The Id of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100161 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100162 * \note This function doesn't check if any of the partition_ids is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100163 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100164void tfm_spm_partition_set_caller_partition_id(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100165 uint32_t caller_partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100166
167/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100168 * \brief Set the original PSP value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100169 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100170 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100171 * \param[in] orig_psp The PSP value to set
172 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100173 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100174 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100175void tfm_spm_partition_set_orig_psp(uint32_t partition_idx, uint32_t orig_psp);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100176
177/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100178 * \brief Set the original PSP limit value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100179 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100180 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100181 * \param[in] orig_psplim The PSP limit value to set
182 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100183 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100184 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100185void tfm_spm_partition_set_orig_psplim(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100186 uint32_t orig_psplim);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100187
188/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100189 * \brief Set the original link register value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100190 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100191 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100192 * \param[in] orig_lr The link register value to set
193 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100194 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100195 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100196void tfm_spm_partition_set_orig_lr(uint32_t partition_idx, uint32_t orig_lr);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100197
198/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100199 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100200 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100201 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100202 * \param[in] share The buffer share region to be set
203 *
204 * \return Error code \ref spm_err_t
205 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100206 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100207 * \note share has to have the value set of \ref tfm_buffer_share_region_e
208 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100209enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100210 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100211
212/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100213 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000214 *
215 * \return Error code \ref spm_err_t
216 */
217enum spm_err_t tfm_spm_db_init(void);
218
219/**
220 * \brief Apply default MPU configuration for execution
221 *
222 * \return Error code \ref spm_err_t
223 */
224enum spm_err_t tfm_spm_mpu_init(void);
225
226/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100227 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000228 *
229 * \return Error code \ref spm_err_t
230 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100231enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000232
233/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100234 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000235 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100236 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000237 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100238 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000239 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100240void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000241
242#endif /*__SPM_API_H__ */