]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Copyright (C) 2004 IBM Corporation | |
a74f8b36 | 3 | * Copyright (C) 2015 Intel Corporation |
1da177e4 LT |
4 | * |
5 | * Authors: | |
6 | * Leendert van Doorn <leendert@watson.ibm.com> | |
7 | * Dave Safford <safford@watson.ibm.com> | |
8 | * Reiner Sailer <sailer@watson.ibm.com> | |
9 | * Kylene Hall <kjhall@us.ibm.com> | |
10 | * | |
8e81cc13 | 11 | * Maintained by: <tpmdd-devel@lists.sourceforge.net> |
1da177e4 LT |
12 | * |
13 | * Device driver for TCG/TCPA TPM (trusted platform module). | |
3b09825d | 14 | * Specifications at www.trustedcomputinggroup.org |
1da177e4 LT |
15 | * |
16 | * This program is free software; you can redistribute it and/or | |
17 | * modify it under the terms of the GNU General Public License as | |
18 | * published by the Free Software Foundation, version 2 of the | |
19 | * License. | |
3b09825d | 20 | * |
1da177e4 | 21 | */ |
d2efee6e CR |
22 | |
23 | #ifndef __TPM_H__ | |
24 | #define __TPM_H__ | |
25 | ||
1da177e4 | 26 | #include <linux/module.h> |
1da177e4 LT |
27 | #include <linux/delay.h> |
28 | #include <linux/fs.h> | |
d081d470 | 29 | #include <linux/mutex.h> |
914e2637 | 30 | #include <linux/sched.h> |
bbc5b212 | 31 | #include <linux/platform_device.h> |
276ad0c1 | 32 | #include <linux/io.h> |
659aaf2b | 33 | #include <linux/tpm.h> |
0dc55365 | 34 | #include <linux/acpi.h> |
313d21ee | 35 | #include <linux/cdev.h> |
a74f8b36 | 36 | #include <linux/highmem.h> |
c1f92b4b | 37 | #include <crypto/hash_info.h> |
1da177e4 | 38 | |
5e572cab AS |
39 | #ifdef CONFIG_X86 |
40 | #include <asm/intel-family.h> | |
41 | #endif | |
42 | ||
41ab999c KY |
43 | enum tpm_const { |
44 | TPM_MINOR = 224, /* officially assigned */ | |
45 | TPM_BUFSIZE = 4096, | |
15516788 | 46 | TPM_NUM_DEVICES = 65536, |
32d33b29 | 47 | TPM_RETRY = 50, /* 5 seconds */ |
cd9b7631 | 48 | TPM_NUM_EVENT_LOG_FILES = 3, |
41ab999c KY |
49 | }; |
50 | ||
3122a88a KH |
51 | enum tpm_timeout { |
52 | TPM_TIMEOUT = 5, /* msecs */ | |
32d33b29 | 53 | TPM_TIMEOUT_RETRY = 100 /* msecs */ |
3122a88a | 54 | }; |
1da177e4 LT |
55 | |
56 | /* TPM addresses */ | |
3122a88a | 57 | enum tpm_addr { |
daacdfa6 | 58 | TPM_SUPERIO_ADDR = 0x2E, |
3122a88a | 59 | TPM_ADDR = 0x4E, |
3122a88a KH |
60 | }; |
61 | ||
000a07b0 JG |
62 | /* Indexes the duration array */ |
63 | enum tpm_duration { | |
64 | TPM_SHORT = 0, | |
65 | TPM_MEDIUM = 1, | |
66 | TPM_LONG = 2, | |
67 | TPM_UNDEFINED, | |
68 | }; | |
69 | ||
32d33b29 | 70 | #define TPM_WARN_RETRY 0x800 |
68d6e671 | 71 | #define TPM_WARN_DOING_SELFTEST 0x802 |
be405411 SB |
72 | #define TPM_ERR_DEACTIVATED 0x6 |
73 | #define TPM_ERR_DISABLED 0x7 | |
c584af19 | 74 | #define TPM_ERR_INVALID_POSTINIT 38 |
be405411 | 75 | |
b9e3238a | 76 | #define TPM_HEADER_SIZE 10 |
7a1d7e6d JS |
77 | |
78 | enum tpm2_const { | |
79 | TPM2_PLATFORM_PCR = 24, | |
80 | TPM2_PCR_SELECT_MIN = ((TPM2_PLATFORM_PCR + 7) / 8), | |
81 | TPM2_TIMEOUT_A = 750, | |
82 | TPM2_TIMEOUT_B = 2000, | |
83 | TPM2_TIMEOUT_C = 200, | |
84 | TPM2_TIMEOUT_D = 30, | |
85 | TPM2_DURATION_SHORT = 20, | |
86 | TPM2_DURATION_MEDIUM = 750, | |
87 | TPM2_DURATION_LONG = 2000, | |
88 | }; | |
89 | ||
90 | enum tpm2_structures { | |
91 | TPM2_ST_NO_SESSIONS = 0x8001, | |
92 | TPM2_ST_SESSIONS = 0x8002, | |
93 | }; | |
94 | ||
95 | enum tpm2_return_codes { | |
745b361e | 96 | TPM2_RC_SUCCESS = 0x0000, |
5ca4c20c | 97 | TPM2_RC_HASH = 0x0083, /* RC_FMT1 */ |
745b361e | 98 | TPM2_RC_HANDLE = 0x008B, |
5ca4c20c | 99 | TPM2_RC_INITIALIZE = 0x0100, /* RC_VER1 */ |
7a1d7e6d | 100 | TPM2_RC_DISABLED = 0x0120, |
5ca4c20c | 101 | TPM2_RC_TESTING = 0x090A, /* RC_WARN */ |
745b361e | 102 | TPM2_RC_REFERENCE_H0 = 0x0910, |
7a1d7e6d JS |
103 | }; |
104 | ||
105 | enum tpm2_algorithms { | |
1db15344 | 106 | TPM2_ALG_ERROR = 0x0000, |
7a1d7e6d | 107 | TPM2_ALG_SHA1 = 0x0004, |
954650ef JS |
108 | TPM2_ALG_KEYEDHASH = 0x0008, |
109 | TPM2_ALG_SHA256 = 0x000B, | |
5ca4c20c JS |
110 | TPM2_ALG_SHA384 = 0x000C, |
111 | TPM2_ALG_SHA512 = 0x000D, | |
112 | TPM2_ALG_NULL = 0x0010, | |
113 | TPM2_ALG_SM3_256 = 0x0012, | |
7a1d7e6d JS |
114 | }; |
115 | ||
116 | enum tpm2_command_codes { | |
117 | TPM2_CC_FIRST = 0x011F, | |
118 | TPM2_CC_SELF_TEST = 0x0143, | |
119 | TPM2_CC_STARTUP = 0x0144, | |
120 | TPM2_CC_SHUTDOWN = 0x0145, | |
954650ef JS |
121 | TPM2_CC_CREATE = 0x0153, |
122 | TPM2_CC_LOAD = 0x0157, | |
123 | TPM2_CC_UNSEAL = 0x015E, | |
745b361e | 124 | TPM2_CC_CONTEXT_LOAD = 0x0161, |
58472f5c | 125 | TPM2_CC_CONTEXT_SAVE = 0x0162, |
954650ef | 126 | TPM2_CC_FLUSH_CONTEXT = 0x0165, |
7a1d7e6d JS |
127 | TPM2_CC_GET_CAPABILITY = 0x017A, |
128 | TPM2_CC_GET_RANDOM = 0x017B, | |
129 | TPM2_CC_PCR_READ = 0x017E, | |
130 | TPM2_CC_PCR_EXTEND = 0x0182, | |
131 | TPM2_CC_LAST = 0x018F, | |
132 | }; | |
133 | ||
134 | enum tpm2_permanent_handles { | |
135 | TPM2_RS_PW = 0x40000009, | |
136 | }; | |
137 | ||
138 | enum tpm2_capabilities { | |
745b361e | 139 | TPM2_CAP_HANDLES = 1, |
58472f5c | 140 | TPM2_CAP_COMMANDS = 2, |
1db15344 | 141 | TPM2_CAP_PCRS = 5, |
7a1d7e6d JS |
142 | TPM2_CAP_TPM_PROPERTIES = 6, |
143 | }; | |
144 | ||
58472f5c JS |
145 | enum tpm2_properties { |
146 | TPM_PT_TOTAL_COMMANDS = 0x0129, | |
147 | }; | |
148 | ||
7a1d7e6d JS |
149 | enum tpm2_startup_types { |
150 | TPM2_SU_CLEAR = 0x0000, | |
151 | TPM2_SU_STATE = 0x0001, | |
152 | }; | |
153 | ||
58472f5c JS |
154 | enum tpm2_cc_attrs { |
155 | TPM2_CC_ATTR_CHANDLES = 25, | |
156 | TPM2_CC_ATTR_RHANDLE = 28, | |
157 | }; | |
158 | ||
4e401fb0 | 159 | #define TPM_VID_INTEL 0x8086 |
1f866057 SB |
160 | #define TPM_VID_WINBOND 0x1050 |
161 | #define TPM_VID_STM 0x104A | |
4e401fb0 | 162 | |
0dc55365 JS |
163 | #define TPM_PPI_VERSION_LEN 3 |
164 | ||
745b361e JS |
165 | struct tpm_space { |
166 | u32 context_tbl[3]; | |
167 | u8 *context_buf; | |
4d57856a JB |
168 | u32 session_tbl[3]; |
169 | u8 *session_buf; | |
745b361e JS |
170 | }; |
171 | ||
afb5abc2 | 172 | enum tpm_chip_flags { |
9b774d5c | 173 | TPM_CHIP_FLAG_TPM2 = BIT(1), |
570a3609 | 174 | TPM_CHIP_FLAG_IRQ = BIT(2), |
2f9f5377 | 175 | TPM_CHIP_FLAG_VIRTUAL = BIT(3), |
d1d253cf | 176 | TPM_CHIP_FLAG_HAVE_TIMEOUTS = BIT(4), |
afb5abc2 JS |
177 | }; |
178 | ||
4d23cc32 NJ |
179 | struct tpm_bios_log { |
180 | void *bios_event_log; | |
181 | void *bios_event_log_end; | |
182 | }; | |
183 | ||
748935ee NJ |
184 | struct tpm_chip_seqops { |
185 | struct tpm_chip *chip; | |
186 | const struct seq_operations *seqops; | |
187 | }; | |
188 | ||
1da177e4 | 189 | struct tpm_chip { |
313d21ee | 190 | struct device dev; |
fdc915f7 | 191 | struct device devs; |
313d21ee | 192 | struct cdev cdev; |
fdc915f7 | 193 | struct cdev cdevs; |
313d21ee | 194 | |
4e26195f JG |
195 | /* A driver callback under ops cannot be run unless ops_sem is held |
196 | * (sometimes implicitly, eg for the sysfs code). ops becomes null | |
197 | * when the driver is unregistered, see tpm_try_get_ops. | |
198 | */ | |
199 | struct rw_semaphore ops_sem; | |
5f82e9f0 | 200 | const struct tpm_class_ops *ops; |
4e26195f | 201 | |
748935ee NJ |
202 | struct tpm_bios_log log; |
203 | struct tpm_chip_seqops bin_log_seqops; | |
204 | struct tpm_chip_seqops ascii_log_seqops; | |
205 | ||
afb5abc2 | 206 | unsigned int flags; |
1da177e4 LT |
207 | |
208 | int dev_num; /* /dev/tpm# */ | |
dc36d32c | 209 | unsigned long is_open; /* only one allowed */ |
1da177e4 | 210 | |
d081d470 | 211 | struct mutex tpm_mutex; /* tpm is processing */ |
1da177e4 | 212 | |
af782f33 CR |
213 | unsigned long timeout_a; /* jiffies */ |
214 | unsigned long timeout_b; /* jiffies */ | |
215 | unsigned long timeout_c; /* jiffies */ | |
216 | unsigned long timeout_d; /* jiffies */ | |
217 | bool timeout_adjusted; | |
218 | unsigned long duration[3]; /* jiffies */ | |
219 | bool duration_adjusted; | |
1da177e4 | 220 | |
cd9b7631 | 221 | struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES]; |
55a82ab3 | 222 | |
062807f2 | 223 | const struct attribute_group *groups[3]; |
9b774d5c | 224 | unsigned int groups_cnt; |
1db15344 NJ |
225 | |
226 | u16 active_banks[7]; | |
062807f2 | 227 | #ifdef CONFIG_ACPI |
0dc55365 JS |
228 | acpi_handle acpi_dev_handle; |
229 | char ppi_version[TPM_PPI_VERSION_LEN + 1]; | |
230 | #endif /* CONFIG_ACPI */ | |
58472f5c | 231 | |
745b361e | 232 | struct tpm_space work_space; |
58472f5c JS |
233 | u32 nr_commands; |
234 | u32 *cc_attrs_tbl; | |
877c57d0 JS |
235 | |
236 | /* active locality */ | |
237 | int locality; | |
1da177e4 LT |
238 | }; |
239 | ||
9b774d5c | 240 | #define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) |
27084efe | 241 | |
08837438 RA |
242 | struct tpm_input_header { |
243 | __be16 tag; | |
244 | __be32 length; | |
245 | __be32 ordinal; | |
348df8db | 246 | } __packed; |
08837438 RA |
247 | |
248 | struct tpm_output_header { | |
249 | __be16 tag; | |
250 | __be32 length; | |
251 | __be32 return_code; | |
348df8db | 252 | } __packed; |
08837438 | 253 | |
06e93279 | 254 | #define TPM_TAG_RQU_COMMAND 193 |
000a07b0 | 255 | |
08837438 RA |
256 | struct stclear_flags_t { |
257 | __be16 tag; | |
258 | u8 deactivated; | |
259 | u8 disableForceClear; | |
260 | u8 physicalPresence; | |
261 | u8 physicalPresenceLock; | |
262 | u8 bGlobalLock; | |
348df8db | 263 | } __packed; |
08837438 RA |
264 | |
265 | struct tpm_version_t { | |
266 | u8 Major; | |
267 | u8 Minor; | |
268 | u8 revMajor; | |
269 | u8 revMinor; | |
348df8db | 270 | } __packed; |
08837438 RA |
271 | |
272 | struct tpm_version_1_2_t { | |
273 | __be16 tag; | |
274 | u8 Major; | |
275 | u8 Minor; | |
276 | u8 revMajor; | |
277 | u8 revMinor; | |
348df8db | 278 | } __packed; |
08837438 RA |
279 | |
280 | struct timeout_t { | |
281 | __be32 a; | |
282 | __be32 b; | |
283 | __be32 c; | |
284 | __be32 d; | |
348df8db | 285 | } __packed; |
08837438 RA |
286 | |
287 | struct duration_t { | |
288 | __be32 tpm_short; | |
289 | __be32 tpm_medium; | |
290 | __be32 tpm_long; | |
348df8db | 291 | } __packed; |
08837438 RA |
292 | |
293 | struct permanent_flags_t { | |
294 | __be16 tag; | |
295 | u8 disable; | |
296 | u8 ownership; | |
297 | u8 deactivated; | |
298 | u8 readPubek; | |
299 | u8 disableOwnerClear; | |
300 | u8 allowMaintenance; | |
301 | u8 physicalPresenceLifetimeLock; | |
302 | u8 physicalPresenceHWEnable; | |
303 | u8 physicalPresenceCMDEnable; | |
304 | u8 CEKPUsed; | |
305 | u8 TPMpost; | |
306 | u8 TPMpostLock; | |
307 | u8 FIPS; | |
308 | u8 operator; | |
309 | u8 enableRevokeEK; | |
310 | u8 nvLocked; | |
311 | u8 readSRKPub; | |
312 | u8 tpmEstablished; | |
313 | u8 maintenanceDone; | |
314 | u8 disableFullDALogicInfo; | |
348df8db | 315 | } __packed; |
08837438 RA |
316 | |
317 | typedef union { | |
318 | struct permanent_flags_t perm_flags; | |
319 | struct stclear_flags_t stclear_flags; | |
a118cf2a | 320 | __u8 owned; |
08837438 RA |
321 | __be32 num_pcrs; |
322 | struct tpm_version_t tpm_version; | |
323 | struct tpm_version_1_2_t tpm_version_1_2; | |
324 | __be32 manufacturer_id; | |
325 | struct timeout_t timeout; | |
326 | struct duration_t duration; | |
327 | } cap_t; | |
328 | ||
000a07b0 | 329 | enum tpm_capabilities { |
84fda152 JS |
330 | TPM_CAP_FLAG = 4, |
331 | TPM_CAP_PROP = 5, | |
332 | TPM_CAP_VERSION_1_1 = 0x06, | |
333 | TPM_CAP_VERSION_1_2 = 0x1A, | |
000a07b0 JG |
334 | }; |
335 | ||
336 | enum tpm_sub_capabilities { | |
84fda152 JS |
337 | TPM_CAP_PROP_PCR = 0x101, |
338 | TPM_CAP_PROP_MANUFACTURER = 0x103, | |
339 | TPM_CAP_FLAG_PERM = 0x108, | |
340 | TPM_CAP_FLAG_VOL = 0x109, | |
341 | TPM_CAP_PROP_OWNER = 0x111, | |
342 | TPM_CAP_PROP_TIS_TIMEOUT = 0x115, | |
343 | TPM_CAP_PROP_TIS_DURATION = 0x120, | |
000a07b0 JG |
344 | }; |
345 | ||
08837438 RA |
346 | struct tpm_readpubek_params_out { |
347 | u8 algorithm[4]; | |
348 | u8 encscheme[2]; | |
349 | u8 sigscheme[2]; | |
02a077c5 | 350 | __be32 paramsize; |
08837438 RA |
351 | u8 parameters[12]; /*assuming RSA*/ |
352 | __be32 keysize; | |
353 | u8 modulus[256]; | |
354 | u8 checksum[20]; | |
348df8db | 355 | } __packed; |
08837438 RA |
356 | |
357 | typedef union { | |
358 | struct tpm_input_header in; | |
359 | struct tpm_output_header out; | |
360 | } tpm_cmd_header; | |
361 | ||
659aaf2b RA |
362 | struct tpm_pcrread_out { |
363 | u8 pcr_result[TPM_DIGEST_SIZE]; | |
348df8db | 364 | } __packed; |
659aaf2b RA |
365 | |
366 | struct tpm_pcrread_in { | |
367 | __be32 pcr_idx; | |
348df8db | 368 | } __packed; |
659aaf2b | 369 | |
41ab999c KY |
370 | /* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18 |
371 | * bytes, but 128 is still a relatively large number of random bytes and | |
372 | * anything much bigger causes users of struct tpm_cmd_t to start getting | |
373 | * compiler warnings about stack frame size. */ | |
374 | #define TPM_MAX_RNG_DATA 128 | |
375 | ||
376 | struct tpm_getrandom_out { | |
377 | __be32 rng_data_len; | |
378 | u8 rng_data[TPM_MAX_RNG_DATA]; | |
348df8db | 379 | } __packed; |
41ab999c KY |
380 | |
381 | struct tpm_getrandom_in { | |
382 | __be32 num_bytes; | |
348df8db | 383 | } __packed; |
41ab999c | 384 | |
08837438 | 385 | typedef union { |
08837438 RA |
386 | struct tpm_readpubek_params_out readpubek_out; |
387 | u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; | |
659aaf2b RA |
388 | struct tpm_pcrread_in pcrread_in; |
389 | struct tpm_pcrread_out pcrread_out; | |
41ab999c KY |
390 | struct tpm_getrandom_in getrandom_in; |
391 | struct tpm_getrandom_out getrandom_out; | |
08837438 RA |
392 | } tpm_cmd_params; |
393 | ||
394 | struct tpm_cmd_t { | |
395 | tpm_cmd_header header; | |
396 | tpm_cmd_params params; | |
348df8db | 397 | } __packed; |
08837438 | 398 | |
c1f92b4b NJ |
399 | struct tpm2_digest { |
400 | u16 alg_id; | |
401 | u8 digest[SHA512_DIGEST_SIZE]; | |
402 | } __packed; | |
403 | ||
a74f8b36 JS |
404 | /* A string buffer type for constructing TPM commands. This is based on the |
405 | * ideas of string buffer code in security/keys/trusted.h but is heap based | |
406 | * in order to keep the stack usage minimal. | |
407 | */ | |
408 | ||
409 | enum tpm_buf_flags { | |
410 | TPM_BUF_OVERFLOW = BIT(0), | |
411 | }; | |
412 | ||
413 | struct tpm_buf { | |
414 | struct page *data_page; | |
415 | unsigned int flags; | |
416 | u8 *data; | |
417 | }; | |
418 | ||
954650ef | 419 | static inline int tpm_buf_init(struct tpm_buf *buf, u16 tag, u32 ordinal) |
a74f8b36 JS |
420 | { |
421 | struct tpm_input_header *head; | |
422 | ||
423 | buf->data_page = alloc_page(GFP_HIGHUSER); | |
424 | if (!buf->data_page) | |
425 | return -ENOMEM; | |
426 | ||
427 | buf->flags = 0; | |
428 | buf->data = kmap(buf->data_page); | |
429 | ||
430 | head = (struct tpm_input_header *) buf->data; | |
431 | ||
432 | head->tag = cpu_to_be16(tag); | |
433 | head->length = cpu_to_be32(sizeof(*head)); | |
434 | head->ordinal = cpu_to_be32(ordinal); | |
435 | ||
436 | return 0; | |
437 | } | |
438 | ||
439 | static inline void tpm_buf_destroy(struct tpm_buf *buf) | |
440 | { | |
441 | kunmap(buf->data_page); | |
442 | __free_page(buf->data_page); | |
443 | } | |
444 | ||
445 | static inline u32 tpm_buf_length(struct tpm_buf *buf) | |
446 | { | |
447 | struct tpm_input_header *head = (struct tpm_input_header *) buf->data; | |
448 | ||
449 | return be32_to_cpu(head->length); | |
450 | } | |
451 | ||
452 | static inline u16 tpm_buf_tag(struct tpm_buf *buf) | |
453 | { | |
454 | struct tpm_input_header *head = (struct tpm_input_header *) buf->data; | |
455 | ||
456 | return be16_to_cpu(head->tag); | |
457 | } | |
458 | ||
459 | static inline void tpm_buf_append(struct tpm_buf *buf, | |
460 | const unsigned char *new_data, | |
461 | unsigned int new_len) | |
462 | { | |
463 | struct tpm_input_header *head = (struct tpm_input_header *) buf->data; | |
464 | u32 len = tpm_buf_length(buf); | |
465 | ||
466 | /* Return silently if overflow has already happened. */ | |
467 | if (buf->flags & TPM_BUF_OVERFLOW) | |
468 | return; | |
469 | ||
470 | if ((len + new_len) > PAGE_SIZE) { | |
471 | WARN(1, "tpm_buf: overflow\n"); | |
472 | buf->flags |= TPM_BUF_OVERFLOW; | |
473 | return; | |
474 | } | |
475 | ||
476 | memcpy(&buf->data[len], new_data, new_len); | |
477 | head->length = cpu_to_be32(len + new_len); | |
478 | } | |
479 | ||
480 | static inline void tpm_buf_append_u8(struct tpm_buf *buf, const u8 value) | |
481 | { | |
482 | tpm_buf_append(buf, &value, 1); | |
483 | } | |
484 | ||
485 | static inline void tpm_buf_append_u16(struct tpm_buf *buf, const u16 value) | |
486 | { | |
487 | __be16 value2 = cpu_to_be16(value); | |
488 | ||
489 | tpm_buf_append(buf, (u8 *) &value2, 2); | |
490 | } | |
491 | ||
492 | static inline void tpm_buf_append_u32(struct tpm_buf *buf, const u32 value) | |
493 | { | |
494 | __be32 value2 = cpu_to_be32(value); | |
495 | ||
496 | tpm_buf_append(buf, (u8 *) &value2, 4); | |
497 | } | |
498 | ||
313d21ee | 499 | extern struct class *tpm_class; |
fdc915f7 | 500 | extern struct class *tpmrm_class; |
313d21ee JS |
501 | extern dev_t tpm_devt; |
502 | extern const struct file_operations tpm_fops; | |
fdc915f7 | 503 | extern const struct file_operations tpmrm_fops; |
15516788 | 504 | extern struct idr dev_nums_idr; |
313d21ee | 505 | |
d4816edf JS |
506 | enum tpm_transmit_flags { |
507 | TPM_TRANSMIT_UNLOCKED = BIT(0), | |
85ab3bf3 | 508 | TPM_TRANSMIT_RAW = BIT(1), |
d4816edf JS |
509 | }; |
510 | ||
745b361e JS |
511 | ssize_t tpm_transmit(struct tpm_chip *chip, struct tpm_space *space, |
512 | u8 *buf, size_t bufsiz, unsigned int flags); | |
513 | ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, | |
514 | const void *buf, size_t bufsiz, | |
515 | size_t min_rsp_body_length, unsigned int flags, | |
c659af78 | 516 | const char *desc); |
19cbe4f6 | 517 | int tpm_startup(struct tpm_chip *chip); |
84fda152 | 518 | ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, |
c659af78 | 519 | const char *desc, size_t min_cap_length); |
d4abd956 | 520 | int tpm_get_timeouts(struct tpm_chip *); |
cae8b441 | 521 | int tpm1_auto_startup(struct tpm_chip *chip); |
d4abd956 JS |
522 | int tpm_do_selftest(struct tpm_chip *chip); |
523 | unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); | |
524 | int tpm_pm_suspend(struct device *dev); | |
525 | int tpm_pm_resume(struct device *dev); | |
526 | int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, | |
527 | wait_queue_head_t *queue, bool check_cancel); | |
f84fdff0 | 528 | |
afb5abc2 | 529 | struct tpm_chip *tpm_chip_find_get(int chip_num); |
4e26195f JG |
530 | __must_check int tpm_try_get_ops(struct tpm_chip *chip); |
531 | void tpm_put_ops(struct tpm_chip *chip); | |
532 | ||
d4abd956 JS |
533 | struct tpm_chip *tpm_chip_alloc(struct device *dev, |
534 | const struct tpm_class_ops *ops); | |
535 | struct tpm_chip *tpmm_chip_alloc(struct device *pdev, | |
536 | const struct tpm_class_ops *ops); | |
537 | int tpm_chip_register(struct tpm_chip *chip); | |
538 | void tpm_chip_unregister(struct tpm_chip *chip); | |
afb5abc2 | 539 | |
062807f2 | 540 | void tpm_sysfs_add_device(struct tpm_chip *chip); |
afdba32e | 541 | |
000a07b0 JG |
542 | int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); |
543 | ||
f84fdff0 | 544 | #ifdef CONFIG_ACPI |
9b774d5c | 545 | extern void tpm_add_ppi(struct tpm_chip *chip); |
f84fdff0 | 546 | #else |
9b774d5c | 547 | static inline void tpm_add_ppi(struct tpm_chip *chip) |
1631cfb7 GW |
548 | { |
549 | } | |
f84fdff0 | 550 | #endif |
7a1d7e6d | 551 | |
7d761119 JS |
552 | static inline inline u32 tpm2_rc_value(u32 rc) |
553 | { | |
554 | return (rc & BIT(7)) ? rc & 0xff : rc; | |
555 | } | |
556 | ||
7a1d7e6d | 557 | int tpm2_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf); |
c1f92b4b NJ |
558 | int tpm2_pcr_extend(struct tpm_chip *chip, int pcr_idx, u32 count, |
559 | struct tpm2_digest *digests); | |
7a1d7e6d | 560 | int tpm2_get_random(struct tpm_chip *chip, u8 *out, size_t max); |
9aa36b39 JS |
561 | void tpm2_flush_context_cmd(struct tpm_chip *chip, u32 handle, |
562 | unsigned int flags); | |
954650ef JS |
563 | int tpm2_seal_trusted(struct tpm_chip *chip, |
564 | struct trusted_key_payload *payload, | |
565 | struct trusted_key_options *options); | |
566 | int tpm2_unseal_trusted(struct tpm_chip *chip, | |
567 | struct trusted_key_payload *payload, | |
568 | struct trusted_key_options *options); | |
7a1d7e6d JS |
569 | ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, |
570 | u32 *value, const char *desc); | |
571 | ||
cae8b441 | 572 | int tpm2_auto_startup(struct tpm_chip *chip); |
d4abd956 JS |
573 | void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); |
574 | unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); | |
d4abd956 | 575 | int tpm2_probe(struct tpm_chip *chip); |
58472f5c | 576 | int tpm2_find_cc(struct tpm_chip *chip, u32 cc); |
745b361e | 577 | int tpm2_init_space(struct tpm_space *space); |
4d57856a | 578 | void tpm2_del_space(struct tpm_chip *chip, struct tpm_space *space); |
745b361e JS |
579 | int tpm2_prepare_space(struct tpm_chip *chip, struct tpm_space *space, u32 cc, |
580 | u8 *cmd); | |
581 | int tpm2_commit_space(struct tpm_chip *chip, struct tpm_space *space, | |
582 | u32 cc, u8 *buf, size_t *bufsiz); | |
d2efee6e | 583 | #endif |