Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 1 | /* |
Summer Qin | d00e4db | 2019-05-09 18:03:52 +0800 | [diff] [blame] | 2 | * Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_SPM_HAL_H__ |
| 9 | #define __TFM_SPM_HAL_H__ |
| 10 | |
| 11 | #include <stdint.h> |
| 12 | #include "tfm_secure_api.h" |
| 13 | #include "spm_api.h" |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 14 | #include "tfm_plat_defs.h" |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 15 | |
| 16 | /** |
| 17 | * \brief Holds peripheral specific data fields required to manage the |
| 18 | * peripherals isolation |
| 19 | * |
| 20 | * This structure has to be defined in the platform directory, and may have |
| 21 | * different definition for each platform. The structure should contain fields |
| 22 | * that describe the peripheral for the functions that are prototyped in this |
| 23 | * file and are responsible for configuring the isolation of the peripherals. |
| 24 | * |
| 25 | * Pointers to structures of this type are managed by the SPM, and passed to the |
| 26 | * necessary function on isolation request. The pointers are also defined by the |
| 27 | * platform in the header file tfm_peripherals_def.h. For details on this, see |
| 28 | * the documentation of that file. |
| 29 | */ |
| 30 | struct tfm_spm_partition_platform_data_t; |
| 31 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 32 | enum irq_target_state_t { |
| 33 | TFM_IRQ_TARGET_STATE_SECURE, |
| 34 | TFM_IRQ_TARGET_STATE_NON_SECURE, |
| 35 | }; |
| 36 | |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 37 | #if defined (TFM_PSA_API) || (TFM_LVL != 1) |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 38 | /** |
| 39 | * \brief Holds SPM db fields that define the memory regions used by a |
| 40 | * partition. |
| 41 | */ |
| 42 | struct tfm_spm_partition_memory_data_t |
| 43 | { |
| 44 | uint32_t code_start; /*!< Start of the code memory of this partition. */ |
| 45 | uint32_t code_limit; /*!< Address of the byte beyond the end of the code |
| 46 | * memory of this partition. |
| 47 | */ |
| 48 | uint32_t ro_start; /*!< Start of the read only memory of this |
| 49 | * partition. |
| 50 | */ |
| 51 | uint32_t ro_limit; /*!< Address of the byte beyond the end of the read |
| 52 | * only memory of this partition. |
| 53 | */ |
| 54 | uint32_t rw_start; /*!< Start of the data region of this partition. */ |
| 55 | uint32_t rw_limit; /*!< Address of the byte beyond the end of the data |
| 56 | * region of this partition. |
| 57 | */ |
| 58 | uint32_t zi_start; /*!< Start of the zero initialised data region of |
| 59 | * this partition. |
| 60 | */ |
| 61 | uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero |
| 62 | * initialised region of this partition. |
| 63 | */ |
| 64 | uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */ |
| 65 | uint32_t stack_top; /*!< The top of the stack for the partition. */ |
| 66 | }; |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 67 | #endif |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * \brief This function initialises the HW used for isolation, and sets the |
| 71 | * default configuration for them. |
| 72 | * |
| 73 | * This function is called during TF-M core early startup, before DB init |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 74 | * |
| 75 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 76 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 77 | enum tfm_plat_err_t tfm_spm_hal_init_isolation_hw(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * \brief This function initialises the HW used for isolation, and sets the |
| 81 | * default configuration for them. |
| 82 | * This function is called during TF-M core early startup, after DB init |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 83 | * |
| 84 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 85 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 86 | enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 87 | |
| 88 | /** |
| 89 | * \brief Configure peripherals for a partition based on the platfotm data from |
| 90 | * the DB |
| 91 | * |
| 92 | * This function is called during partition initialisation (before calling the |
| 93 | * init function for the partition) |
| 94 | * |
| 95 | * \param[in] platform_data The platform fields of the partition DB record to |
| 96 | * be used for configuration. Can be NULL. |
| 97 | */ |
| 98 | void tfm_spm_hal_configure_default_isolation( |
| 99 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 100 | /** |
| 101 | * \brief Configures the system debug properties. |
| 102 | * The default configuration of this function should disable secure debug |
| 103 | * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the |
| 104 | * platform owner to decide if secure debug can be turned on in their |
| 105 | * system, if DAUTH_FULL define is present. |
| 106 | * The DAUTH_CHIP_DEFAULT define should not be considered a safe default |
| 107 | * option unless explicitly noted by the chip vendor. |
| 108 | * The implementation has to expect that one of those defines is going to |
| 109 | * be set. Otherwise, a compile error needs to be triggered. |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 110 | * |
| 111 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 112 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 113 | enum tfm_plat_err_t tfm_spm_hal_init_debug(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 114 | |
| 115 | /** |
Mate Toth-Pal | 3e2ebd0 | 2019-05-07 14:22:16 +0200 | [diff] [blame] | 116 | * \brief Enables the fault handlers and sets priorities. |
| 117 | * |
| 118 | * Secure fault (if present) must have the highest possible priority |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 119 | * |
| 120 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 121 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 122 | enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 123 | |
| 124 | /** |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 125 | * \brief Configures the system reset request properties |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 126 | * |
| 127 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 128 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 129 | enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 130 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 131 | /** |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 132 | * \brief Configures all external interrupts to target the |
| 133 | * NS state, apart for the ones associated to secure |
| 134 | * peripherals (plus MPC and PPC) |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 135 | * |
| 136 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 137 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 138 | enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_target_state_cfg(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * \brief This function enable the interrupts associated |
| 142 | * to the secure peripherals (plus the isolation boundary violation |
| 143 | * interrupts) |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 144 | * |
| 145 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 146 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 147 | enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * \brief Get the VTOR value of non-secure image |
| 151 | * |
| 152 | * \return Returns the address where the vector table of the non-secure image |
| 153 | * is located |
| 154 | */ |
| 155 | uint32_t tfm_spm_hal_get_ns_VTOR(void); |
| 156 | |
| 157 | /** |
| 158 | * \brief Get the initial address of non-secure image main stack |
| 159 | * |
| 160 | * \return Returns the initial non-secure MSP |
| 161 | */ |
| 162 | uint32_t tfm_spm_hal_get_ns_MSP(void); |
| 163 | |
| 164 | /** |
| 165 | * \brief Get the entry point of the non-secure image |
| 166 | * |
| 167 | * \return Returns the address of the non-secure image entry point |
| 168 | */ |
| 169 | uint32_t tfm_spm_hal_get_ns_entry_point(void); |
| 170 | |
Mate Toth-Pal | 9492572 | 2019-06-27 15:10:48 +0200 | [diff] [blame] | 171 | /** |
| 172 | * \brief Set the priority of a secure IRQ |
| 173 | * |
| 174 | * \param[in] irq_line The IRQ to set the priority for. Might be less than 0 |
| 175 | * \param[in] priority The priority to set. [0..255] |
| 176 | * |
| 177 | * \details This function sets the priority for the IRQ passed in the parameter. |
| 178 | * The precision of the priority value might be adjusted to match the |
| 179 | * available priority bits in the underlying target platform. |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 180 | * |
| 181 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Mate Toth-Pal | 9492572 | 2019-06-27 15:10:48 +0200 | [diff] [blame] | 182 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame^] | 183 | enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(int32_t irq_line, |
| 184 | uint32_t priority); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 185 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 186 | /** |
| 187 | * \brief Clears a pending IRQ |
| 188 | * |
| 189 | * \param[in] irq_line The IRQ to clear pending for. |
| 190 | */ |
| 191 | void tfm_spm_hal_clear_pending_irq(int32_t irq_line); |
| 192 | |
| 193 | /** |
| 194 | * \brief Enables an IRQ |
| 195 | * |
| 196 | * \param[in] irq_line The IRQ to be enabled. |
| 197 | */ |
| 198 | void tfm_spm_hal_enable_irq(int32_t irq_line); |
| 199 | |
| 200 | /** |
| 201 | * \brief Disables an IRQ |
| 202 | * |
| 203 | * \param[in] irq_line The IRQ to be disabled |
| 204 | */ |
| 205 | void tfm_spm_hal_disable_irq(int32_t irq_line); |
| 206 | |
| 207 | /** |
| 208 | * \brief Set the target state of an IRQ |
| 209 | * |
| 210 | * \param[in] irq_line The IRQ to set the priority for. |
| 211 | * \param[in] target_state Target state to ret for the IRQ. |
| 212 | * |
| 213 | * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned |
| 214 | * to Secure |
| 215 | * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is |
| 216 | * assigned to Non-Secure |
| 217 | */ |
| 218 | enum irq_target_state_t tfm_spm_hal_set_irq_target_state( |
| 219 | int32_t irq_line, |
| 220 | enum irq_target_state_t target_state); |
| 221 | |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 222 | #if (TFM_LVL != 1) && !defined(TFM_PSA_API) |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 223 | /** |
| 224 | * \brief Configure the sandbox for a partition. |
| 225 | * |
| 226 | * \param[in] memory_data The memory ranges from the partition DB for this |
| 227 | * partition |
| 228 | * \param[in] platform_data The platform fields of the partition DB record |
| 229 | * for this partition. Can be NULL. |
| 230 | * |
| 231 | * \return Returns the result operation as per \ref spm_err_t |
| 232 | */ |
| 233 | enum spm_err_t tfm_spm_hal_partition_sandbox_config( |
| 234 | const struct tfm_spm_partition_memory_data_t *memory_data, |
| 235 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 236 | |
| 237 | /** |
| 238 | * \brief Deconfigure the sandbox for a partition. |
| 239 | * |
| 240 | * \param[in] memory_data The memory ranges from the partition DB for this |
| 241 | * partition |
| 242 | * \param[in] platform_data The platform fields of the partition DB record |
| 243 | * for this partition. Can be NULL. |
| 244 | * |
| 245 | * \return Returns the result operation as per \ref spm_err_t |
| 246 | */ |
| 247 | enum spm_err_t tfm_spm_hal_partition_sandbox_deconfig( |
| 248 | const struct tfm_spm_partition_memory_data_t *memory_data, |
| 249 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 250 | |
| 251 | /** |
| 252 | * \brief Set the share region mode |
| 253 | * |
| 254 | * \param[in] share The mode to set |
| 255 | * |
| 256 | * \return Returns the result operation as per \ref spm_err_t |
| 257 | */ |
Hugues de Valon | 9957856 | 2019-06-18 16:08:51 +0100 | [diff] [blame] | 258 | enum spm_err_t tfm_spm_hal_set_share_region(uint32_t share); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 259 | #endif |
| 260 | |
| 261 | #endif /* __TFM_SPM_HAL_H__ */ |