blob: 45b7a4831d46a6b8903b6fe59c0e7f4f4cda0821 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Vadim Bendeburydac69642011-10-17 08:36:14 +00002/*
Che-liang Chiouc18f9012013-02-28 09:34:57 +00003 * Copyright (c) 2013 The Chromium OS Authors.
Reinhard Pfau4fece432013-06-26 15:55:13 +02004 * Coypright (c) 2013 Guntermann & Drunck GmbH
Vadim Bendeburydac69642011-10-17 08:36:14 +00005 */
6
Miquel Raynal4c6759e2018-05-15 11:57:06 +02007#ifndef __TPM_V1_H
8#define __TPM_V1_H
Vadim Bendeburydac69642011-10-17 08:36:14 +00009
Miquel Raynal4c6759e2018-05-15 11:57:06 +020010#include <tpm-common.h>
Simon Glass6c7a2322015-08-22 18:31:31 -060011
Miquel Raynal4c6759e2018-05-15 11:57:06 +020012/* Useful constants */
13enum {
14 TPM_REQUEST_HEADER_LENGTH = 10,
15 TPM_RESPONSE_HEADER_LENGTH = 10,
16 PCR_DIGEST_LENGTH = 20,
17 DIGEST_LENGTH = 20,
18 TPM_REQUEST_AUTH_LENGTH = 45,
19 TPM_RESPONSE_AUTH_LENGTH = 41,
20 /* some max lengths, valid for RSA keys <= 2048 bits */
21 TPM_KEY12_MAX_LENGTH = 618,
22 TPM_PUBKEY_MAX_LENGTH = 288,
Simon Glass6c7a2322015-08-22 18:31:31 -060023};
24
Che-liang Chiouc18f9012013-02-28 09:34:57 +000025enum tpm_startup_type {
26 TPM_ST_CLEAR = 0x0001,
27 TPM_ST_STATE = 0x0002,
28 TPM_ST_DEACTIVATED = 0x0003,
29};
30
31enum tpm_physical_presence {
32 TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200,
33 TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100,
34 TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080,
35 TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040,
36 TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020,
37 TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010,
38 TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008,
39 TPM_PHYSICAL_PRESENCE_LOCK = 0x0004,
40};
41
42enum tpm_nv_index {
43 TPM_NV_INDEX_LOCK = 0xffffffff,
44 TPM_NV_INDEX_0 = 0x00000000,
45 TPM_NV_INDEX_DIR = 0x10000001,
46};
47
Mario Six4eceb6c2017-01-11 16:00:50 +010048enum tpm_resource_type {
49 TPM_RT_KEY = 0x00000001,
50 TPM_RT_AUTH = 0x00000002,
51 TPM_RT_HASH = 0x00000003,
52 TPM_RT_TRANS = 0x00000004,
53 TPM_RT_CONTEXT = 0x00000005,
54 TPM_RT_COUNTER = 0x00000006,
55 TPM_RT_DELEGATE = 0x00000007,
56 TPM_RT_DAA_TPM = 0x00000008,
57 TPM_RT_DAA_V0 = 0x00000009,
58 TPM_RT_DAA_V1 = 0x0000000A,
59};
60
61enum tpm_capability_areas {
62 TPM_CAP_ORD = 0x00000001,
63 TPM_CAP_ALG = 0x00000002,
64 TPM_CAP_PID = 0x00000003,
65 TPM_CAP_FLAG = 0x00000004,
66 TPM_CAP_PROPERTY = 0x00000005,
67 TPM_CAP_VERSION = 0x00000006,
68 TPM_CAP_KEY_HANDLE = 0x00000007,
69 TPM_CAP_CHECK_LOADED = 0x00000008,
70 TPM_CAP_SYM_MODE = 0x00000009,
71 TPM_CAP_KEY_STATUS = 0x0000000C,
72 TPM_CAP_NV_LIST = 0x0000000D,
73 TPM_CAP_MFR = 0x00000010,
74 TPM_CAP_NV_INDEX = 0x00000011,
75 TPM_CAP_TRANS_ALG = 0x00000012,
76 TPM_CAP_HANDLE = 0x00000014,
77 TPM_CAP_TRANS_ES = 0x00000015,
78 TPM_CAP_AUTH_ENCRYPT = 0x00000017,
79 TPM_CAP_SELECT_SIZE = 0x00000018,
80 TPM_CAP_DA_LOGIC = 0x00000019,
81 TPM_CAP_VERSION_VAL = 0x0000001A,
82};
83
Simon Glass5ff3f162018-10-01 11:55:17 -060084enum tmp_cap_flag {
85 TPM_CAP_FLAG_PERMANENT = 0x108,
86};
87
88#define TPM_TAG_PERMANENT_FLAGS 0x001f
89
Miquel Raynal02c4bba2018-05-15 11:57:01 +020090#define TPM_NV_PER_GLOBALLOCK BIT(15)
91#define TPM_NV_PER_PPREAD BIT(16)
92#define TPM_NV_PER_PPWRITE BIT(0)
93#define TPM_NV_PER_READ_STCLEAR BIT(31)
94#define TPM_NV_PER_WRITE_STCLEAR BIT(14)
95#define TPM_NV_PER_WRITEDEFINE BIT(13)
96#define TPM_NV_PER_WRITEALL BIT(12)
Simon Glassff9f04a2015-08-22 18:31:41 -060097
98enum {
99 TPM_PUBEK_SIZE = 256,
100};
101
Simon Glass5ff3f162018-10-01 11:55:17 -0600102enum {
103 TPM_CMD_EXTEND = 0x14,
104 TPM_CMD_GET_CAPABILITY = 0x65,
105 TPM_CMD_NV_DEFINE_SPACE = 0xcc,
106 TPM_CMD_NV_WRITE_VALUE = 0xcd,
107 TPM_CMD_NV_READ_VALUE = 0xcf,
108};
109
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000110/**
Reinhard Pfau4fece432013-06-26 15:55:13 +0200111 * TPM return codes as defined in the TCG Main specification
112 * (TPM Main Part 2 Structures; Specification version 1.2)
113 */
114enum tpm_return_code {
115 TPM_BASE = 0x00000000,
116 TPM_NON_FATAL = 0x00000800,
117 TPM_SUCCESS = TPM_BASE,
118 /* TPM-defined fatal error codes */
119 TPM_AUTHFAIL = TPM_BASE + 1,
120 TPM_BADINDEX = TPM_BASE + 2,
121 TPM_BAD_PARAMETER = TPM_BASE + 3,
122 TPM_AUDITFAILURE = TPM_BASE + 4,
123 TPM_CLEAR_DISABLED = TPM_BASE + 5,
124 TPM_DEACTIVATED = TPM_BASE + 6,
125 TPM_DISABLED = TPM_BASE + 7,
126 TPM_DISABLED_CMD = TPM_BASE + 8,
127 TPM_FAIL = TPM_BASE + 9,
128 TPM_BAD_ORDINAL = TPM_BASE + 10,
129 TPM_INSTALL_DISABLED = TPM_BASE + 11,
130 TPM_INVALID_KEYHANDLE = TPM_BASE + 12,
131 TPM_KEYNOTFOUND = TPM_BASE + 13,
132 TPM_INAPPROPRIATE_ENC = TPM_BASE + 14,
133 TPM_MIGRATE_FAIL = TPM_BASE + 15,
134 TPM_INVALID_PCR_INFO = TPM_BASE + 16,
135 TPM_NOSPACE = TPM_BASE + 17,
136 TPM_NOSRK = TPM_BASE + 18,
137 TPM_NOTSEALED_BLOB = TPM_BASE + 19,
138 TPM_OWNER_SET = TPM_BASE + 20,
139 TPM_RESOURCES = TPM_BASE + 21,
140 TPM_SHORTRANDOM = TPM_BASE + 22,
141 TPM_SIZE = TPM_BASE + 23,
142 TPM_WRONGPCRVAL = TPM_BASE + 24,
143 TPM_BAD_PARAM_SIZE = TPM_BASE + 25,
144 TPM_SHA_THREAD = TPM_BASE + 26,
145 TPM_SHA_ERROR = TPM_BASE + 27,
146 TPM_FAILEDSELFTEST = TPM_BASE + 28,
147 TPM_AUTH2FAIL = TPM_BASE + 29,
148 TPM_BADTAG = TPM_BASE + 30,
149 TPM_IOERROR = TPM_BASE + 31,
150 TPM_ENCRYPT_ERROR = TPM_BASE + 32,
151 TPM_DECRYPT_ERROR = TPM_BASE + 33,
152 TPM_INVALID_AUTHHANDLE = TPM_BASE + 34,
153 TPM_NO_ENDORSEMENT = TPM_BASE + 35,
154 TPM_INVALID_KEYUSAGE = TPM_BASE + 36,
155 TPM_WRONG_ENTITYTYPE = TPM_BASE + 37,
156 TPM_INVALID_POSTINIT = TPM_BASE + 38,
157 TPM_INAPPROPRIATE_SIG = TPM_BASE + 39,
158 TPM_BAD_KEY_PROPERTY = TPM_BASE + 40,
159 TPM_BAD_MIGRATION = TPM_BASE + 41,
160 TPM_BAD_SCHEME = TPM_BASE + 42,
161 TPM_BAD_DATASIZE = TPM_BASE + 43,
162 TPM_BAD_MODE = TPM_BASE + 44,
163 TPM_BAD_PRESENCE = TPM_BASE + 45,
164 TPM_BAD_VERSION = TPM_BASE + 46,
165 TPM_NO_WRAP_TRANSPORT = TPM_BASE + 47,
166 TPM_AUDITFAIL_UNSUCCESSFUL = TPM_BASE + 48,
167 TPM_AUDITFAIL_SUCCESSFUL = TPM_BASE + 49,
168 TPM_NOTRESETABLE = TPM_BASE + 50,
169 TPM_NOTLOCAL = TPM_BASE + 51,
170 TPM_BAD_TYPE = TPM_BASE + 52,
171 TPM_INVALID_RESOURCE = TPM_BASE + 53,
172 TPM_NOTFIPS = TPM_BASE + 54,
173 TPM_INVALID_FAMILY = TPM_BASE + 55,
174 TPM_NO_NV_PERMISSION = TPM_BASE + 56,
175 TPM_REQUIRES_SIGN = TPM_BASE + 57,
176 TPM_KEY_NOTSUPPORTED = TPM_BASE + 58,
177 TPM_AUTH_CONFLICT = TPM_BASE + 59,
178 TPM_AREA_LOCKED = TPM_BASE + 60,
179 TPM_BAD_LOCALITY = TPM_BASE + 61,
180 TPM_READ_ONLY = TPM_BASE + 62,
181 TPM_PER_NOWRITE = TPM_BASE + 63,
182 TPM_FAMILY_COUNT = TPM_BASE + 64,
183 TPM_WRITE_LOCKED = TPM_BASE + 65,
184 TPM_BAD_ATTRIBUTES = TPM_BASE + 66,
185 TPM_INVALID_STRUCTURE = TPM_BASE + 67,
186 TPM_KEY_OWNER_CONTROL = TPM_BASE + 68,
187 TPM_BAD_COUNTER = TPM_BASE + 69,
188 TPM_NOT_FULLWRITE = TPM_BASE + 70,
189 TPM_CONTEXT_GAP = TPM_BASE + 71,
190 TPM_MAXNVWRITES = TPM_BASE + 72,
191 TPM_NOOPERATOR = TPM_BASE + 73,
192 TPM_RESOURCEMISSING = TPM_BASE + 74,
193 TPM_DELEGATE_LOCK = TPM_BASE + 75,
194 TPM_DELEGATE_FAMILY = TPM_BASE + 76,
195 TPM_DELEGATE_ADMIN = TPM_BASE + 77,
196 TPM_TRANSPORT_NOTEXCLUSIVE = TPM_BASE + 78,
197 TPM_OWNER_CONTROL = TPM_BASE + 79,
198 TPM_DAA_RESOURCES = TPM_BASE + 80,
199 TPM_DAA_INPUT_DATA0 = TPM_BASE + 81,
200 TPM_DAA_INPUT_DATA1 = TPM_BASE + 82,
201 TPM_DAA_ISSUER_SETTINGS = TPM_BASE + 83,
202 TPM_DAA_TPM_SETTINGS = TPM_BASE + 84,
203 TPM_DAA_STAGE = TPM_BASE + 85,
204 TPM_DAA_ISSUER_VALIDITY = TPM_BASE + 86,
205 TPM_DAA_WRONG_W = TPM_BASE + 87,
206 TPM_BAD_HANDLE = TPM_BASE + 88,
207 TPM_BAD_DELEGATE = TPM_BASE + 89,
208 TPM_BADCONTEXT = TPM_BASE + 90,
209 TPM_TOOMANYCONTEXTS = TPM_BASE + 91,
210 TPM_MA_TICKET_SIGNATURE = TPM_BASE + 92,
211 TPM_MA_DESTINATION = TPM_BASE + 93,
212 TPM_MA_SOURCE = TPM_BASE + 94,
213 TPM_MA_AUTHORITY = TPM_BASE + 95,
214 TPM_PERMANENTEK = TPM_BASE + 97,
215 TPM_BAD_SIGNATURE = TPM_BASE + 98,
216 TPM_NOCONTEXTSPACE = TPM_BASE + 99,
217 /* TPM-defined non-fatal errors */
218 TPM_RETRY = TPM_BASE + TPM_NON_FATAL,
219 TPM_NEEDS_SELFTEST = TPM_BASE + TPM_NON_FATAL + 1,
220 TPM_DOING_SELFTEST = TPM_BASE + TPM_NON_FATAL + 2,
221 TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3,
222};
223
Simon Glassff9f04a2015-08-22 18:31:41 -0600224struct tpm_permanent_flags {
225 __be16 tag;
226 u8 disable;
227 u8 ownership;
228 u8 deactivated;
229 u8 read_pubek;
230 u8 disable_owner_clear;
231 u8 allow_maintenance;
232 u8 physical_presence_lifetime_lock;
233 u8 physical_presence_hw_enable;
234 u8 physical_presence_cmd_enable;
235 u8 cekp_used;
236 u8 tpm_post;
237 u8 tpm_post_lock;
238 u8 fips;
239 u8 operator;
240 u8 enable_revoke_ek;
241 u8 nv_locked;
242 u8 read_srk_pub;
243 u8 tpm_established;
244 u8 maintenance_done;
245 u8 disable_full_da_logic_info;
246} __packed;
247
Simon Glassf99c3292018-10-01 11:55:18 -0600248#define TPM_SHA1_160_HASH_LEN 0x14
249
250struct __packed tpm_composite_hash {
251 u8 digest[TPM_SHA1_160_HASH_LEN];
252};
253
254struct __packed tpm_pcr_selection {
255 __be16 size_of_select;
256 u8 pcr_select[3]; /* matches vboot's struct */
257};
258
259struct __packed tpm_pcr_info_short {
260 struct tpm_pcr_selection pcr_selection;
261 u8 locality_at_release;
262 struct tpm_composite_hash digest_at_release;
263};
264
265struct __packed tpm_nv_attributes {
266 __be16 tag;
267 __be32 attributes;
268};
269
270struct __packed tpm_nv_data_public {
271 __be16 tag;
272 __be32 nv_index;
273 struct tpm_pcr_info_short pcr_info_read;
274 struct tpm_pcr_info_short pcr_info_write;
275 struct tpm_nv_attributes permission;
276 u8 read_st_clear;
277 u8 write_st_clear;
278 u8 write_define;
279 __be32 data_size;
280};
281
Simon Glass6c7a2322015-08-22 18:31:31 -0600282/**
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000283 * Issue a TPM_Startup command.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000284 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700285 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000286 * @param mode TPM startup mode
287 * @return return code of the operation
288 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700289u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000290
291/**
292 * Issue a TPM_SelfTestFull command.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000293 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700294 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000295 * @return return code of the operation
Vadim Bendeburydac69642011-10-17 08:36:14 +0000296 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700297u32 tpm_self_test_full(struct udevice *dev);
Vadim Bendeburydac69642011-10-17 08:36:14 +0000298
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000299/**
300 * Issue a TPM_ContinueSelfTest command.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000301 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700302 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000303 * @return return code of the operation
Vadim Bendeburydac69642011-10-17 08:36:14 +0000304 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700305u32 tpm_continue_self_test(struct udevice *dev);
Vadim Bendeburydac69642011-10-17 08:36:14 +0000306
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000307/**
308 * Issue a TPM_NV_DefineSpace command. The implementation is limited
309 * to specify TPM_NV_ATTRIBUTES and size of the area. The area index
310 * could be one of the special value listed in enum tpm_nv_index.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000311 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700312 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000313 * @param index index of the area
314 * @param perm TPM_NV_ATTRIBUTES of the area
315 * @param size size of the area
316 * @return return code of the operation
317 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700318u32 tpm_nv_define_space(struct udevice *dev, u32 index, u32 perm, u32 size);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000319
320/**
321 * Issue a TPM_NV_ReadValue command. This implementation is limited
322 * to read the area from offset 0. The area index could be one of
323 * the special value listed in enum tpm_nv_index.
324 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700325 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000326 * @param index index of the area
327 * @param data output buffer of the area contents
328 * @param count size of output buffer
329 * @return return code of the operation
330 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700331u32 tpm_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000332
333/**
334 * Issue a TPM_NV_WriteValue command. This implementation is limited
335 * to write the area from offset 0. The area index could be one of
336 * the special value listed in enum tpm_nv_index.
337 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700338 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000339 * @param index index of the area
340 * @param data input buffer to be wrote to the area
341 * @param length length of data bytes of input buffer
342 * @return return code of the operation
343 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700344u32 tpm_nv_write_value(struct udevice *dev, u32 index, const void *data,
345 u32 length);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000346
347/**
348 * Issue a TPM_Extend command.
349 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700350 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000351 * @param index index of the PCR
352 * @param in_digest 160-bit value representing the event to be
353 * recorded
354 * @param out_digest 160-bit PCR value after execution of the
355 * command
356 * @return return code of the operation
357 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700358u32 tpm_extend(struct udevice *dev, u32 index, const void *in_digest,
359 void *out_digest);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000360
361/**
362 * Issue a TPM_PCRRead command.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000363 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700364 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000365 * @param index index of the PCR
366 * @param data output buffer for contents of the named PCR
367 * @param count size of output buffer
368 * @return return code of the operation
369 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700370u32 tpm_pcr_read(struct udevice *dev, u32 index, void *data, size_t count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000371
372/**
373 * Issue a TSC_PhysicalPresence command. TPM physical presence flag
374 * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
375 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700376 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000377 * @param presence TPM physical presence flag
378 * @return return code of the operation
379 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700380u32 tpm_tsc_physical_presence(struct udevice *dev, u16 presence);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000381
382/**
383 * Issue a TPM_ReadPubek command.
384 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700385 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000386 * @param data output buffer for the public endorsement key
Miquel Raynala59aa342018-05-15 11:57:02 +0200387 * @param count size of output buffer
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000388 * @return return code of the operation
389 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700390u32 tpm_read_pubek(struct udevice *dev, void *data, size_t count);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000391
392/**
393 * Issue a TPM_ForceClear command.
394 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700395 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000396 * @return return code of the operation
397 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700398u32 tpm_force_clear(struct udevice *dev);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000399
400/**
401 * Issue a TPM_PhysicalEnable command.
402 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700403 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000404 * @return return code of the operation
405 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700406u32 tpm_physical_enable(struct udevice *dev);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000407
408/**
409 * Issue a TPM_PhysicalDisable command.
410 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700411 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000412 * @return return code of the operation
413 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700414u32 tpm_physical_disable(struct udevice *dev);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000415
416/**
417 * Issue a TPM_PhysicalSetDeactivated command.
418 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700419 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000420 * @param state boolean state of the deactivated flag
421 * @return return code of the operation
422 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700423u32 tpm_physical_set_deactivated(struct udevice *dev, u8 state);
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000424
425/**
426 * Issue a TPM_GetCapability command. This implementation is limited
427 * to query sub_cap index that is 4-byte wide.
Vadim Bendeburydac69642011-10-17 08:36:14 +0000428 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700429 * @param dev TPM device
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000430 * @param cap_area partition of capabilities
431 * @param sub_cap further definition of capability, which is
432 * limited to be 4-byte wide
433 * @param cap output buffer for capability information
Miquel Raynala59aa342018-05-15 11:57:02 +0200434 * @param count size of output buffer
Che-liang Chiouc18f9012013-02-28 09:34:57 +0000435 * @return return code of the operation
Vadim Bendeburydac69642011-10-17 08:36:14 +0000436 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700437u32 tpm_get_capability(struct udevice *dev, u32 cap_area, u32 sub_cap,
438 void *cap, size_t count);
Vadim Bendeburydac69642011-10-17 08:36:14 +0000439
Reinhard Pfau4fece432013-06-26 15:55:13 +0200440/**
Miquel Raynala59aa342018-05-15 11:57:02 +0200441 * Issue a TPM_FlushSpecific command for a AUTH resource.
Reinhard Pfau4fece432013-06-26 15:55:13 +0200442 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700443 * @param dev TPM device
Reinhard Pfau4fece432013-06-26 15:55:13 +0200444 * @param auth_handle handle of the auth session
445 * @return return code of the operation
446 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700447u32 tpm_terminate_auth_session(struct udevice *dev, u32 auth_handle);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200448
449/**
Miquel Raynala59aa342018-05-15 11:57:02 +0200450 * Issue a TPM_OIAP command to setup an object independent authorization
Reinhard Pfau4fece432013-06-26 15:55:13 +0200451 * session.
452 * Information about the session is stored internally.
453 * If there was already an OIAP session active it is terminated and a new
454 * session is set up.
455 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700456 * @param dev TPM device
Reinhard Pfau4fece432013-06-26 15:55:13 +0200457 * @param auth_handle pointer to the (new) auth handle or NULL.
458 * @return return code of the operation
459 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700460u32 tpm_oiap(struct udevice *dev, u32 *auth_handle);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200461
462/**
463 * Ends an active OIAP session.
464 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700465 * @param dev TPM device
Reinhard Pfau4fece432013-06-26 15:55:13 +0200466 * @return return code of the operation
467 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700468u32 tpm_end_oiap(struct udevice *dev);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200469
470/**
471 * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating
472 * the usage of the parent key.
473 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700474 * @param dev TPM device
Reinhard Pfau4fece432013-06-26 15:55:13 +0200475 * @param parent_handle handle of the parent key.
476 * @param key pointer to the key structure (TPM_KEY or TPM_KEY12).
477 * @param key_length size of the key structure
478 * @param parent_key_usage_auth usage auth for the parent key
479 * @param key_handle pointer to the key handle
480 * @return return code of the operation
481 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700482u32 tpm_load_key2_oiap(struct udevice *dev, u32 parent_handle, const void *key,
483 size_t key_length, const void *parent_key_usage_auth,
484 u32 *key_handle);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200485
486/**
487 * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for
488 * authenticating the usage of the key.
489 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700490 * @param dev TPM device
Reinhard Pfau4fece432013-06-26 15:55:13 +0200491 * @param key_handle handle of the key
492 * @param usage_auth usage auth for the key
493 * @param pubkey pointer to the pub key buffer; may be NULL if the pubkey
494 * should not be stored.
495 * @param pubkey_len pointer to the pub key buffer len. On entry: the size of
496 * the provided pubkey buffer. On successful exit: the size
497 * of the stored TPM_PUBKEY structure (iff pubkey != NULL).
498 * @return return code of the operation
499 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700500u32 tpm_get_pub_key_oiap(struct udevice *dev, u32 key_handle,
501 const void *usage_auth, void *pubkey,
Miquel Raynald790f552018-05-15 11:56:59 +0200502 size_t *pubkey_len);
Reinhard Pfau4fece432013-06-26 15:55:13 +0200503
Simon Glassff9f04a2015-08-22 18:31:41 -0600504/**
505 * Get the TPM permanent flags value
506 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700507 * @param dev TPM device
Simon Glassff9f04a2015-08-22 18:31:41 -0600508 * @param pflags Place to put permanent flags
509 * @return return code of the operation
510 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700511u32 tpm_get_permanent_flags(struct udevice *dev,
512 struct tpm_permanent_flags *pflags);
Simon Glassff9f04a2015-08-22 18:31:41 -0600513
514/**
515 * Get the TPM permissions
516 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700517 * @param dev TPM device
Simon Glassff9f04a2015-08-22 18:31:41 -0600518 * @param perm Returns permissions value
519 * @return return code of the operation
520 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700521u32 tpm_get_permissions(struct udevice *dev, u32 index, u32 *perm);
Simon Glassff9f04a2015-08-22 18:31:41 -0600522
Mario Six4eceb6c2017-01-11 16:00:50 +0100523/**
524 * Flush a resource with a given handle and type from the TPM
525 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700526 * @param dev TPM device
Mario Six4eceb6c2017-01-11 16:00:50 +0100527 * @param key_handle handle of the resource
528 * @param resource_type type of the resource
529 * @return return code of the operation
530 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700531u32 tpm_flush_specific(struct udevice *dev, u32 key_handle, u32 resource_type);
Mario Six4eceb6c2017-01-11 16:00:50 +0100532
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100533#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
534/**
535 * Search for a key by usage AuthData and the hash of the parent's pub key.
536 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700537 * @param dev TPM device
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100538 * @param auth Usage auth of the key to search for
539 * @param pubkey_digest SHA1 hash of the pub key structure of the key
540 * @param[out] handle The handle of the key (Non-null iff found)
541 * @return 0 if key was found in TPM; != 0 if not.
542 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700543u32 tpm_find_key_sha1(struct udevice *dev, const u8 auth[20],
544 const u8 pubkey_digest[20], u32 *handle);
mario.six@gdsys.cca5a7ea22017-03-20 10:28:28 +0100545#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
André Draszik2c6e5ff2017-10-03 16:55:52 +0100546
547/**
548 * Read random bytes from the TPM RNG. The implementation deals with the fact
549 * that the TPM may legally return fewer bytes than requested by retrying
550 * until @p count bytes have been received.
551 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700552 * @param dev TPM device
André Draszik2c6e5ff2017-10-03 16:55:52 +0100553 * @param data output buffer for the random bytes
554 * @param count size of output buffer
555 * @return return code of the operation
556 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700557u32 tpm_get_random(struct udevice *dev, void *data, u32 count);
André Draszik2c6e5ff2017-10-03 16:55:52 +0100558
Simon Glassbccabbe2018-10-01 12:22:29 -0600559/**
560 * tpm_finalise_physical_presence() - Finalise physical presence
561 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700562 * @param dev TPM device
Simon Glassbccabbe2018-10-01 12:22:29 -0600563 * @return return code of the operation (0 = success)
564 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700565u32 tpm_finalise_physical_presence(struct udevice *dev);
Simon Glassbccabbe2018-10-01 12:22:29 -0600566
567/**
568 * tpm_nv_set_locked() - lock the non-volatile space
569 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700570 * @param dev TPM device
Simon Glassbccabbe2018-10-01 12:22:29 -0600571 * @return return code of the operation (0 = success)
572 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700573u32 tpm_nv_set_locked(struct udevice *dev);
Simon Glassbccabbe2018-10-01 12:22:29 -0600574
575/**
576 * tpm_set_global_lock() - set the global lock
577 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700578 * @param dev TPM device
Simon Glassbccabbe2018-10-01 12:22:29 -0600579 * @return return code of the operation (0 = success)
580 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700581u32 tpm_set_global_lock(struct udevice *dev);
Simon Glassbccabbe2018-10-01 12:22:29 -0600582
583/**
584 * tpm_resume() - start up the TPM from resume (after suspend)
585 *
Simon Glass8ceca1d2018-11-18 14:22:27 -0700586 * @param dev TPM device
Simon Glassbccabbe2018-10-01 12:22:29 -0600587 * @return return code of the operation (0 = success)
588 */
Simon Glass8ceca1d2018-11-18 14:22:27 -0700589u32 tpm_resume(struct udevice *dev);
Simon Glassbccabbe2018-10-01 12:22:29 -0600590
Miquel Raynal4c6759e2018-05-15 11:57:06 +0200591#endif /* __TPM_V1_H */