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