1 /*
2  * Copyright (c) 2022, Arm Limited. All rights reserved.
3  * Copyright (c) 2023 Cypress Semiconductor Corporation (an Infineon
4  * company) or an affiliate of Cypress Semiconductor Corporation. All rights
5  * reserved.
6  *
7  * SPDX-License-Identifier: BSD-3-Clause
8  *
9  */
10 
11 #ifndef __RUNTIME_DEFS_H__
12 #define __RUNTIME_DEFS_H__
13 
14 #include <stdint.h>
15 
16 #include "config_impl.h"
17 #include "psa/client.h"
18 #include "psa/error.h"
19 #include "psa/service.h"
20 
21 /* SFN defs */
22 typedef psa_status_t (*service_fn_t)(psa_msg_t *msg);
23 typedef psa_status_t (*sfn_init_fn_t)(void *param);
24 
25 /* PSA API dispatcher for IPC model. */
26 #if CONFIG_TFM_SPM_BACKEND_IPC == 1
27 struct psa_api_tbl_t {
28     psa_status_t     (*psa_call)(psa_handle_t handle, uint32_t ctrl_param, const psa_invec *in_vec,
29                                  psa_outvec *out_vec);
30     uint32_t         (*psa_version)(uint32_t sid);
31     uint32_t         (*psa_framework_version)(void);
32     psa_signal_t     (*psa_wait)(psa_signal_t signal_mask, uint32_t timeout);
33     psa_status_t     (*psa_get)(psa_signal_t signal, psa_msg_t *msg);
34     size_t           (*psa_read)(psa_handle_t msg_handle, uint32_t invec_idx, void *buffer,
35                                  size_t num_bytes);
36     size_t           (*psa_skip)(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
37     void             (*psa_write)(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer,
38                                   size_t num_bytes);
39     void             (*psa_reply)(psa_handle_t msg_handle, psa_status_t retval);
40     void             (*psa_panic)(void);
41     uint32_t         (*psa_rot_lifecycle_state)(void);
42 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
43     psa_handle_t     (*psa_connect)(uint32_t sid, uint32_t version);
44     void             (*psa_close)(psa_handle_t handle);
45     void             (*psa_set_rhandle)(psa_handle_t msg_handle, void *rhandle);
46 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
47 #if CONFIG_TFM_DOORBELL_API == 1
48     void             (*psa_notify)(int32_t partition_id);
49     void             (*psa_clear)(void);
50 #endif /* CONFIG_TFM_DOORBELL_API == 1 */
51 #if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
52     void             (*psa_irq_enable)(psa_signal_t irq_signal);
53     psa_irq_status_t (*psa_irq_disable)(psa_signal_t irq_signal);
54 #if CONFIG_TFM_FLIH_API == 1
55     void             (*psa_reset_signal)(psa_signal_t irq_signal);
56 #endif /* CONFIG_TFM_FLIH_API == 1 */
57 #if CONFIG_TFM_SLIH_API == 1
58     void             (*psa_eoi)(psa_signal_t irq_signal);
59 #endif /* CONFIG_TFM_SLIH_API == 1 */
60 #endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
61 #if PSA_FRAMEWORK_HAS_MM_IOVEC
62     void *           (*psa_map_invec)(psa_handle_t msg_handle, uint32_t invec_idx);
63     void             (*psa_unmap_invec)(psa_handle_t msg_handle, uint32_t invec_idx);
64     void *           (*psa_map_outvec)(psa_handle_t msg_handle, uint32_t outvec_idx);
65     void             (*psa_unmap_outvec)(psa_handle_t msg_handle, uint32_t outvec_idx, size_t len);
66 #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
67 };
68 
69 struct runtime_metadata_t {
70     uintptr_t            entry;      /* Entry function */
71     struct psa_api_tbl_t *psa_fns;   /* PSA API entry table */
72     uint32_t             n_sfn;      /* Number of Secure FuNctions */
73     service_fn_t         sfn_table[];/* Secure FuNctions Table */
74 };
75 #endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
76 
77 #endif /* __RUNTIME_DEFS_H__ */
78