1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
25
26
27struct tpm_tis_phy_ops {
28
29
30
31
32
33
34
35
36
37 int (*read_bytes)(struct udevice *udev, u32 addr, u16 len,
38 u8 *result);
39
40
41
42
43
44
45
46
47
48 int (*write_bytes)(struct udevice *udev, u32 addr, u16 len,
49 const u8 *value);
50
51
52
53
54
55
56
57
58 int (*read32)(struct udevice *udev, u32 addr, u32 *result);
59
60
61
62
63
64
65
66
67 int (*write32)(struct udevice *udev, u32 addr, u32 src);
68};
69
70enum tis_int_flags {
71 TPM_GLOBAL_INT_ENABLE = 0x80000000,
72 TPM_INTF_BURST_COUNT_STATIC = 0x100,
73 TPM_INTF_CMD_READY_INT = 0x080,
74 TPM_INTF_INT_EDGE_FALLING = 0x040,
75 TPM_INTF_INT_EDGE_RISING = 0x020,
76 TPM_INTF_INT_LEVEL_LOW = 0x010,
77 TPM_INTF_INT_LEVEL_HIGH = 0x008,
78 TPM_INTF_LOCALITY_CHANGE_INT = 0x004,
79 TPM_INTF_STS_VALID_INT = 0x002,
80 TPM_INTF_DATA_AVAIL_INT = 0x001,
81};
82
83#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
84#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
85#define TPM_STS(l) (0x0018 | ((l) << 12))
86#define TPM_DATA_FIFO(l) (0x0024 | ((l) << 12))
87#define TPM_DID_VID(l) (0x0f00 | ((l) << 12))
88#define TPM_RID(l) (0x0f04 | ((l) << 12))
89#define TPM_INTF_CAPS(l) (0x0014 | ((l) << 12))
90
91enum tpm_timeout {
92 TPM_TIMEOUT_MS = 5,
93 TIS_SHORT_TIMEOUT_MS = 750,
94 TIS_LONG_TIMEOUT_MS = 2000,
95 SLEEP_DURATION_US = 60,
96 SLEEP_DURATION_LONG_US = 210,
97};
98
99
100#define TPM_BUFSIZE 4096
101
102
103#define TPM_RSP_SIZE_BYTE 2
104#define TPM_RSP_RC_BYTE 6
105
106struct tpm_chip {
107 int is_open;
108 int locality;
109 u32 vend_dev;
110 u8 rid;
111 unsigned long timeout_a, timeout_b, timeout_c, timeout_d;
112 ulong chip_type;
113 struct tpm_tis_phy_ops *phy_ops;
114};
115
116struct tpm_input_header {
117 __be16 tag;
118 __be32 length;
119 __be32 ordinal;
120} __packed;
121
122struct tpm_output_header {
123 __be16 tag;
124 __be32 length;
125 __be32 return_code;
126} __packed;
127
128struct timeout_t {
129 __be32 a;
130 __be32 b;
131 __be32 c;
132 __be32 d;
133} __packed;
134
135struct duration_t {
136 __be32 tpm_short;
137 __be32 tpm_medium;
138 __be32 tpm_long;
139} __packed;
140
141union cap_t {
142 struct timeout_t timeout;
143 struct duration_t duration;
144};
145
146struct tpm_getcap_params_in {
147 __be32 cap;
148 __be32 subcap_size;
149 __be32 subcap;
150} __packed;
151
152struct tpm_getcap_params_out {
153 __be32 cap_size;
154 union cap_t cap;
155} __packed;
156
157union tpm_cmd_header {
158 struct tpm_input_header in;
159 struct tpm_output_header out;
160};
161
162union tpm_cmd_params {
163 struct tpm_getcap_params_out getcap_out;
164 struct tpm_getcap_params_in getcap_in;
165};
166
167struct tpm_cmd_t {
168 union tpm_cmd_header header;
169 union tpm_cmd_params params;
170} __packed;
171
172
173#define MAX_COUNT 3
174
175#ifndef __TPM_V2_H
176
177
178
179
180
181
182
183#define MAX_COUNT_LONG 50
184
185enum tis_access {
186 TPM_ACCESS_VALID = 0x80,
187 TPM_ACCESS_ACTIVE_LOCALITY = 0x20,
188 TPM_ACCESS_REQUEST_PENDING = 0x04,
189 TPM_ACCESS_REQUEST_USE = 0x02,
190};
191
192enum tis_status {
193 TPM_STS_VALID = 0x80,
194 TPM_STS_COMMAND_READY = 0x40,
195 TPM_STS_GO = 0x20,
196 TPM_STS_DATA_AVAIL = 0x10,
197 TPM_STS_DATA_EXPECT = 0x08,
198};
199#endif
200
201
202
203
204
205
206
207
208int tpm_tis_open(struct udevice *udev);
209
210
211
212
213
214
215
216int tpm_tis_close(struct udevice *udev);
217
218
219
220
221
222
223int tpm_tis_cleanup(struct udevice *udev);
224
225
226
227
228
229
230
231
232
233int tpm_tis_send(struct udevice *udev, const u8 *buf, size_t len);
234
235
236
237
238
239
240
241
242
243int tpm_tis_recv(struct udevice *udev, u8 *buf, size_t count);
244
245
246
247
248
249
250
251
252
253int tpm_tis_get_desc(struct udevice *udev, char *buf, int size);
254
255
256
257
258
259
260
261int tpm_tis_init(struct udevice *udev);
262
263
264
265
266
267
268void tpm_tis_ops_register(struct udevice *udev, struct tpm_tis_phy_ops *ops);
269#endif
270