]> git.ipfire.org Git - thirdparty/u-boot.git/blob - drivers/tpm/tpm_tis.h
SPDX: Convert all of our single license tags to Linux Kernel style
[thirdparty/u-boot.git] / drivers / tpm / tpm_tis.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 2011 Infineon Technologies
4 *
5 * Authors:
6 * Peter Huewe <huewe.external@infineon.com>
7 *
8 * Version: 2.1.1
9 *
10 * Description:
11 * Device driver for TCG/TCPA TPM (trusted platform module).
12 * Specifications at www.trustedcomputinggroup.org
13 *
14 * It is based on the Linux kernel driver tpm.c from Leendert van
15 * Dorn, Dave Safford, Reiner Sailer, and Kyleen Hall.
16 */
17
18 #ifndef _TPM_TIS_I2C_H
19 #define _TPM_TIS_I2C_H
20
21 #include <linux/compiler.h>
22 #include <linux/types.h>
23
24 enum tpm_timeout {
25 TPM_TIMEOUT_MS = 5,
26 TIS_SHORT_TIMEOUT_MS = 750,
27 TIS_LONG_TIMEOUT_MS = 2000,
28 SLEEP_DURATION_US = 60,
29 SLEEP_DURATION_LONG_US = 210,
30 };
31
32 /* Size of external transmit buffer (used in tpm_transmit)*/
33 #define TPM_BUFSIZE 4096
34
35 /* Index of Count field in TPM response buffer */
36 #define TPM_RSP_SIZE_BYTE 2
37 #define TPM_RSP_RC_BYTE 6
38
39 struct tpm_chip {
40 int is_open;
41 int locality;
42 u32 vend_dev;
43 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* msec */
44 ulong chip_type;
45 };
46
47 struct tpm_input_header {
48 __be16 tag;
49 __be32 length;
50 __be32 ordinal;
51 } __packed;
52
53 struct tpm_output_header {
54 __be16 tag;
55 __be32 length;
56 __be32 return_code;
57 } __packed;
58
59 struct timeout_t {
60 __be32 a;
61 __be32 b;
62 __be32 c;
63 __be32 d;
64 } __packed;
65
66 struct duration_t {
67 __be32 tpm_short;
68 __be32 tpm_medium;
69 __be32 tpm_long;
70 } __packed;
71
72 union cap_t {
73 struct timeout_t timeout;
74 struct duration_t duration;
75 };
76
77 struct tpm_getcap_params_in {
78 __be32 cap;
79 __be32 subcap_size;
80 __be32 subcap;
81 } __packed;
82
83 struct tpm_getcap_params_out {
84 __be32 cap_size;
85 union cap_t cap;
86 } __packed;
87
88 union tpm_cmd_header {
89 struct tpm_input_header in;
90 struct tpm_output_header out;
91 };
92
93 union tpm_cmd_params {
94 struct tpm_getcap_params_out getcap_out;
95 struct tpm_getcap_params_in getcap_in;
96 };
97
98 struct tpm_cmd_t {
99 union tpm_cmd_header header;
100 union tpm_cmd_params params;
101 } __packed;
102
103 /* Max number of iterations after i2c NAK */
104 #define MAX_COUNT 3
105
106 /*
107 * Max number of iterations after i2c NAK for 'long' commands
108 *
109 * We need this especially for sending TPM_READY, since the cleanup after the
110 * transtion to the ready state may take some time, but it is unpredictable
111 * how long it will take.
112 */
113 #define MAX_COUNT_LONG 50
114
115 enum tis_access {
116 TPM_ACCESS_VALID = 0x80,
117 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
118 TPM_ACCESS_REQUEST_PENDING = 0x04,
119 TPM_ACCESS_REQUEST_USE = 0x02,
120 };
121
122 enum tis_status {
123 TPM_STS_VALID = 0x80,
124 TPM_STS_COMMAND_READY = 0x40,
125 TPM_STS_GO = 0x20,
126 TPM_STS_DATA_AVAIL = 0x10,
127 TPM_STS_DATA_EXPECT = 0x08,
128 };
129
130 #endif