Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 1 | /* |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 2 | * Copyright (c) 2020-2022, Arm Limited. All rights reserved. |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_HAL_ISOLATION_H__ |
| 9 | #define __TFM_HAL_ISOLATION_H__ |
| 10 | |
| 11 | #include <stddef.h> |
| 12 | #include <stdint.h> |
Chendi Sun | 0f7d282 | 2022-10-28 12:24:12 +0800 | [diff] [blame] | 13 | #include <stdbool.h> |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 14 | #include "fih.h" |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 15 | #include "tfm_hal_defs.h" |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 16 | #include "load/partition_defs.h" |
| 17 | #include "load/asset_defs.h" |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | /* Memory access attributes */ |
| 24 | #define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0) |
| 25 | #define TFM_HAL_ACCESS_READABLE (1UL << 1) |
| 26 | #define TFM_HAL_ACCESS_WRITABLE (1UL << 2) |
| 27 | #define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3) |
| 28 | #define TFM_HAL_ACCESS_DEVICE (1UL << 4) |
| 29 | #define TFM_HAL_ACCESS_NS (1UL << 5) |
| 30 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 31 | #define TFM_HAL_ACCESS_READWRITE \ |
| 32 | (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE) |
| 33 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 34 | #ifdef TFM_FIH_PROFILE_ON |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 35 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 36 | /** |
Kevin Peng | 38788a1 | 2021-09-08 16:23:50 +0800 | [diff] [blame] | 37 | * \brief This function is responsible for checking all critical isolation |
| 38 | configurations. |
| 39 | * |
| 40 | * \return TFM_HAL_SUCCESS - the verification passed. |
| 41 | * TFM_HAL_ERROR_GENERIC - the verification failed. |
| 42 | */ |
| 43 | fih_int tfm_hal_verify_static_boundaries(void); |
| 44 | |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 45 | #endif /* TFM_FIH_PROFILE_ON */ |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 46 | /** |
| 47 | * \brief Sets up the static isolation boundaries which are constant throughout |
| 48 | * the runtime of the system, including the SPE/NSPE and partition |
| 49 | * boundaries. |
| 50 | * |
Chendi Sun | 0f7d282 | 2022-10-28 12:24:12 +0800 | [diff] [blame] | 51 | * \param[out] p_spm_boundary Pointer of the boundary value |
| 52 | * |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 53 | * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up. |
| 54 | * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 55 | */ |
Chendi Sun | 0f7d282 | 2022-10-28 12:24:12 +0800 | [diff] [blame] | 56 | FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_set_up_static_boundaries( |
| 57 | uintptr_t *p_spm_boundary); |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 58 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 59 | /** |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 60 | * \brief Activate one Secure Partition boundary. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 61 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 62 | * \param[in] p_ldinf Partition load information. |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 63 | * \param[in] boundary Platform boundary value for partition. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 64 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 65 | * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded. |
| 66 | * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 67 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 68 | FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_activate_boundary( |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 69 | const struct partition_load_info_t *p_ldinf, |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 70 | uintptr_t boundary); |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 71 | |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 72 | /** |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 73 | * \brief This API checks if a given range of memory can be accessed with |
| 74 | * specified access types in boundary. The boundary belongs to |
| 75 | * a partition which contains all asset info. |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 76 | * |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 77 | * \param[in] boundary The boundary that the given memory is to be |
| 78 | * checked with. |
| 79 | * \param[in] base The base address of the region. |
| 80 | * \param[in] size The size of the region. |
| 81 | * \param[in] access_type The memory access types to be checked between |
| 82 | * given memory and boundaries. |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 83 | * |
| 84 | * \return TFM_HAL_SUCCESS - The memory region has the access permissions. |
| 85 | * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access |
| 86 | * permissions. |
| 87 | * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs. |
| 88 | * TFM_HAL_ERROR_GENERIC - An error occurred. |
| 89 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 90 | FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_memory_check( |
| 91 | uintptr_t boundary, uintptr_t base, |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame] | 92 | size_t size, uint32_t access_type); |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 93 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 94 | /** |
| 95 | * \brief This API binds partition boundaries with the platform. The platform |
| 96 | * maintains the platform-specific settings for SPM further |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 97 | * usage, such as update partition boundaries or |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 98 | * check resource accessibility. The platform needs to manage |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 99 | * the settings with internal mechanism, and return a value |
| 100 | * to SPM. SPM delivers this value back to platform when |
| 101 | * necessary. And SPM checks this value to decide if the |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 102 | * platform-specific settings need to be updated. Hence |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 103 | * multiple partitions can have the same value if they have |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 104 | * the same platform-specific settings, depending on isolation level. |
| 105 | * |
| 106 | * \param[in] p_ldinf Partition load information. |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 107 | * \param[in] p_boundary Pointer of the boundary value |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 108 | * |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 109 | * \return TFM_HAL_SUCCESS - A platform value bound successfully. |
| 110 | * TFM_HAL_ERROR_GENERIC - Error occurred while binding. |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 111 | */ |
Xinyu Zhang | 6ad0703 | 2022-08-10 14:45:56 +0800 | [diff] [blame] | 112 | FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_bind_boundary( |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 113 | const struct partition_load_info_t *p_ldinf, |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 114 | uintptr_t *p_boundary); |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 115 | |
Chendi Sun | 0f7d282 | 2022-10-28 12:24:12 +0800 | [diff] [blame] | 116 | /** |
| 117 | * \brief This API let the platform decide if a boundary switch is needed. |
| 118 | * |
| 119 | * \param[in] boundary_from The current boundary to be switched. |
| 120 | * \param[in] boundary_to The target boundary to be switched to. |
| 121 | * |
| 122 | * \return true - a switching is needed. |
| 123 | * false - do not need a switch. |
| 124 | */ |
Chris Brand | 272317e | 2024-04-05 15:29:32 -0700 | [diff] [blame] | 125 | FIH_RET_TYPE(bool) tfm_hal_boundary_need_switch(uintptr_t boundary_from, |
| 126 | uintptr_t boundary_to); |
Chendi Sun | 0f7d282 | 2022-10-28 12:24:12 +0800 | [diff] [blame] | 127 | |
Roman Mazurak | 96585b8 | 2024-04-03 14:35:00 +0300 | [diff] [blame^] | 128 | #if CONFIG_TFM_POST_PARTITION_INIT_HOOK == 1 |
| 129 | /** |
| 130 | * \brief This API let the platform to finish static isolation after all partitions |
| 131 | * have been bound. |
| 132 | * |
| 133 | * It's called by SPM right before starting scheduler. |
| 134 | * |
| 135 | * \return TFM_HAL_SUCCESS - Booting has been successful. |
| 136 | * TFM_HAL_ERROR_GENERIC - Error occurred. |
| 137 | */ |
| 138 | FIH_RET_TYPE(enum tfm_hal_status_t) tfm_hal_post_partition_init_hook(void); |
| 139 | #endif /* CONFIG_TFM_POST_PARTITION_INIT_HOOK == 1 */ |
| 140 | |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 141 | #ifdef __cplusplus |
| 142 | } |
| 143 | #endif |
| 144 | |
| 145 | #endif /* __TFM_HAL_ISOLATION_H__ */ |