1 /* 2 * Copyright (c) 2019-2022, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __TFM_MULTI_CORE_H__ 9 #define __TFM_MULTI_CORE_H__ 10 11 #include <stdbool.h> 12 13 #include "tfm_api.h" 14 15 /* Follow CMSE flag definitions */ 16 #define MEM_CHECK_MPU_READWRITE (1 << 0x0) 17 #define MEM_CHECK_AU_NONSECURE (1 << 0x1) 18 #define MEM_CHECK_MPU_UNPRIV (1 << 0x2) 19 #define MEM_CHECK_MPU_READ (1 << 0x3) 20 #define MEM_CHECK_MPU_NONSECURE (1 << 0x4) 21 #define MEM_CHECK_NONSECURE (MEM_CHECK_AU_NONSECURE | \ 22 MEM_CHECK_MPU_NONSECURE) 23 24 /* Security attributes of target memory region in memory access check. */ 25 struct security_attr_info_t { 26 bool is_valid; /* Whether the target memory region is valid */ 27 bool is_secure; /* Secure memory or non-secure memory */ 28 }; 29 30 /* Memory access attributes of target memory region in memory access check. */ 31 struct mem_attr_info_t { 32 bool is_mpu_enabled; /* Whether memory protection unit(s) enabled */ 33 bool is_valid; /* Whether the target memory region is valid */ 34 bool is_xn; /* Execute Never or not */ 35 bool is_priv_rd_allow; /* Privileged read is allowed or not */ 36 bool is_priv_wr_allow; /* Privileged write is allowed or not */ 37 bool is_unpriv_rd_allow; /* Unprivileged read is allowed or not */ 38 bool is_unpriv_wr_allow; /* Unprivileged write is allowed or not */ 39 }; 40 41 /** 42 * \brief Retrieve general security isolation configuration information of the 43 * target memory region according to the system memory region layout and 44 * fill the \ref security_attr_info_t. 45 * 46 * \param[in] p Base address of target memory region 47 * \param[in] s Size of target memory region 48 * \param[out] p_attr Address of \ref security_attr_info_t to be filled 49 * 50 * \return void 51 * 52 * \note This function doesn't access any hardware security isolation unit. 53 */ 54 void tfm_get_mem_region_security_attr(const void *p, size_t s, 55 struct security_attr_info_t *p_attr); 56 57 /** 58 * \brief Retrieve general secure memory protection configuration information of 59 * the target memory region according to the system memory region layout 60 * and symbol addresses and fill the \ref mem_attr_info_t. 61 * 62 * \param[in] p Base address of target memory region 63 * \param[in] s Size of target memory region 64 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled 65 * 66 * \return void 67 * 68 * \note This function doesn't access any hardware memory protection unit. 69 * The \ref is_mpu_enabled field is set to false by default. 70 */ 71 void tfm_get_secure_mem_region_attr(const void *p, size_t s, 72 struct mem_attr_info_t *p_attr); 73 74 /** 75 * \brief Retrieve general non-secure memory protection configuration 76 * information of the target memory region according to the system memory 77 * region layout and fill the \ref mem_attr_info_t. 78 * 79 * \param[in] p Base address of target memory region 80 * \param[in] s Size of target memory region 81 * \param[out] p_attr Address of \ref mem_attr_info_t to be filled 82 * 83 * \return void 84 * 85 * \note This function doesn't access any hardware memory protection unit. 86 * The \ref is_mpu_enabled field is set to false by default. 87 */ 88 void tfm_get_ns_mem_region_attr(const void *p, size_t s, 89 struct mem_attr_info_t *p_attr); 90 91 /** 92 * \brief Check whether a memory access is allowed to access to a memory range 93 * 94 * \param[in] p The start address of the range to check 95 * \param[in] s The size of the range to check 96 * \param[in] flags The memory access types to be checked between 97 * given memory and boundaries. 98 * 99 * \return TFM_SUCCESS if the access is allowed, 100 * TFM_ERROR_GENERIC otherwise. 101 */ 102 enum tfm_status_e tfm_has_access_to_region(const void *p, size_t s, 103 uint32_t flags); 104 105 /** 106 * \brief Initialization of the multi core communication. 107 * 108 * \retval 0 Operation succeeded. 109 * \retval Other return code Operation failed with an error code. 110 */ 111 int32_t tfm_inter_core_comm_init(void); 112 113 /** 114 * \brief Check whether a memory range is inside a memory region. 115 * 116 * \param[in] p The start address of the range to check 117 * \param[in] s The size of the range to check 118 * \param[in] region_start The start address of the region, which should 119 * contain the range 120 * \param[in] region_limit The end address of the region, which should contain 121 * the range 122 * 123 * \return TFM_SUCCESS if the region contains the range, 124 * TFM_ERROR_GENERIC otherwise. 125 */ 126 enum tfm_status_e check_address_range(const void *p, size_t s, 127 uintptr_t region_start, 128 uintptr_t region_limit); 129 #endif /* __TFM_MULTI_CORE_H__ */ 130