Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 1 | /* |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, 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" |
David Hu | 520dcd0 | 2019-11-18 16:04:36 +0800 | [diff] [blame] | 13 | #ifdef TFM_MULTI_CORE_TOPOLOGY |
| 14 | #include "tfm_multi_core.h" |
| 15 | #endif |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 16 | #include "tfm_plat_defs.h" |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * \brief Holds peripheral specific data fields required to manage the |
| 20 | * peripherals isolation |
| 21 | * |
| 22 | * This structure has to be defined in the platform directory, and may have |
| 23 | * different definition for each platform. The structure should contain fields |
| 24 | * that describe the peripheral for the functions that are prototyped in this |
| 25 | * file and are responsible for configuring the isolation of the peripherals. |
| 26 | * |
| 27 | * Pointers to structures of this type are managed by the SPM, and passed to the |
| 28 | * necessary function on isolation request. The pointers are also defined by the |
| 29 | * platform in the header file tfm_peripherals_def.h. For details on this, see |
| 30 | * the documentation of that file. |
| 31 | */ |
| 32 | struct tfm_spm_partition_platform_data_t; |
| 33 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 34 | enum irq_target_state_t { |
| 35 | TFM_IRQ_TARGET_STATE_SECURE, |
| 36 | TFM_IRQ_TARGET_STATE_NON_SECURE, |
| 37 | }; |
| 38 | |
Edison Ai | 14dd137 | 2019-07-11 18:02:18 +0800 | [diff] [blame] | 39 | #ifdef TFM_PSA_API |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 40 | /** |
| 41 | * \brief Holds SPM db fields that define the memory regions used by a |
| 42 | * partition. |
| 43 | */ |
| 44 | struct tfm_spm_partition_memory_data_t |
| 45 | { |
Kevin Peng | 25b190b | 2020-10-30 17:10:45 +0800 | [diff] [blame^] | 46 | #if TFM_LVL == 3 |
| 47 | uint32_t data_start; /* Start of the private data region of current |
| 48 | * partition. Specifically, the private data |
| 49 | * includes RW, ZI and the partition stack below. |
| 50 | */ |
| 51 | uint32_t data_limit; /* Address of the byte beyond the end of the data |
| 52 | * region of this partition. |
| 53 | */ |
| 54 | #endif |
| 55 | uint32_t stack_bottom; /* The bottom of the stack for the partition. */ |
| 56 | uint32_t stack_top; /* The top of the stack for the partition. */ |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 57 | }; |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 58 | #endif |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 59 | |
| 60 | /** |
| 61 | * \brief This function initialises the HW used for isolation, and sets the |
| 62 | * default configuration for them. |
| 63 | * |
| 64 | * 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] | 65 | * |
| 66 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 67 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 68 | enum tfm_plat_err_t tfm_spm_hal_init_isolation_hw(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 69 | |
Edison Ai | 1dfd7b1 | 2020-02-23 14:16:08 +0800 | [diff] [blame] | 70 | #ifdef CONFIG_TFM_ENABLE_MEMORY_PROTECT |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 71 | /** |
| 72 | * \brief This function initialises the HW used for isolation, and sets the |
| 73 | * default configuration for them. |
| 74 | * 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] | 75 | * |
| 76 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 77 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 78 | enum tfm_plat_err_t tfm_spm_hal_setup_isolation_hw(void); |
Edison Ai | 1dfd7b1 | 2020-02-23 14:16:08 +0800 | [diff] [blame] | 79 | #endif /* CONFIG_TFM_ENABLE_MEMORY_PROTECT */ |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 80 | |
| 81 | /** |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 82 | * \brief Configure peripherals for a partition based on the platform data and |
| 83 | * partition index from the DB |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 84 | * |
| 85 | * This function is called during partition initialisation (before calling the |
| 86 | * init function for the partition) |
| 87 | * |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 88 | * \param[in] partition_idx The index of the partition that this peripheral |
| 89 | * is assigned to. |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 90 | * \param[in] platform_data The platform fields of the partition DB record to |
Edison Ai | 6be3df1 | 2020-02-14 22:14:33 +0800 | [diff] [blame] | 91 | * be used for configuration. |
| 92 | * |
| 93 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 94 | */ |
Edison Ai | 6be3df1 | 2020-02-14 22:14:33 +0800 | [diff] [blame] | 95 | enum tfm_plat_err_t tfm_spm_hal_configure_default_isolation( |
Mate Toth-Pal | 5e6d034 | 2019-11-22 11:43:20 +0100 | [diff] [blame] | 96 | uint32_t partition_idx, |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 97 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 98 | /** |
| 99 | * \brief Configures the system debug properties. |
| 100 | * The default configuration of this function should disable secure debug |
| 101 | * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the |
| 102 | * platform owner to decide if secure debug can be turned on in their |
| 103 | * system, if DAUTH_FULL define is present. |
| 104 | * The DAUTH_CHIP_DEFAULT define should not be considered a safe default |
| 105 | * option unless explicitly noted by the chip vendor. |
| 106 | * The implementation has to expect that one of those defines is going to |
| 107 | * be set. Otherwise, a compile error needs to be triggered. |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 108 | * |
| 109 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 110 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 111 | enum tfm_plat_err_t tfm_spm_hal_init_debug(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 112 | |
| 113 | /** |
Mate Toth-Pal | 3e2ebd0 | 2019-05-07 14:22:16 +0200 | [diff] [blame] | 114 | * \brief Enables the fault handlers and sets priorities. |
| 115 | * |
| 116 | * Secure fault (if present) must have the highest possible priority |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 117 | * |
| 118 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 119 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 120 | enum tfm_plat_err_t tfm_spm_hal_enable_fault_handlers(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 121 | |
| 122 | /** |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 123 | * \brief Configures the system reset request properties |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 124 | * |
| 125 | * \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] | 126 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 127 | enum tfm_plat_err_t tfm_spm_hal_system_reset_cfg(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 128 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 129 | /** |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 130 | * \brief Configures all external interrupts to target the |
| 131 | * NS state, apart for the ones associated to secure |
| 132 | * peripherals (plus MPC and PPC) |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 133 | * |
| 134 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 135 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 136 | 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] | 137 | |
| 138 | /** |
| 139 | * \brief This function enable the interrupts associated |
| 140 | * to the secure peripherals (plus the isolation boundary violation |
| 141 | * interrupts) |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 142 | * |
| 143 | * \return Returns values as specified by the \ref tfm_plat_err_t |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 144 | */ |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 145 | enum tfm_plat_err_t tfm_spm_hal_nvic_interrupt_enable(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * \brief Get the VTOR value of non-secure image |
| 149 | * |
| 150 | * \return Returns the address where the vector table of the non-secure image |
| 151 | * is located |
| 152 | */ |
| 153 | uint32_t tfm_spm_hal_get_ns_VTOR(void); |
| 154 | |
| 155 | /** |
| 156 | * \brief Get the initial address of non-secure image main stack |
| 157 | * |
| 158 | * \return Returns the initial non-secure MSP |
| 159 | */ |
| 160 | uint32_t tfm_spm_hal_get_ns_MSP(void); |
| 161 | |
| 162 | /** |
| 163 | * \brief Get the entry point of the non-secure image |
| 164 | * |
| 165 | * \return Returns the address of the non-secure image entry point |
| 166 | */ |
| 167 | uint32_t tfm_spm_hal_get_ns_entry_point(void); |
| 168 | |
Mate Toth-Pal | 9492572 | 2019-06-27 15:10:48 +0200 | [diff] [blame] | 169 | /** |
| 170 | * \brief Set the priority of a secure IRQ |
| 171 | * |
| 172 | * \param[in] irq_line The IRQ to set the priority for. Might be less than 0 |
| 173 | * \param[in] priority The priority to set. [0..255] |
| 174 | * |
| 175 | * \details This function sets the priority for the IRQ passed in the parameter. |
| 176 | * The precision of the priority value might be adjusted to match the |
| 177 | * available priority bits in the underlying target platform. |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 178 | * |
| 179 | * \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] | 180 | */ |
TTornblom | faf74f5 | 2020-03-04 17:56:27 +0100 | [diff] [blame] | 181 | enum tfm_plat_err_t tfm_spm_hal_set_secure_irq_priority(IRQn_Type irq_line, |
Mate Toth-Pal | b9c3355 | 2019-07-10 16:13:20 +0200 | [diff] [blame] | 182 | uint32_t priority); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 183 | |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 184 | /** |
| 185 | * \brief Clears a pending IRQ |
| 186 | * |
| 187 | * \param[in] irq_line The IRQ to clear pending for. |
| 188 | */ |
TTornblom | faf74f5 | 2020-03-04 17:56:27 +0100 | [diff] [blame] | 189 | void tfm_spm_hal_clear_pending_irq(IRQn_Type irq_line); |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 190 | |
| 191 | /** |
| 192 | * \brief Enables an IRQ |
| 193 | * |
| 194 | * \param[in] irq_line The IRQ to be enabled. |
| 195 | */ |
TTornblom | faf74f5 | 2020-03-04 17:56:27 +0100 | [diff] [blame] | 196 | void tfm_spm_hal_enable_irq(IRQn_Type irq_line); |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * \brief Disables an IRQ |
| 200 | * |
| 201 | * \param[in] irq_line The IRQ to be disabled |
| 202 | */ |
TTornblom | faf74f5 | 2020-03-04 17:56:27 +0100 | [diff] [blame] | 203 | void tfm_spm_hal_disable_irq(IRQn_Type irq_line); |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * \brief Set the target state of an IRQ |
| 207 | * |
| 208 | * \param[in] irq_line The IRQ to set the priority for. |
| 209 | * \param[in] target_state Target state to ret for the IRQ. |
| 210 | * |
| 211 | * \return TFM_IRQ_TARGET_STATE_SECURE if interrupt is assigned |
| 212 | * to Secure |
| 213 | * TFM_IRQ_TARGET_STATE_NON_SECURE if interrupt is |
| 214 | * assigned to Non-Secure |
| 215 | */ |
| 216 | enum irq_target_state_t tfm_spm_hal_set_irq_target_state( |
TTornblom | faf74f5 | 2020-03-04 17:56:27 +0100 | [diff] [blame] | 217 | IRQn_Type irq_line, |
Mate Toth-Pal | 4341de0 | 2018-10-02 12:55:47 +0200 | [diff] [blame] | 218 | enum irq_target_state_t target_state); |
| 219 | |
David Hu | 520dcd0 | 2019-11-18 16:04:36 +0800 | [diff] [blame] | 220 | #ifdef TFM_MULTI_CORE_TOPOLOGY |
| 221 | /** |
| 222 | * \brief Performs the necessary actions to start the non-secure CPU running |
| 223 | * the code at the specified address. |
| 224 | * |
| 225 | * \param[in] start_addr The entry point address of non-secure code. |
| 226 | */ |
| 227 | void tfm_spm_hal_boot_ns_cpu(uintptr_t start_addr); |
| 228 | |
| 229 | /** |
| 230 | * \brief Called on the secure CPU. |
| 231 | * Flags that the secure CPU has completed its initialization |
| 232 | * Waits, if necessary, for the non-secure CPU to flag that |
| 233 | * it has completed its initialisation |
| 234 | */ |
| 235 | void tfm_spm_hal_wait_for_ns_cpu_ready(void); |
| 236 | |
| 237 | /** |
| 238 | * \brief Retrieve the current active security configuration information and |
| 239 | * fills the \ref security_attr_info_t. |
| 240 | * |
| 241 | * \param[in] p Base address of target memory region |
| 242 | * \param[in] s Size of target memory region |
| 243 | * \param[out] p_attr Address of \ref security_attr_info_t to be filled |
| 244 | * |
| 245 | * \return void |
| 246 | */ |
| 247 | void tfm_spm_hal_get_mem_security_attr(const void *p, size_t s, |
| 248 | struct security_attr_info_t *p_attr); |
| 249 | |
| 250 | /** |
| 251 | * \brief Retrieve the secure memory protection configuration information and |
| 252 | * fills the \ref mem_attr_info_t. |
| 253 | * |
| 254 | * \param[in] p Base address of target memory region |
| 255 | * \param[in] s Size of target memory region |
| 256 | * \param[out] p_attr Address of \ref mem_attr_info_t to be filled |
| 257 | * |
| 258 | * \return void |
| 259 | */ |
| 260 | void tfm_spm_hal_get_secure_access_attr(const void *p, size_t s, |
| 261 | struct mem_attr_info_t *p_attr); |
| 262 | |
| 263 | /** |
| 264 | * \brief Retrieve the non-secure memory protection configuration information |
| 265 | * and fills the \ref mem_attr_info_t. |
| 266 | * |
| 267 | * \param[in] p Base address of target memory region |
| 268 | * \param[in] s Size of target memory region |
| 269 | * \param[out] p_attr Address of \ref mem_attr_info_t to be filled |
| 270 | * |
| 271 | * \return void |
| 272 | */ |
| 273 | void tfm_spm_hal_get_ns_access_attr(const void *p, size_t s, |
| 274 | struct mem_attr_info_t *p_attr); |
| 275 | |
| 276 | #endif /*TFM_MULTI_CORE_TOPOLOGY*/ |
| 277 | |
Ioannis Glaropoulos | 130248c | 2020-07-30 15:09:01 +0200 | [diff] [blame] | 278 | #if !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0) |
| 279 | /** |
| 280 | * \brief Platform-specific check whether the current partition has access to a memory range |
| 281 | * |
| 282 | * The function checks whether the current partition has access to a memory range, |
| 283 | * taking into consideration the implementation-defined attribution unit that is |
| 284 | * present on a particular platform. |
| 285 | * |
| 286 | * \param[in] p The start address of the range to check |
| 287 | * \param[in] s The size of the range to check |
| 288 | * \param[in] flags The flags to pass to the cmse_check_address_range func |
| 289 | * |
| 290 | * \return True if the access is granted, false otherwise. |
| 291 | */ |
| 292 | bool tfm_spm_hal_has_access_to_region(const void *p, size_t s, |
| 293 | int flags); |
| 294 | #endif /* !defined(__SAUREGION_PRESENT) || (__SAUREGION_PRESENT == 0) */ |
| 295 | |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 296 | #endif /* __TFM_SPM_HAL_H__ */ |