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