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