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