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 #include "ffm/agent_api.h"
21 
22 /* SFN defs */
23 typedef psa_status_t (*service_fn_t)(psa_msg_t *msg);
24 typedef psa_status_t (*sfn_init_fn_t)(void *param);
25 
26 /* PSA API dispatcher for IPC model. */
27 #if CONFIG_TFM_SPM_BACKEND_IPC == 1
28 struct psa_api_tbl_t {
29     psa_status_t     (*psa_call)(psa_handle_t handle, uint32_t ctrl_param, const psa_invec *in_vec,
30                                  psa_outvec *out_vec);
31     uint32_t         (*psa_version)(uint32_t sid);
32     uint32_t         (*psa_framework_version)(void);
33     psa_signal_t     (*psa_wait)(psa_signal_t signal_mask, uint32_t timeout);
34     psa_status_t     (*psa_get)(psa_signal_t signal, psa_msg_t *msg);
35     size_t           (*psa_read)(psa_handle_t msg_handle, uint32_t invec_idx, void *buffer,
36                                  size_t num_bytes);
37     size_t           (*psa_skip)(psa_handle_t msg_handle, uint32_t invec_idx, size_t num_bytes);
38     void             (*psa_write)(psa_handle_t msg_handle, uint32_t outvec_idx, const void *buffer,
39                                   size_t num_bytes);
40     void             (*psa_reply)(psa_handle_t msg_handle, psa_status_t retval);
41     void             (*psa_panic)(void);
42     uint32_t         (*psa_rot_lifecycle_state)(void);
43 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
44     psa_handle_t     (*psa_connect)(uint32_t sid, uint32_t version);
45     void             (*psa_close)(psa_handle_t handle);
46     void             (*psa_set_rhandle)(psa_handle_t msg_handle, void *rhandle);
47 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
48 #if CONFIG_TFM_DOORBELL_API == 1
49     void             (*psa_notify)(int32_t partition_id);
50     void             (*psa_clear)(void);
51 #endif /* CONFIG_TFM_DOORBELL_API == 1 */
52 #if CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1
53     void             (*psa_irq_enable)(psa_signal_t irq_signal);
54     psa_irq_status_t (*psa_irq_disable)(psa_signal_t irq_signal);
55 #if CONFIG_TFM_FLIH_API == 1
56     void             (*psa_reset_signal)(psa_signal_t irq_signal);
57 #endif /* CONFIG_TFM_FLIH_API == 1 */
58 #if CONFIG_TFM_SLIH_API == 1
59     void             (*psa_eoi)(psa_signal_t irq_signal);
60 #endif /* CONFIG_TFM_SLIH_API == 1 */
61 #endif /* CONFIG_TFM_FLIH_API == 1 || CONFIG_TFM_SLIH_API == 1 */
62 #if PSA_FRAMEWORK_HAS_MM_IOVEC
63     void *           (*psa_map_invec)(psa_handle_t msg_handle, uint32_t invec_idx);
64     void             (*psa_unmap_invec)(psa_handle_t msg_handle, uint32_t invec_idx);
65     void *           (*psa_map_outvec)(psa_handle_t msg_handle, uint32_t outvec_idx);
66     void             (*psa_unmap_outvec)(psa_handle_t msg_handle, uint32_t outvec_idx, size_t len);
67 #endif /* PSA_FRAMEWORK_HAS_MM_IOVEC */
68 #ifdef TFM_PARTITION_NS_AGENT_MAILBOX
69     psa_status_t     (*agent_psa_call)(psa_handle_t handle, uint32_t control,
70                                        const struct client_params_t *params,
71                                        const void *client_data);
72 #if CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1
73     psa_handle_t     (*agent_psa_connect)(uint32_t sid, uint32_t version,
74                                           int32_t ns_client_id,
75                                           const void *client_data);
76 #endif /* CONFIG_TFM_CONNECTION_BASED_SERVICE_API == 1 */
77 #endif /* TFM_PARTITION_NS_AGENT_MAILBOX */
78 };
79 
80 struct runtime_metadata_t {
81     uintptr_t            entry;      /* Entry function */
82     struct psa_api_tbl_t *psa_fns;   /* PSA API entry table */
83     uint32_t             n_sfn;      /* Number of Secure FuNctions */
84     service_fn_t         sfn_table[];/* Secure FuNctions Table */
85 };
86 #endif /* CONFIG_TFM_SPM_BACKEND_IPC == 1 */
87 
88 #endif /* __RUNTIME_DEFS_H__ */
89