]> git.ipfire.org Git - thirdparty/u-boot.git/blame - lib/tpm-utils.h
mmc: sdhci: Correct ADMA_DESC_LEN to 12
[thirdparty/u-boot.git] / lib / tpm-utils.h
CommitLineData
d677bfe2
MR
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2013 The Chromium OS Authors.
4 * Coypright (c) 2013 Guntermann & Drunck GmbH
5 */
6
7#ifndef __TPM_UTILS_H
8#define __TPM_UTILS_H
9
10#define COMMAND_BUFFER_SIZE 256
11
12/* Internal error of TPM command library */
13#define TPM_LIB_ERROR ((u32)~0u)
14
f6872816
MR
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)
20
d677bfe2
MR
21/**
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
28 * value.
29 *
30 * @param str output string
31 * @param size size of output string
32 * @param format format string
33 * @param ... data points
185f812c 34 * Return: 0 on success, non-0 on error
d677bfe2
MR
35 */
36int pack_byte_string(u8 *str, size_t size, const char *format, ...);
37
38/**
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
43 * lengths).
44 *
45 * @param str output string
46 * @param size size of output string
47 * @param format format string
48 * @param ... data points
185f812c 49 * Return: 0 on success, non-0 on error
d677bfe2
MR
50 */
51int unpack_byte_string(const u8 *str, size_t size, const char *format, ...);
52
53/**
54 * Get TPM command size.
55 *
56 * @param command byte string of TPM command
185f812c 57 * Return: command size of the TPM command
d677bfe2
MR
58 */
59u32 tpm_command_size(const void *command);
60
61/**
62 * Get TPM response return code, which is one of TPM_RESULT values.
63 *
64 * @param response byte string of TPM response
185f812c 65 * Return: return code of the TPM response
d677bfe2
MR
66 */
67u32 tpm_return_code(const void *response);
68
69/**
70 * Send a TPM command and return response's return code, and optionally
71 * return response to caller.
72 *
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
78 * is a bidirectional
185f812c 79 * Return: return code of the TPM response
d677bfe2 80 */
abdc7b8a
SG
81u32 tpm_sendrecv_command(struct udevice *dev, const void *command,
82 void *response, size_t *size_ptr);
d677bfe2
MR
83
84#endif /* __TPM_UTILS_H */