Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 8 | #ifndef __RSE_COMMS_PROTOCOL_H__ |
| 9 | #define __RSE_COMMS_PROTOCOL_H__ |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 10 | |
| 11 | #include <cdefs.h> |
| 12 | #include <stdint.h> |
| 13 | |
| 14 | #include <psa/client.h> |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 15 | #include "rse_comms_protocol_embed.h" |
| 16 | #include "rse_comms_protocol_pointer_access.h" |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 17 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 18 | enum rse_comms_protocol_version_t { |
| 19 | RSE_COMMS_PROTOCOL_EMBED = 0, |
| 20 | RSE_COMMS_PROTOCOL_POINTER_ACCESS = 1, |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 21 | }; |
| 22 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 23 | struct __packed serialized_rse_comms_header_t { |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 24 | uint8_t protocol_ver; |
| 25 | uint8_t seq_num; |
| 26 | uint16_t client_id; |
| 27 | }; |
| 28 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 29 | /* MHU message passed from Host to RSE to deliver a PSA client call */ |
| 30 | struct __packed serialized_rse_comms_msg_t { |
| 31 | struct serialized_rse_comms_header_t header; |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 32 | union __packed { |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 33 | struct rse_embed_msg_t embed; |
| 34 | struct rse_pointer_access_msg_t pointer_access; |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 35 | } msg; |
| 36 | }; |
| 37 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 38 | /* MHU reply message to hold the PSA client reply result returned by RSE */ |
| 39 | struct __packed serialized_rse_comms_reply_t { |
| 40 | struct serialized_rse_comms_header_t header; |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 41 | union __packed { |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 42 | struct rse_embed_reply_t embed; |
| 43 | struct rse_pointer_access_reply_t pointer_access; |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 44 | } reply; |
| 45 | }; |
| 46 | |
| 47 | /* in_len and out_len are uint8_ts, therefore if there are more than 255 iovecs |
| 48 | * an error may occur. |
| 49 | */ |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 50 | CASSERT(PSA_MAX_IOVEC <= UINT8_MAX, assert_rse_comms_max_iovec_too_large); |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 51 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 52 | psa_status_t rse_protocol_serialize_msg(psa_handle_t handle, |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 53 | int16_t type, |
| 54 | const psa_invec *in_vec, |
| 55 | uint8_t in_len, |
| 56 | const psa_outvec *out_vec, |
| 57 | uint8_t out_len, |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 58 | struct serialized_rse_comms_msg_t *msg, |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 59 | size_t *msg_len); |
| 60 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 61 | psa_status_t rse_protocol_deserialize_reply(psa_outvec *out_vec, |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 62 | uint8_t out_len, |
| 63 | psa_status_t *return_val, |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 64 | const struct serialized_rse_comms_reply_t *reply, |
Raef Coles | 734aaac | 2022-06-15 14:37:22 +0100 | [diff] [blame] | 65 | size_t reply_size); |
| 66 | |
Tamas Ban | d097318 | 2024-02-21 12:42:00 +0100 | [diff] [blame] | 67 | #endif /* __RSE_COMMS_PROTOCOL_H__ */ |