blob: 9fe8c9816cf089d478fcd6c8901273963954ceed [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
Jason Gunthorpecae8b442016-07-12 11:41:49 -060050enum TPM_OPS_FLAGS {
51 TPM_OPS_AUTO_STARTUP = BIT(0),
52};
53
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070054struct tpm_class_ops {
Jason Gunthorpecae8b442016-07-12 11:41:49 -060055 unsigned int flags;
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070056 const u8 req_complete_mask;
57 const u8 req_complete_val;
58 bool (*req_canceled)(struct tpm_chip *chip, u8 status);
59 int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
60 int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
61 void (*cancel) (struct tpm_chip *chip);
62 u8 (*status) (struct tpm_chip *chip);
Jerry Snitselaar36ce0892019-01-30 15:06:58 -070063 void (*update_timeouts)(struct tpm_chip *chip,
Jason Gunthorpe8e54caf2014-05-21 18:26:44 -060064 unsigned long *timeout_cap);
Tomas Winkler627448e2018-06-28 18:13:33 +030065 int (*go_idle)(struct tpm_chip *chip);
66 int (*cmd_ready)(struct tpm_chip *chip);
Jarkko Sakkinen877c57d2017-03-24 11:45:49 +020067 int (*request_locality)(struct tpm_chip *chip, int loc);
Tomas Winkler888d8672018-03-05 13:34:49 +020068 int (*relinquish_locality)(struct tpm_chip *chip, int loc);
Azhar Shaikhb3e958c2017-12-22 12:13:44 -080069 void (*clk_enable)(struct tpm_chip *chip, bool value);
Jason Gunthorpe01ad1fa2013-11-26 13:30:43 -070070};
71
Randy Dunlapff76ec12009-10-28 12:26:39 -070072#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
Rajiv Andrade659aaf22009-02-02 15:23:44 -020073
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020074extern int tpm_is_tpm2(struct tpm_chip *chip);
Tomas Winkler95adc6b2018-10-19 21:23:07 +030075extern int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
76extern int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx, const u8 *hash);
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020077extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
78extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
79extern int tpm_seal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030080 struct trusted_key_payload *payload,
81 struct trusted_key_options *options);
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020082extern int tpm_unseal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030083 struct trusted_key_payload *payload,
84 struct trusted_key_options *options);
Stefan Bergeraaae8152018-06-26 15:09:30 -040085extern struct tpm_chip *tpm_default_chip(void);
Mimi Zohard6ba4522009-10-26 09:26:18 -040086#else
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020087static inline int tpm_is_tpm2(struct tpm_chip *chip)
Jarkko Sakkinen954650e2015-05-30 08:09:04 +030088{
89 return -ENODEV;
90}
Tomas Winkler95adc6b2018-10-19 21:23:07 +030091
92static inline int tpm_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf)
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020093{
Mimi Zohard6ba4522009-10-26 09:26:18 -040094 return -ENODEV;
95}
Tomas Winkler95adc6b2018-10-19 21:23:07 +030096
97static inline int tpm_pcr_extend(struct tpm_chip *chip, u32 pcr_idx,
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +020098 const u8 *hash)
99{
Mimi Zohard6ba4522009-10-26 09:26:18 -0400100 return -ENODEV;
101}
Tomas Winkler95adc6b2018-10-19 21:23:07 +0300102
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200103static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
104{
Mimi Zoharc749ba92010-11-23 18:54:16 -0500105 return -ENODEV;
106}
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200107static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
108{
Kent Yoder41ab9992012-06-07 13:47:14 -0500109 return -ENODEV;
110}
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300111
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200112static inline int tpm_seal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300113 struct trusted_key_payload *payload,
114 struct trusted_key_options *options)
115{
116 return -ENODEV;
117}
Jarkko Sakkinenaad887f2017-11-05 13:16:26 +0200118static inline int tpm_unseal_trusted(struct tpm_chip *chip,
Jarkko Sakkinen954650e2015-05-30 08:09:04 +0300119 struct trusted_key_payload *payload,
120 struct trusted_key_options *options)
121{
122 return -ENODEV;
123}
Stefan Bergeraaae8152018-06-26 15:09:30 -0400124static inline struct tpm_chip *tpm_default_chip(void)
125{
126 return NULL;
127}
Rajiv Andrade659aaf22009-02-02 15:23:44 -0200128#endif
129#endif