blob: 039506c5c3ff1f680a274c262b0f92da94fba6aa [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-Pal18b83922018-02-26 17:58:18 +010033 * \brief Runtime context information of a partition
34 */
35struct spm_partition_runtime_data_t {
36 uint32_t partition_state;
37 uint32_t caller_partition_id;
38 uint32_t orig_psp;
39 uint32_t orig_psplim;
40 uint32_t orig_lr;
41 uint32_t share;
42#if TFM_LVL != 1
43 uint32_t stack_ptr;
44#endif
45};
46
47/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010048 * \brief Configure isolated sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000049 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010050 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000051 *
52 * \return Error code \ref spm_err_t
53 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010054 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000055 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010056enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000057
58/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010059 * \brief Deconfigure sandbox for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000060 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010061 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000062 *
63 * \return Error code \ref spm_err_t
64 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010065 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000066 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010067enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000068
69/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010070 * \brief Get bottom of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000071 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010072 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000073 *
74 * \return Stack region bottom value
75 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010076 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000077 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010078uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000079
80/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +010081 * \brief Get top of stack region for a partition
Miklos Balint386b8b52017-11-29 13:12:32 +000082 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010083 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +000084 *
85 * \return Stack region top value
86 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010087 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +000088 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +010089uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +000090
91/**
Mate Toth-Pal18b83922018-02-26 17:58:18 +010092 * \brief Get the current runtime data of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +010093 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010094 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +010095 *
Mate Toth-Pal18b83922018-02-26 17:58:18 +010096 * \return The runtime data of the specified partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +010097 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +010098 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +010099 */
Mate Toth-Pal18b83922018-02-26 17:58:18 +0100100const struct spm_partition_runtime_data_t *
101 tfm_spm_partition_get_runtime_data(uint32_t partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100102
103/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100104 * \brief Returns the id of the partition that has running state
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100105 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100106 * \return The Id of the partition with the running state, if there is any set.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100107 * 0 otherwise.
108 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100109uint32_t tfm_spm_partition_get_running_partition_id(void);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100110
111/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100112 * \brief Save stack pointer for partition in database
Miklos Balint386b8b52017-11-29 13:12:32 +0000113 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100114 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000115 * \param[in] stack_ptr Stack pointer to be stored
116 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100117 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000118 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100119void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr);
Miklos Balint386b8b52017-11-29 13:12:32 +0000120
121/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100122 * \brief Set the current state of a 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 * \param[in] state The state to be set
126 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100127 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100128 * \note The \ref state has to have the value set of \ref spm_part_state_t.
129 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100130void tfm_spm_partition_set_state(uint32_t partition_id, uint32_t state);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100131
132/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100133 * \brief Set the caller partition Id for a given 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
136 * \param[in] caller_partition_id The Id of the caller partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100137 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100138 * \note This function doesn't check if any of the partition_ids is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100139 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100140void tfm_spm_partition_set_caller_partition_id(uint32_t partition_id,
141 uint32_t caller_partition_id);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100142
143/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100144 * \brief Set the original PSP value of a 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 * \param[in] orig_psp The PSP value to set
148 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100149 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100150 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100151void tfm_spm_partition_set_orig_psp(uint32_t partition_id, uint32_t orig_psp);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100152
153/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100154 * \brief Set the original PSP limit value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100155 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100156 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100157 * \param[in] orig_psplim The PSP limit value to set
158 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100159 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100160 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100161void tfm_spm_partition_set_orig_psplim(uint32_t partition_id,
162 uint32_t orig_psplim);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100163
164/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100165 * \brief Set the original link register value of a partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100166 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100167 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100168 * \param[in] orig_lr The link register value to set
169 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100170 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100171 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100172void tfm_spm_partition_set_orig_lr(uint32_t partition_id, uint32_t orig_lr);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100173
174/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100175 * \brief Set the buffer share region of the partition
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100176 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100177 * \param[in] partition_id Partition id
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100178 * \param[in] share The buffer share region to be set
179 *
180 * \return Error code \ref spm_err_t
181 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100182 * \note This function doesn't check if partition_id is valid.
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100183 * \note share has to have the value set of \ref tfm_buffer_share_region_e
184 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100185enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_id,
186 uint32_t share);
Mate Toth-Pal65291f32018-02-23 14:35:22 +0100187
188/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100189 * \brief Initialize partition database
Miklos Balint386b8b52017-11-29 13:12:32 +0000190 *
191 * \return Error code \ref spm_err_t
192 */
193enum spm_err_t tfm_spm_db_init(void);
194
195/**
196 * \brief Apply default MPU configuration for execution
197 *
198 * \return Error code \ref spm_err_t
199 */
200enum spm_err_t tfm_spm_mpu_init(void);
201
202/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100203 * \brief Execute partition init function
Miklos Balint386b8b52017-11-29 13:12:32 +0000204 *
205 * \return Error code \ref spm_err_t
206 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100207enum spm_err_t tfm_spm_partition_init(void);
Miklos Balint386b8b52017-11-29 13:12:32 +0000208
209/**
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100210 * \brief Clears the context info from the database for a partition.
Miklos Balint386b8b52017-11-29 13:12:32 +0000211 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100212 * \param[in] partition_id Partition id
Miklos Balint386b8b52017-11-29 13:12:32 +0000213 *
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100214 * \note This function doesn't check if partition_id is valid.
Miklos Balint386b8b52017-11-29 13:12:32 +0000215 */
Mate Toth-Pal349714a2018-02-23 15:30:24 +0100216void tfm_spm_partition_cleanup_context(uint32_t partition_id);
Miklos Balint386b8b52017-11-29 13:12:32 +0000217
218#endif /*__SPM_API_H__ */