1 /*
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 
25 #define TPM_DIGEST_SIZE 20	/* Max TPM v1.2 PCR size */
26 
27 struct tpm_chip;
28 struct trusted_key_payload;
29 struct trusted_key_options;
30 
31 enum TPM_OPS_FLAGS {
32 	TPM_OPS_AUTO_STARTUP = BIT(0),
33 };
34 
35 struct tpm_class_ops {
36 	unsigned int flags;
37 	const u8 req_complete_mask;
38 	const u8 req_complete_val;
39 	bool (*req_canceled)(struct tpm_chip *chip, u8 status);
40 	int (*recv) (struct tpm_chip *chip, u8 *buf, size_t len);
41 	int (*send) (struct tpm_chip *chip, u8 *buf, size_t len);
42 	void (*cancel) (struct tpm_chip *chip);
43 	u8 (*status) (struct tpm_chip *chip);
44 	bool (*update_timeouts)(struct tpm_chip *chip,
45 				unsigned long *timeout_cap);
46 	int (*go_idle)(struct tpm_chip *chip);
47 	int (*cmd_ready)(struct tpm_chip *chip);
48 	int (*request_locality)(struct tpm_chip *chip, int loc);
49 	int (*relinquish_locality)(struct tpm_chip *chip, int loc);
50 	void (*clk_enable)(struct tpm_chip *chip, bool value);
51 };
52 
53 #if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
54 
55 extern int tpm_is_tpm2(struct tpm_chip *chip);
56 extern int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
57 extern int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash);
58 extern int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen);
59 extern int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max);
60 extern int tpm_seal_trusted(struct tpm_chip *chip,
61 			    struct trusted_key_payload *payload,
62 			    struct trusted_key_options *options);
63 extern int tpm_unseal_trusted(struct tpm_chip *chip,
64 			      struct trusted_key_payload *payload,
65 			      struct trusted_key_options *options);
66 extern struct tpm_chip *tpm_default_chip(void);
67 #else
tpm_is_tpm2(struct tpm_chip * chip)68 static inline int tpm_is_tpm2(struct tpm_chip *chip)
69 {
70 	return -ENODEV;
71 }
tpm_pcr_read(struct tpm_chip * chip,int pcr_idx,u8 * res_buf)72 static inline int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
73 {
74 	return -ENODEV;
75 }
tpm_pcr_extend(struct tpm_chip * chip,int pcr_idx,const u8 * hash)76 static inline int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx,
77 				 const u8 *hash)
78 {
79 	return -ENODEV;
80 }
tpm_send(struct tpm_chip * chip,void * cmd,size_t buflen)81 static inline int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen)
82 {
83 	return -ENODEV;
84 }
tpm_get_random(struct tpm_chip * chip,u8 * data,size_t max)85 static inline int tpm_get_random(struct tpm_chip *chip, u8 *data, size_t max)
86 {
87 	return -ENODEV;
88 }
89 
tpm_seal_trusted(struct tpm_chip * chip,struct trusted_key_payload * payload,struct trusted_key_options * options)90 static inline int tpm_seal_trusted(struct tpm_chip *chip,
91 				   struct trusted_key_payload *payload,
92 				   struct trusted_key_options *options)
93 {
94 	return -ENODEV;
95 }
tpm_unseal_trusted(struct tpm_chip * chip,struct trusted_key_payload * payload,struct trusted_key_options * options)96 static inline int tpm_unseal_trusted(struct tpm_chip *chip,
97 				     struct trusted_key_payload *payload,
98 				     struct trusted_key_options *options)
99 {
100 	return -ENODEV;
101 }
tpm_default_chip(void)102 static inline struct tpm_chip *tpm_default_chip(void)
103 {
104 	return NULL;
105 }
106 #endif
107 #endif
108