rse_comms_protocol_pointer_access.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "rse_comms_protocol_common.h"
  9. #include "rse_comms_protocol_pointer_access.h"
  10. psa_status_t rse_protocol_pointer_access_serialize_msg(psa_handle_t handle,
  11. int16_t type,
  12. const psa_invec *in_vec,
  13. uint8_t in_len,
  14. const psa_outvec *out_vec,
  15. uint8_t out_len,
  16. struct rse_pointer_access_msg_t *msg,
  17. size_t *msg_len)
  18. {
  19. unsigned int i;
  20. assert(msg != NULL);
  21. assert(msg_len != NULL);
  22. assert(in_vec != NULL);
  23. msg->ctrl_param = PARAM_PACK(type, in_len, out_len);
  24. msg->handle = handle;
  25. /* Fill msg iovec lengths */
  26. for (i = 0U; i < in_len; ++i) {
  27. msg->io_sizes[i] = in_vec[i].len;
  28. msg->host_ptrs[i] = (uint64_t)in_vec[i].base;
  29. }
  30. for (i = 0U; i < out_len; ++i) {
  31. msg->io_sizes[in_len + i] = out_vec[i].len;
  32. msg->host_ptrs[in_len + i] = (uint64_t)out_vec[i].base;
  33. }
  34. *msg_len = sizeof(*msg);
  35. return PSA_SUCCESS;
  36. }
  37. psa_status_t rse_protocol_pointer_access_deserialize_reply(psa_outvec *out_vec,
  38. uint8_t out_len,
  39. psa_status_t *return_val,
  40. const struct rse_pointer_access_reply_t *reply,
  41. size_t reply_size)
  42. {
  43. unsigned int i;
  44. assert(reply != NULL);
  45. assert(return_val != NULL);
  46. for (i = 0U; i < out_len; ++i) {
  47. out_vec[i].len = reply->out_sizes[i];
  48. }
  49. *return_val = reply->return_val;
  50. return PSA_SUCCESS;
  51. }