1 /*
2  * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef TS_RPC_ENDPOINT_SP_H
8 #define TS_RPC_ENDPOINT_SP_H
9 
10 #include "components/rpc/common/endpoint/rpc_service_interface.h"
11 #include "components/rpc/ts_rpc/common/ts_rpc_abi.h"
12 #include "sp_messaging.h"
13 #include <stdbool.h>
14 #include <stddef.h>
15 #include <stdint.h>
16 
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20 
21 /**
22  * @brief TS RPC shared memory
23  *
24  * The structure describes an FF-A shared memory slot in the endpoint implementation. The shared
25  * memory is identified by its owner (FF-A ID) and handle (FF-A memory handle). After retrieval the
26  * data and size fields are filled. The used field indicates if a given memory slot of the pool is
27  * used and contains valid information.
28  */
29 struct ts_rpc_shared_memory {
30 	uint16_t owner_id;
31 	uint64_t handle;
32 	void *data;
33 	size_t size;
34 	bool used;
35 };
36 
37 /**
38  * @brief TS RPC endpoint for SPs
39  *
40  * This component connects the FF-A layer and the services by implementing TS RPC on FF-A direct
41  * messages and shared memories.
42  * The structure contains the endpoint's own FF-A ID to be used in FF-A calls.
43  * It also contains of list of services. These services are selected based on the interface ID of
44  * the RPC request. The endpoint handles the shared memory pool.
45  */
46 struct ts_rpc_endpoint_sp {
47 	uint16_t own_id;
48 	struct rpc_service_interface **services;
49 	size_t service_count;
50 	struct ts_rpc_shared_memory *shared_memories;
51 	size_t shared_memory_count;
52 };
53 
54 /**
55  * @brief Init TS RPC endpoint
56  *
57  * @param endpoint The endpoint instance
58  * @param service_count Service count
59  * @param shared_memory_count Shared memory pool size
60  * @return rpc_status_t
61  */
62 rpc_status_t ts_rpc_endpoint_sp_init(struct ts_rpc_endpoint_sp *endpoint, size_t service_count,
63 				     size_t shared_memory_count);
64 
65 /**
66  * @brief Deinit TS RPC endpoint
67  *
68  * @param endpoint The endpoint instance
69  * @return rpc_status_t
70  */
71 rpc_status_t ts_rpc_endpoint_sp_deinit(struct ts_rpc_endpoint_sp *endpoint);
72 
73 /**
74  * @brief Add service to the endpoint. The interface IDs are assigned sequentially. The maximal
75  * service count is determined by the service_count parameter of ts_rpc_endpoint_sp_init.
76  *
77  * @param endpoint The endpoint instance
78  * @param service The service instance
79  * @return rpc_status_t
80  */
81 rpc_status_t ts_rpc_endpoint_sp_add_service(struct ts_rpc_endpoint_sp *endpoint,
82 					    struct rpc_service_interface *service);
83 
84 /**
85  * @brief Handle received FF-A message
86  *
87  * @param endpoint The endpoint instance
88  * @param request The request FF-A message
89  * @param response The response FF-A message
90  */
91 void ts_rpc_endpoint_sp_receive(struct ts_rpc_endpoint_sp *endpoint, const struct sp_msg *request,
92 				struct sp_msg *response);
93 
94 #ifdef __cplusplus
95 }
96 #endif
97 
98 #endif /* TS_RPC_ENDPOINT_SP_H */
99