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> |
| 13 | #include "tfm_hal_defs.h" |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 14 | #include "load/partition_defs.h" |
| 15 | #include "load/asset_defs.h" |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /* Memory access attributes */ |
| 22 | #define TFM_HAL_ACCESS_EXECUTABLE (1UL << 0) |
| 23 | #define TFM_HAL_ACCESS_READABLE (1UL << 1) |
| 24 | #define TFM_HAL_ACCESS_WRITABLE (1UL << 2) |
| 25 | #define TFM_HAL_ACCESS_UNPRIVILEGED (1UL << 3) |
| 26 | #define TFM_HAL_ACCESS_DEVICE (1UL << 4) |
| 27 | #define TFM_HAL_ACCESS_NS (1UL << 5) |
| 28 | |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame^] | 29 | #define TFM_HAL_ACCESS_READWRITE \ |
| 30 | (TFM_HAL_ACCESS_READABLE | TFM_HAL_ACCESS_WRITABLE) |
| 31 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 32 | #ifdef TFM_FIH_PROFILE_ON |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 33 | #include "fih.h" |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 34 | /** |
| 35 | * \brief Sets up the static isolation boundaries which are constant throughout |
| 36 | * the runtime of the system, including the SPE/NSPE and partition |
| 37 | * boundaries. |
| 38 | * |
| 39 | * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up. |
| 40 | * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries. |
| 41 | */ |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 42 | fih_int tfm_hal_set_up_static_boundaries(void); |
| 43 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 44 | /** |
Kevin Peng | 38788a1 | 2021-09-08 16:23:50 +0800 | [diff] [blame] | 45 | * \brief This function is responsible for checking all critical isolation |
| 46 | configurations. |
| 47 | * |
| 48 | * \return TFM_HAL_SUCCESS - the verification passed. |
| 49 | * TFM_HAL_ERROR_GENERIC - the verification failed. |
| 50 | */ |
| 51 | fih_int tfm_hal_verify_static_boundaries(void); |
| 52 | |
| 53 | /** |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 54 | * \brief Activate one Secure Partition boundary. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 55 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 56 | * \param[in] p_ldinf Partition load information. |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 57 | * \param[in] boundary Platform boundary value for partition. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 58 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 59 | * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded. |
| 60 | * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 61 | * |
| 62 | * \note When FIH_ENABLE_DOUBLE_VARS is enabled, the return code will be |
| 63 | * wrapped and protected in \ref fih_int structure. |
| 64 | */ |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 65 | fih_int tfm_hal_activate_boundary(const struct partition_load_info_t *p_ldinf, |
| 66 | uintptr_t boundary); |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 67 | #else /* TFM_FIH_PROFILE_ON */ |
| 68 | /** |
| 69 | * \brief Sets up the static isolation boundaries which are constant throughout |
| 70 | * the runtime of the system, including the SPE/NSPE and partition |
| 71 | * boundaries. |
| 72 | * |
| 73 | * \return TFM_HAL_SUCCESS - the isolation boundaries have been set up. |
| 74 | * TFM_HAL_ERROR_GENERIC - failed to set up the isolation boundaries. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 75 | */ |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 76 | enum tfm_hal_status_t tfm_hal_set_up_static_boundaries(void); |
| 77 | |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 78 | /** |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 79 | * \brief Activate one Secure Partition boundary. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 80 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 81 | * \param[in] p_ldinf Partition load information. |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 82 | * \param[in] boundary Platform boundary value for partition. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 83 | * |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 84 | * \return TFM_HAL_SUCCESS The isolation boundaries update succeeded. |
| 85 | * TFM_HAL_ERROR_GENERIC Failed to update the isolation boundaries. |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 86 | */ |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 87 | enum tfm_hal_status_t tfm_hal_activate_boundary( |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 88 | const struct partition_load_info_t *p_ldinf, |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 89 | uintptr_t boundary); |
Tamas Ban | d28286e | 2020-11-27 12:58:39 +0000 | [diff] [blame] | 90 | #endif /* TFM_FIH_PROFILE_ON */ |
| 91 | |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 92 | /** |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame^] | 93 | * \brief This API checks if a given range of memory can be accessed with |
| 94 | * specified access types in boundary. The boundary belongs to |
| 95 | * a partition which contains all asset info. |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 96 | * |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame^] | 97 | * \param[in] boundary The boundary that the given memory is to be |
| 98 | * checked with. |
| 99 | * \param[in] base The base address of the region. |
| 100 | * \param[in] size The size of the region. |
| 101 | * \param[in] access_type The memory access types to be checked between |
| 102 | * given memory and boundaries. |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 103 | * |
| 104 | * \return TFM_HAL_SUCCESS - The memory region has the access permissions. |
| 105 | * TFM_HAL_ERROR_MEM_FAULT - The memory region has not the access |
| 106 | * permissions. |
| 107 | * TFM_HAL_ERROR_INVALID_INPUT - Invalid inputs. |
| 108 | * TFM_HAL_ERROR_GENERIC - An error occurred. |
| 109 | */ |
Summer Qin | 56725eb | 2022-05-06 15:23:40 +0800 | [diff] [blame^] | 110 | enum tfm_hal_status_t tfm_hal_memory_check(uintptr_t boundary, uintptr_t base, |
| 111 | size_t size, uint32_t access_type); |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 112 | |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 113 | /** |
| 114 | * \brief This API binds partition boundaries with the platform. The platform |
| 115 | * maintains the platform-specific settings for SPM further |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 116 | * usage, such as update partition boundaries or |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 117 | * check resource accessibility. The platform needs to manage |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 118 | * the settings with internal mechanism, and return a value |
| 119 | * to SPM. SPM delivers this value back to platform when |
| 120 | * necessary. And SPM checks this value to decide if the |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 121 | * platform-specific settings need to be updated. Hence |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 122 | * multiple partitions can have the same value if they have |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 123 | * the same platform-specific settings, depending on isolation level. |
| 124 | * |
| 125 | * \param[in] p_ldinf Partition load information. |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 126 | * \param[in] p_boundary Pointer of the boundary value |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 127 | * |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 128 | * \return TFM_HAL_SUCCESS - A platform value bound successfully. |
| 129 | * TFM_HAL_ERROR_GENERIC - Error occurred while binding. |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 130 | */ |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 131 | enum tfm_hal_status_t tfm_hal_bind_boundary( |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 132 | const struct partition_load_info_t *p_ldinf, |
Ken Liu | 967ffa9 | 2022-05-25 15:13:34 +0800 | [diff] [blame] | 133 | uintptr_t *p_boundary); |
Ken Liu | ce58bfc | 2021-05-12 17:54:48 +0800 | [diff] [blame] | 134 | |
Kevin Peng | 93fb9f5 | 2020-09-17 11:45:54 +0800 | [diff] [blame] | 135 | #ifdef __cplusplus |
| 136 | } |
| 137 | #endif |
| 138 | |
| 139 | #endif /* __TFM_HAL_ISOLATION_H__ */ |