1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2022, Linaro Limited 4 */ 5 6 #ifndef __DRIVERS_TPM2_CMD_H 7 #define __DRIVERS_TPM2_CMD_H 8 9 #include <compiler.h> 10 #include <io.h> 11 #include <stdint.h> 12 #include <utee_defines.h> 13 14 /* TPM Command Response structure */ 15 struct tpm2_cmd_hdr { 16 uint16_t tag; 17 uint32_t size; /* size of command/response */ 18 uint32_t code; /* command code or response code */ 19 } __packed; 20 21 #define TPM2_HDR_LEN sizeof(struct tpm2_cmd_hdr) 22 23 /* 24 * A command indicates the operation to be performed by the TPM. It contains 25 * a command header followed by command dependent data which may include 26 * handles, authorization area and command dependent parameters. 27 */ 28 struct tpm2_cmd { 29 struct tpm2_cmd_hdr hdr; 30 uint8_t data[]; 31 } __packed; 32 33 /* Returns total number of octets in the command/response starting from tag */ tpm2_cmd_len(struct tpm2_cmd * cmd)34static inline uint16_t tpm2_cmd_len(struct tpm2_cmd *cmd) 35 { 36 return TEE_U32_FROM_BIG_ENDIAN(cmd->hdr.size); 37 } 38 tpm2_cmd_code(struct tpm2_cmd * cmd)39static inline uint16_t tpm2_cmd_code(struct tpm2_cmd *cmd) 40 { 41 return TEE_U32_FROM_BIG_ENDIAN(cmd->hdr.code); 42 } 43 tpm2_ret_code(struct tpm2_cmd * cmd)44static inline uint16_t tpm2_ret_code(struct tpm2_cmd *cmd) 45 { 46 return TEE_U32_FROM_BIG_ENDIAN(cmd->hdr.code); 47 } 48 49 #endif /* __DRIVERS_TPM2_CMD_H */ 50 51