1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright (c) 2013 The Chromium OS Authors.
4 * Coypright (c) 2013 Guntermann & Drunck GmbH
10 #define COMMAND_BUFFER_SIZE 256
12 /* Internal error of TPM command library */
13 #define TPM_LIB_ERROR ((u32)~0u)
15 /* To make strings of commands more easily */
16 #define __MSB(x) ((x) >> 8)
17 #define __LSB(x) ((x) & 0xFF)
18 #define tpm_u16(x) __MSB(x), __LSB(x)
19 #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF)
22 * Pack data into a byte string. The data types are specified in
23 * the format string: 'b' means unsigned byte, 'w' unsigned word,
24 * 'd' unsigned double word, and 's' byte string. The data are a
25 * series of offsets and values (for type byte string there are also
26 * lengths). The data values are packed into the byte string
27 * sequentially, and so a latter value could over-write a former
30 * @param str output string
31 * @param size size of output string
32 * @param format format string
33 * @param ... data points
34 * Return: 0 on success, non-0 on error
36 int pack_byte_string(u8 *str, size_t size, const char *format, ...);
39 * Unpack data from a byte string. The data types are specified in
40 * the format string: 'b' means unsigned byte, 'w' unsigned word,
41 * 'd' unsigned double word, and 's' byte string. The data are a
42 * series of offsets and pointers (for type byte string there are also
45 * @param str output string
46 * @param size size of output string
47 * @param format format string
48 * @param ... data points
49 * Return: 0 on success, non-0 on error
51 int unpack_byte_string(const u8 *str, size_t size, const char *format, ...);
54 * Get TPM command size.
56 * @param command byte string of TPM command
57 * Return: command size of the TPM command
59 u32 tpm_command_size(const void *command);
62 * Get TPM response return code, which is one of TPM_RESULT values.
64 * @param response byte string of TPM response
65 * Return: return code of the TPM response
67 u32 tpm_return_code(const void *response);
70 * Send a TPM command and return response's return code, and optionally
71 * return response to caller.
73 * @param command byte string of TPM command
74 * @param response output buffer for TPM response, or NULL if the
75 * caller does not care about it
76 * @param size_ptr output buffer size (input parameter) and TPM
77 * response length (output parameter); this parameter
79 * Return: return code of the TPM response
81 u32 tpm_sendrecv_command(struct udevice *dev, const void *command,
82 void *response, size_t *size_ptr);
84 #endif /* __TPM_UTILS_H */