blob: 67cbfbf64d2a8e80c097e9da13379558864fac1a [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-Pal18b83922018-02-26 17:58:18 +010045 uint32_t share;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010046 uint32_t stack_ptr;
Miklos Balintace4c3f2018-07-30 12:31:15 +020047 uint32_t lr;
Mate Toth-Pal18b83922018-02-26 17:58:18 +010048};
49
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010050
Mate Toth-Pal18b83922018-02-26 17:58:18 +010051/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010052 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000053 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010054 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000055 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010056 * \return the partition idx if partition_id is valid,
57 * \ref SPM_INVALID_PARTITION_IDX othervise
58 */
59uint32_t get_partition_idx(uint32_t partition_id);
60
61/**
62 * \brief Configure isolated sandbox for a partition
63 *
64 * \param[in] partition_idx Partition index
65 *
Miklos Balint386b8b52017-11-29 13:12:32 +000066 * \return Error code \ref spm_err_t
67 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010068 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000069 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010070enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000071
72/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010073 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000074 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010075 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000076 *
77 * \return Error code \ref spm_err_t
78 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010079 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000080 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010081enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000082
83/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010084 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000085 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010086 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000087 *
88 * \return Stack region bottom value
89 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010090 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000091 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010092uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000093
94/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010095 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000096 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010097 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000098 *
99 * \return Stack region top value
100 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100101 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000102 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100103uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
104
105/**
106 * \brief Get the id of the partition for its index from the db
107 *
108 * \param[in] partition_idx Partition index
109 *
110 * \return Partition ID for that partition
111 *
112 * \note This function doesn't check if partition_idx is valid.
113 */
114uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000115
116/**
Mate Toth-Pal59398712018-02-28 17:06:40 +0100117 * \brief Get the flags associated with a partition
118 *
119 * \param[in] partition_idx Partition index
120 *
121 * \return Flags associated with the partition
122 *
123 * \note This function doesn't check if partition_idx is valid.
124 */
125uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
126
127/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100128 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100129 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100130 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100131 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100132 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100133 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100134 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100135 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100136const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100137 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100138
139/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100140 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100141 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100142 * \return The index of the partition with the running state, if there is any
143 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100144 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100145uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100146
147/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100148 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000149 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100150 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000151 * \param[in] stack_ptr Stack pointer to be stored
152 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100153 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000154 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100155void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000156
157/**
Miklos Balintace4c3f2018-07-30 12:31:15 +0200158 * \brief Save stack pointer and link register for partition in database
159 *
160 * \param[in] partition_idx Partition index
161 * \param[in] stack_ptr Stack pointer to be stored
162 * \param[in] lr Link register to be stored
163 *
164 * \note This function doesn't check if partition_idx is valid.
165 */
166void tfm_spm_partition_store_context(uint32_t partition_idx,
167 uint32_t stack_ptr, uint32_t lr);
168
169/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100170 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100171 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100172 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100173 * \param[in] state The state to be set
174 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100175 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100176 * \note The \ref state has to have the value set of \ref spm_part_state_t.
177 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100178void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100179
180/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200181 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100182 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100183 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200184 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100185 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200186 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100187 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200188void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
189 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100190
191/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100192 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100193 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100194 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100195 * \param[in] share The buffer share region to be set
196 *
197 * \return Error code \ref spm_err_t
198 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100199 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100200 * \note share has to have the value set of \ref tfm_buffer_share_region_e
201 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100202enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100203 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100204
205/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100206 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000207 *
208 * \return Error code \ref spm_err_t
209 */
210enum spm_err_t tfm_spm_db_init(void);
211
212/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100213 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000214 *
215 * \return Error code \ref spm_err_t
216 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100217enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000218
219/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100220 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000221 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100222 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000223 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100224 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000225 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100226void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000227
228#endif /*__SPM_API_H__ */