Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Jamie Fox | d4c3c74 | 2020-02-17 16:08:40 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020, Arm Limited. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef __TFM_SECURE_API_H__ |
| 9 | #define __TFM_SECURE_API_H__ |
| 10 | |
David Hu | d0d2195 | 2019-09-23 20:35:43 +0800 | [diff] [blame] | 11 | #ifndef TFM_MULTI_CORE_TOPOLOGY |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 12 | #include <arm_cmse.h> |
David Hu | d0d2195 | 2019-09-23 20:35:43 +0800 | [diff] [blame] | 13 | #endif |
David Hu | 50711e3 | 2019-06-12 18:32:30 +0800 | [diff] [blame] | 14 | #include "tfm_arch.h" |
Ken Liu | 1f345b0 | 2020-05-30 21:11:05 +0800 | [diff] [blame] | 15 | #include "tfm/tfm_core_svc.h" |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 16 | #include "tfm_api.h" |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 17 | #include "utilities.h" |
Mingyang Sun | 67a1c0e | 2020-06-04 17:18:16 +0800 | [diff] [blame] | 18 | #include "tfm_boot_status.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 19 | #include "psa/service.h" |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 20 | |
David Hu | d0d2195 | 2019-09-23 20:35:43 +0800 | [diff] [blame] | 21 | #ifndef TFM_MULTI_CORE_TOPOLOGY |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 22 | #ifndef TFM_PSA_API |
Antonio de Angelis | eba14e1 | 2018-03-27 11:03:20 +0100 | [diff] [blame] | 23 | /*! |
| 24 | * \def __tfm_secure_gateway_attributes__ |
| 25 | * |
| 26 | * \brief Attributes for secure gateway functions |
| 27 | */ |
David Hu | 94d424a | 2020-04-29 15:49:24 +0800 | [diff] [blame] | 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 | */ |
Antonio de Angelis | eba14e1 | 2018-03-27 11:03:20 +0100 | [diff] [blame] | 33 | #define __tfm_secure_gateway_attributes__ \ |
David Hu | 94d424a | 2020-04-29 15:49:24 +0800 | [diff] [blame] | 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 */ |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 39 | #endif /* !TFM_PSA_API */ |
Summer Qin | 483da64 | 2019-09-25 17:57:41 +0800 | [diff] [blame] | 40 | |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 41 | #ifdef TFM_PSA_API |
Summer Qin | 483da64 | 2019-09-25 17:57:41 +0800 | [diff] [blame] | 42 | /*! |
| 43 | * \def __tfm_psa_secure_gateway_attributes__ |
| 44 | * |
| 45 | * \brief Attributes for psa api secure gateway functions |
| 46 | */ |
David Hu | 94d424a | 2020-04-29 15:49:24 +0800 | [diff] [blame] | 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 | */ |
Summer Qin | 483da64 | 2019-09-25 17:57:41 +0800 | [diff] [blame] | 52 | #define __tfm_psa_secure_gateway_attributes__ \ |
David Hu | 94d424a | 2020-04-29 15:49:24 +0800 | [diff] [blame] | 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 */ |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 58 | #endif /* TFM_PSA_API */ |
David Hu | 94d424a | 2020-04-29 15:49:24 +0800 | [diff] [blame] | 59 | #endif /* TFM_MULTI_CORE_TOPOLOGY */ |
Antonio de Angelis | eba14e1 | 2018-03-27 11:03:20 +0100 | [diff] [blame] | 60 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 61 | /* Hide specific errors if not debugging */ |
| 62 | #ifdef TFM_CORE_DEBUG |
| 63 | #define TFM_ERROR_STATUS(status) (status) |
| 64 | #else |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 65 | #define TFM_ERROR_STATUS(status) (TFM_PARTITION_BUSY) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 66 | #endif |
| 67 | |
| 68 | #ifndef TFM_LVL |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 69 | #error TFM_LVL is not defined! |
| 70 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 71 | |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 72 | #ifndef TFM_PSA_API |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 73 | extern void tfm_secure_api_error_handler(void); |
| 74 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 75 | typedef int32_t(*sfn_t)(int32_t, int32_t, int32_t, int32_t); |
| 76 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 77 | struct tfm_sfn_req_s { |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 78 | uint32_t sp_id; |
| 79 | sfn_t sfn; |
| 80 | int32_t *args; |
Miklos Balint | 1fdb12f | 2018-09-11 11:30:30 +0200 | [diff] [blame] | 81 | uint32_t caller_part_idx; |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 82 | bool ns_caller; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 83 | }; |
| 84 | |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 85 | extern int32_t tfm_core_get_caller_client_id(int32_t *caller_client_id); |
| 86 | |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 87 | int32_t tfm_core_sfn_request(const struct tfm_sfn_req_s *desc_ptr); |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 88 | |
Mingyang Sun | abb1aab | 2020-02-18 13:49:08 +0800 | [diff] [blame] | 89 | int32_t tfm_spm_sfn_request_thread_mode(struct tfm_sfn_req_s *desc_ptr); |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 90 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 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, \ |
Mate Toth-Pal | b8ce0dd | 2018-07-25 10:18:34 +0200 | [diff] [blame] | 93 | (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 94 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 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); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 97 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 98 | __attribute__ ((always_inline)) __STATIC_INLINE |
| 99 | bool tfm_core_is_ns_client(void) |
| 100 | { |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 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 | */ |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 116 | return !( |
| 117 | (uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0U)) |
| 118 | & 0x1); |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 119 | #else |
| 120 | /* |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 121 | * Convert the result of cmse_nonsecure_caller from an int to a bool |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 122 | * to prevent using an int in the tfm_sfn_req_s structure. |
| 123 | */ |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 124 | return (cmse_nonsecure_caller() != 0) ? true : false; |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 125 | #endif /* Check for GCC compiler version smaller than 7.3.1 */ |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 126 | } |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 127 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 128 | |
| 129 | #endif /* __TFM_SECURE_API_H__ */ |