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