1 /* 2 * Copyright (c) 2022-2024, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 #include <assert.h> 8 9 #include "rse_comms_protocol_common.h" 10 #include "rse_comms_protocol_pointer_access.h" 11 12 psa_status_t rse_protocol_pointer_access_serialize_msg(psa_handle_t handle, 13 int16_t type, 14 const psa_invec *in_vec, 15 uint8_t in_len, 16 const psa_outvec *out_vec, 17 uint8_t out_len, 18 struct rse_pointer_access_msg_t *msg, 19 size_t *msg_len) 20 { 21 unsigned int i; 22 23 assert(msg != NULL); 24 assert(msg_len != NULL); 25 assert(in_vec != NULL); 26 27 msg->ctrl_param = PARAM_PACK(type, in_len, out_len); 28 msg->handle = handle; 29 30 /* Fill msg iovec lengths */ 31 for (i = 0U; i < in_len; ++i) { 32 msg->io_sizes[i] = in_vec[i].len; 33 msg->host_ptrs[i] = (uint64_t)in_vec[i].base; 34 } 35 for (i = 0U; i < out_len; ++i) { 36 msg->io_sizes[in_len + i] = out_vec[i].len; 37 msg->host_ptrs[in_len + i] = (uint64_t)out_vec[i].base; 38 } 39 40 *msg_len = sizeof(*msg); 41 42 return PSA_SUCCESS; 43 } 44 45 psa_status_t rse_protocol_pointer_access_deserialize_reply(psa_outvec *out_vec, 46 uint8_t out_len, 47 psa_status_t *return_val, 48 const struct rse_pointer_access_reply_t *reply, 49 size_t reply_size) 50 { 51 unsigned int i; 52 53 assert(reply != NULL); 54 assert(return_val != NULL); 55 56 for (i = 0U; i < out_len; ++i) { 57 out_vec[i].len = reply->out_sizes[i]; 58 } 59 60 *return_val = reply->return_val; 61 62 return PSA_SUCCESS; 63 } 64