TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tfm_secure_api.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2020, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef __TFM_SECURE_API_H__
9 #define __TFM_SECURE_API_H__
10 
11 #ifndef TFM_MULTI_CORE_TOPOLOGY
12 #include <arm_cmse.h>
13 #endif
14 #include "tfm_arch.h"
15 #include "tfm/tfm_core_svc.h"
16 #include "tfm_api.h"
17 #include "utilities.h"
18 #include "tfm_boot_status.h"
19 #include "psa/service.h"
20 
21 #ifndef TFM_MULTI_CORE_TOPOLOGY
22 #ifndef TFM_PSA_API
23 
28 #if defined(__GNUC__) && !defined(__ARMCC_VERSION)
29 /*
30  * GNUARM requires noclone attribute to protect gateway function symbol from
31  * being renamed and cloned
32  */
33 #define __tfm_secure_gateway_attributes__ \
34  __attribute__((cmse_nonsecure_entry, noclone, section("SFN")))
35 #else
36 #define __tfm_secure_gateway_attributes__ \
37  __attribute__((cmse_nonsecure_entry, section("SFN")))
38 #endif /* __GNUC__ && !__ARMCC_VERSION */
39 #endif /* !TFM_PSA_API */
40 
41 #ifdef TFM_PSA_API
42 
47 #if defined(__GNUC__) && !defined(__ARMCC_VERSION)
48 /*
49  * GNUARM requires noclone attribute to protect gateway function symbol from
50  * being renamed and cloned
51  */
52 #define __tfm_psa_secure_gateway_attributes__ \
53  __attribute__((cmse_nonsecure_entry, noclone, naked, section("SFN")))
54 #else
55 #define __tfm_psa_secure_gateway_attributes__ \
56  __attribute__((cmse_nonsecure_entry, naked, section("SFN")))
57 #endif /* __GNUC__ && !__ARMCC_VERSION */
58 #endif /* TFM_PSA_API */
59 #endif /* TFM_MULTI_CORE_TOPOLOGY */
60 
61 /* Hide specific errors if not debugging */
62 #ifdef TFM_CORE_DEBUG
63 #define TFM_ERROR_STATUS(status) (status)
64 #else
65 #define TFM_ERROR_STATUS(status) (TFM_PARTITION_BUSY)
66 #endif
67 
68 #ifndef TFM_LVL
69 #error TFM_LVL is not defined!
70 #endif
71 
72 #ifndef TFM_PSA_API
73 extern void tfm_secure_api_error_handler(void);
74 
75 typedef int32_t(*sfn_t)(int32_t, int32_t, int32_t, int32_t);
76 
77 struct tfm_sfn_req_s {
78  uint32_t sp_id;
80  int32_t *args;
81  uint32_t caller_part_idx;
82  bool ns_caller;
83 };
84 
85 extern int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id);
86 
87 int32_t tfm_core_sfn_request(const struct tfm_sfn_req_s *desc_ptr);
88 
89 int32_t tfm_spm_sfn_request_thread_mode(struct tfm_sfn_req_s *desc_ptr);
90 
91 #define TFM_CORE_IOVEC_SFN_REQUEST(id, is_ns, fn, a, b, c, d) \
92  return tfm_core_partition_request(id, is_ns, fn, \
93  (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d)
94 
95 int32_t tfm_core_partition_request(uint32_t id, bool is_ns, void *fn,
96  int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4);
97 
98 __attribute__ ((always_inline)) __STATIC_INLINE
100 {
101  /*
102  * This preprocessor condition checks if a version of GCC smaller than
103  * 7.3.1 is being used to compile the code.
104  * These versions are affected by a bug on the cmse_nonsecure_caller
105  * intrinsic which returns incorrect results.
106  * Please check Bug 85203 on GCC Bugzilla for more information.
107  */
108 #if defined(__GNUC__) && !defined(__ARMCC_VERSION) && \
109  (__GNUC__ < 7 || \
110  (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || \
111  (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ < 1))))
112  /*
113  * Use the fact that, if called from Non-Secure, the LSB of the return
114  * address is set to 0.
115  */
116  return !(
117  (uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0U))
118  & 0x1);
119 #else
120  /*
121  * Convert the result of cmse_nonsecure_caller from an int to a bool
122  * to prevent using an int in the tfm_sfn_req_s structure.
123  */
124  return (cmse_nonsecure_caller() != 0) ? true : false;
125 #endif /* Check for GCC compiler version smaller than 7.3.1 */
126 }
127 #endif
128 
129 #endif /* __TFM_SECURE_API_H__ */
uint32_t sp_id
int32_t tfm_core_partition_request(uint32_t id, bool is_ns, void *fn, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4)
int32_t(* sfn_t)(int32_t, int32_t, int32_t, int32_t)
int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id)
Definition: arch.c:28
int32_t tfm_core_sfn_request(const struct tfm_sfn_req_s *desc_ptr)
void tfm_secure_api_error_handler(void)
__STATIC_INLINE bool tfm_core_is_ns_client(void)
int32_t * args
uint32_t caller_part_idx
int32_t tfm_spm_sfn_request_thread_mode(struct tfm_sfn_req_s *desc_ptr)
Definition: spm_func.c:780