8 #ifndef __TFM_SECURE_API_H__ 9 #define __TFM_SECURE_API_H__ 13 #include "secure_utilities.h" 16 #include "bl2/include/tfm_boot_status.h" 23 #define __tfm_secure_gateway_attributes__ \ 24 __attribute__((cmse_nonsecure_entry, noinline, section("SFN"))) 28 #define TFM_ERROR_STATUS(status) (status) 30 #define TFM_ERROR_STATUS(status) (TFM_PARTITION_BUSY) 33 #define TFM_SFN_API_LEGACY 0 34 #define TFM_SFN_API_IOVEC 1 37 #error TFM_LVL is not defined! 40 extern void tfm_secure_api_error_handler(
void);
42 typedef int32_t(*sfn_t)(int32_t, int32_t, int32_t, int32_t);
48 uint32_t caller_part_idx;
53 enum tfm_buffer_share_region_e {
54 TFM_BUFFER_SHARE_DISABLE,
55 TFM_BUFFER_SHARE_NS_CODE,
56 TFM_BUFFER_SHARE_SCRATCH,
57 TFM_BUFFER_SHARE_PRIV,
58 TFM_BUFFER_SHARE_DEFAULT,
61 enum tfm_ns_region_e {
62 TFM_NS_REGION_CODE = 0,
65 TFM_NS_REGION_PERIPH_1,
66 TFM_NS_REGION_PERIPH_2,
67 TFM_NS_SECONDARY_IMAGE_REGION,
70 enum tfm_memory_access_e {
71 TFM_MEMORY_ACCESS_RO = 1,
72 TFM_MEMORY_ACCESS_RW = 2,
75 extern int32_t tfm_core_set_buffer_area(
enum tfm_buffer_share_region_e share);
77 extern int32_t tfm_core_validate_secure_caller(
void);
79 extern int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id);
81 extern int32_t tfm_core_memory_permission_check(
const void *ptr,
85 extern int32_t tfm_core_get_boot_data(uint8_t major_type,
89 int32_t tfm_core_sfn_request(
const struct tfm_sfn_req_s *desc_ptr);
91 int32_t tfm_core_sfn_request_thread_mode(
struct tfm_sfn_req_s *desc_ptr);
109 int32_t tfm_core_has_read_access_to_region(
const void *p,
size_t s,
111 uint32_t privileged);
129 int32_t tfm_core_has_write_access_to_region(
void *p,
size_t s,
131 uint32_t privileged);
137 #define TFM_CORE_IOVEC_SFN_REQUEST(id, fn, a, b, c, d) \ 139 ERROR_MSG("Invalid TF-M configuration detected"); \ 140 tfm_secure_api_error_handler(); \ 142 return (int32_t)TFM_ERROR_GENERIC; \ 144 #define TFM_CORE_SFN_REQUEST(id, fn, a, b, c, d) \ 146 ERROR_MSG("Invalid TF-M configuration detected"); \ 147 tfm_secure_api_error_handler(); \ 149 return (int32_t)TFM_ERROR_GENERIC; \ 152 #define TFM_CORE_IOVEC_SFN_REQUEST(id, fn, a, b, c, d) \ 153 return tfm_core_partition_request(id, fn, TFM_SFN_API_IOVEC, \ 154 (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d) 156 #define TFM_CORE_SFN_REQUEST(id, fn, a, b, c, d) \ 157 return tfm_core_partition_request(id, fn, TFM_SFN_API_LEGACY, \ 158 (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d) 160 __attribute__ ((always_inline)) __STATIC_INLINE
161 int32_t tfm_core_partition_request(uint32_t
id,
void *fn, int32_t iovec_api,
162 int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4)
164 int32_t args[4] = {arg1, arg2, arg3, arg4};
168 desc.sfn = (sfn_t) fn;
177 #if defined(__GNUC__) && !defined(__ARMCC_VERSION) && \ 179 (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || \ 180 (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ < 1)))) 185 desc.ns_caller = (uint32_t)!(
186 (intptr_t)__builtin_extract_return_addr(__builtin_return_address(0U))
193 desc.ns_caller = (cmse_nonsecure_caller() != 0) ? 1U : 0U;
195 desc.iovec_api = iovec_api;
196 if (__get_active_exc_num() != EXC_NUM_THREAD_MODE) {
198 return TFM_ERROR_GENERIC;
201 if (desc.ns_caller) {
202 return tfm_core_sfn_request(desc_ptr);
204 return tfm_core_sfn_request_thread_mode(desc_ptr);
207 return tfm_core_sfn_request(desc_ptr);
Store the data for the runtime SW.