blob: afd022fc9d3dfa5bb162c955d763bc22754562e3 [file] [log] [blame]
Rajiv Andrade659aaf22009-02-02 15:23:44 -02001/*
2 * Copyright (C) 2004,2007,2008 IBM Corporation
3 *
4 * Authors:
5 * Leendert van Doorn <leendert@watson.ibm.com>
6 * Dave Safford <safford@watson.ibm.com>
7 * Reiner Sailer <sailer@watson.ibm.com>
8 * Kylene Hall <kjhall@us.ibm.com>
9 * Debora Velarde <dvelarde@us.ibm.com>
10 *
11 * Maintained by: <tpmdd_devel@lists.sourceforge.net>
12 *
13 * Device driver for TCG/TCPA TPM (trusted platform module).
14 * Specifications at www.trustedcomputinggroup.org
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.
20 *
21 */
22#ifndef __LINUX_TPM_H__
23#define __LINUX_TPM_H__
24
Roberto Sassuaa042472019-02-06 17:24:48 +010025#include <crypto/hash_info.h>
26
Mimi Zohar1c16c962013-05-21 10:40:47 -040027#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
Roberto Sassuaa042472019-02-06 17:24:48 +010028#define TPM_MAX_DIGEST_SIZE SHA512_DIGEST_SIZE
Mimi Zohar1c16c962013-05-21 10:40:47 -040029
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070030struct tpm_chip;
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030031struct trusted_key_payload;
32struct trusted_key_options;
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070033
Roberto Sassuaa042472019-02-06 17:24:48 +010034enum tpm_algorithms {
35 TPM_ALG_ERROR = 0x0000,
36 TPM_ALG_SHA1 = 0x0004,
37 TPM_ALG_KEYEDHASH = 0x0008,
38 TPM_ALG_SHA256 = 0x000B,
39 TPM_ALG_SHA384 = 0x000C,
40 TPM_ALG_SHA512 = 0x000D,
41 TPM_ALG_NULL = 0x0010,
42 TPM_ALG_SM3_256 = 0x0012,
43};
44
45struct tpm_digest {
46 u16 alg_id;
47 u8 digest[TPM_MAX_DIGEST_SIZE];
48} __packed;
49
Roberto Sassu879b5892019-02-06 17:24:49 +010050struct tpm_bank_info {
51 u16 alg_id;
52 u16 digest_size;
53 u16 crypto_id;
54};
55
Jason Gunthorpecae8b442016-07-12 11:41:49 -060056enum TPM_OPS_FLAGS {
57 TPM_OPS_AUTO_STARTUP = BIT(0),
58};
59
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070060struct tpm_class_ops {
Jason Gunthorpecae8b442016-07-12 11:41:49 -060061 unsigned int flags;
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070062 const u8 req_complete_mask;
63 const u8 req_complete_val;
64 bool (*req_canceled)(struct tpm_chip *chip, u8 status);
65 int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
66 int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
67 void (*cancel) (struct tpm_chip *chip);
68 u8 (*status) (struct tpm_chip *chip);
Jerry Snitselaar36ce0892019-01-30 15:06:58 -070069 void (*update_timeouts)(struct tpm_chip *chip,
Jason Gunthorpe8e54caf2014-05-21 18:26:44 -060070 unsigned long *timeout_cap);
Tomas Winkler627448e2018-06-28 18:13:33 +030071 int (*go_idle)(struct tpm_chip *chip);
72 int (*cmd_ready)(struct tpm_chip *chip);
Jarkko Sakkinen877c57d2017-03-24 11:45:49 +020073 int (*request_locality)(struct tpm_chip *chip, int loc);
Tomas Winkler888d8672018-03-05 13:34:49 +020074 int (*relinquish_locality)(struct tpm_chip *chip, int loc);
Azhar Shaikhb3e958c2017-12-22 12:13:44 -080075 void (*clk_enable)(struct tpm_chip *chip, bool value);
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070076};
77
Randy Dunlapff76ec12009-10-28 12:26:39 -070078#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
Rajiv Andrade659aaf22009-02-02 15:23:44 -020079
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020080extern int tpm_is_tpm2(struct tpm_chip *chip);
Roberto Sassu879b5892019-02-06 17:24:49 +010081extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx,
82 struct tpm_digest *digest);
Tomas Winkler95adc6b2018-10-19 21:23:07 +030083extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash);
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020084extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
85extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
86extern int tpm_seal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030087 struct trusted_key_payload *payload,
88 struct trusted_key_options *options);
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020089extern int tpm_unseal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030090 struct trusted_key_payload *payload,
91 struct trusted_key_options *options);
Stefan Bergeraaae8152018-06-26 15:09:30 -040092extern struct tpm_chip *tpm_default_chip(void);
Mimi Zohard6ba4522009-10-26 09:26:18 -040093#else
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020094static inline int tpm_is_tpm2(struct tpm_chip *chip)
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030095{
96 return -ENODEV;
97}
Tomas Winkler95adc6b2018-10-19 21:23:07 +030098
Roberto Sassu879b5892019-02-06 17:24:49 +010099static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx,
100 struct tpm_digest *digest)
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200101{
Mimi Zohard6ba4522009-10-26 09:26:18 -0400102 return -ENODEV;
103}
Tomas Winkler95adc6b2018-10-19 21:23:07 +0300104
105static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200106 const u8 *hash)
107{
Mimi Zohard6ba4522009-10-26 09:26:18 -0400108 return -ENODEV;
109}
Tomas Winkler95adc6b2018-10-19 21:23:07 +0300110
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200111static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
112{
Mimi Zoharc749ba92010-11-23 18:54:16 -0500113 return -ENODEV;
114}
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200115static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
116{
Kent Yoder41ab9992012-06-07 13:47:14 -0500117 return -ENODEV;
118}
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300119
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200120static inline int tpm_seal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300121 struct trusted_key_payload *payload,
122 struct trusted_key_options *options)
123{
124 return -ENODEV;
125}
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200126static inline int tpm_unseal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300127 struct trusted_key_payload *payload,
128 struct trusted_key_options *options)
129{
130 return -ENODEV;
131}
Stefan Bergeraaae8152018-06-26 15:09:30 -0400132static inline struct tpm_chip *tpm_default_chip(void)
133{
134 return NULL;
135}
Rajiv Andrade659aaf22009-02-02 15:23:44 -0200136#endif
137#endif