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 * tpm_open() - Request access to locality 0 for the caller
24 * After all commands have been completed the caller is supposed to
27 * Returns 0 on success, -ve on failure.
29 int tpm_open(struct udevice *dev);
32 * tpm_close() - Close the current session
34 * Releasing the locked locality. Returns 0 on success, -ve 1 on
35 * failure (in case lock removal did not succeed).
37 int tpm_close(struct udevice *dev);
40 * Pack data into a byte string. The data types are specified in
41 * the format string: 'b' means unsigned byte, 'w' unsigned word,
42 * 'd' unsigned double word, and 's' byte string. The data are a
43 * series of offsets and values (for type byte string there are also
44 * lengths). The data values are packed into the byte string
45 * sequentially, and so a latter value could over-write a former
48 * @param str output string
49 * @param size size of output string
50 * @param format format string
51 * @param ... data points
52 * @return 0 on success, non-0 on error
54 int pack_byte_string(u8 *str, size_t size, const char *format, ...);
57 * Unpack data from a byte string. The data types are specified in
58 * the format string: 'b' means unsigned byte, 'w' unsigned word,
59 * 'd' unsigned double word, and 's' byte string. The data are a
60 * series of offsets and pointers (for type byte string there are also
63 * @param str output string
64 * @param size size of output string
65 * @param format format string
66 * @param ... data points
67 * @return 0 on success, non-0 on error
69 int unpack_byte_string(const u8 *str, size_t size, const char *format, ...);
72 * Get TPM command size.
74 * @param command byte string of TPM command
75 * @return command size of the TPM command
77 u32 tpm_command_size(const void *command);
80 * Get TPM response return code, which is one of TPM_RESULT values.
82 * @param response byte string of TPM response
83 * @return return code of the TPM response
85 u32 tpm_return_code(const void *response);
88 * Send a TPM command and return response's return code, and optionally
89 * return response to caller.
91 * @param command byte string of TPM command
92 * @param response output buffer for TPM response, or NULL if the
93 * caller does not care about it
94 * @param size_ptr output buffer size (input parameter) and TPM
95 * response length (output parameter); this parameter
97 * @return return code of the TPM response
99 u32 tpm_sendrecv_command(const void *command, void *response, size_t *size_ptr);
101 #endif /* __TPM_UTILS_H */