1 /* 2 * Copyright (c) 2026, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __SFCP_PSA_PROTOCOL_H__ 9 #define __SFCP_PSA_PROTOCOL_H__ 10 11 #include <cdefs.h> 12 13 #include "psa/client.h" 14 15 #ifdef SFCP_PROTOCOL_EMBED_ENABLED 16 #include "sfcp_psa_protocol_embed.h" 17 #endif /* SFCP_PROTOCOL_EMBED_ENABLED */ 18 19 #ifdef SFCP_PROTOCOL_POINTER_ACCESS_ENABLED 20 #include "sfcp_psa_protocol_pointer_access.h" 21 #endif /* RSE_MHU_PROTOCOL_V0_ENABLED */ 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 enum sfcp_protocol_version_t { 28 #ifdef SFCP_PROTOCOL_EMBED_ENABLED 29 SFCP_PROTOCOL_EMBED = 0, 30 #endif /* SFCP_PROTOCOL_EMBED_ENABLED */ 31 #ifdef SFCP_PROTOCOL_POINTER_ACCESS_ENABLED 32 SFCP_PROTOCOL_POINTER_ACCESS = 1, 33 #endif /* SFCP_PROTOCOL_POINTER_ACCESS_ENABLED */ 34 }; 35 36 struct __packed serialized_sfcp_header_t { 37 uint8_t protocol_ver; 38 /* Pad out to 4 bytes to ensure alignment */ 39 uint8_t __reserved[3]; 40 }; 41 42 /* MHU message passed from NSPE to SPE to deliver a PSA client call */ 43 struct __packed serialized_psa_msg_t { 44 struct serialized_sfcp_header_t header; 45 union __packed { 46 #ifdef SFCP_PROTOCOL_EMBED_ENABLED 47 struct sfcp_embed_msg_t embed; 48 #endif /* SFCP_PROTOCOL_EMBED_ENABLED */ 49 #ifdef SFCP_PROTOCOL_POINTER_ACCESS_ENABLED 50 struct sfcp_pointer_access_msg_t pointer_access; 51 #endif /* SFCP_PROTOCOL_POINTER_ACCESS_ENABLED */ 52 } msg; 53 }; 54 55 /* MHU reply message to hold the PSA client call return result from SPE */ 56 struct __packed serialized_psa_reply_t { 57 struct serialized_sfcp_header_t header; 58 union __packed { 59 #ifdef SFCP_PROTOCOL_EMBED_ENABLED 60 struct sfcp_embed_reply_t embed; 61 #endif /* SFCP_PROTOCOL_EMBED_ENABLED */ 62 #ifdef SFCP_PROTOCOL_POINTER_ACCESS_ENABLED 63 struct sfcp_pointer_access_reply_t pointer_access; 64 #endif /* SFCP_PROTOCOL_POINTER_ACCESS_ENABLED */ 65 } reply; 66 }; 67 68 struct client_request_t; 69 70 /** 71 * \brief Serialize a PSA client call into a protocol message. 72 * 73 * \param[in] handle Target PSA partition handle. 74 * \param[in] type PSA signal type. 75 * \param[in] in_vec List of input vectors to copy into the message. 76 * \param[in] in_len Number of valid entries in \p in_vec. 77 * \param[in] out_vec List of output vectors describing expected replies. 78 * \param[in] out_len Number of valid entries in \p out_vec. 79 * \param[out] msg Buffer to populate with the serialized message. 80 * \param[out] msg_len Final serialized message size on success. 81 * 82 * \retval PSA_SUCCESS Operation succeeded. 83 * \retval Other return code Operation failed with an error code. 84 */ 85 psa_status_t 86 sfcp_protocol_serialize_msg(psa_handle_t handle, int16_t type, 87 const psa_invec *in_vec, uint8_t in_len, 88 const psa_outvec *out_vec, uint8_t out_len, 89 struct serialized_psa_msg_t *msg, size_t *msg_len); 90 91 /** 92 * \brief Deserialize a protocol reply into PSA client outputs. 93 * 94 * \param[out] out_vec Array of output buffers to populate. 95 * \param[in] out_len Number of valid entries in \p out_vec. 96 * \param[out] return_val PSA status returned by the service. 97 * \param[in] reply Serialized reply received from the peer. 98 * \param[in] reply_size Size, in bytes, of \p reply. 99 * 100 * \retval PSA_SUCCESS Operation succeeded.. 101 * \retval Other return code Operation failed with an error code. 102 */ 103 psa_status_t sfcp_protocol_deserialize_reply( 104 psa_outvec *out_vec, uint8_t out_len, psa_status_t *return_val, 105 const struct serialized_psa_reply_t *reply, size_t reply_size); 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif /* __SFCP_PSA_PROTOCOL_H__ */ 112