2 * Copyright 2016 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
6 * Some TPM constants and type definitions for standalone compilation for use
10 #ifndef __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM2_TSS_CONSTANTS_H
11 #define __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM2_TSS_CONSTANTS_H
13 #define TPM_BUFFER_SIZE 256
15 /* Tpm2 command tags. */
16 #define TPM_ST_NO_SESSIONS 0x8001
17 #define TPM_ST_SESSIONS 0x8002
19 /* TPM2 command codes. */
20 #define TPM2_Hierarchy_Control ((TPM_CC)0x00000121)
21 #define TPM2_NV_Write ((TPM_CC)0x00000137)
22 #define TPM2_NV_WriteLock ((TPM_CC)0x00000138)
23 #define TPM2_NV_Read ((TPM_CC)0x0000014E)
24 #define TPM2_GetCapability ((TPM_CC)0x0000017A)
26 /* TCG Spec defined, verify for TPM2.
27 * TODO(apronin): find TPM2 RC substitutes for TPM1.2 error codes.
29 #define TPM_E_BADINDEX ((uint32_t) 0x00000002)
30 #define TPM_E_INVALID_POSTINIT ((uint32_t) 0x00000026)
31 #define TPM_E_BADTAG ((uint32_t) 0x0000001E)
32 #define TPM_E_IOERROR ((uint32_t) 0x0000001F)
33 #define TPM_E_MAXNVWRITES ((uint32_t) 0x00000048)
36 #define TPM_HT_NV_INDEX 0x01
37 #define HR_NV_INDEX (TPM_HT_NV_INDEX << HR_SHIFT)
38 #define TPM_RH_PLATFORM 0x4000000C
39 #define TPM_RS_PW 0x40000009
41 /* TPM2 capabilities. */
42 #define TPM_CAP_FIRST ((TPM_CAP)0x00000000)
43 #define TPM_CAP_TPM_PROPERTIES ((TPM_CAP)0x00000006)
46 #define TPM_PT_NONE ((TPM_PT)0x00000000)
47 #define PT_GROUP ((TPM_PT)0x00000100)
48 #define PT_FIXED PT_GROUP
49 #define PT_VAR (PT_GROUP * 2)
50 #define TPM_PT_PERMANENT (PT_VAR + 0)
51 #define TPM_PT_STARTUP_CLEAR (PT_VAR + 1)
53 typedef uint8_t TPMI_YES_NO;
54 typedef uint32_t TPM_CC;
55 typedef uint32_t TPM_HANDLE;
56 typedef TPM_HANDLE TPMI_RH_NV_INDEX;
57 typedef TPM_HANDLE TPMI_RH_ENABLES;
58 typedef uint32_t TPM_CAP;
59 typedef uint32_t TPM_PT;
69 const uint8_t *buffer;
72 } TPM2B_MAX_NV_BUFFER;
77 } TPMS_TAGGED_PROPERTY;
81 TPMS_TAGGED_PROPERTY tpm_property[1];
82 } TPML_TAGGED_TPM_PROPERTY;
85 TPML_TAGGED_TPM_PROPERTY tpm_properties;
90 TPMU_CAPABILITIES data;
91 } TPMS_CAPABILITY_DATA;
93 struct tpm2_nv_read_cmd {
94 TPMI_RH_NV_INDEX nvIndex;
99 struct tpm2_nv_write_cmd {
100 TPMI_RH_NV_INDEX nvIndex;
101 TPM2B_MAX_NV_BUFFER data;
105 struct tpm2_nv_write_lock_cmd {
106 TPMI_RH_NV_INDEX nvIndex;
109 struct tpm2_hierarchy_control_cmd {
110 TPMI_RH_ENABLES enable;
114 struct tpm2_get_capability_cmd {
117 uint32_t property_count;
120 /* Common command/response header. */
125 } __attribute__((packed));
127 struct nv_read_response {
128 uint32_t params_size;
129 TPM2B_MAX_NV_BUFFER buffer;
132 struct tpm2_session_attrs {
133 uint8_t continueSession : 1;
134 uint8_t auditExclusive : 1;
135 uint8_t auditReset : 1;
136 uint8_t reserved3_4 : 2;
142 struct tpm2_session_header {
143 uint32_t session_handle;
147 struct tpm2_session_attrs session_attr_bits;
148 uint8_t session_attrs;
149 } __attribute__((packed));
154 struct get_capability_response {
155 TPMI_YES_NO more_data;
156 TPMS_CAPABILITY_DATA capability_data;
157 } __attribute__((packed));
159 struct tpm2_response {
160 struct tpm_header hdr;
162 struct nv_read_response nvr;
163 struct tpm2_session_header def_space;
164 struct get_capability_response cap;
169 uint32_t ownerAuthSet : 1;
170 uint32_t endorsementAuthSet : 1;
171 uint32_t lockoutAuthSet : 1;
172 uint32_t reserved3_7 : 5;
173 uint32_t disableClear : 1;
174 uint32_t inLockout : 1;
175 uint32_t tpmGeneratedEPS : 1;
176 uint32_t reserved11_31 : 21;
177 } TPM_PERMANENT_FLAGS;
180 uint32_t phEnable : 1;
181 uint32_t shEnable : 1;
182 uint32_t ehEnable : 1;
183 uint32_t phEnableNV : 1;
184 uint32_t reserved4_30 : 27;
185 uint32_t orderly : 1;
188 /* TODO(apronin): For TPM2 certain properties must be received using
189 * TPM2_GetCapability instead of being hardcoded as they are now:
190 * TPM_MAX_COMMAND_SIZE -> use TPM_PT_MAX_COMMAND_SIZE for TPM2.
191 * TPM_PCR_DIGEST -> use TPM_PT_MAX_DIGEST for TPM2.
193 #define TPM_MAX_COMMAND_SIZE 4096
194 #define TPM_PCR_DIGEST 32
196 #endif /* ! __VBOOT_REFERENCE_FIRMWARE_INCLUDE_TPM2_TSS_CONSTANTS_H */