blob: ca90a105ab8740f7d44bc32665b0a7f15d64335e [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
63#define TPM_ORD_SHA1Start 0x000000a0
64#define TPM_ORD_SHA1Update 0x000000a1
65#define TPM_ORD_SHA1Complete 0x000000a2
66#define TSC_ORD_ResetEstablishmentBit 0x4000000b
67
68
69#define TPM_ST_CLEAR 0x1
70#define TPM_ST_STATE 0x2
71#define TPM_ST_DEACTIVATED 0x3
72
73
74/* TPM command error codes */
75#define TPM_INVALID_POSTINIT 0x26
76#define TPM_BAD_LOCALITY 0x3d
77
78/* TPM command tags */
79#define TPM_TAG_RQU_CMD 0x00c1
80
81/* interrupt identifiers (al register) */
82enum irq_ids {
83 TCG_StatusCheck = 0,
84 TCG_HashLogExtendEvent = 1,
85 TCG_PassThroughToTPM = 2,
86 TCG_ShutdownPreBootInterface = 3,
87 TCG_HashLogEvent = 4,
88 TCG_HashAll = 5,
89 TCG_TSS = 6,
90 TCG_CompactHashLogExtendEvent = 7,
91};
92
93/* event types: 10.4.1 / table 11 */
94#define EV_POST_CODE 1
95#define EV_SEPARATOR 4
96#define EV_ACTION 5
97#define EV_EVENT_TAG 6
98#define EV_COMPACT_HASH 12
99#define EV_IPL 13
100#define EV_IPL_PARTITION_DATA 14
101
102#define SHA1_BUFSIZE 20
103
104/* Input and Output blocks for the TCG BIOS commands */
105
106struct hleei_short
107{
108 u16 ipblength;
109 u16 reserved;
110 const void *hashdataptr;
111 u32 hashdatalen;
112 u32 pcrindex;
113 const void *logdataptr;
114 u32 logdatalen;
115} PACKED;
116
117
118struct hleei_long
119{
120 u16 ipblength;
121 u16 reserved;
122 void *hashdataptr;
123 u32 hashdatalen;
124 u32 pcrindex;
125 u32 reserved2;
126 void *logdataptr;
127 u32 logdatalen;
128} PACKED;
129
130
131struct hleeo
132{
133 u16 opblength;
134 u16 reserved;
135 u32 eventnumber;
136 u8 digest[SHA1_BUFSIZE];
137} PACKED;
138
139
140struct pttti
141{
142 u16 ipblength;
143 u16 reserved;
144 u16 opblength;
145 u16 reserved2;
146 u8 tpmopin[0];
147} PACKED;
148
149
150struct pttto
151{
152 u16 opblength;
153 u16 reserved;
154 u8 tpmopout[0];
155};
156
157
158struct hlei
159{
160 u16 ipblength;
161 u16 reserved;
162 const void *hashdataptr;
163 u32 hashdatalen;
164 u32 pcrindex;
165 u32 logeventtype;
166 const void *logdataptr;
167 u32 logdatalen;
168} PACKED;
169
170
171struct hleo
172{
173 u16 opblength;
174 u16 reserved;
175 u32 eventnumber;
176} PACKED;
177
178
179struct hai
180{
181 u16 ipblength;
182 u16 reserved;
183 const void *hashdataptr;
184 u32 hashdatalen;
185 u32 algorithmid;
186} PACKED;
187
188
189struct ti
190{
191 u16 ipblength;
192 u16 reserved;
193 u16 opblength;
194 u16 reserved2;
195 u8 tssoperandin[0];
196} PACKED;
197
198
199struct to
200{
201 u16 opblength;
202 u16 reserved;
203 u8 tssoperandout[0];
204} PACKED;
205
206
207struct pcpes
208{
209 u32 pcrindex;
210 u32 eventtype;
211 u8 digest[SHA1_BUFSIZE];
212 u32 eventdatasize;
213 u32 event;
214} PACKED;
215
216struct pcctes
217{
218 u32 eventid;
219 u32 eventdatasize;
220 u8 digest[SHA1_BUFSIZE];
221} PACKED;
222
223struct pcctes_romex
224{
225 u32 eventid;
226 u32 eventdatasize;
227 u16 reserved;
228 u16 pfa;
229 u8 digest[SHA1_BUFSIZE];
230} PACKED;
231
232
233#define TPM_REQ_HEADER \
234 u16 tag; \
235 u32 totlen; \
236 u32 ordinal;
237
238#define TPM_REQ_HEADER_SIZE (sizeof(u16) + sizeof(u32) + sizeof(u32))
239
240#define TPM_RSP_HEADER \
241 u16 tag; \
242 u32 totlen; \
243 u32 errcode;
244
245#define TPM_RSP_HEADER_SIZE (sizeof(u16) + sizeof(u32) + sizeof(u32))
246
247struct tpm_req_header {
248 TPM_REQ_HEADER;
249} PACKED;
250
251
252struct tpm_rsp_header {
253 TPM_RSP_HEADER;
254} PACKED;
255
256
257struct tpm_req_extend {
258 TPM_REQ_HEADER
259 u32 pcrindex;
260 u8 digest[SHA1_BUFSIZE];
261} PACKED;
262
263
264struct tpm_rsp_extend {
265 TPM_RSP_HEADER
266 u8 digest[SHA1_BUFSIZE];
267} PACKED;
268
269
270struct tpm_req_getcap_perm_flags {
271 TPM_REQ_HEADER
272 u32 capArea;
273 u32 subCapSize;
274 u32 subCap;
275} PACKED;
276
277
278struct tpm_permanent_flags {
279 u16 tag;
280 u8 flags[20];
281} PACKED;
282
283
284enum permFlagsIndex {
285 PERM_FLAG_IDX_DISABLE = 0,
286 PERM_FLAG_IDX_OWNERSHIP,
287 PERM_FLAG_IDX_DEACTIVATED,
288 PERM_FLAG_IDX_READPUBEK,
289 PERM_FLAG_IDX_DISABLEOWNERCLEAR,
290 PERM_FLAG_IDX_ALLOW_MAINTENANCE,
291 PERM_FLAG_IDX_PHYSICAL_PRESENCE_LIFETIME_LOCK,
292 PERM_FLAG_IDX_PHYSICAL_PRESENCE_HW_ENABLE,
293};
294
295
296struct tpm_res_getcap_perm_flags {
297 TPM_RSP_HEADER
298 u32 size;
299 struct tpm_permanent_flags perm_flags;
300} PACKED;
301
302
303struct tpm_res_getcap_ownerauth {
304 TPM_RSP_HEADER
305 u32 size;
306 u8 flag;
307} PACKED;
308
309
310struct tpm_res_getcap_timeouts {
311 TPM_RSP_HEADER
312 u32 size;
313 u32 timeouts[4];
314} PACKED;
315
316
317struct tpm_res_getcap_durations {
318 TPM_RSP_HEADER
319 u32 size;
320 u32 durations[3];
321} PACKED;
322
323
324struct tpm_res_sha1start {
325 TPM_RSP_HEADER
326 u32 max_num_bytes;
327} PACKED;
328
329
330struct tpm_res_sha1complete {
331 TPM_RSP_HEADER
332 u8 hash[20];
333} PACKED;
334
335struct pttti_extend {
336 struct pttti pttti;
337 struct tpm_req_extend req;
338} PACKED;
339
340
341struct pttto_extend {
342 struct pttto pttto;
343 struct tpm_rsp_extend rsp;
344} PACKED;
345
346#endif // tcg.h