summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto Sassu <roberto.sassu@huawei.com>2019-02-06 11:24:50 -0500
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>2019-02-13 02:48:51 -0500
commit901615cb916dc955fb7bda4e34402bf263532e4a (patch)
treeaf217a92b23d5288074251d6735978375f1785c6
parent879b589210a9a0c9f77d301aaf0ddee20f2c5052 (diff)
tpm: move tpm_chip definition to include/linux/tpm.h
The tpm_chip structure contains the list of PCR banks currently allocated in the TPM. When support for crypto agility will be added to the TPM driver, users of the driver have to provide a digest for each allocated bank to tpm_pcr_extend(). With this patch, they can obtain the PCR bank algorithms directly from chip->allocated_banks. Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
-rw-r--r--drivers/char/tpm/tpm.h101
-rw-r--r--include/linux/tpm.h91
2 files changed, 95 insertions, 97 deletions
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 4efa304e9ece..4f85ce909122 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -25,30 +25,22 @@
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include <linux/fs.h>
29#include <linux/hw_random.h>
30#include <linux/mutex.h> 28#include <linux/mutex.h>
31#include <linux/sched.h> 29#include <linux/sched.h>
32#include <linux/platform_device.h> 30#include <linux/platform_device.h>
33#include <linux/io.h> 31#include <linux/io.h>
34#include <linux/tpm.h> 32#include <linux/tpm.h>
35#include <linux/acpi.h>
36#include <linux/cdev.h>
37#include <linux/highmem.h> 33#include <linux/highmem.h>
38#include <linux/tpm_eventlog.h> 34#include <linux/tpm_eventlog.h>
39#include <crypto/hash_info.h>
40 35
41#ifdef CONFIG_X86 36#ifdef CONFIG_X86
42#include <asm/intel-family.h> 37#include <asm/intel-family.h>
43#endif 38#endif
44 39
45enum tpm_const { 40#define TPM_MINOR 224 /* officially assigned */
46 TPM_MINOR = 224, /* officially assigned */ 41#define TPM_BUFSIZE 4096
47 TPM_BUFSIZE = 4096, 42#define TPM_NUM_DEVICES 65536
48 TPM_NUM_DEVICES = 65536, 43#define TPM_RETRY 50
49 TPM_RETRY = 50, /* 5 seconds */
50 TPM_NUM_EVENT_LOG_FILES = 3,
51};
52 44
53enum tpm_timeout { 45enum tpm_timeout {
54 TPM_TIMEOUT = 5, /* msecs */ 46 TPM_TIMEOUT = 5, /* msecs */
@@ -65,16 +57,6 @@ enum tpm_addr {
65 TPM_ADDR = 0x4E, 57 TPM_ADDR = 0x4E,
66}; 58};
67 59
68/* Indexes the duration array */
69enum tpm_duration {
70 TPM_SHORT = 0,
71 TPM_MEDIUM = 1,
72 TPM_LONG = 2,
73 TPM_LONG_LONG = 3,
74 TPM_UNDEFINED,
75 TPM_NUM_DURATIONS = TPM_UNDEFINED,
76};
77
78#define TPM_WARN_RETRY 0x800 60#define TPM_WARN_RETRY 0x800
79#define TPM_WARN_DOING_SELFTEST 0x802 61#define TPM_WARN_DOING_SELFTEST 0x802
80#define TPM_ERR_DEACTIVATED 0x6 62#define TPM_ERR_DEACTIVATED 0x6
@@ -179,15 +161,6 @@ enum tpm2_cc_attrs {
179#define TPM_VID_WINBOND 0x1050 161#define TPM_VID_WINBOND 0x1050
180#define TPM_VID_STM 0x104A 162#define TPM_VID_STM 0x104A
181 163
182#define TPM_PPI_VERSION_LEN 3
183
184struct tpm_space {
185 u32 context_tbl[3];
186 u8 *context_buf;
187 u32 session_tbl[3];
188 u8 *session_buf;
189};
190
191enum tpm_chip_flags { 164enum tpm_chip_flags {
192 TPM_CHIP_FLAG_TPM2 = BIT(1), 165 TPM_CHIP_FLAG_TPM2 = BIT(1),
193 TPM_CHIP_FLAG_IRQ = BIT(2), 166 TPM_CHIP_FLAG_IRQ = BIT(2),
@@ -196,72 +169,6 @@ enum tpm_chip_flags {
196 TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5), 169 TPM_CHIP_FLAG_ALWAYS_POWERED = BIT(5),
197}; 170};
198 171
199struct tpm_bios_log {
200 void *bios_event_log;
201 void *bios_event_log_end;
202};
203
204struct tpm_chip_seqops {
205 struct tpm_chip *chip;
206 const struct seq_operations *seqops;
207};
208
209struct tpm_chip {
210 struct device dev;
211 struct device devs;
212 struct cdev cdev;
213 struct cdev cdevs;
214
215 /* A driver callback under ops cannot be run unless ops_sem is held
216 * (sometimes implicitly, eg for the sysfs code). ops becomes null
217 * when the driver is unregistered, see tpm_try_get_ops.
218 */
219 struct rw_semaphore ops_sem;
220 const struct tpm_class_ops *ops;
221
222 struct tpm_bios_log log;
223 struct tpm_chip_seqops bin_log_seqops;
224 struct tpm_chip_seqops ascii_log_seqops;
225
226 unsigned int flags;
227
228 int dev_num; /* /dev/tpm# */
229 unsigned long is_open; /* only one allowed */
230
231 char hwrng_name[64];
232 struct hwrng hwrng;
233
234 struct mutex tpm_mutex; /* tpm is processing */
235
236 unsigned long timeout_a; /* jiffies */
237 unsigned long timeout_b; /* jiffies */
238 unsigned long timeout_c; /* jiffies */
239 unsigned long timeout_d; /* jiffies */
240 bool timeout_adjusted;
241 unsigned long duration[TPM_NUM_DURATIONS]; /* jiffies */
242 bool duration_adjusted;
243
244 struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
245
246 const struct attribute_group *groups[3];
247 unsigned int groups_cnt;
248
249 u32 nr_allocated_banks;
250 struct tpm_bank_info *allocated_banks;
251#ifdef CONFIG_ACPI
252 acpi_handle acpi_dev_handle;
253 char ppi_version[TPM_PPI_VERSION_LEN + 1];
254#endif /* CONFIG_ACPI */
255
256 struct tpm_space work_space;
257 u32 last_cc;
258 u32 nr_commands;
259 u32 *cc_attrs_tbl;
260
261 /* active locality */
262 int locality;
263};
264
265#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev) 172#define to_tpm_chip(d) container_of(d, struct tpm_chip, dev)
266 173
267struct tpm_header { 174struct tpm_header {
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
index afd022fc9d3d..816e686a73ac 100644
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -22,6 +22,10 @@
22#ifndef __LINUX_TPM_H__ 22#ifndef __LINUX_TPM_H__
23#define __LINUX_TPM_H__ 23#define __LINUX_TPM_H__
24 24
25#include <linux/hw_random.h>
26#include <linux/acpi.h>
27#include <linux/cdev.h>
28#include <linux/fs.h>
25#include <crypto/hash_info.h> 29#include <crypto/hash_info.h>
26 30
27#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */ 31#define TPM_DIGEST_SIZE 20 /* Max TPM v1.2 PCR size */
@@ -75,6 +79,93 @@ struct tpm_class_ops {
75 void (*clk_enable)(struct tpm_chip *chip, bool value); 79 void (*clk_enable)(struct tpm_chip *chip, bool value);
76}; 80};
77 81
82#define TPM_NUM_EVENT_LOG_FILES 3
83
84/* Indexes the duration array */
85enum tpm_duration {
86 TPM_SHORT = 0,
87 TPM_MEDIUM = 1,
88 TPM_LONG = 2,
89 TPM_LONG_LONG = 3,
90 TPM_UNDEFINED,
91 TPM_NUM_DURATIONS = TPM_UNDEFINED,
92};
93
94#define TPM_PPI_VERSION_LEN 3
95
96struct tpm_space {
97 u32 context_tbl[3];
98 u8 *context_buf;
99 u32 session_tbl[3];
100 u8 *session_buf;
101};
102
103struct tpm_bios_log {
104 void *bios_event_log;
105 void *bios_event_log_end;
106};
107
108struct tpm_chip_seqops {
109 struct tpm_chip *chip;
110 const struct seq_operations *seqops;
111};
112
113struct tpm_chip {
114 struct device dev;
115 struct device devs;
116 struct cdev cdev;
117 struct cdev cdevs;
118
119 /* A driver callback under ops cannot be run unless ops_sem is held
120 * (sometimes implicitly, eg for the sysfs code). ops becomes null
121 * when the driver is unregistered, see tpm_try_get_ops.
122 */
123 struct rw_semaphore ops_sem;
124 const struct tpm_class_ops *ops;
125
126 struct tpm_bios_log log;
127 struct tpm_chip_seqops bin_log_seqops;
128 struct tpm_chip_seqops ascii_log_seqops;
129
130 unsigned int flags;
131
132 int dev_num; /* /dev/tpm# */
133 unsigned long is_open; /* only one allowed */
134
135 char hwrng_name[64];
136 struct hwrng hwrng;
137
138 struct mutex tpm_mutex; /* tpm is processing */
139
140 unsigned long timeout_a; /* jiffies */
141 unsigned long timeout_b; /* jiffies */
142 unsigned long timeout_c; /* jiffies */
143 unsigned long timeout_d; /* jiffies */
144 bool timeout_adjusted;
145 unsigned long duration[TPM_NUM_DURATIONS]; /* jiffies */
146 bool duration_adjusted;
147
148 struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
149
150 const struct attribute_group *groups[3];
151 unsigned int groups_cnt;
152
153 u32 nr_allocated_banks;
154 struct tpm_bank_info *allocated_banks;
155#ifdef CONFIG_ACPI
156 acpi_handle acpi_dev_handle;
157 char ppi_version[TPM_PPI_VERSION_LEN + 1];
158#endif /* CONFIG_ACPI */
159
160 struct tpm_space work_space;
161 u32 last_cc;
162 u32 nr_commands;
163 u32 *cc_attrs_tbl;
164
165 /* active locality */
166 int locality;
167};
168
78#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE) 169#if defined(CONFIG_TCG_TPM) || defined(CONFIG_TCG_TPM_MODULE)
79 170
80extern int tpm_is_tpm2(struct tpm_chip *chip); 171extern int tpm_is_tpm2(struct tpm_chip *chip);