blob: e299fc3d48f3ad756f2e07283ca1ca54cf15b75d [file] [log] [blame]
Miklos Balint386b8b52017-11-29 13:12:32 +00001/*
Kevin Pengfc7b7712021-05-08 13:42:56 +08002 * Copyright (c) 2017-2021, Arm Limited. All rights reserved.
Chris Brandde8a13e2022-05-25 09:45:26 -07003 * Copyright (c) 2022 Cypress Semiconductor Corporation (an Infineon company)
4 * or an affiliate of Cypress Semiconductor Corporation. All rights reserved.
Miklos Balint386b8b52017-11-29 13:12:32 +00005 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 */
9
10#ifndef __TFM_SECURE_API_H__
11#define __TFM_SECURE_API_H__
12
David Hud0d21952019-09-23 20:35:43 +080013#ifndef TFM_MULTI_CORE_TOPOLOGY
Hugues de Valon4bf875b2019-02-19 14:53:49 +000014#include <arm_cmse.h>
David Hud0d21952019-09-23 20:35:43 +080015#endif
David Hu50711e32019-06-12 18:32:30 +080016#include "tfm_arch.h"
Miklos Balintace4c3f2018-07-30 12:31:15 +020017#include "tfm_api.h"
Summer Qin5fdcf632020-06-22 16:49:24 +080018#include "utilities.h"
Mingyang Sun67a1c0e2020-06-04 17:18:16 +080019#include "tfm_boot_status.h"
Jamie Foxcc31d402019-01-28 17:13:52 +000020#include "psa/service.h"
Kevin Pengfc7b7712021-05-08 13:42:56 +080021#ifdef TFM_PSA_API
22#include "svc_num.h"
23#else
24#include "tfm_core_svc.h"
25#endif /* TFM_PSA_API */
Miklos Balint386b8b52017-11-29 13:12:32 +000026
Summer Qin5fdcf632020-06-22 16:49:24 +080027#ifdef TFM_PSA_API
Chris Brandde8a13e2022-05-25 09:45:26 -070028#ifndef TFM_MULTI_CORE_TOPOLOGY
Summer Qin483da642019-09-25 17:57:41 +080029/*!
30 * \def __tfm_psa_secure_gateway_attributes__
31 *
32 * \brief Attributes for psa api secure gateway functions
33 */
David Hu94d424a2020-04-29 15:49:24 +080034#if defined(__GNUC__) && !defined(__ARMCC_VERSION)
35/*
36 * GNUARM requires noclone attribute to protect gateway function symbol from
37 * being renamed and cloned
38 */
Summer Qin483da642019-09-25 17:57:41 +080039#define __tfm_psa_secure_gateway_attributes__ \
David Hu94d424a2020-04-29 15:49:24 +080040 __attribute__((cmse_nonsecure_entry, noclone, naked, section("SFN")))
41#else
42#define __tfm_psa_secure_gateway_attributes__ \
43 __attribute__((cmse_nonsecure_entry, naked, section("SFN")))
44#endif /* __GNUC__ && !__ARMCC_VERSION */
45#endif /* TFM_MULTI_CORE_TOPOLOGY */
Chris Brandde8a13e2022-05-25 09:45:26 -070046#else /* TFM_PSA_API */
47/*!
48 * \def __tfm_secure_gateway_attributes__
49 *
50 * \brief Attributes for secure gateway functions
51 */
52#if defined(__GNUC__) && !defined(__ARMCC_VERSION)
53/*
54 * GNUARM requires noclone attribute to protect gateway function symbol from
55 * being renamed and cloned
56 */
57#define __tfm_secure_gateway_attributes__ \
58 __attribute__((cmse_nonsecure_entry, noclone, section("SFN")))
59#else
60#define __tfm_secure_gateway_attributes__ \
61 __attribute__((cmse_nonsecure_entry, section("SFN")))
62#endif /* __GNUC__ && !__ARMCC_VERSION */
63#endif /* TFM_PSA_API */
Antonio de Angeliseba14e12018-03-27 11:03:20 +010064
Miklos Balint386b8b52017-11-29 13:12:32 +000065/* Hide specific errors if not debugging */
66#ifdef TFM_CORE_DEBUG
67#define TFM_ERROR_STATUS(status) (status)
68#else
Mate Toth-Pal7de74b52018-02-23 15:46:47 +010069#define TFM_ERROR_STATUS(status) (TFM_PARTITION_BUSY)
Miklos Balint386b8b52017-11-29 13:12:32 +000070#endif
71
72#ifndef TFM_LVL
Miklos Balint386b8b52017-11-29 13:12:32 +000073#error TFM_LVL is not defined!
74#endif
Miklos Balint386b8b52017-11-29 13:12:32 +000075
Summer Qin5fdcf632020-06-22 16:49:24 +080076#ifndef TFM_PSA_API
Miklos Balint386b8b52017-11-29 13:12:32 +000077extern void tfm_secure_api_error_handler(void);
78
Miklos Balint6a139ae2018-04-04 19:44:37 +020079typedef int32_t(*sfn_t)(int32_t, int32_t, int32_t, int32_t);
80
Miklos Balint386b8b52017-11-29 13:12:32 +000081struct tfm_sfn_req_s {
Miklos Balint6a139ae2018-04-04 19:44:37 +020082 uint32_t sp_id;
83 sfn_t sfn;
84 int32_t *args;
Miklos Balint1fdb12f2018-09-11 11:30:30 +020085 uint32_t caller_part_idx;
Summer Qin43c185d2019-10-10 15:44:42 +080086 bool ns_caller;
Miklos Balint386b8b52017-11-29 13:12:32 +000087};
88
Antonio de Angelis5b64bb72021-04-27 08:37:14 +010089enum tfm_status_e tfm_core_get_caller_client_id(int32_t *caller_client_id);
Mate Toth-Pal21a74c92018-04-13 14:05:41 +020090
Hugues de Valon4bf875b2019-02-19 14:53:49 +000091int32_t tfm_core_sfn_request(const struct tfm_sfn_req_s *desc_ptr);
Miklos Balintace4c3f2018-07-30 12:31:15 +020092
Mingyang Sunabb1aab2020-02-18 13:49:08 +080093int32_t tfm_spm_sfn_request_thread_mode(struct tfm_sfn_req_s *desc_ptr);
Miklos Balintace4c3f2018-07-30 12:31:15 +020094
David Hu8d1f1072020-04-30 12:52:14 +080095#define TFM_CORE_IOVEC_SFN_REQUEST(id, is_ns, fn, a, b, c, d) \
96 return tfm_core_partition_request(id, is_ns, fn, \
Mate Toth-Palb8ce0dd2018-07-25 10:18:34 +020097 (int32_t)a, (int32_t)b, (int32_t)c, (int32_t)d)
Miklos Balint386b8b52017-11-29 13:12:32 +000098
David Hu8d1f1072020-04-30 12:52:14 +080099int32_t tfm_core_partition_request(uint32_t id, bool is_ns, void *fn,
100 int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4);
Miklos Balint386b8b52017-11-29 13:12:32 +0000101
David Hu8d1f1072020-04-30 12:52:14 +0800102__attribute__ ((always_inline)) __STATIC_INLINE
103bool tfm_core_is_ns_client(void)
104{
Hugues de Valon4bf875b2019-02-19 14:53:49 +0000105 /*
106 * This preprocessor condition checks if a version of GCC smaller than
107 * 7.3.1 is being used to compile the code.
108 * These versions are affected by a bug on the cmse_nonsecure_caller
109 * intrinsic which returns incorrect results.
110 * Please check Bug 85203 on GCC Bugzilla for more information.
111 */
112#if defined(__GNUC__) && !defined(__ARMCC_VERSION) && \
113 (__GNUC__ < 7 || \
114 (__GNUC__ == 7 && (__GNUC_MINOR__ < 3 || \
115 (__GNUC_MINOR__ == 3 && __GNUC_PATCHLEVEL__ < 1))))
116 /*
117 * Use the fact that, if called from Non-Secure, the LSB of the return
118 * address is set to 0.
119 */
David Hu8d1f1072020-04-30 12:52:14 +0800120 return !(
121 (uintptr_t)__builtin_extract_return_addr(__builtin_return_address(0U))
122 & 0x1);
Hugues de Valon4bf875b2019-02-19 14:53:49 +0000123#else
124 /*
Summer Qin43c185d2019-10-10 15:44:42 +0800125 * Convert the result of cmse_nonsecure_caller from an int to a bool
Hugues de Valon4bf875b2019-02-19 14:53:49 +0000126 * to prevent using an int in the tfm_sfn_req_s structure.
127 */
David Hu8d1f1072020-04-30 12:52:14 +0800128 return (cmse_nonsecure_caller() != 0) ? true : false;
Hugues de Valon4bf875b2019-02-19 14:53:49 +0000129#endif /* Check for GCC compiler version smaller than 7.3.1 */
Miklos Balint386b8b52017-11-29 13:12:32 +0000130}
Miklos Balintdd02bb32019-05-26 21:13:12 +0200131#endif
Miklos Balint386b8b52017-11-29 13:12:32 +0000132
133#endif /* __TFM_SECURE_API_H__ */