]> Git Repo - J-u-boot.git/blame - include/tpm-v2.h
efi_loader: remove unneeded header files
[J-u-boot.git] / include / tpm-v2.h
CommitLineData
ff32245b
MR
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
915e3ae5
IA
3 * Defines APIs and structures that allow software to interact with a
4 * TPM2 device
5 *
6 * Copyright (c) 2020 Linaro
ff32245b 7 * Copyright (c) 2018 Bootlin
915e3ae5
IA
8 *
9 * https://trustedcomputinggroup.org/resource/tss-overview-common-structures-specification/
10 *
ff32245b
MR
11 * Author: Miquel Raynal <[email protected]>
12 */
13
14#ifndef __TPM_V2_H
15#define __TPM_V2_H
16
17#include <tpm-common.h>
18
401d1c4f
SG
19struct udevice;
20
ff32245b
MR
21#define TPM2_DIGEST_LEN 32
22
8e0b0871
IA
23#define TPM2_SHA1_DIGEST_SIZE 20
24#define TPM2_SHA256_DIGEST_SIZE 32
25#define TPM2_SHA384_DIGEST_SIZE 48
26#define TPM2_SHA512_DIGEST_SIZE 64
27#define TPM2_SM3_256_DIGEST_SIZE 32
28
915e3ae5
IA
29#define TPM2_MAX_PCRS 32
30#define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8)
31#define TPM2_MAX_CAP_BUFFER 1024
32#define TPM2_MAX_TPM_PROPERTIES ((TPM2_MAX_CAP_BUFFER - sizeof(u32) /* TPM2_CAP */ - \
33 sizeof(u32)) / sizeof(struct tpms_tagged_property))
34
d8f105dd
SG
35#define TPM2_HDR_LEN 10
36
915e3ae5
IA
37/*
38 * We deviate from this draft of the specification by increasing the value of
39 * TPM2_NUM_PCR_BANKS from 3 to 16 to ensure compatibility with TPM2
40 * implementations that have enabled a larger than typical number of PCR
41 * banks. This larger value for TPM2_NUM_PCR_BANKS is expected to be included
42 * in a future revision of the specification.
43 */
44#define TPM2_NUM_PCR_BANKS 16
45
46/* Definition of (UINT32) TPM2_CAP Constants */
47#define TPM2_CAP_PCRS 0x00000005U
48#define TPM2_CAP_TPM_PROPERTIES 0x00000006U
49
50/* Definition of (UINT32) TPM2_PT Constants */
51#define TPM2_PT_GROUP (u32)(0x00000100)
52#define TPM2_PT_FIXED (u32)(TPM2_PT_GROUP * 1)
53#define TPM2_PT_MANUFACTURER (u32)(TPM2_PT_FIXED + 5)
54#define TPM2_PT_PCR_COUNT (u32)(TPM2_PT_FIXED + 18)
55#define TPM2_PT_MAX_COMMAND_SIZE (u32)(TPM2_PT_FIXED + 30)
56#define TPM2_PT_MAX_RESPONSE_SIZE (u32)(TPM2_PT_FIXED + 31)
57
58/* TPMS_TAGGED_PROPERTY Structure */
59struct tpms_tagged_property {
60 u32 property;
61 u32 value;
62} __packed;
63
64/* TPMS_PCR_SELECTION Structure */
65struct tpms_pcr_selection {
66 u16 hash;
67 u8 size_of_select;
68 u8 pcr_select[TPM2_PCR_SELECT_MAX];
69} __packed;
70
71/* TPML_PCR_SELECTION Structure */
72struct tpml_pcr_selection {
73 u32 count;
74 struct tpms_pcr_selection selection[TPM2_NUM_PCR_BANKS];
75} __packed;
76
77/* TPML_TAGGED_TPM_PROPERTY Structure */
78struct tpml_tagged_tpm_property {
79 u32 count;
80 struct tpms_tagged_property tpm_property[TPM2_MAX_TPM_PROPERTIES];
81} __packed;
82
83/* TPMU_CAPABILITIES Union */
84union tpmu_capabilities {
85 /*
86 * Non exhaustive. Only added the structs needed for our
87 * current code
88 */
89 struct tpml_pcr_selection assigned_pcr;
90 struct tpml_tagged_tpm_property tpm_properties;
91} __packed;
92
93/* TPMS_CAPABILITY_DATA Structure */
94struct tpms_capability_data {
95 u32 capability;
96 union tpmu_capabilities data;
97} __packed;
98
8e0b0871
IA
99/**
100 * Definition of TPMU_HA Union
101 */
73f40716 102union tpmu_ha {
8e0b0871
IA
103 u8 sha1[TPM2_SHA1_DIGEST_SIZE];
104 u8 sha256[TPM2_SHA256_DIGEST_SIZE];
105 u8 sm3_256[TPM2_SM3_256_DIGEST_SIZE];
106 u8 sha384[TPM2_SHA384_DIGEST_SIZE];
107 u8 sha512[TPM2_SHA512_DIGEST_SIZE];
108} __packed;
109
110/**
111 * Definition of TPMT_HA Structure
112 *
113 * @hash_alg: Hash algorithm defined in enum tpm2_algorithms
114 * @digest: Digest value for a given algorithm
115 */
116struct tpmt_ha {
117 u16 hash_alg;
73f40716 118 union tpmu_ha digest;
8e0b0871
IA
119} __packed;
120
121/**
122 * Definition of TPML_DIGEST_VALUES Structure
123 *
124 * @count: Number of algorithms supported by hardware
125 * @digests: struct for algorithm id and hash value
126 */
127struct tpml_digest_values {
128 u32 count;
129 struct tpmt_ha digests[TPM2_NUM_PCR_BANKS];
130} __packed;
131
ff32245b
MR
132/**
133 * TPM2 Structure Tags for command/response buffers.
134 *
135 * @TPM2_ST_NO_SESSIONS: the command does not need an authentication.
136 * @TPM2_ST_SESSIONS: the command needs an authentication.
137 */
138enum tpm2_structures {
139 TPM2_ST_NO_SESSIONS = 0x8001,
140 TPM2_ST_SESSIONS = 0x8002,
141};
142
143/**
144 * TPM2 type of boolean.
145 */
146enum tpm2_yes_no {
147 TPMI_YES = 1,
148 TPMI_NO = 0,
149};
150
151/**
152 * TPM2 startup values.
153 *
154 * @TPM2_SU_CLEAR: reset the internal state.
155 * @TPM2_SU_STATE: restore saved state (if any).
156 */
157enum tpm2_startup_types {
158 TPM2_SU_CLEAR = 0x0000,
159 TPM2_SU_STATE = 0x0001,
160};
161
162/**
163 * TPM2 permanent handles.
164 *
165 * @TPM2_RH_OWNER: refers to the 'owner' hierarchy.
166 * @TPM2_RS_PW: indicates a password.
167 * @TPM2_RH_LOCKOUT: refers to the 'lockout' hierarchy.
168 * @TPM2_RH_ENDORSEMENT: refers to the 'endorsement' hierarchy.
169 * @TPM2_RH_PLATFORM: refers to the 'platform' hierarchy.
170 */
171enum tpm2_handles {
172 TPM2_RH_OWNER = 0x40000001,
173 TPM2_RS_PW = 0x40000009,
174 TPM2_RH_LOCKOUT = 0x4000000A,
175 TPM2_RH_ENDORSEMENT = 0x4000000B,
176 TPM2_RH_PLATFORM = 0x4000000C,
177};
178
179/**
180 * TPM2 command codes used at the beginning of a buffer, gives the command.
181 *
182 * @TPM2_CC_STARTUP: TPM2_Startup().
183 * @TPM2_CC_SELF_TEST: TPM2_SelfTest().
184 * @TPM2_CC_CLEAR: TPM2_Clear().
185 * @TPM2_CC_CLEARCONTROL: TPM2_ClearControl().
186 * @TPM2_CC_HIERCHANGEAUTH: TPM2_HierarchyChangeAuth().
187 * @TPM2_CC_PCR_SETAUTHPOL: TPM2_PCR_SetAuthPolicy().
188 * @TPM2_CC_DAM_RESET: TPM2_DictionaryAttackLockReset().
189 * @TPM2_CC_DAM_PARAMETERS: TPM2_DictionaryAttackParameters().
190 * @TPM2_CC_GET_CAPABILITY: TPM2_GetCapibility().
06bea498 191 * @TPM2_CC_GET_RANDOM: TPM2_GetRandom().
ff32245b
MR
192 * @TPM2_CC_PCR_READ: TPM2_PCR_Read().
193 * @TPM2_CC_PCR_EXTEND: TPM2_PCR_Extend().
194 * @TPM2_CC_PCR_SETAUTHVAL: TPM2_PCR_SetAuthValue().
195 */
196enum tpm2_command_codes {
197 TPM2_CC_STARTUP = 0x0144,
198 TPM2_CC_SELF_TEST = 0x0143,
63af92e8 199 TPM2_CC_HIER_CONTROL = 0x0121,
ff32245b
MR
200 TPM2_CC_CLEAR = 0x0126,
201 TPM2_CC_CLEARCONTROL = 0x0127,
202 TPM2_CC_HIERCHANGEAUTH = 0x0129,
eadcbc78 203 TPM2_CC_NV_DEFINE_SPACE = 0x012a,
b9dd4fab 204 TPM2_CC_PCR_SETAUTHPOL = 0x012C,
6719cbe3 205 TPM2_CC_NV_WRITE = 0x0137,
7785bc1d 206 TPM2_CC_NV_WRITELOCK = 0x0138,
ff32245b
MR
207 TPM2_CC_DAM_RESET = 0x0139,
208 TPM2_CC_DAM_PARAMETERS = 0x013A,
998af319 209 TPM2_CC_NV_READ = 0x014E,
ff32245b 210 TPM2_CC_GET_CAPABILITY = 0x017A,
06bea498 211 TPM2_CC_GET_RANDOM = 0x017B,
ff32245b
MR
212 TPM2_CC_PCR_READ = 0x017E,
213 TPM2_CC_PCR_EXTEND = 0x0182,
b9dd4fab 214 TPM2_CC_PCR_SETAUTHVAL = 0x0183,
ff32245b
MR
215};
216
217/**
218 * TPM2 return codes.
219 */
220enum tpm2_return_codes {
221 TPM2_RC_SUCCESS = 0x0000,
222 TPM2_RC_BAD_TAG = 0x001E,
223 TPM2_RC_FMT1 = 0x0080,
224 TPM2_RC_HASH = TPM2_RC_FMT1 + 0x0003,
225 TPM2_RC_VALUE = TPM2_RC_FMT1 + 0x0004,
226 TPM2_RC_SIZE = TPM2_RC_FMT1 + 0x0015,
227 TPM2_RC_BAD_AUTH = TPM2_RC_FMT1 + 0x0022,
228 TPM2_RC_HANDLE = TPM2_RC_FMT1 + 0x000B,
229 TPM2_RC_VER1 = 0x0100,
230 TPM2_RC_INITIALIZE = TPM2_RC_VER1 + 0x0000,
231 TPM2_RC_FAILURE = TPM2_RC_VER1 + 0x0001,
232 TPM2_RC_DISABLED = TPM2_RC_VER1 + 0x0020,
233 TPM2_RC_AUTH_MISSING = TPM2_RC_VER1 + 0x0025,
234 TPM2_RC_COMMAND_CODE = TPM2_RC_VER1 + 0x0043,
235 TPM2_RC_AUTHSIZE = TPM2_RC_VER1 + 0x0044,
236 TPM2_RC_AUTH_CONTEXT = TPM2_RC_VER1 + 0x0045,
63af92e8 237 TPM2_RC_NV_DEFINED = TPM2_RC_VER1 + 0x004c,
ff32245b
MR
238 TPM2_RC_NEEDS_TEST = TPM2_RC_VER1 + 0x0053,
239 TPM2_RC_WARN = 0x0900,
240 TPM2_RC_TESTING = TPM2_RC_WARN + 0x000A,
241 TPM2_RC_REFERENCE_H0 = TPM2_RC_WARN + 0x0010,
242 TPM2_RC_LOCKOUT = TPM2_RC_WARN + 0x0021,
243};
244
245/**
246 * TPM2 algorithms.
247 */
248enum tpm2_algorithms {
915e3ae5 249 TPM2_ALG_SHA1 = 0x04,
ff32245b
MR
250 TPM2_ALG_XOR = 0x0A,
251 TPM2_ALG_SHA256 = 0x0B,
252 TPM2_ALG_SHA384 = 0x0C,
253 TPM2_ALG_SHA512 = 0x0D,
254 TPM2_ALG_NULL = 0x10,
915e3ae5 255 TPM2_ALG_SM3_256 = 0x12,
ff32245b
MR
256};
257
954b95e7
TH
258/**
259 * struct digest_info - details of supported digests
260 *
261 * @hash_name: hash name
262 * @hash_alg: hash algorithm id
263 * @hash_mask: hash registry mask
264 * @hash_len: hash digest length
265 */
266struct digest_info {
267 const char *hash_name;
268 u16 hash_alg;
269 u32 hash_mask;
270 u16 hash_len;
271};
272
273/* Algorithm Registry */
274#define TCG2_BOOT_HASH_ALG_SHA1 0x00000001
275#define TCG2_BOOT_HASH_ALG_SHA256 0x00000002
276#define TCG2_BOOT_HASH_ALG_SHA384 0x00000004
277#define TCG2_BOOT_HASH_ALG_SHA512 0x00000008
278#define TCG2_BOOT_HASH_ALG_SM3_256 0x00000010
279
280static const struct digest_info hash_algo_list[] = {
281 {
282 "sha1",
283 TPM2_ALG_SHA1,
284 TCG2_BOOT_HASH_ALG_SHA1,
285 TPM2_SHA1_DIGEST_SIZE,
286 },
287 {
288 "sha256",
289 TPM2_ALG_SHA256,
290 TCG2_BOOT_HASH_ALG_SHA256,
291 TPM2_SHA256_DIGEST_SIZE,
292 },
293 {
294 "sha384",
295 TPM2_ALG_SHA384,
296 TCG2_BOOT_HASH_ALG_SHA384,
297 TPM2_SHA384_DIGEST_SIZE,
298 },
299 {
300 "sha512",
301 TPM2_ALG_SHA512,
302 TCG2_BOOT_HASH_ALG_SHA512,
303 TPM2_SHA512_DIGEST_SIZE,
304 },
305};
97707f12
EJ
306
307static inline u16 tpm2_algorithm_to_len(enum tpm2_algorithms a)
308{
309 switch (a) {
310 case TPM2_ALG_SHA1:
311 return TPM2_SHA1_DIGEST_SIZE;
312 case TPM2_ALG_SHA256:
313 return TPM2_SHA256_DIGEST_SIZE;
314 case TPM2_ALG_SHA384:
315 return TPM2_SHA384_DIGEST_SIZE;
316 case TPM2_ALG_SHA512:
317 return TPM2_SHA512_DIGEST_SIZE;
318 default:
319 return 0;
320 }
321}
322
be8a025e
SG
323/* NV index attributes */
324enum tpm_index_attrs {
325 TPMA_NV_PPWRITE = 1UL << 0,
326 TPMA_NV_OWNERWRITE = 1UL << 1,
327 TPMA_NV_AUTHWRITE = 1UL << 2,
328 TPMA_NV_POLICYWRITE = 1UL << 3,
329 TPMA_NV_COUNTER = 1UL << 4,
330 TPMA_NV_BITS = 1UL << 5,
331 TPMA_NV_EXTEND = 1UL << 6,
332 TPMA_NV_POLICY_DELETE = 1UL << 10,
333 TPMA_NV_WRITELOCKED = 1UL << 11,
334 TPMA_NV_WRITEALL = 1UL << 12,
335 TPMA_NV_WRITEDEFINE = 1UL << 13,
336 TPMA_NV_WRITE_STCLEAR = 1UL << 14,
337 TPMA_NV_GLOBALLOCK = 1UL << 15,
338 TPMA_NV_PPREAD = 1UL << 16,
339 TPMA_NV_OWNERREAD = 1UL << 17,
340 TPMA_NV_AUTHREAD = 1UL << 18,
341 TPMA_NV_POLICYREAD = 1UL << 19,
342 TPMA_NV_NO_DA = 1UL << 25,
343 TPMA_NV_ORDERLY = 1UL << 26,
344 TPMA_NV_CLEAR_STCLEAR = 1UL << 27,
345 TPMA_NV_READLOCKED = 1UL << 28,
346 TPMA_NV_WRITTEN = 1UL << 29,
347 TPMA_NV_PLATFORMCREATE = 1UL << 30,
348 TPMA_NV_READ_STCLEAR = 1UL << 31,
349
350 TPMA_NV_MASK_READ = TPMA_NV_PPREAD | TPMA_NV_OWNERREAD |
351 TPMA_NV_AUTHREAD | TPMA_NV_POLICYREAD,
352 TPMA_NV_MASK_WRITE = TPMA_NV_PPWRITE | TPMA_NV_OWNERWRITE |
353 TPMA_NV_AUTHWRITE | TPMA_NV_POLICYWRITE,
354};
355
1400a7f3
SG
356enum {
357 TPM_ACCESS_VALID = 1 << 7,
358 TPM_ACCESS_ACTIVE_LOCALITY = 1 << 5,
359 TPM_ACCESS_REQUEST_PENDING = 1 << 2,
360 TPM_ACCESS_REQUEST_USE = 1 << 1,
361 TPM_ACCESS_ESTABLISHMENT = 1 << 0,
362};
363
364enum {
365 TPM_STS_FAMILY_SHIFT = 26,
366 TPM_STS_FAMILY_MASK = 0x3 << TPM_STS_FAMILY_SHIFT,
367 TPM_STS_FAMILY_TPM2 = 1 << TPM_STS_FAMILY_SHIFT,
368 TPM_STS_RESE_TESTABLISMENT_BIT = 1 << 25,
369 TPM_STS_COMMAND_CANCEL = 1 << 24,
370 TPM_STS_BURST_COUNT_SHIFT = 8,
371 TPM_STS_BURST_COUNT_MASK = 0xffff << TPM_STS_BURST_COUNT_SHIFT,
372 TPM_STS_VALID = 1 << 7,
373 TPM_STS_COMMAND_READY = 1 << 6,
374 TPM_STS_GO = 1 << 5,
375 TPM_STS_DATA_AVAIL = 1 << 4,
376 TPM_STS_DATA_EXPECT = 1 << 3,
377 TPM_STS_SELF_TEST_DONE = 1 << 2,
378 TPM_STS_RESPONSE_RETRY = 1 << 1,
2c9626c4 379 TPM_STS_READ_ZERO = 0x23
1400a7f3
SG
380};
381
382enum {
383 TPM_CMD_COUNT_OFFSET = 2,
384 TPM_CMD_ORDINAL_OFFSET = 6,
385 TPM_MAX_BUF_SIZE = 1260,
386};
387
6719cbe3
SG
388enum {
389 /* Secure storage for firmware settings */
390 TPM_HT_PCR = 0,
391 TPM_HT_NV_INDEX,
392 TPM_HT_HMAC_SESSION,
393 TPM_HT_POLICY_SESSION,
394
395 HR_SHIFT = 24,
396 HR_PCR = TPM_HT_PCR << HR_SHIFT,
397 HR_HMAC_SESSION = TPM_HT_HMAC_SESSION << HR_SHIFT,
398 HR_POLICY_SESSION = TPM_HT_POLICY_SESSION << HR_SHIFT,
399 HR_NV_INDEX = TPM_HT_NV_INDEX << HR_SHIFT,
400};
401
1922df20
MR
402/**
403 * Issue a TPM2_Startup command.
404 *
abdc7b8a 405 * @dev TPM device
1922df20
MR
406 * @mode TPM startup mode
407 *
185f812c 408 * Return: code of the operation
1922df20 409 */
abdc7b8a 410u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode);
1922df20 411
2dc6d97e
MR
412/**
413 * Issue a TPM2_SelfTest command.
414 *
abdc7b8a 415 * @dev TPM device
2dc6d97e
MR
416 * @full_test Asking to perform all tests or only the untested ones
417 *
185f812c 418 * Return: code of the operation
2dc6d97e 419 */
abdc7b8a 420u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test);
2dc6d97e 421
bad8ff56
MR
422/**
423 * Issue a TPM2_Clear command.
424 *
abdc7b8a 425 * @dev TPM device
bad8ff56
MR
426 * @handle Handle
427 * @pw Password
428 * @pw_sz Length of the password
429 *
185f812c 430 * Return: code of the operation
bad8ff56 431 */
abdc7b8a
SG
432u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw,
433 const ssize_t pw_sz);
bad8ff56 434
eadcbc78
SG
435/**
436 * Issue a TPM_NV_DefineSpace command
437 *
438 * This allows a space to be defined with given attributes and policy
439 *
440 * @dev TPM device
441 * @space_index index of the area
442 * @space_size size of area in bytes
443 * @nv_attributes TPM_NV_ATTRIBUTES of the area
444 * @nv_policy policy to use
445 * @nv_policy_size size of the policy
185f812c 446 * Return: return code of the operation
eadcbc78
SG
447 */
448u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index,
449 size_t space_size, u32 nv_attributes,
450 const u8 *nv_policy, size_t nv_policy_size);
451
6284be5a
MR
452/**
453 * Issue a TPM2_PCR_Extend command.
454 *
abdc7b8a 455 * @dev TPM device
6284be5a 456 * @index Index of the PCR
e926136b 457 * @algorithm Algorithm used, defined in 'enum tpm2_algorithms'
6284be5a 458 * @digest Value representing the event to be recorded
e926136b 459 * @digest_len len of the hash
6284be5a 460 *
185f812c 461 * Return: code of the operation
6284be5a 462 */
e926136b
IA
463u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm,
464 const u8 *digest, u32 digest_len);
6284be5a 465
6719cbe3
SG
466/**
467 * Read data from the secure storage
468 *
469 * @dev TPM device
470 * @index Index of data to read
471 * @data Place to put data
472 * @count Number of bytes of data
185f812c 473 * Return: code of the operation
6719cbe3
SG
474 */
475u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count);
476
477/**
478 * Write data to the secure storage
479 *
480 * @dev TPM device
481 * @index Index of data to write
482 * @data Data to write
483 * @count Number of bytes of data
185f812c 484 * Return: code of the operation
6719cbe3
SG
485 */
486u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data,
487 u32 count);
488
1c4ea8f4
MR
489/**
490 * Issue a TPM2_PCR_Read command.
491 *
abdc7b8a 492 * @dev TPM device
1c4ea8f4
MR
493 * @idx Index of the PCR
494 * @idx_min_sz Minimum size in bytes of the pcrSelect array
2957a1e2 495 * @algorithm Algorithm used, defined in 'enum tpm2_algorithms'
1c4ea8f4 496 * @data Output buffer for contents of the named PCR
2957a1e2 497 * @digest_len len of the data
1c4ea8f4
MR
498 * @updates Optional out parameter: number of updates for this PCR
499 *
185f812c 500 * Return: code of the operation
1c4ea8f4 501 */
abdc7b8a 502u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz,
2957a1e2
RG
503 u16 algorithm, void *data, u32 digest_len,
504 unsigned int *updates);
1c4ea8f4 505
69cd8f06
MR
506/**
507 * Issue a TPM2_GetCapability command. This implementation is limited
508 * to query property index that is 4-byte wide.
509 *
abdc7b8a 510 * @dev TPM device
69cd8f06
MR
511 * @capability Partition of capabilities
512 * @property Further definition of capability, limited to be 4 bytes wide
513 * @buf Output buffer for capability information
514 * @prop_count Size of output buffer
515 *
185f812c 516 * Return: code of the operation
69cd8f06 517 */
abdc7b8a
SG
518u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property,
519 void *buf, size_t prop_count);
69cd8f06 520
97707f12
EJ
521/**
522 * tpm2_get_pcr_info() - get the supported, active PCRs and number of banks
523 *
524 * @dev: TPM device
525 * @supported_pcr: bitmask with the algorithms supported
526 * @active_pcr: bitmask with the active algorithms
527 * @pcr_banks: number of PCR banks
528 *
529 * @return 0 on success, code of operation or negative errno on failure
530 */
531int tpm2_get_pcr_info(struct udevice *dev, u32 *supported_pcr, u32 *active_pcr,
532 u32 *pcr_banks);
533
da9c3392
MR
534/**
535 * Issue a TPM2_DictionaryAttackLockReset command.
536 *
abdc7b8a 537 * @dev TPM device
da9c3392
MR
538 * @pw Password
539 * @pw_sz Length of the password
540 *
185f812c 541 * Return: code of the operation
da9c3392 542 */
abdc7b8a 543u32 tpm2_dam_reset(struct udevice *dev, const char *pw, const ssize_t pw_sz);
da9c3392
MR
544
545/**
546 * Issue a TPM2_DictionaryAttackParameters command.
547 *
abdc7b8a 548 * @dev TPM device
da9c3392
MR
549 * @pw Password
550 * @pw_sz Length of the password
551 * @max_tries Count of authorizations before lockout
552 * @recovery_time Time before decrementation of the failure count
553 * @lockout_recovery Time to wait after a lockout
554 *
185f812c 555 * Return: code of the operation
da9c3392 556 */
abdc7b8a
SG
557u32 tpm2_dam_parameters(struct udevice *dev, const char *pw,
558 const ssize_t pw_sz, unsigned int max_tries,
559 unsigned int recovery_time,
da9c3392
MR
560 unsigned int lockout_recovery);
561
dc26e913
MR
562/**
563 * Issue a TPM2_HierarchyChangeAuth command.
564 *
abdc7b8a 565 * @dev TPM device
dc26e913
MR
566 * @handle Handle
567 * @newpw New password
568 * @newpw_sz Length of the new password
569 * @oldpw Old password
570 * @oldpw_sz Length of the old password
571 *
185f812c 572 * Return: code of the operation
dc26e913 573 */
abdc7b8a
SG
574int tpm2_change_auth(struct udevice *dev, u32 handle, const char *newpw,
575 const ssize_t newpw_sz, const char *oldpw,
576 const ssize_t oldpw_sz);
dc26e913 577
b9dd4fab
MR
578/**
579 * Issue a TPM_PCR_SetAuthPolicy command.
580 *
abdc7b8a 581 * @dev TPM device
b9dd4fab
MR
582 * @pw Platform password
583 * @pw_sz Length of the password
584 * @index Index of the PCR
585 * @digest New key to access the PCR
586 *
185f812c 587 * Return: code of the operation
b9dd4fab 588 */
abdc7b8a
SG
589u32 tpm2_pcr_setauthpolicy(struct udevice *dev, const char *pw,
590 const ssize_t pw_sz, u32 index, const char *key);
b9dd4fab
MR
591
592/**
593 * Issue a TPM_PCR_SetAuthValue command.
594 *
abdc7b8a 595 * @dev TPM device
b9dd4fab
MR
596 * @pw Platform password
597 * @pw_sz Length of the password
598 * @index Index of the PCR
599 * @digest New key to access the PCR
600 * @key_sz Length of the new key
601 *
185f812c 602 * Return: code of the operation
b9dd4fab 603 */
abdc7b8a
SG
604u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw,
605 const ssize_t pw_sz, u32 index, const char *key,
606 const ssize_t key_sz);
b9dd4fab 607
06bea498
DP
608/**
609 * Issue a TPM2_GetRandom command.
610 *
611 * @dev TPM device
612 * @param data output buffer for the random bytes
613 * @param count size of output buffer
614 *
185f812c 615 * Return: return code of the operation
06bea498
DP
616 */
617u32 tpm2_get_random(struct udevice *dev, void *data, u32 count);
618
7785bc1d
SG
619/**
620 * Lock data in the TPM
621 *
622 * Once locked the data cannot be written until after a reboot
623 *
624 * @dev TPM device
625 * @index Index of data to lock
185f812c 626 * Return: code of the operation
7785bc1d
SG
627 */
628u32 tpm2_write_lock(struct udevice *dev, u32 index);
629
63af92e8
SG
630/**
631 * Disable access to any platform data
632 *
633 * This can be called to close off access to the firmware data in the data,
634 * before calling the kernel.
635 *
636 * @dev TPM device
185f812c 637 * Return: code of the operation
63af92e8
SG
638 */
639u32 tpm2_disable_platform_hierarchy(struct udevice *dev);
640
7fc93cae
MK
641/**
642 * submit user specified data to the TPM and get response
643 *
644 * @dev TPM device
645 * @sendbuf: Buffer of the data to send
646 * @recvbuf: Buffer to save the response to
647 * @recv_size: Pointer to the size of the response buffer
648 *
185f812c 649 * Return: code of the operation
7fc93cae
MK
650 */
651u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf,
652 u8 *recvbuf, size_t *recv_size);
653
4c57ec76
SG
654/**
655 * tpm_cr50_report_state() - Report the Cr50 internal state
656 *
657 * @dev: TPM device
658 * @vendor_cmd: Vendor command number to send
659 * @vendor_subcmd: Vendor sub-command number to send
660 * @recvbuf: Buffer to save the response to
661 * @recv_size: Pointer to the size of the response buffer
662 * Return: result of the operation
663 */
664u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd,
665 u8 *recvbuf, size_t *recv_size);
666
5208ed18
SG
667/**
668 * tpm2_enable_nvcommits() - Tell TPM to commit NV data immediately
669 *
670 * For Chromium OS verified boot, we may reboot or reset at different times,
671 * possibly leaving non-volatile data unwritten by the TPM.
672 *
673 * This vendor command is used to indicate that non-volatile data should be
674 * written to its store immediately.
675 *
676 * @dev TPM device
677 * @vendor_cmd: Vendor command number to send
678 * @vendor_subcmd: Vendor sub-command number to send
679 * Return: result of the operation
680 */
681u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd,
682 uint vendor_subcmd);
683
a595be3a
IA
684/**
685 * tpm2_auto_start() - start up the TPM and perform selftests.
686 * If a testable function has not been tested and is
687 * requested the TPM2 will return TPM_RC_NEEDS_TEST.
688 *
689 * @param dev TPM device
690 * Return: TPM2_RC_TESTING, if TPM2 self-test is in progress.
691 * TPM2_RC_SUCCESS, if testing of all functions is complete without
692 * functional failures.
693 * TPM2_RC_FAILURE, if any test failed.
694 * TPM2_RC_INITIALIZE, if the TPM has not gone through the Startup
695 * sequence
696
697 */
698u32 tpm2_auto_start(struct udevice *dev);
699
954b95e7
TH
700/**
701 * tpm2_name_to_algorithm() - Return an algorithm id given a supported
702 * algorithm name
703 *
704 * @name: algorithm name
705 * Return: enum tpm2_algorithms or -EINVAL
706 */
707enum tpm2_algorithms tpm2_name_to_algorithm(const char *name);
708
709/**
710 * tpm2_algorithm_name() - Return an algorithm name string for a
711 * supported algorithm id
712 *
713 * @algorithm_id: algorithm defined in enum tpm2_algorithms
714 * Return: algorithm name string or ""
715 */
716const char *tpm2_algorithm_name(enum tpm2_algorithms);
717
ff32245b 718#endif /* __TPM_V2_H */
This page took 0.368475 seconds and 4 git commands to generate.