blob: df3cb2f4c2cf8ef0ac214f259609cca8caeffa49 [file] [log] [blame]
Patrick Williams7784c422022-11-17 07:29:11 -06001From 0311fc8f131fe7a2b0f4dd9988c610fda47394aa Mon Sep 17 00:00:00 2001
Patrick Williams975a06f2022-10-21 14:42:47 -05002From: Vishnu Banavath <vishnu.banavath@arm.com>
3Date: Fri, 3 Dec 2021 19:13:03 +0000
Patrick Williams7784c422022-11-17 07:29:11 -06004Subject: [PATCH 05/20] Add common service component to ipc support
Patrick Williams975a06f2022-10-21 14:42:47 -05005
6Add support for inter processor communication for PSA
7including, the openamp client side structures lib.
8
9Upstream-Status: Pending
10Signed-off-by: Vishnu Banavath <vishnu.banavath@arm.com>
11Signed-off-by: Rui Miguel Silva <rui.silva@linaro.org>
12---
13 .../service/common/psa_ipc/component.cmake | 13 ++
14 .../service/common/psa_ipc/service_psa_ipc.c | 97 +++++++++++++
15 .../psa_ipc/service_psa_ipc_openamp_lib.h | 131 ++++++++++++++++++
16 deployments/se-proxy/se-proxy.cmake | 1 +
17 4 files changed, 242 insertions(+)
18 create mode 100644 components/service/common/psa_ipc/component.cmake
19 create mode 100644 components/service/common/psa_ipc/service_psa_ipc.c
20 create mode 100644 components/service/common/psa_ipc/service_psa_ipc_openamp_lib.h
21
22diff --git a/components/service/common/psa_ipc/component.cmake b/components/service/common/psa_ipc/component.cmake
23new file mode 100644
24index 000000000000..5a1c9e62e2f0
25--- /dev/null
26+++ b/components/service/common/psa_ipc/component.cmake
27@@ -0,0 +1,13 @@
28+#-------------------------------------------------------------------------------
29+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
30+#
31+# SPDX-License-Identifier: BSD-3-Clause
32+#
33+#-------------------------------------------------------------------------------
34+if (NOT DEFINED TGT)
35+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
36+endif()
37+
38+target_sources(${TGT} PRIVATE
39+ "${CMAKE_CURRENT_LIST_DIR}/service_psa_ipc.c"
40+ )
41diff --git a/components/service/common/psa_ipc/service_psa_ipc.c b/components/service/common/psa_ipc/service_psa_ipc.c
42new file mode 100644
43index 000000000000..e8093c20a523
44--- /dev/null
45+++ b/components/service/common/psa_ipc/service_psa_ipc.c
46@@ -0,0 +1,97 @@
47+/*
48+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
49+ *
50+ * SPDX-License-Identifier: BSD-3-Clause
51+ */
52+
53+#include <stddef.h>
54+#include <stdint.h>
55+#include <string.h>
56+#include <trace.h>
57+
58+#include <protocols/rpc/common/packed-c/status.h>
59+#include <psa/error.h>
60+#include <rpc_caller.h>
61+
62+#include <psa/client.h>
63+#include "service_psa_ipc_openamp_lib.h"
64+
65+psa_handle_t psa_connect(struct rpc_caller *caller, uint32_t sid,
66+ uint32_t version)
67+{
68+ psa_status_t psa_status = PSA_SUCCESS;
69+ struct s_openamp_msg *resp_msg = NULL;
70+ struct ns_openamp_msg *req_msg;
71+ rpc_call_handle rpc_handle;
72+ size_t resp_len;
73+ uint8_t *resp;
74+ uint8_t *req;
75+ int ret;
76+
77+ rpc_handle = rpc_caller_begin(caller, &req,
78+ sizeof(struct ns_openamp_msg));
79+ if (!rpc_handle) {
80+ EMSG("psa_connect: could not get handle");
81+ return PSA_ERROR_GENERIC_ERROR;
82+ }
83+
84+ req_msg = (struct ns_openamp_msg *)req;
85+
86+ req_msg->call_type = OPENAMP_PSA_CONNECT;
87+ req_msg->params.psa_connect_params.sid = sid;
88+ req_msg->params.psa_connect_params.version = version;
89+
90+ ret = rpc_caller_invoke(caller, rpc_handle, 0, &psa_status, &resp,
91+ &resp_len);
92+ if (ret != TS_RPC_CALL_ACCEPTED) {
93+ EMSG("psa_connect: invoke failed: %d", ret);
94+ return PSA_ERROR_GENERIC_ERROR;
95+ }
96+
97+ if (psa_status == PSA_SUCCESS)
98+ resp_msg = (struct s_openamp_msg *)resp;
99+
100+ rpc_caller_end(caller, rpc_handle);
101+
102+ return resp_msg ? (psa_handle_t)resp_msg->reply : PSA_NULL_HANDLE;
103+}
104+
105+psa_status_t psa_call(struct rpc_caller *caller, psa_handle_t handle,
106+ int32_t type, const struct psa_invec *in_vec,
107+ size_t in_len, struct psa_outvec *out_vec, size_t out_len)
108+{
109+
110+}
111+
112+void psa_close(struct rpc_caller *caller, psa_handle_t handle)
113+{
114+ psa_status_t psa_status = PSA_SUCCESS;
115+ struct s_openamp_msg *resp_msg = NULL;
116+ struct ns_openamp_msg *req_msg;
117+ rpc_call_handle rpc_handle;
118+ size_t resp_len;
119+ uint8_t *resp;
120+ uint8_t *req;
121+ int ret;
122+
123+ rpc_handle = rpc_caller_begin(caller, &req,
124+ sizeof(struct ns_openamp_msg));
125+ if (!rpc_handle) {
126+ EMSG("psa_close: could not get handle");
127+ return;
128+ }
129+
130+ req_msg = (struct ns_openamp_msg *)req;
131+
132+ req_msg->call_type = OPENAMP_PSA_CLOSE;
133+ req_msg->params.psa_close_params.handle = handle;
134+
135+ ret = rpc_caller_invoke(caller, rpc_handle, 0, &psa_status, &resp,
136+ &resp_len);
137+ if (ret != TS_RPC_CALL_ACCEPTED) {
138+ EMSG("psa_close: invoke failed: %d", ret);
139+ return;
140+ }
141+
142+ rpc_caller_end(caller, rpc_handle);
143+}
144diff --git a/components/service/common/psa_ipc/service_psa_ipc_openamp_lib.h b/components/service/common/psa_ipc/service_psa_ipc_openamp_lib.h
145new file mode 100644
146index 000000000000..33ea96660572
147--- /dev/null
148+++ b/components/service/common/psa_ipc/service_psa_ipc_openamp_lib.h
149@@ -0,0 +1,131 @@
150+/*
151+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
152+ *
153+ * SPDX-License-Identifier: BSD-3-Clause
154+ */
155+
156+#ifndef SERVICE_PSA_IPC_OPENAMP_LIB_H
157+#define SERVICE_PSA_IPC_OPENAMP_LIB_H
158+
159+#include <stddef.h>
160+#include <stdint.h>
161+
162+#include <compiler.h>
163+#include <psa/error.h>
164+
165+#include <stdint.h>
166+#include <psa/client.h>
167+
168+#ifdef __cplusplus
169+extern "C" {
170+#endif
171+
172+/* PSA client call type value */
173+#define OPENAMP_PSA_FRAMEWORK_VERSION (0x1)
174+#define OPENAMP_PSA_VERSION (0x2)
175+#define OPENAMP_PSA_CONNECT (0x3)
176+#define OPENAMP_PSA_CALL (0x4)
177+#define OPENAMP_PSA_CLOSE (0x5)
178+
179+/* Return code of openamp APIs */
180+#define OPENAMP_SUCCESS (0)
181+#define OPENAMP_MAP_FULL (INT32_MIN + 1)
182+#define OPENAMP_MAP_ERROR (INT32_MIN + 2)
183+#define OPENAMP_INVAL_PARAMS (INT32_MIN + 3)
184+#define OPENAMP_NO_PERMS (INT32_MIN + 4)
185+#define OPENAMP_NO_PEND_EVENT (INT32_MIN + 5)
186+#define OPENAMP_CHAN_BUSY (INT32_MIN + 6)
187+#define OPENAMP_CALLBACK_REG_ERROR (INT32_MIN + 7)
188+#define OPENAMP_INIT_ERROR (INT32_MIN + 8)
189+
190+#define HOLD_INPUT_BUFFER (1) /* IF true, TF-M Library will hold the openamp
191+ * buffer so that openamp shared memory buffer
192+ * does not get freed.
193+ */
194+
195+/*
196+ * This structure holds the parameters used in a PSA client call.
197+ */
198+typedef struct __packed psa_client_in_params {
199+ union {
200+ struct __packed {
201+ uint32_t sid;
202+ } psa_version_params;
203+
204+ struct __packed {
205+ uint32_t sid;
206+ uint32_t version;
207+ } psa_connect_params;
208+
209+ struct __packed {
210+ psa_handle_t handle;
211+ int32_t type;
212+ uint32_t in_vec;
213+ uint32_t in_len;
214+ uint32_t out_vec;
215+ uint32_t out_len;
216+ } psa_call_params;
217+
218+ struct __packed {
219+ psa_handle_t handle;
220+ } psa_close_params;
221+ };
222+} psa_client_in_params_t;
223+
224+/* Openamp message passed from NSPE to SPE to deliver a PSA client call */
225+struct __packed ns_openamp_msg {
226+ uint32_t call_type; /* PSA client call type */
227+ struct psa_client_in_params params; /* Contain parameters used in PSA
228+ * client call
229+ */
230+
231+ int32_t client_id; /* Optional client ID of the
232+ * non-secure caller.
233+ * It is required to identify the
234+ * non-secure task when NSPE OS
235+ * enforces non-secure task
236+ * isolation
237+ */
238+ int32_t request_id; /* This is the unique ID for a
239+ * request send to TF-M by the
240+ * non-secure core. TF-M forward
241+ * the ID back to non-secure on the
242+ * reply to a given request. Using
243+ * this id, the non-secure library
244+ * can identify the request for
245+ * which the reply has received.
246+ */
247+};
248+
249+/*
250+ * This structure holds the location of the out data of the PSA client call.
251+ */
252+struct __packed psa_client_out_params {
253+ uint32_t out_vec;
254+ uint32_t out_len;
255+};
256+
257+
258+/* Openamp message from SPE to NSPE delivering the reply back for a PSA client
259+ * call.
260+ */
261+struct __packed s_openamp_msg {
262+ int32_t request_id; /* Using this id, the non-secure
263+ * library identifies the request.
264+ * TF-M forwards the same
265+ * request-id received on the
266+ * initial request.
267+ */
268+ int32_t reply; /* Reply of the PSA client call */
269+ struct psa_client_out_params params; /* Contain out data result of the
270+ * PSA client call.
271+ */
272+};
273+
274+#ifdef __cplusplus
275+}
276+#endif
277+
278+#endif /* SERVICE_PSA_IPC_OPENAMP_LIB_H */
279+
280+
281diff --git a/deployments/se-proxy/se-proxy.cmake b/deployments/se-proxy/se-proxy.cmake
282index 34fe5ff1b925..dd0c5d00c21e 100644
283--- a/deployments/se-proxy/se-proxy.cmake
284+++ b/deployments/se-proxy/se-proxy.cmake
285@@ -24,6 +24,7 @@ add_components(TARGET "se-proxy"
286 "components/service/common/include"
287 "components/service/common/serializer/protobuf"
288 "components/service/common/client"
289+ "components/service/common/psa_ipc"
290 "components/service/common/provider"
291 "components/service/discovery/provider"
292 "components/service/discovery/provider/serializer/packed-c"
293--
Patrick Williams7784c422022-11-17 07:29:11 -06002942.38.1
Patrick Williams975a06f2022-10-21 14:42:47 -0500295