1 /* 2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __TFM_PSA_CALL_PACK_H__ 9 #define __TFM_PSA_CALL_PACK_H__ 10 11 #include "psa/client.h" 12 13 #ifdef __cplusplus 14 extern "C" { 15 #endif 16 17 /* 18 * 31 30-28 27 26-24 23-20 19 18-16 15-0 19 * +------------+-----+------+-------+-----+-------+-------+------+ 20 * | NS vector | | NS | invec | | NS | outvec| type | 21 * | descriptor | Res | invec| number| Res | outvec| number| | 22 * +------------+-----+------+-------+-----+-------+-------+------+ 23 * 24 * Res: Reserved. 25 */ 26 #define TYPE_MASK 0xFFFFUL 27 28 #define IN_LEN_OFFSET 24 29 #define IN_LEN_MASK (0x7UL << IN_LEN_OFFSET) 30 31 #define OUT_LEN_OFFSET 16 32 #define OUT_LEN_MASK (0x7UL << OUT_LEN_OFFSET) 33 34 /* 35 * NS_VEC_DESC_BIT is referenced by inline assembly, which does not 36 * support composited bit operations. So NS_VEC_DESC_BIT must be 37 * defined as a number. 38 */ 39 #define NS_VEC_DESC_BIT 0x80000000UL 40 41 #define NS_INVEC_OFFSET 27 42 #define NS_INVEC_BIT (1UL << NS_INVEC_OFFSET) 43 #define NS_OUTVEC_OFFSET 19 44 #define NS_OUTVEC_BIT (1UL << NS_OUTVEC_OFFSET) 45 46 #define PARAM_PACK(type, in_len, out_len) \ 47 ((((uint32_t)(type)) & TYPE_MASK) | \ 48 ((((uint32_t)(in_len)) << IN_LEN_OFFSET) & IN_LEN_MASK) | \ 49 ((((uint32_t)(out_len)) << OUT_LEN_OFFSET) & OUT_LEN_MASK)) 50 51 #define PARAM_UNPACK_TYPE(ctrl_param) \ 52 ((int32_t)(int16_t)((ctrl_param) & TYPE_MASK)) 53 54 #define PARAM_UNPACK_IN_LEN(ctrl_param) \ 55 ((size_t)(((ctrl_param) & IN_LEN_MASK) >> IN_LEN_OFFSET)) 56 57 #define PARAM_UNPACK_OUT_LEN(ctrl_param) \ 58 ((size_t)(((ctrl_param) & OUT_LEN_MASK) >> OUT_LEN_OFFSET)) 59 60 #define PARAM_SET_NS_VEC(ctrl_param) ((ctrl_param) | NS_VEC_DESC_BIT) 61 #define PARAM_IS_NS_VEC(ctrl_param) ((ctrl_param) & NS_VEC_DESC_BIT) 62 63 #define PARAM_SET_NS_INVEC(ctrl_param) ((ctrl_param) | NS_INVEC_BIT) 64 #define PARAM_IS_NS_INVEC(ctrl_param) ((ctrl_param) & NS_INVEC_BIT) 65 #define PARAM_SET_NS_OUTVEC(ctrl_param) ((ctrl_param) | NS_OUTVEC_BIT) 66 #define PARAM_IS_NS_OUTVEC(ctrl_param) ((ctrl_param) & NS_OUTVEC_BIT) 67 68 #define PARAM_HAS_IOVEC(ctrl_param) \ 69 ((ctrl_param) != (uint32_t)PARAM_UNPACK_TYPE(ctrl_param)) 70 71 psa_status_t tfm_psa_call_pack(psa_handle_t handle, 72 uint32_t ctrl_param, 73 const psa_invec *in_vec, 74 psa_outvec *out_vec); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 80 #endif /* __TFM_PSA_CALL_PACK_H__ */ 81