blob: 7743d4590189a1e788cb8391275abdf1c6abf95c [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 orig_psp;
46 uint32_t orig_psplim;
47 uint32_t orig_lr;
48 uint32_t share;
49#if TFM_LVL != 1
50 uint32_t stack_ptr;
51#endif
52};
53
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010054
Mate Toth-Pal18b83922018-02-26 17:58:18 +010055/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010056 * \brief Returns the index of the partition with the given partition ID.
Miklos Balint386b8b52017-11-29 13:12:32 +000057 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010058 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000059 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010060 * \return the partition idx if partition_id is valid,
61 * \ref SPM_INVALID_PARTITION_IDX othervise
62 */
63uint32_t get_partition_idx(uint32_t partition_id);
64
65/**
66 * \brief Configure isolated sandbox for a partition
67 *
68 * \param[in] partition_idx Partition index
69 *
Miklos Balint386b8b52017-11-29 13:12:32 +000070 * \return Error code \ref spm_err_t
71 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010072 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000073 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010074enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000075
76/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010077 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000078 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010079 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000080 *
81 * \return Error code \ref spm_err_t
82 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010083 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000084 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010085enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000086
87/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010088 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000089 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010090 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +000091 *
92 * \return Stack region bottom value
93 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010094 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000095 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +010096uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +000097
98/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010099 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +0000100 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100101 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000102 *
103 * \return Stack region top value
104 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100105 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000106 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100107uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_idx);
108
109/**
110 * \brief Get the id of the partition for its index from the db
111 *
112 * \param[in] partition_idx Partition index
113 *
114 * \return Partition ID for that partition
115 *
116 * \note This function doesn't check if partition_idx is valid.
117 */
118uint32_t tfm_spm_partition_get_partition_id(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000119
120/**
Mate Toth-Pal59398712018-02-28 17:06:40 +0100121 * \brief Get the flags associated with a partition
122 *
123 * \param[in] partition_idx Partition index
124 *
125 * \return Flags associated with the partition
126 *
127 * \note This function doesn't check if partition_idx is valid.
128 */
129uint32_t tfm_spm_partition_get_flags(uint32_t partition_idx);
130
131/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100132 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100133 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100134 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100135 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100136 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100137 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100138 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100139 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100140const struct spm_partition_runtime_data_t *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100141 tfm_spm_partition_get_runtime_data(uint32_t partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100142
143/**
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100144 * \brief Returns the index of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100145 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100146 * \return The index of the partition with the running state, if there is any
147 * set. 0 otherwise.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100148 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100149uint32_t tfm_spm_partition_get_running_partition_idx(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100150
151/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100152 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000153 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100154 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000155 * \param[in] stack_ptr Stack pointer to be stored
156 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100157 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000158 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100159void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000160
161/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100162 * \brief Set the current state of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100163 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100164 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100165 * \param[in] state The state to be set
166 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100167 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100168 * \note The \ref state has to have the value set of \ref spm_part_state_t.
169 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100170void tfm_spm_partition_set_state(uint32_t partition_idx, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100171
172/**
Miklos Balint6a139ae2018-04-04 19:44:37 +0200173 * \brief Set the caller partition index for a given partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100174 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100175 * \param[in] partition_idx Partition index
Miklos Balint6a139ae2018-04-04 19:44:37 +0200176 * \param[in] caller_partition_idx The index of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100177 *
Miklos Balint6a139ae2018-04-04 19:44:37 +0200178 * \note This function doesn't check if any of the partition_idxs are valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100179 */
Miklos Balint6a139ae2018-04-04 19:44:37 +0200180void tfm_spm_partition_set_caller_partition_idx(uint32_t partition_idx,
181 uint32_t caller_partition_idx);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100182
183/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100184 * \brief Set the original PSP value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100185 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100186 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100187 * \param[in] orig_psp The PSP value to set
188 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100189 * \note This function doesn't check if partition_idx is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100190 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100191void tfm_spm_partition_set_orig_psp(uint32_t partition_idx, uint32_t orig_psp);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100192
193/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100194 * \brief Set the original PSP limit value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100195 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100196 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100197 * \param[in] orig_psplim The PSP limit value to set
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 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100201void tfm_spm_partition_set_orig_psplim(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100202 uint32_t orig_psplim);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100203
204/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100205 * \brief Set the original link register value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100206 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100207 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100208 * \param[in] orig_lr The link register value to set
209 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100210 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100211 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100212void tfm_spm_partition_set_orig_lr(uint32_t partition_idx, uint32_t orig_lr);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100213
214/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100215 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100216 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100217 * \param[in] partition_idx Partition index
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100218 * \param[in] share The buffer share region to be set
219 *
220 * \return Error code \ref spm_err_t
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 share has to have the value set of \ref tfm_buffer_share_region_e
224 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100225enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_idx,
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100226 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100227
228/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100229 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000230 *
231 * \return Error code \ref spm_err_t
232 */
233enum spm_err_t tfm_spm_db_init(void);
234
235/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100236 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000237 *
238 * \return Error code \ref spm_err_t
239 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100240enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000241
242/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100243 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000244 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100245 * \param[in] partition_idx Partition index
Miklos Balint386b8b52017-11-29 13:12:32 +0000246 *
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100247 * \note This function doesn't check if partition_idx is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000248 */
Mate Toth-Pal52674ab2018-02-26 09:47:56 +0100249void tfm_spm_partition_cleanup_context(uint32_t partition_idx);
Miklos Balint386b8b52017-11-29 13:12:32 +0000250
251#endif /*__SPM_API_H__ */