blob: e0d6f3079d3484ba8fe9f147d3b25c5b4d77e7c9 [file] [log] [blame]
Kevin O'Connordf50aaa2015-11-19 09:24:18 -05001#ifndef STD_TCG_H
2#define STD_TCG_H
3
4#include "types.h"
5
6/* Define for section 12.3 */
7#define TCG_PC_OK 0x0
8#define TCG_PC_TPMERROR 0x1
9#define TCG_PC_LOGOVERFLOW 0x2
10#define TCG_PC_UNSUPPORTED 0x3
11
12#define TPM_ALG_SHA 0x4
13
14#define TCG_MAGIC 0x41504354L
15#define TCG_VERSION_MAJOR 1
16#define TCG_VERSION_MINOR 2
17
18#define TPM_OK 0x0
19#define TPM_RET_BASE 0x1
20#define TCG_GENERAL_ERROR (TPM_RET_BASE + 0x0)
21#define TCG_TPM_IS_LOCKED (TPM_RET_BASE + 0x1)
22#define TCG_NO_RESPONSE (TPM_RET_BASE + 0x2)
23#define TCG_INVALID_RESPONSE (TPM_RET_BASE + 0x3)
24#define TCG_INVALID_ACCESS_REQUEST (TPM_RET_BASE + 0x4)
25#define TCG_FIRMWARE_ERROR (TPM_RET_BASE + 0x5)
26#define TCG_INTEGRITY_CHECK_FAILED (TPM_RET_BASE + 0x6)
27#define TCG_INVALID_DEVICE_ID (TPM_RET_BASE + 0x7)
28#define TCG_INVALID_VENDOR_ID (TPM_RET_BASE + 0x8)
29#define TCG_UNABLE_TO_OPEN (TPM_RET_BASE + 0x9)
30#define TCG_UNABLE_TO_CLOSE (TPM_RET_BASE + 0xa)
31#define TCG_RESPONSE_TIMEOUT (TPM_RET_BASE + 0xb)
32#define TCG_INVALID_COM_REQUEST (TPM_RET_BASE + 0xc)
33#define TCG_INVALID_ADR_REQUEST (TPM_RET_BASE + 0xd)
34#define TCG_WRITE_BYTE_ERROR (TPM_RET_BASE + 0xe)
35#define TCG_READ_BYTE_ERROR (TPM_RET_BASE + 0xf)
36#define TCG_BLOCK_WRITE_TIMEOUT (TPM_RET_BASE + 0x10)
37#define TCG_CHAR_WRITE_TIMEOUT (TPM_RET_BASE + 0x11)
38#define TCG_CHAR_READ_TIMEOUT (TPM_RET_BASE + 0x12)
39#define TCG_BLOCK_READ_TIMEOUT (TPM_RET_BASE + 0x13)
40#define TCG_TRANSFER_ABORT (TPM_RET_BASE + 0x14)
41#define TCG_INVALID_DRV_FUNCTION (TPM_RET_BASE + 0x15)
42#define TCG_OUTPUT_BUFFER_TOO_SHORT (TPM_RET_BASE + 0x16)
43#define TCG_FATAL_COM_ERROR (TPM_RET_BASE + 0x17)
44#define TCG_INVALID_INPUT_PARA (TPM_RET_BASE + 0x18)
45#define TCG_TCG_COMMAND_ERROR (TPM_RET_BASE + 0x19)
46#define TCG_INTERFACE_SHUTDOWN (TPM_RET_BASE + 0x20)
47//define TCG_PC_UNSUPPORTED (TPM_RET_BASE + 0x21)
48#define TCG_PC_TPM_NOT_PRESENT (TPM_RET_BASE + 0x22)
49#define TCG_PC_TPM_DEACTIVATED (TPM_RET_BASE + 0x23)
50
51
52#define TPM_ORD_SelfTestFull 0x00000050
53#define TPM_ORD_ForceClear 0x0000005d
54#define TPM_ORD_GetCapability 0x00000065
55#define TPM_ORD_PhysicalEnable 0x0000006f
56#define TPM_ORD_PhysicalDisable 0x00000070
57#define TPM_ORD_SetOwnerInstall 0x00000071
58#define TPM_ORD_PhysicalSetDeactivated 0x00000072
59#define TPM_ORD_SetTempDeactivated 0x00000073
60#define TPM_ORD_Startup 0x00000099
61#define TPM_ORD_PhysicalPresence 0x4000000a
62#define TPM_ORD_Extend 0x00000014
Kevin O'Connordf50aaa2015-11-19 09:24:18 -050063#define TSC_ORD_ResetEstablishmentBit 0x4000000b
64
65
66#define TPM_ST_CLEAR 0x1
67#define TPM_ST_STATE 0x2
68#define TPM_ST_DEACTIVATED 0x3
69
70
71/* TPM command error codes */
72#define TPM_INVALID_POSTINIT 0x26
73#define TPM_BAD_LOCALITY 0x3d
74
75/* TPM command tags */
76#define TPM_TAG_RQU_CMD 0x00c1
77
78/* interrupt identifiers (al register) */
79enum irq_ids {
80 TCG_StatusCheck = 0,
81 TCG_HashLogExtendEvent = 1,
82 TCG_PassThroughToTPM = 2,
83 TCG_ShutdownPreBootInterface = 3,
84 TCG_HashLogEvent = 4,
85 TCG_HashAll = 5,
86 TCG_TSS = 6,
87 TCG_CompactHashLogExtendEvent = 7,
88};
89
90/* event types: 10.4.1 / table 11 */
91#define EV_POST_CODE 1
92#define EV_SEPARATOR 4
93#define EV_ACTION 5
94#define EV_EVENT_TAG 6
95#define EV_COMPACT_HASH 12
96#define EV_IPL 13
97#define EV_IPL_PARTITION_DATA 14
98
99#define SHA1_BUFSIZE 20
100
101/* Input and Output blocks for the TCG BIOS commands */
102
103struct hleei_short
104{
105 u16 ipblength;
106 u16 reserved;
107 const void *hashdataptr;
108 u32 hashdatalen;
109 u32 pcrindex;
110 const void *logdataptr;
111 u32 logdatalen;
112} PACKED;
113
114
115struct hleei_long
116{
117 u16 ipblength;
118 u16 reserved;
119 void *hashdataptr;
120 u32 hashdatalen;
121 u32 pcrindex;
122 u32 reserved2;
123 void *logdataptr;
124 u32 logdatalen;
125} PACKED;
126
127
128struct hleeo
129{
130 u16 opblength;
131 u16 reserved;
132 u32 eventnumber;
133 u8 digest[SHA1_BUFSIZE];
134} PACKED;
135
136
137struct pttti
138{
139 u16 ipblength;
140 u16 reserved;
141 u16 opblength;
142 u16 reserved2;
143 u8 tpmopin[0];
144} PACKED;
145
146
147struct pttto
148{
149 u16 opblength;
150 u16 reserved;
151 u8 tpmopout[0];
152};
153
154
155struct hlei
156{
157 u16 ipblength;
158 u16 reserved;
159 const void *hashdataptr;
160 u32 hashdatalen;
161 u32 pcrindex;
162 u32 logeventtype;
163 const void *logdataptr;
164 u32 logdatalen;
165} PACKED;
166
167
168struct hleo
169{
170 u16 opblength;
171 u16 reserved;
172 u32 eventnumber;
173} PACKED;
174
175
176struct hai
177{
178 u16 ipblength;
179 u16 reserved;
180 const void *hashdataptr;
181 u32 hashdatalen;
182 u32 algorithmid;
183} PACKED;
184
185
186struct ti
187{
188 u16 ipblength;
189 u16 reserved;
190 u16 opblength;
191 u16 reserved2;
192 u8 tssoperandin[0];
193} PACKED;
194
195
196struct to
197{
198 u16 opblength;
199 u16 reserved;
200 u8 tssoperandout[0];
201} PACKED;
202
203
204struct pcpes
205{
206 u32 pcrindex;
207 u32 eventtype;
208 u8 digest[SHA1_BUFSIZE];
209 u32 eventdatasize;
Kevin O'Connorbad6f962015-11-23 22:32:09 -0500210 u8 event[0];
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500211} PACKED;
212
213struct pcctes
214{
215 u32 eventid;
216 u32 eventdatasize;
217 u8 digest[SHA1_BUFSIZE];
218} PACKED;
219
220struct pcctes_romex
221{
222 u32 eventid;
223 u32 eventdatasize;
224 u16 reserved;
225 u16 pfa;
226 u8 digest[SHA1_BUFSIZE];
227} PACKED;
228
229
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500230struct tpm_req_header {
Kevin O'Connora0599152015-11-28 08:08:57 -0500231 u16 tag;
232 u32 totlen;
233 u32 ordinal;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500234} PACKED;
235
236
237struct tpm_rsp_header {
Kevin O'Connora0599152015-11-28 08:08:57 -0500238 u16 tag;
239 u32 totlen;
240 u32 errcode;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500241} PACKED;
242
243
244struct tpm_req_extend {
Kevin O'Connora0599152015-11-28 08:08:57 -0500245 struct tpm_req_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500246 u32 pcrindex;
247 u8 digest[SHA1_BUFSIZE];
248} PACKED;
249
250
251struct tpm_rsp_extend {
Kevin O'Connora0599152015-11-28 08:08:57 -0500252 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500253 u8 digest[SHA1_BUFSIZE];
254} PACKED;
255
256
Kevin O'Connorca606362015-12-29 14:21:29 -0500257struct tpm_req_getcap {
Kevin O'Connora0599152015-11-28 08:08:57 -0500258 struct tpm_req_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500259 u32 capArea;
260 u32 subCapSize;
261 u32 subCap;
262} PACKED;
263
Kevin O'Connorca606362015-12-29 14:21:29 -0500264#define TPM_CAP_FLAG 0x04
265#define TPM_CAP_PROPERTY 0x05
266#define TPM_CAP_FLAG_PERMANENT 0x108
267#define TPM_CAP_FLAG_VOLATILE 0x109
268#define TPM_CAP_PROP_OWNER 0x111
269#define TPM_CAP_PROP_TIS_TIMEOUT 0x115
270#define TPM_CAP_PROP_DURATION 0x120
271
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500272
273struct tpm_permanent_flags {
274 u16 tag;
275 u8 flags[20];
276} PACKED;
277
278
279enum permFlagsIndex {
280 PERM_FLAG_IDX_DISABLE = 0,
281 PERM_FLAG_IDX_OWNERSHIP,
282 PERM_FLAG_IDX_DEACTIVATED,
283 PERM_FLAG_IDX_READPUBEK,
284 PERM_FLAG_IDX_DISABLEOWNERCLEAR,
285 PERM_FLAG_IDX_ALLOW_MAINTENANCE,
286 PERM_FLAG_IDX_PHYSICAL_PRESENCE_LIFETIME_LOCK,
287 PERM_FLAG_IDX_PHYSICAL_PRESENCE_HW_ENABLE,
Stefan Bergera2206d32016-01-07 12:02:48 -0500288 PERM_FLAG_IDX_PHYSICAL_PRESENCE_CMD_ENABLE,
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500289};
290
291
292struct tpm_res_getcap_perm_flags {
Kevin O'Connora0599152015-11-28 08:08:57 -0500293 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500294 u32 size;
295 struct tpm_permanent_flags perm_flags;
296} PACKED;
297
Stefan Berger320df852015-11-30 11:14:19 -0500298struct tpm_stclear_flags {
299 u16 tag;
300 u8 flags[5];
301} PACKED;
302
303#define STCLEAR_FLAG_IDX_DEACTIVATED 0
304#define STCLEAR_FLAG_IDX_DISABLE_FORCE_CLEAR 1
305#define STCLEAR_FLAG_IDX_PHYSICAL_PRESENCE 2
306#define STCLEAR_FLAG_IDX_PHYSICAL_PRESENCE_LOCK 3
307#define STCLEAR_FLAG_IDX_GLOBAL_LOCK 4
308
309struct tpm_res_getcap_stclear_flags {
Kevin O'Connora0599152015-11-28 08:08:57 -0500310 struct tpm_rsp_header hdr;
Stefan Berger320df852015-11-30 11:14:19 -0500311 u32 size;
312 struct tpm_stclear_flags stclear_flags;
313} PACKED;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500314
315struct tpm_res_getcap_ownerauth {
Kevin O'Connora0599152015-11-28 08:08:57 -0500316 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500317 u32 size;
318 u8 flag;
319} PACKED;
320
321
322struct tpm_res_getcap_timeouts {
Kevin O'Connora0599152015-11-28 08:08:57 -0500323 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500324 u32 size;
325 u32 timeouts[4];
326} PACKED;
327
328
329struct tpm_res_getcap_durations {
Kevin O'Connora0599152015-11-28 08:08:57 -0500330 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500331 u32 size;
332 u32 durations[3];
333} PACKED;
334
335
336struct tpm_res_sha1start {
Kevin O'Connora0599152015-11-28 08:08:57 -0500337 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500338 u32 max_num_bytes;
339} PACKED;
340
341
342struct tpm_res_sha1complete {
Kevin O'Connora0599152015-11-28 08:08:57 -0500343 struct tpm_rsp_header hdr;
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500344 u8 hash[20];
345} PACKED;
346
Stefan Berger320df852015-11-30 11:14:19 -0500347#define TPM_STATE_ENABLED 1
348#define TPM_STATE_ACTIVE 2
349#define TPM_STATE_OWNED 4
350#define TPM_STATE_OWNERINSTALL 8
351
352/*
353 * physical presence interface
354 */
355
356#define TPM_PPI_OP_NOOP 0
357#define TPM_PPI_OP_ENABLE 1
358#define TPM_PPI_OP_DISABLE 2
359#define TPM_PPI_OP_ACTIVATE 3
360#define TPM_PPI_OP_DEACTIVATE 4
361#define TPM_PPI_OP_CLEAR 5
362#define TPM_PPI_OP_SET_OWNERINSTALL_TRUE 8
363#define TPM_PPI_OP_SET_OWNERINSTALL_FALSE 9
364
Stefan Bergerf53b93b2016-02-02 13:09:12 -0500365/*
366 * TPM 2
367 */
368
369#define TPM2_NO 0
370#define TPM2_YES 1
371
372#define TPM2_SU_CLEAR 0x0000
373#define TPM2_SU_STATE 0x0001
374
Stefan Bergerd766c1a2016-02-02 13:09:14 -0500375#define TPM2_RS_PW 0x40000009
376#define TPM2_RH_PLATFORM 0x4000000c
377
Stefan Bergerf53b93b2016-02-02 13:09:12 -0500378/* TPM 2 command tags */
379#define TPM2_ST_NO_SESSIONS 0x8001
Stefan Bergerd766c1a2016-02-02 13:09:14 -0500380#define TPM2_ST_SESSIONS 0x8002
Stefan Bergerf53b93b2016-02-02 13:09:12 -0500381
382/* TPM 2 commands */
Stefan Bergerd766c1a2016-02-02 13:09:14 -0500383#define TPM2_CC_HierarchyChangeAuth 0x129
Stefan Bergerf53b93b2016-02-02 13:09:12 -0500384#define TPM2_CC_SelfTest 0x143
385#define TPM2_CC_Startup 0x144
Stefan Bergerd766c1a2016-02-02 13:09:14 -0500386#define TPM2_CC_StirRandom 0x146
387#define TPM2_CC_GetRandom 0x17b
Stefan Bergerf53b93b2016-02-02 13:09:12 -0500388
389/* TPM 2 error codes */
390#define TPM2_RC_INITIALIZE 0x100
391
Stefan Bergerd766c1a2016-02-02 13:09:14 -0500392/* TPM 2 data structures */
393
394struct tpm2b_stir {
395 u16 size;
396 u64 stir;
397} PACKED;
398
399struct tpm2_req_getrandom {
400 struct tpm_req_header hdr;
401 u16 bytesRequested;
402} PACKED;
403
404struct tpm2b_20 {
405 u16 size;
406 u8 buffer[20];
407} PACKED;
408
409struct tpm2_res_getrandom {
410 struct tpm_rsp_header hdr;
411 struct tpm2b_20 rnd;
412} PACKED;
413
414struct tpm2_authblock {
415 u32 handle;
416 u16 noncesize; /* always 0 */
417 u8 contsession; /* always TPM2_YES */
418 u16 pwdsize; /* always 0 */
419} PACKED;
420
421struct tpm2_req_hierarchychangeauth {
422 struct tpm_req_header hdr;
423 u32 authhandle;
424 u32 authblocksize;
425 struct tpm2_authblock authblock;
426 struct tpm2b_20 newAuth;
427} PACKED;
428
Kevin O'Connordf50aaa2015-11-19 09:24:18 -0500429#endif // tcg.h