Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, Arm Limited. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 3 | * |
| 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 | |
| 15 | enum spm_err_t { |
| 16 | SPM_ERR_OK = 0, |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 17 | SPM_ERR_PARTITION_DB_NOT_INIT, |
| 18 | SPM_ERR_PARTITION_ALREADY_ACTIVE, |
| 19 | SPM_ERR_PARTITION_NOT_AVAILABLE, |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 20 | SPM_ERR_INVALID_CONFIG, |
| 21 | }; |
| 22 | |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 23 | enum spm_part_state_t { |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 24 | 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-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 32 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 33 | * \brief Runtime context information of a partition |
| 34 | */ |
| 35 | struct 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-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 48 | * \brief Configure isolated sandbox for a partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 49 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 50 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 51 | * |
| 52 | * \return Error code \ref spm_err_t |
| 53 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 54 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 55 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 56 | enum spm_err_t tfm_spm_partition_sandbox_config(uint32_t partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 57 | |
| 58 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 59 | * \brief Deconfigure sandbox for a partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 60 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 61 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 62 | * |
| 63 | * \return Error code \ref spm_err_t |
| 64 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 65 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 66 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 67 | enum spm_err_t tfm_spm_partition_sandbox_deconfig(uint32_t partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 68 | |
| 69 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 70 | * \brief Get bottom of stack region for a partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 71 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 72 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 73 | * |
| 74 | * \return Stack region bottom value |
| 75 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 76 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 77 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 78 | uint32_t tfm_spm_partition_get_stack_bottom(uint32_t partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 79 | |
| 80 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 81 | * \brief Get top of stack region for a partition |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 82 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 83 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 84 | * |
| 85 | * \return Stack region top value |
| 86 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 87 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 88 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 89 | uint32_t tfm_spm_partition_get_stack_top(uint32_t partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 90 | |
| 91 | /** |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 92 | * \brief Get the current runtime data of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 93 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 94 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 95 | * |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 96 | * \return The runtime data of the specified partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 97 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 98 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 99 | */ |
Mate Toth-Pal | 18b8392 | 2018-02-26 17:58:18 +0100 | [diff] [blame] | 100 | const struct spm_partition_runtime_data_t * |
| 101 | tfm_spm_partition_get_runtime_data(uint32_t partition_id); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 102 | |
| 103 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 104 | * \brief Returns the id of the partition that has running state |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 105 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 106 | * \return The Id of the partition with the running state, if there is any set. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 107 | * 0 otherwise. |
| 108 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 109 | uint32_t tfm_spm_partition_get_running_partition_id(void); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 110 | |
| 111 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 112 | * \brief Save stack pointer for partition in database |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 113 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 114 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 115 | * \param[in] stack_ptr Stack pointer to be stored |
| 116 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 117 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 118 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 119 | void tfm_spm_partition_set_stack(uint32_t partition_id, uint32_t stack_ptr); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 120 | |
| 121 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 122 | * \brief Set the current state of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 123 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 124 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 125 | * \param[in] state The state to be set |
| 126 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 127 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 128 | * \note The \ref state has to have the value set of \ref spm_part_state_t. |
| 129 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 130 | void tfm_spm_partition_set_state(uint32_t partition_id, uint32_t state); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 131 | |
| 132 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 133 | * \brief Set the caller partition Id for a given partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 134 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 135 | * \param[in] partition_id Partition id |
| 136 | * \param[in] caller_partition_id The Id of the caller partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 137 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 138 | * \note This function doesn't check if any of the partition_ids is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 139 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 140 | void tfm_spm_partition_set_caller_partition_id(uint32_t partition_id, |
| 141 | uint32_t caller_partition_id); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 142 | |
| 143 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 144 | * \brief Set the original PSP value of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 145 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 146 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 147 | * \param[in] orig_psp The PSP value to set |
| 148 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 149 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 150 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 151 | void tfm_spm_partition_set_orig_psp(uint32_t partition_id, uint32_t orig_psp); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 152 | |
| 153 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 154 | * \brief Set the original PSP limit value of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 155 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 156 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 157 | * \param[in] orig_psplim The PSP limit value to set |
| 158 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 159 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 160 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 161 | void tfm_spm_partition_set_orig_psplim(uint32_t partition_id, |
| 162 | uint32_t orig_psplim); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 163 | |
| 164 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 165 | * \brief Set the original link register value of a partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 166 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 167 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 168 | * \param[in] orig_lr The link register value to set |
| 169 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 170 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 171 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 172 | void tfm_spm_partition_set_orig_lr(uint32_t partition_id, uint32_t orig_lr); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 173 | |
| 174 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 175 | * \brief Set the buffer share region of the partition |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 176 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 177 | * \param[in] partition_id Partition id |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 178 | * \param[in] share The buffer share region to be set |
| 179 | * |
| 180 | * \return Error code \ref spm_err_t |
| 181 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 182 | * \note This function doesn't check if partition_id is valid. |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 183 | * \note share has to have the value set of \ref tfm_buffer_share_region_e |
| 184 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 185 | enum spm_err_t tfm_spm_partition_set_share(uint32_t partition_id, |
| 186 | uint32_t share); |
Mate Toth-Pal | 65291f3 | 2018-02-23 14:35:22 +0100 | [diff] [blame] | 187 | |
| 188 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 189 | * \brief Initialize partition database |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 190 | * |
| 191 | * \return Error code \ref spm_err_t |
| 192 | */ |
| 193 | enum 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 | */ |
| 200 | enum spm_err_t tfm_spm_mpu_init(void); |
| 201 | |
| 202 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 203 | * \brief Execute partition init function |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 204 | * |
| 205 | * \return Error code \ref spm_err_t |
| 206 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 207 | enum spm_err_t tfm_spm_partition_init(void); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 208 | |
| 209 | /** |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 210 | * \brief Clears the context info from the database for a partition. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 211 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 212 | * \param[in] partition_id Partition id |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 213 | * |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 214 | * \note This function doesn't check if partition_id is valid. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 215 | */ |
Mate Toth-Pal | 349714a | 2018-02-23 15:30:24 +0100 | [diff] [blame] | 216 | void tfm_spm_partition_cleanup_context(uint32_t partition_id); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 217 | |
| 218 | #endif /*__SPM_API_H__ */ |