blob: a89d6899378107f7cb533f8b717256e545e019d3 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Vadim Bendebury5e124722011-10-17 08:36:14 +00002/*
Che-liang Chiou8732b072013-02-28 09:34:57 +00003 * Copyright (c) 2013 The Chromium OS Authors.
Reinhard Pfaube6c1522013-06-26 15:55:13 +02004 * Coypright (c) 2013 Guntermann & Drunck GmbH
Vadim Bendebury5e124722011-10-17 08:36:14 +00005 */
6
Che-liang Chiou8732b072013-02-28 09:34:57 +00007#ifndef __TPM_H
8#define __TPM_H
Vadim Bendebury5e124722011-10-17 08:36:14 +00009
Vadim Bendebury5e124722011-10-17 08:36:14 +000010/*
Che-liang Chiou8732b072013-02-28 09:34:57 +000011 * Here is a partial implementation of TPM commands. Please consult TCG Main
12 * Specification for definitions of TPM commands.
Vadim Bendebury5e124722011-10-17 08:36:14 +000013 */
Vadim Bendebury5e124722011-10-17 08:36:14 +000014
Simon Glassf255d312015-08-22 18:31:31 -060015#define TPM_HEADER_SIZE 10
16
17enum tpm_duration {
18 TPM_SHORT = 0,
19 TPM_MEDIUM = 1,
20 TPM_LONG = 2,
21 TPM_UNDEFINED,
22
23 TPM_DURATION_COUNT,
24};
25
Che-liang Chiou8732b072013-02-28 09:34:57 +000026enum tpm_startup_type {
27 TPM_ST_CLEAR = 0x0001,
28 TPM_ST_STATE = 0x0002,
29 TPM_ST_DEACTIVATED = 0x0003,
30};
31
32enum tpm_physical_presence {
33 TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200,
34 TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100,
35 TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080,
36 TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040,
37 TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020,
38 TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010,
39 TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008,
40 TPM_PHYSICAL_PRESENCE_LOCK = 0x0004,
41};
42
43enum tpm_nv_index {
44 TPM_NV_INDEX_LOCK = 0xffffffff,
45 TPM_NV_INDEX_0 = 0x00000000,
46 TPM_NV_INDEX_DIR = 0x10000001,
47};
48
Mario Six7690be32017-01-11 16:00:50 +010049enum tpm_resource_type {
50 TPM_RT_KEY = 0x00000001,
51 TPM_RT_AUTH = 0x00000002,
52 TPM_RT_HASH = 0x00000003,
53 TPM_RT_TRANS = 0x00000004,
54 TPM_RT_CONTEXT = 0x00000005,
55 TPM_RT_COUNTER = 0x00000006,
56 TPM_RT_DELEGATE = 0x00000007,
57 TPM_RT_DAA_TPM = 0x00000008,
58 TPM_RT_DAA_V0 = 0x00000009,
59 TPM_RT_DAA_V1 = 0x0000000A,
60};
61
62enum tpm_capability_areas {
63 TPM_CAP_ORD = 0x00000001,
64 TPM_CAP_ALG = 0x00000002,
65 TPM_CAP_PID = 0x00000003,
66 TPM_CAP_FLAG = 0x00000004,
67 TPM_CAP_PROPERTY = 0x00000005,
68 TPM_CAP_VERSION = 0x00000006,
69 TPM_CAP_KEY_HANDLE = 0x00000007,
70 TPM_CAP_CHECK_LOADED = 0x00000008,
71 TPM_CAP_SYM_MODE = 0x00000009,
72 TPM_CAP_KEY_STATUS = 0x0000000C,
73 TPM_CAP_NV_LIST = 0x0000000D,
74 TPM_CAP_MFR = 0x00000010,
75 TPM_CAP_NV_INDEX = 0x00000011,
76 TPM_CAP_TRANS_ALG = 0x00000012,
77 TPM_CAP_HANDLE = 0x00000014,
78 TPM_CAP_TRANS_ES = 0x00000015,
79 TPM_CAP_AUTH_ENCRYPT = 0x00000017,
80 TPM_CAP_SELECT_SIZE = 0x00000018,
81 TPM_CAP_DA_LOGIC = 0x00000019,
82 TPM_CAP_VERSION_VAL = 0x0000001A,
83};
84
Miquel Raynalfded8372018-05-15 11:57:01 +020085#define TPM_NV_PER_GLOBALLOCK BIT(15)
86#define TPM_NV_PER_PPREAD BIT(16)
87#define TPM_NV_PER_PPWRITE BIT(0)
88#define TPM_NV_PER_READ_STCLEAR BIT(31)
89#define TPM_NV_PER_WRITE_STCLEAR BIT(14)
90#define TPM_NV_PER_WRITEDEFINE BIT(13)
91#define TPM_NV_PER_WRITEALL BIT(12)
Simon Glass2132f972015-08-22 18:31:41 -060092
93enum {
94 TPM_PUBEK_SIZE = 256,
95};
96
Che-liang Chiou8732b072013-02-28 09:34:57 +000097/**
Reinhard Pfaube6c1522013-06-26 15:55:13 +020098 * TPM return codes as defined in the TCG Main specification
99 * (TPM Main Part 2 Structures; Specification version 1.2)
100 */
101enum tpm_return_code {
102 TPM_BASE = 0x00000000,
103 TPM_NON_FATAL = 0x00000800,
104 TPM_SUCCESS = TPM_BASE,
105 /* TPM-defined fatal error codes */
106 TPM_AUTHFAIL = TPM_BASE + 1,
107 TPM_BADINDEX = TPM_BASE + 2,
108 TPM_BAD_PARAMETER = TPM_BASE + 3,
109 TPM_AUDITFAILURE = TPM_BASE + 4,
110 TPM_CLEAR_DISABLED = TPM_BASE + 5,
111 TPM_DEACTIVATED = TPM_BASE + 6,
112 TPM_DISABLED = TPM_BASE + 7,
113 TPM_DISABLED_CMD = TPM_BASE + 8,
114 TPM_FAIL = TPM_BASE + 9,
115 TPM_BAD_ORDINAL = TPM_BASE + 10,
116 TPM_INSTALL_DISABLED = TPM_BASE + 11,
117 TPM_INVALID_KEYHANDLE = TPM_BASE + 12,
118 TPM_KEYNOTFOUND = TPM_BASE + 13,
119 TPM_INAPPROPRIATE_ENC = TPM_BASE + 14,
120 TPM_MIGRATE_FAIL = TPM_BASE + 15,
121 TPM_INVALID_PCR_INFO = TPM_BASE + 16,
122 TPM_NOSPACE = TPM_BASE + 17,
123 TPM_NOSRK = TPM_BASE + 18,
124 TPM_NOTSEALED_BLOB = TPM_BASE + 19,
125 TPM_OWNER_SET = TPM_BASE + 20,
126 TPM_RESOURCES = TPM_BASE + 21,
127 TPM_SHORTRANDOM = TPM_BASE + 22,
128 TPM_SIZE = TPM_BASE + 23,
129 TPM_WRONGPCRVAL = TPM_BASE + 24,
130 TPM_BAD_PARAM_SIZE = TPM_BASE + 25,
131 TPM_SHA_THREAD = TPM_BASE + 26,
132 TPM_SHA_ERROR = TPM_BASE + 27,
133 TPM_FAILEDSELFTEST = TPM_BASE + 28,
134 TPM_AUTH2FAIL = TPM_BASE + 29,
135 TPM_BADTAG = TPM_BASE + 30,
136 TPM_IOERROR = TPM_BASE + 31,
137 TPM_ENCRYPT_ERROR = TPM_BASE + 32,
138 TPM_DECRYPT_ERROR = TPM_BASE + 33,
139 TPM_INVALID_AUTHHANDLE = TPM_BASE + 34,
140 TPM_NO_ENDORSEMENT = TPM_BASE + 35,
141 TPM_INVALID_KEYUSAGE = TPM_BASE + 36,
142 TPM_WRONG_ENTITYTYPE = TPM_BASE + 37,
143 TPM_INVALID_POSTINIT = TPM_BASE + 38,
144 TPM_INAPPROPRIATE_SIG = TPM_BASE + 39,
145 TPM_BAD_KEY_PROPERTY = TPM_BASE + 40,
146 TPM_BAD_MIGRATION = TPM_BASE + 41,
147 TPM_BAD_SCHEME = TPM_BASE + 42,
148 TPM_BAD_DATASIZE = TPM_BASE + 43,
149 TPM_BAD_MODE = TPM_BASE + 44,
150 TPM_BAD_PRESENCE = TPM_BASE + 45,
151 TPM_BAD_VERSION = TPM_BASE + 46,
152 TPM_NO_WRAP_TRANSPORT = TPM_BASE + 47,
153 TPM_AUDITFAIL_UNSUCCESSFUL = TPM_BASE + 48,
154 TPM_AUDITFAIL_SUCCESSFUL = TPM_BASE + 49,
155 TPM_NOTRESETABLE = TPM_BASE + 50,
156 TPM_NOTLOCAL = TPM_BASE + 51,
157 TPM_BAD_TYPE = TPM_BASE + 52,
158 TPM_INVALID_RESOURCE = TPM_BASE + 53,
159 TPM_NOTFIPS = TPM_BASE + 54,
160 TPM_INVALID_FAMILY = TPM_BASE + 55,
161 TPM_NO_NV_PERMISSION = TPM_BASE + 56,
162 TPM_REQUIRES_SIGN = TPM_BASE + 57,
163 TPM_KEY_NOTSUPPORTED = TPM_BASE + 58,
164 TPM_AUTH_CONFLICT = TPM_BASE + 59,
165 TPM_AREA_LOCKED = TPM_BASE + 60,
166 TPM_BAD_LOCALITY = TPM_BASE + 61,
167 TPM_READ_ONLY = TPM_BASE + 62,
168 TPM_PER_NOWRITE = TPM_BASE + 63,
169 TPM_FAMILY_COUNT = TPM_BASE + 64,
170 TPM_WRITE_LOCKED = TPM_BASE + 65,
171 TPM_BAD_ATTRIBUTES = TPM_BASE + 66,
172 TPM_INVALID_STRUCTURE = TPM_BASE + 67,
173 TPM_KEY_OWNER_CONTROL = TPM_BASE + 68,
174 TPM_BAD_COUNTER = TPM_BASE + 69,
175 TPM_NOT_FULLWRITE = TPM_BASE + 70,
176 TPM_CONTEXT_GAP = TPM_BASE + 71,
177 TPM_MAXNVWRITES = TPM_BASE + 72,
178 TPM_NOOPERATOR = TPM_BASE + 73,
179 TPM_RESOURCEMISSING = TPM_BASE + 74,
180 TPM_DELEGATE_LOCK = TPM_BASE + 75,
181 TPM_DELEGATE_FAMILY = TPM_BASE + 76,
182 TPM_DELEGATE_ADMIN = TPM_BASE + 77,
183 TPM_TRANSPORT_NOTEXCLUSIVE = TPM_BASE + 78,
184 TPM_OWNER_CONTROL = TPM_BASE + 79,
185 TPM_DAA_RESOURCES = TPM_BASE + 80,
186 TPM_DAA_INPUT_DATA0 = TPM_BASE + 81,
187 TPM_DAA_INPUT_DATA1 = TPM_BASE + 82,
188 TPM_DAA_ISSUER_SETTINGS = TPM_BASE + 83,
189 TPM_DAA_TPM_SETTINGS = TPM_BASE + 84,
190 TPM_DAA_STAGE = TPM_BASE + 85,
191 TPM_DAA_ISSUER_VALIDITY = TPM_BASE + 86,
192 TPM_DAA_WRONG_W = TPM_BASE + 87,
193 TPM_BAD_HANDLE = TPM_BASE + 88,
194 TPM_BAD_DELEGATE = TPM_BASE + 89,
195 TPM_BADCONTEXT = TPM_BASE + 90,
196 TPM_TOOMANYCONTEXTS = TPM_BASE + 91,
197 TPM_MA_TICKET_SIGNATURE = TPM_BASE + 92,
198 TPM_MA_DESTINATION = TPM_BASE + 93,
199 TPM_MA_SOURCE = TPM_BASE + 94,
200 TPM_MA_AUTHORITY = TPM_BASE + 95,
201 TPM_PERMANENTEK = TPM_BASE + 97,
202 TPM_BAD_SIGNATURE = TPM_BASE + 98,
203 TPM_NOCONTEXTSPACE = TPM_BASE + 99,
204 /* TPM-defined non-fatal errors */
205 TPM_RETRY = TPM_BASE + TPM_NON_FATAL,
206 TPM_NEEDS_SELFTEST = TPM_BASE + TPM_NON_FATAL + 1,
207 TPM_DOING_SELFTEST = TPM_BASE + TPM_NON_FATAL + 2,
208 TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3,
209};
210
Simon Glass2132f972015-08-22 18:31:41 -0600211struct tpm_permanent_flags {
212 __be16 tag;
213 u8 disable;
214 u8 ownership;
215 u8 deactivated;
216 u8 read_pubek;
217 u8 disable_owner_clear;
218 u8 allow_maintenance;
219 u8 physical_presence_lifetime_lock;
220 u8 physical_presence_hw_enable;
221 u8 physical_presence_cmd_enable;
222 u8 cekp_used;
223 u8 tpm_post;
224 u8 tpm_post_lock;
225 u8 fips;
226 u8 operator;
227 u8 enable_revoke_ek;
228 u8 nv_locked;
229 u8 read_srk_pub;
230 u8 tpm_established;
231 u8 maintenance_done;
232 u8 disable_full_da_logic_info;
233} __packed;
234
Simon Glassf255d312015-08-22 18:31:31 -0600235/* Max buffer size supported by our tpm */
236#define TPM_DEV_BUFSIZE 1260
237
238/**
239 * struct tpm_chip_priv - Information about a TPM, stored by the uclass
240 *
241 * These values must be set up by the device's probe() method before
242 * communcation is attempted. If the device has an xfer() method, this is
243 * not needed. There is no need to set up @buf.
244 *
245 * @duration_ms: Length of each duration type in milliseconds
246 * @retry_time_ms: Time to wait before retrying receive
247 */
248struct tpm_chip_priv {
249 uint duration_ms[TPM_DURATION_COUNT];
250 uint retry_time_ms;
251 u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */
252};
253
254/**
255 * struct tpm_ops - low-level TPM operations
256 *
257 * These are designed to avoid loops and delays in the driver itself. These
258 * should be handled in the uclass.
259 *
260 * In gneral you should implement everything except xfer(). Where you need
261 * complete control of the transfer, then xfer() can be provided and will
262 * override the other methods.
263 *
264 * This interface is for low-level TPM access. It does not understand the
265 * concept of localities or the various TPM messages. That interface is
266 * defined in the functions later on in this file, but they all translate
267 * to bytes which are sent and received.
268 */
269struct tpm_ops {
270 /**
271 * open() - Request access to locality 0 for the caller
272 *
273 * After all commands have been completed the caller should call
274 * close().
275 *
276 * @dev: Device to close
277 * @return 0 ok OK, -ve on error
278 */
279 int (*open)(struct udevice *dev);
280
281 /**
282 * close() - Close the current session
283 *
284 * Releasing the locked locality. Returns 0 on success, -ve 1 on
285 * failure (in case lock removal did not succeed).
286 *
287 * @dev: Device to close
288 * @return 0 ok OK, -ve on error
289 */
290 int (*close)(struct udevice *dev);
291
292 /**
293 * get_desc() - Get a text description of the TPM
294 *
295 * @dev: Device to check
296 * @buf: Buffer to put the string
297 * @size: Maximum size of buffer
298 * @return length of string, or -ENOSPC it no space
299 */
300 int (*get_desc)(struct udevice *dev, char *buf, int size);
301
302 /**
303 * send() - send data to the TPM
304 *
305 * @dev: Device to talk to
306 * @sendbuf: Buffer of the data to send
307 * @send_size: Size of the data to send
308 *
309 * Returns 0 on success or -ve on failure.
310 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200311 int (*send)(struct udevice *dev, const u8 *sendbuf, size_t send_size);
Simon Glassf255d312015-08-22 18:31:31 -0600312
313 /**
314 * recv() - receive a response from the TPM
315 *
316 * @dev: Device to talk to
317 * @recvbuf: Buffer to save the response to
318 * @max_size: Maximum number of bytes to receive
319 *
320 * Returns number of bytes received on success, -EAGAIN if the TPM
321 * response is not ready, -EINTR if cancelled, or other -ve value on
322 * failure.
323 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200324 int (*recv)(struct udevice *dev, u8 *recvbuf, size_t max_size);
Simon Glassf255d312015-08-22 18:31:31 -0600325
326 /**
327 * cleanup() - clean up after an operation in progress
328 *
329 * This is called if receiving times out. The TPM may need to abort
330 * the current transaction if it did not complete, and make itself
331 * ready for another.
332 *
333 * @dev: Device to talk to
334 */
335 int (*cleanup)(struct udevice *dev);
336
337 /**
338 * xfer() - send data to the TPM and get response
339 *
340 * This method is optional. If it exists it is used in preference
341 * to send(), recv() and cleanup(). It should handle all aspects of
342 * TPM communication for a single transfer.
343 *
344 * @dev: Device to talk to
345 * @sendbuf: Buffer of the data to send
346 * @send_size: Size of the data to send
347 * @recvbuf: Buffer to save the response to
348 * @recv_size: Pointer to the size of the response buffer
349 *
350 * Returns 0 on success (and places the number of response bytes at
351 * recv_size) or -ve on failure.
352 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200353 int (*xfer)(struct udevice *dev, const u8 *sendbuf, size_t send_size,
354 u8 *recvbuf, size_t *recv_size);
Simon Glassf255d312015-08-22 18:31:31 -0600355};
356
357#define tpm_get_ops(dev) ((struct tpm_ops *)device_get_ops(dev))
358
359/**
360 * tpm_open() - Request access to locality 0 for the caller
361 *
362 * After all commands have been completed the caller is supposed to
363 * call tpm_close().
364 *
365 * Returns 0 on success, -ve on failure.
366 */
367int tpm_open(struct udevice *dev);
368
369/**
370 * tpm_close() - Close the current session
371 *
372 * Releasing the locked locality. Returns 0 on success, -ve 1 on
373 * failure (in case lock removal did not succeed).
374 */
375int tpm_close(struct udevice *dev);
376
377/**
378 * tpm_get_desc() - Get a text description of the TPM
379 *
380 * @dev: Device to check
381 * @buf: Buffer to put the string
382 * @size: Maximum size of buffer
383 * @return length of string, or -ENOSPC it no space
384 */
385int tpm_get_desc(struct udevice *dev, char *buf, int size);
386
387/**
388 * tpm_xfer() - send data to the TPM and get response
389 *
390 * This first uses the device's send() method to send the bytes. Then it calls
391 * recv() to get the reply. If recv() returns -EAGAIN then it will delay a
392 * short time and then call recv() again.
393 *
394 * Regardless of whether recv() completes successfully, it will then call
395 * cleanup() to finish the transaction.
396 *
397 * Note that the outgoing data is inspected to determine command type
398 * (ordinal) and a timeout is used for that command type.
399 *
400 * @sendbuf - buffer of the data to send
401 * @send_size size of the data to send
402 * @recvbuf - memory to save the response to
403 * @recv_len - pointer to the size of the response buffer
404 *
405 * Returns 0 on success (and places the number of response bytes at
406 * recv_len) or -ve on failure.
407 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200408int tpm_xfer(struct udevice *dev, const u8 *sendbuf, size_t send_size,
409 u8 *recvbuf, size_t *recv_size);
Simon Glassf255d312015-08-22 18:31:31 -0600410
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200411/**
Che-liang Chiou8732b072013-02-28 09:34:57 +0000412 * Initialize TPM device. It must be called before any TPM commands.
Vadim Bendebury5e124722011-10-17 08:36:14 +0000413 *
Che-liang Chiou8732b072013-02-28 09:34:57 +0000414 * @return 0 on success, non-0 on error.
Vadim Bendebury5e124722011-10-17 08:36:14 +0000415 */
Simon Glassc8a8c512015-08-22 18:31:32 -0600416int tpm_init(void);
Vadim Bendebury5e124722011-10-17 08:36:14 +0000417
Che-liang Chiou8732b072013-02-28 09:34:57 +0000418/**
419 * Issue a TPM_Startup command.
Vadim Bendebury5e124722011-10-17 08:36:14 +0000420 *
Che-liang Chiou8732b072013-02-28 09:34:57 +0000421 * @param mode TPM startup mode
422 * @return return code of the operation
Vadim Bendebury5e124722011-10-17 08:36:14 +0000423 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200424u32 tpm_startup(enum tpm_startup_type mode);
Vadim Bendebury5e124722011-10-17 08:36:14 +0000425
Che-liang Chiou8732b072013-02-28 09:34:57 +0000426/**
427 * Issue a TPM_SelfTestFull command.
Vadim Bendebury5e124722011-10-17 08:36:14 +0000428 *
Che-liang Chiou8732b072013-02-28 09:34:57 +0000429 * @return return code of the operation
Vadim Bendebury5e124722011-10-17 08:36:14 +0000430 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200431u32 tpm_self_test_full(void);
Vadim Bendebury5e124722011-10-17 08:36:14 +0000432
Che-liang Chiou8732b072013-02-28 09:34:57 +0000433/**
434 * Issue a TPM_ContinueSelfTest command.
435 *
436 * @return return code of the operation
437 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200438u32 tpm_continue_self_test(void);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000439
440/**
441 * Issue a TPM_NV_DefineSpace command. The implementation is limited
442 * to specify TPM_NV_ATTRIBUTES and size of the area. The area index
443 * could be one of the special value listed in enum tpm_nv_index.
444 *
445 * @param index index of the area
446 * @param perm TPM_NV_ATTRIBUTES of the area
447 * @param size size of the area
448 * @return return code of the operation
449 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200450u32 tpm_nv_define_space(u32 index, u32 perm, u32 size);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000451
452/**
453 * Issue a TPM_NV_ReadValue command. This implementation is limited
454 * to read the area from offset 0. The area index could be one of
455 * the special value listed in enum tpm_nv_index.
456 *
457 * @param index index of the area
458 * @param data output buffer of the area contents
459 * @param count size of output buffer
460 * @return return code of the operation
461 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200462u32 tpm_nv_read_value(u32 index, void *data, u32 count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000463
464/**
465 * Issue a TPM_NV_WriteValue command. This implementation is limited
466 * to write the area from offset 0. The area index could be one of
467 * the special value listed in enum tpm_nv_index.
468 *
469 * @param index index of the area
470 * @param data input buffer to be wrote to the area
471 * @param length length of data bytes of input buffer
472 * @return return code of the operation
473 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200474u32 tpm_nv_write_value(u32 index, const void *data, u32 length);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000475
476/**
477 * Issue a TPM_Extend command.
478 *
479 * @param index index of the PCR
480 * @param in_digest 160-bit value representing the event to be
481 * recorded
482 * @param out_digest 160-bit PCR value after execution of the
483 * command
484 * @return return code of the operation
485 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200486u32 tpm_extend(u32 index, const void *in_digest, void *out_digest);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000487
488/**
489 * Issue a TPM_PCRRead command.
490 *
491 * @param index index of the PCR
492 * @param data output buffer for contents of the named PCR
493 * @param count size of output buffer
494 * @return return code of the operation
495 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200496u32 tpm_pcr_read(u32 index, void *data, size_t count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000497
498/**
499 * Issue a TSC_PhysicalPresence command. TPM physical presence flag
500 * is bit-wise OR'ed of flags listed in enum tpm_physical_presence.
501 *
502 * @param presence TPM physical presence flag
503 * @return return code of the operation
504 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200505u32 tpm_tsc_physical_presence(u16 presence);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000506
507/**
508 * Issue a TPM_ReadPubek command.
509 *
510 * @param data output buffer for the public endorsement key
511 * @param count size of ouput buffer
512 * @return return code of the operation
513 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200514u32 tpm_read_pubek(void *data, size_t count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000515
516/**
517 * Issue a TPM_ForceClear command.
518 *
519 * @return return code of the operation
520 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200521u32 tpm_force_clear(void);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000522
523/**
524 * Issue a TPM_PhysicalEnable command.
525 *
526 * @return return code of the operation
527 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200528u32 tpm_physical_enable(void);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000529
530/**
531 * Issue a TPM_PhysicalDisable command.
532 *
533 * @return return code of the operation
534 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200535u32 tpm_physical_disable(void);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000536
537/**
538 * Issue a TPM_PhysicalSetDeactivated command.
539 *
540 * @param state boolean state of the deactivated flag
541 * @return return code of the operation
542 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200543u32 tpm_physical_set_deactivated(u8 state);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000544
545/**
546 * Issue a TPM_GetCapability command. This implementation is limited
547 * to query sub_cap index that is 4-byte wide.
548 *
549 * @param cap_area partition of capabilities
550 * @param sub_cap further definition of capability, which is
551 * limited to be 4-byte wide
552 * @param cap output buffer for capability information
553 * @param count size of ouput buffer
554 * @return return code of the operation
555 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200556u32 tpm_get_capability(u32 cap_area, u32 sub_cap, void *cap, size_t count);
Che-liang Chiou8732b072013-02-28 09:34:57 +0000557
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200558/**
559 * Issue a TPM_FlushSpecific command for a AUTH ressource.
560 *
561 * @param auth_handle handle of the auth session
562 * @return return code of the operation
563 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200564u32 tpm_terminate_auth_session(u32 auth_handle);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200565
566/**
567 * Issue a TPM_OIAP command to setup an object independant authorization
568 * session.
569 * Information about the session is stored internally.
570 * If there was already an OIAP session active it is terminated and a new
571 * session is set up.
572 *
573 * @param auth_handle pointer to the (new) auth handle or NULL.
574 * @return return code of the operation
575 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200576u32 tpm_oiap(u32 *auth_handle);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200577
578/**
579 * Ends an active OIAP session.
580 *
581 * @return return code of the operation
582 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200583u32 tpm_end_oiap(void);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200584
585/**
586 * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating
587 * the usage of the parent key.
588 *
589 * @param parent_handle handle of the parent key.
590 * @param key pointer to the key structure (TPM_KEY or TPM_KEY12).
591 * @param key_length size of the key structure
592 * @param parent_key_usage_auth usage auth for the parent key
593 * @param key_handle pointer to the key handle
594 * @return return code of the operation
595 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200596u32 tpm_load_key2_oiap(u32 parent_handle, const void *key, size_t key_length,
597 const void *parent_key_usage_auth, u32 *key_handle);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200598
599/**
600 * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for
601 * authenticating the usage of the key.
602 *
603 * @param key_handle handle of the key
604 * @param usage_auth usage auth for the key
605 * @param pubkey pointer to the pub key buffer; may be NULL if the pubkey
606 * should not be stored.
607 * @param pubkey_len pointer to the pub key buffer len. On entry: the size of
608 * the provided pubkey buffer. On successful exit: the size
609 * of the stored TPM_PUBKEY structure (iff pubkey != NULL).
610 * @return return code of the operation
611 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200612u32 tpm_get_pub_key_oiap(u32 key_handle, const void *usage_auth, void *pubkey,
613 size_t *pubkey_len);
Reinhard Pfaube6c1522013-06-26 15:55:13 +0200614
Simon Glass2132f972015-08-22 18:31:41 -0600615/**
616 * Get the TPM permanent flags value
617 *
618 * @param pflags Place to put permanent flags
619 * @return return code of the operation
620 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200621u32 tpm_get_permanent_flags(struct tpm_permanent_flags *pflags);
Simon Glass2132f972015-08-22 18:31:41 -0600622
623/**
624 * Get the TPM permissions
625 *
626 * @param perm Returns permissions value
627 * @return return code of the operation
628 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200629u32 tpm_get_permissions(u32 index, u32 *perm);
Simon Glass2132f972015-08-22 18:31:41 -0600630
Mario Six7690be32017-01-11 16:00:50 +0100631/**
632 * Flush a resource with a given handle and type from the TPM
633 *
634 * @param key_handle handle of the resource
635 * @param resource_type type of the resource
636 * @return return code of the operation
637 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200638u32 tpm_flush_specific(u32 key_handle, u32 resource_type);
Mario Six7690be32017-01-11 16:00:50 +0100639
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100640#ifdef CONFIG_TPM_LOAD_KEY_BY_SHA1
641/**
642 * Search for a key by usage AuthData and the hash of the parent's pub key.
643 *
644 * @param auth Usage auth of the key to search for
645 * @param pubkey_digest SHA1 hash of the pub key structure of the key
646 * @param[out] handle The handle of the key (Non-null iff found)
647 * @return 0 if key was found in TPM; != 0 if not.
648 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200649u32 tpm_find_key_sha1(const u8 auth[20], const u8 pubkey_digest[20],
650 u32 *handle);
mario.six@gdsys.cc0f4b2ba2017-03-20 10:28:28 +0100651#endif /* CONFIG_TPM_LOAD_KEY_BY_SHA1 */
André Draszik3c605022017-10-03 16:55:52 +0100652
653/**
654 * Read random bytes from the TPM RNG. The implementation deals with the fact
655 * that the TPM may legally return fewer bytes than requested by retrying
656 * until @p count bytes have been received.
657 *
658 * @param data output buffer for the random bytes
659 * @param count size of output buffer
660 * @return return code of the operation
661 */
Miquel Raynalb9804e52018-05-15 11:56:59 +0200662u32 tpm_get_random(void *data, u32 count);
André Draszik3c605022017-10-03 16:55:52 +0100663
Che-liang Chiou8732b072013-02-28 09:34:57 +0000664#endif /* __TPM_H */