Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 1 | /* |
Kevin Peng | 1de1e7a | 2022-06-07 17:38:01 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2022, Arm Limited. All rights reserved. |
Chris Brand | de8a13e | 2022-05-25 09:45:26 -0700 | [diff] [blame] | 3 | * Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company) |
| 4 | * or an affiliate of Cypress Semiconductor Corporation. All rights reserved. |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 5 | * |
| 6 | * SPDX-License-Identifier: BSD-3-Clause |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #ifndef __TFM_SECURE_API_H__ |
| 11 | #define __TFM_SECURE_API_H__ |
| 12 | |
Chris Brand | ca81902 | 2022-07-19 09:25:15 -0700 | [diff] [blame^] | 13 | #ifdef CONFIG_TFM_USE_TRUSTZONE |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 14 | #include <arm_cmse.h> |
David Hu | d0d2195 | 2019-09-23 20:35:43 +0800 | [diff] [blame] | 15 | #endif |
David Hu | 50711e3 | 2019-06-12 18:32:30 +0800 | [diff] [blame] | 16 | #include "tfm_arch.h" |
Miklos Balint | ace4c3f | 2018-07-30 12:31:15 +0200 | [diff] [blame] | 17 | #include "tfm_api.h" |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 18 | #include "utilities.h" |
Mingyang Sun | 67a1c0e | 2020-06-04 17:18:16 +0800 | [diff] [blame] | 19 | #include "tfm_boot_status.h" |
Jamie Fox | cc31d40 | 2019-01-28 17:13:52 +0000 | [diff] [blame] | 20 | #include "psa/service.h" |
Kevin Peng | fc7b771 | 2021-05-08 13:42:56 +0800 | [diff] [blame] | 21 | #ifdef TFM_PSA_API |
| 22 | #include "svc_num.h" |
| 23 | #else |
| 24 | #include "tfm_core_svc.h" |
| 25 | #endif /* TFM_PSA_API */ |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 26 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 27 | /* Hide specific errors if not debugging */ |
| 28 | #ifdef TFM_CORE_DEBUG |
| 29 | #define TFM_ERROR_STATUS(status) (status) |
| 30 | #else |
Mate Toth-Pal | 7de74b5 | 2018-02-23 15:46:47 +0100 | [diff] [blame] | 31 | #define TFM_ERROR_STATUS(status) (TFM_PARTITION_BUSY) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 32 | #endif |
| 33 | |
| 34 | #ifndef TFM_LVL |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 35 | #error TFM_LVL is not defined! |
| 36 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 37 | |
Summer Qin | 5fdcf63 | 2020-06-22 16:49:24 +0800 | [diff] [blame] | 38 | #ifndef TFM_PSA_API |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 39 | extern void tfm_secure_api_error_handler(void); |
| 40 | |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 41 | typedef int32_t(*sfn_t)(int32_t, int32_t, int32_t, int32_t); |
| 42 | |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 43 | struct tfm_sfn_req_s { |
Miklos Balint | 6a139ae | 2018-04-04 19:44:37 +0200 | [diff] [blame] | 44 | uint32_t sp_id; |
| 45 | sfn_t sfn; |
| 46 | int32_t *args; |
Miklos Balint | 1fdb12f | 2018-09-11 11:30:30 +0200 | [diff] [blame] | 47 | uint32_t caller_part_idx; |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 48 | bool ns_caller; |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Antonio de Angelis | 5b64bb7 | 2021-04-27 08:37:14 +0100 | [diff] [blame] | 51 | enum tfm_status_e tfm_core_get_caller_client_id(int32_t *caller_client_id); |
Mate Toth-Pal | 21a74c9 | 2018-04-13 14:05:41 +0200 | [diff] [blame] | 52 | |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 53 | 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] | 54 | |
Mingyang Sun | abb1aab | 2020-02-18 13:49:08 +0800 | [diff] [blame] | 55 | 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] | 56 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 57 | #define TFM_CORE_IOVEC_SFN_REQUEST(id, is_ns, fn, a, b, c, d) \ |
| 58 | return tfm_core_partition_request(id, is_ns, fn, \ |
Mate Toth-Pal | b8ce0dd | 2018-07-25 10:18:34 +0200 | [diff] [blame] | 59 | (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d) |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 60 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 61 | int32_t tfm_core_partition_request(uint32_t id, bool is_ns, void *fn, |
| 62 | int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4); |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 63 | |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 64 | __attribute__ ((always_inline)) __STATIC_INLINE |
| 65 | bool tfm_core_is_ns_client(void) |
| 66 | { |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 67 | /* |
| 68 | * This preprocessor condition checks if a version of GCC smaller than |
| 69 | * 7.3.1 is being used to compile the code. |
| 70 | * These versions are affected by a bug on the cmse_nonsecure_caller |
| 71 | * intrinsic which returns incorrect results. |
| 72 | * Please check Bug 85203 on GCC Bugzilla for more information. |
| 73 | */ |
| 74 | #if defined(__GNUC__) && !defined(__ARMCC_VERSION) && \ |
| 75 | (__GNUC__ < 7 || \ |
| 76 | (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || \ |
| 77 | (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ < 1)))) |
| 78 | /* |
| 79 | * Use the fact that, if called from Non-Secure, the LSB of the return |
| 80 | * address is set to 0. |
| 81 | */ |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 82 | return !( |
| 83 | (uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0U)) |
| 84 | & 0x1); |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 85 | #else |
| 86 | /* |
Summer Qin | 43c185d | 2019-10-10 15:44:42 +0800 | [diff] [blame] | 87 | * 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] | 88 | * to prevent using an int in the tfm_sfn_req_s structure. |
| 89 | */ |
David Hu | 8d1f107 | 2020-04-30 12:52:14 +0800 | [diff] [blame] | 90 | return (cmse_nonsecure_caller() != 0) ? true : false; |
Hugues de Valon | 4bf875b | 2019-02-19 14:53:49 +0000 | [diff] [blame] | 91 | #endif /* Check for GCC compiler version smaller than 7.3.1 */ |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 92 | } |
Miklos Balint | dd02bb3 | 2019-05-26 21:13:12 +0200 | [diff] [blame] | 93 | #endif |
Miklos Balint | 386b8b5 | 2017-11-29 13:12:32 +0000 | [diff] [blame] | 94 | |
| 95 | #endif /* __TFM_SECURE_API_H__ */ |