Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | #include "psa/client.h" |
Kevin Peng | 0eca5ea | 2023-07-21 17:32:31 +0800 | [diff] [blame] | 10 | #include "tfm_erpc.h" |
Summer Qin | 153f3df | 2022-11-17 15:51:02 +0800 | [diff] [blame] | 11 | |
| 12 | psa_status_t psa_call(psa_handle_t handle, int32_t type, |
| 13 | const psa_invec *in_vec, size_t in_len, |
| 14 | psa_outvec *out_vec, size_t out_len) |
| 15 | { |
| 16 | psa_status_t status; |
| 17 | size_t i; |
| 18 | binary_t in_elements[PSA_MAX_IOVEC]; |
| 19 | binary_t out_elements[PSA_MAX_IOVEC]; |
| 20 | list_binary_1_t erpc_in_vec = {in_elements, in_len}; |
| 21 | list_binary_1_t erpc_out_vec = {out_elements, out_len}; |
| 22 | |
| 23 | if (in_len + out_len > PSA_MAX_IOVEC) { |
| 24 | return PSA_ERROR_PROGRAMMER_ERROR; |
| 25 | } |
| 26 | |
| 27 | /* Copy PSA iovecs into RPC binary lists */ |
| 28 | for (i = 0; i < in_len; ++i) { |
| 29 | in_elements[i] = (binary_t){(void *)in_vec[i].base, in_vec[i].len}; |
| 30 | } |
| 31 | for (i = 0; i < out_len; ++i) { |
| 32 | out_elements[i] = (binary_t){out_vec[i].base, out_vec[i].len}; |
| 33 | } |
| 34 | |
| 35 | status = erpc_psa_call(handle, type, &erpc_in_vec, &erpc_out_vec); |
| 36 | |
| 37 | if (status != PSA_SUCCESS) { |
| 38 | return status; |
| 39 | } |
| 40 | |
| 41 | /* Copy updated out length into PSA outvec */ |
| 42 | for (i = 0; i < out_len; ++i) { |
| 43 | out_vec[i].len = out_elements[i].dataLength; |
| 44 | } |
| 45 | |
| 46 | return status; |
| 47 | } |