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 | |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 31 | /** |
| 32 | * \brief Holds SPM db fields that define the memory regions used by a |
| 33 | * partition. |
| 34 | */ |
| 35 | struct tfm_spm_partition_memory_data_t |
| 36 | { |
| 37 | uint32_t code_start; /*!< Start of the code memory of this partition. */ |
| 38 | uint32_t code_limit; /*!< Address of the byte beyond the end of the code |
| 39 | * memory of this partition. |
| 40 | */ |
| 41 | uint32_t ro_start; /*!< Start of the read only memory of this |
| 42 | * partition. |
| 43 | */ |
| 44 | uint32_t ro_limit; /*!< Address of the byte beyond the end of the read |
| 45 | * only memory of this partition. |
| 46 | */ |
| 47 | uint32_t rw_start; /*!< Start of the data region of this partition. */ |
| 48 | uint32_t rw_limit; /*!< Address of the byte beyond the end of the data |
| 49 | * region of this partition. |
| 50 | */ |
| 51 | uint32_t zi_start; /*!< Start of the zero initialised data region of |
| 52 | * this partition. |
| 53 | */ |
| 54 | uint32_t zi_limit; /*!< Address of the byte beyond the end of the zero |
| 55 | * initialised region of this partition. |
| 56 | */ |
| 57 | uint32_t stack_bottom; /*!< The bottom of the stack for the partition. */ |
| 58 | uint32_t stack_top; /*!< The top of the stack for the partition. */ |
| 59 | }; |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * \brief This function initialises the HW used for isolation, and sets the |
| 63 | * default configuration for them. |
| 64 | * |
| 65 | * This function is called during TF-M core early startup, before DB init |
| 66 | */ |
| 67 | void tfm_spm_hal_init_isolation_hw(void); |
| 68 | |
| 69 | /** |
| 70 | * \brief This function initialises the HW used for isolation, and sets the |
| 71 | * default configuration for them. |
| 72 | * This function is called during TF-M core early startup, after DB init |
| 73 | */ |
| 74 | void tfm_spm_hal_setup_isolation_hw(void); |
| 75 | |
| 76 | /** |
| 77 | * \brief Configure peripherals for a partition based on the platfotm data from |
| 78 | * the DB |
| 79 | * |
| 80 | * This function is called during partition initialisation (before calling the |
| 81 | * init function for the partition) |
| 82 | * |
| 83 | * \param[in] platform_data The platform fields of the partition DB record to |
| 84 | * be used for configuration. Can be NULL. |
| 85 | */ |
| 86 | void tfm_spm_hal_configure_default_isolation( |
| 87 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 88 | /** |
| 89 | * \brief Configures the system debug properties. |
| 90 | * The default configuration of this function should disable secure debug |
| 91 | * when either DAUTH_NONE or DAUTH_NS_ONLY define is set. It is up to the |
| 92 | * platform owner to decide if secure debug can be turned on in their |
| 93 | * system, if DAUTH_FULL define is present. |
| 94 | * The DAUTH_CHIP_DEFAULT define should not be considered a safe default |
| 95 | * option unless explicitly noted by the chip vendor. |
| 96 | * The implementation has to expect that one of those defines is going to |
| 97 | * be set. Otherwise, a compile error needs to be triggered. |
| 98 | */ |
| 99 | void tfm_spm_hal_init_debug(void); |
| 100 | |
| 101 | /** |
| 102 | * \brief Enables the fault handlers |
| 103 | */ |
| 104 | void enable_fault_handlers(void); |
| 105 | |
| 106 | /** |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 107 | * \brief Configures the system reset request properties |
| 108 | */ |
| 109 | void system_reset_cfg(void); |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 110 | |
Marc Moreno Berengue | 8e0fa7a | 2018-10-04 18:25:13 +0100 | [diff] [blame] | 111 | /** |
Edison Ai | 1c266ae | 2019-03-20 11:21:21 +0800 | [diff] [blame] | 112 | * \brief Configures all external interrupts to target the |
| 113 | * NS state, apart for the ones associated to secure |
| 114 | * peripherals (plus MPC and PPC) |
| 115 | */ |
| 116 | void nvic_interrupt_target_state_cfg(void); |
| 117 | |
| 118 | /** |
| 119 | * \brief This function enable the interrupts associated |
| 120 | * to the secure peripherals (plus the isolation boundary violation |
| 121 | * interrupts) |
| 122 | */ |
| 123 | void nvic_interrupt_enable(void); |
| 124 | |
| 125 | /** |
| 126 | * \brief Get the VTOR value of non-secure image |
| 127 | * |
| 128 | * \return Returns the address where the vector table of the non-secure image |
| 129 | * is located |
| 130 | */ |
| 131 | uint32_t tfm_spm_hal_get_ns_VTOR(void); |
| 132 | |
| 133 | /** |
| 134 | * \brief Get the initial address of non-secure image main stack |
| 135 | * |
| 136 | * \return Returns the initial non-secure MSP |
| 137 | */ |
| 138 | uint32_t tfm_spm_hal_get_ns_MSP(void); |
| 139 | |
| 140 | /** |
| 141 | * \brief Get the entry point of the non-secure image |
| 142 | * |
| 143 | * \return Returns the address of the non-secure image entry point |
| 144 | */ |
| 145 | uint32_t tfm_spm_hal_get_ns_entry_point(void); |
| 146 | |
| 147 | |
| 148 | #if TFM_LVL != 1 |
| 149 | /** |
| 150 | * \brief Configure the sandbox for a partition. |
| 151 | * |
| 152 | * \param[in] memory_data The memory ranges from the partition DB for this |
| 153 | * partition |
| 154 | * \param[in] platform_data The platform fields of the partition DB record |
| 155 | * for this partition. Can be NULL. |
| 156 | * |
| 157 | * \return Returns the result operation as per \ref spm_err_t |
| 158 | */ |
| 159 | enum spm_err_t tfm_spm_hal_partition_sandbox_config( |
| 160 | const struct tfm_spm_partition_memory_data_t *memory_data, |
| 161 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 162 | |
| 163 | /** |
| 164 | * \brief Deconfigure the sandbox for a partition. |
| 165 | * |
| 166 | * \param[in] memory_data The memory ranges from the partition DB for this |
| 167 | * partition |
| 168 | * \param[in] platform_data The platform fields of the partition DB record |
| 169 | * for this partition. Can be NULL. |
| 170 | * |
| 171 | * \return Returns the result operation as per \ref spm_err_t |
| 172 | */ |
| 173 | enum spm_err_t tfm_spm_hal_partition_sandbox_deconfig( |
| 174 | const struct tfm_spm_partition_memory_data_t *memory_data, |
| 175 | const struct tfm_spm_partition_platform_data_t *platform_data); |
| 176 | |
| 177 | /** |
| 178 | * \brief Set the share region mode |
| 179 | * |
| 180 | * \param[in] share The mode to set |
| 181 | * |
| 182 | * \return Returns the result operation as per \ref spm_err_t |
| 183 | */ |
| 184 | enum spm_err_t tfm_spm_hal_set_share_region( |
| 185 | enum tfm_buffer_share_region_e share); |
| 186 | #endif |
| 187 | |
| 188 | #endif /* __TFM_SPM_HAL_H__ */ |