]> git.ipfire.org Git - people/arne_f/kernel.git/blame - drivers/char/tpm/tpm.h
tpm: rename chip->dev to chip->pdev
[people/arne_f/kernel.git] / drivers / char / tpm / tpm.h
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2004 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 *
8e81cc13 10 * Maintained by: <tpmdd-devel@lists.sourceforge.net>
1da177e4
LT
11 *
12 * Device driver for TCG/TCPA TPM (trusted platform module).
13 * Specifications at www.trustedcomputinggroup.org
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation, version 2 of the
18 * License.
19 *
20 */
21#include <linux/module.h>
1da177e4
LT
22#include <linux/delay.h>
23#include <linux/fs.h>
d081d470 24#include <linux/mutex.h>
914e2637 25#include <linux/sched.h>
1da177e4 26#include <linux/miscdevice.h>
bbc5b212 27#include <linux/platform_device.h>
276ad0c1 28#include <linux/io.h>
659aaf2b 29#include <linux/tpm.h>
0dc55365 30#include <linux/acpi.h>
1da177e4 31
41ab999c
KY
32enum tpm_const {
33 TPM_MINOR = 224, /* officially assigned */
34 TPM_BUFSIZE = 4096,
35 TPM_NUM_DEVICES = 256,
32d33b29 36 TPM_RETRY = 50, /* 5 seconds */
41ab999c
KY
37};
38
3122a88a
KH
39enum tpm_timeout {
40 TPM_TIMEOUT = 5, /* msecs */
32d33b29 41 TPM_TIMEOUT_RETRY = 100 /* msecs */
3122a88a 42};
1da177e4
LT
43
44/* TPM addresses */
3122a88a 45enum tpm_addr {
daacdfa6 46 TPM_SUPERIO_ADDR = 0x2E,
3122a88a 47 TPM_ADDR = 0x4E,
3122a88a
KH
48};
49
000a07b0
JG
50/* Indexes the duration array */
51enum tpm_duration {
52 TPM_SHORT = 0,
53 TPM_MEDIUM = 1,
54 TPM_LONG = 2,
55 TPM_UNDEFINED,
56};
57
32d33b29 58#define TPM_WARN_RETRY 0x800
68d6e671 59#define TPM_WARN_DOING_SELFTEST 0x802
be405411
SB
60#define TPM_ERR_DEACTIVATED 0x6
61#define TPM_ERR_DISABLED 0x7
c584af19 62#define TPM_ERR_INVALID_POSTINIT 38
be405411 63
b9e3238a 64#define TPM_HEADER_SIZE 10
1da177e4
LT
65struct tpm_chip;
66
67struct tpm_vendor_specific {
ad5ea3cc
KJH
68 void __iomem *iobase; /* ioremapped address */
69 unsigned long base; /* TPM base address */
70
27084efe 71 int irq;
a7b66822 72 int probed_irq;
27084efe 73
ad5ea3cc
KJH
74 int region_size;
75 int have_region;
1da177e4 76
1da177e4 77 struct miscdevice miscdev;
27084efe
LD
78 struct list_head list;
79 int locality;
36b20020 80 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
62592101 81 bool timeout_adjusted;
36b20020 82 unsigned long duration[3]; /* jiffies */
04ab2293 83 bool duration_adjusted;
775585e4 84 void *priv;
27084efe
LD
85
86 wait_queue_head_t read_queue;
87 wait_queue_head_t int_queue;
3e3a5e90
SB
88
89 u16 manufacturer_id;
1da177e4
LT
90};
91
775585e4
KY
92#define TPM_VPRIV(c) (c)->vendor.priv
93
4e401fb0 94#define TPM_VID_INTEL 0x8086
1f866057
SB
95#define TPM_VID_WINBOND 0x1050
96#define TPM_VID_STM 0x104A
4e401fb0 97
0dc55365
JS
98#define TPM_PPI_VERSION_LEN 3
99
afb5abc2
JS
100enum tpm_chip_flags {
101 TPM_CHIP_FLAG_REGISTERED = BIT(0),
0dc55365 102 TPM_CHIP_FLAG_PPI = BIT(1),
afb5abc2
JS
103};
104
1da177e4 105struct tpm_chip {
71ed848f 106 struct device *pdev; /* Device stuff */
5f82e9f0 107 const struct tpm_class_ops *ops;
afb5abc2 108 unsigned int flags;
1da177e4
LT
109
110 int dev_num; /* /dev/tpm# */
6aff1fdc 111 char devname[7];
dc36d32c 112 unsigned long is_open; /* only one allowed */
1da177e4
LT
113 int time_expired;
114
d081d470 115 struct mutex tpm_mutex; /* tpm is processing */
1da177e4 116
90dda520 117 struct tpm_vendor_specific vendor;
1da177e4 118
55a82ab3
KJH
119 struct dentry **bios_dir;
120
0dc55365
JS
121#ifdef CONFIG_ACPI
122 acpi_handle acpi_dev_handle;
123 char ppi_version[TPM_PPI_VERSION_LEN + 1];
124#endif /* CONFIG_ACPI */
125
1da177e4
LT
126 struct list_head list;
127};
128
27084efe
LD
129#define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
130
a0e39349
MZ
131static inline void tpm_chip_put(struct tpm_chip *chip)
132{
71ed848f 133 module_put(chip->pdev->driver->owner);
a0e39349
MZ
134}
135
daacdfa6 136static inline int tpm_read_index(int base, int index)
1da177e4 137{
daacdfa6
KJH
138 outb(index, base);
139 return inb(base+1) & 0xFF;
1da177e4
LT
140}
141
daacdfa6 142static inline void tpm_write_index(int base, int index, int value)
1da177e4 143{
daacdfa6
KJH
144 outb(index, base);
145 outb(value & 0xFF, base+1);
1da177e4 146}
08837438
RA
147struct tpm_input_header {
148 __be16 tag;
149 __be32 length;
150 __be32 ordinal;
348df8db 151} __packed;
08837438
RA
152
153struct tpm_output_header {
154 __be16 tag;
155 __be32 length;
156 __be32 return_code;
348df8db 157} __packed;
08837438 158
000a07b0
JG
159#define TPM_TAG_RQU_COMMAND cpu_to_be16(193)
160
08837438
RA
161struct stclear_flags_t {
162 __be16 tag;
163 u8 deactivated;
164 u8 disableForceClear;
165 u8 physicalPresence;
166 u8 physicalPresenceLock;
167 u8 bGlobalLock;
348df8db 168} __packed;
08837438
RA
169
170struct tpm_version_t {
171 u8 Major;
172 u8 Minor;
173 u8 revMajor;
174 u8 revMinor;
348df8db 175} __packed;
08837438
RA
176
177struct tpm_version_1_2_t {
178 __be16 tag;
179 u8 Major;
180 u8 Minor;
181 u8 revMajor;
182 u8 revMinor;
348df8db 183} __packed;
08837438
RA
184
185struct timeout_t {
186 __be32 a;
187 __be32 b;
188 __be32 c;
189 __be32 d;
348df8db 190} __packed;
08837438
RA
191
192struct duration_t {
193 __be32 tpm_short;
194 __be32 tpm_medium;
195 __be32 tpm_long;
348df8db 196} __packed;
08837438
RA
197
198struct permanent_flags_t {
199 __be16 tag;
200 u8 disable;
201 u8 ownership;
202 u8 deactivated;
203 u8 readPubek;
204 u8 disableOwnerClear;
205 u8 allowMaintenance;
206 u8 physicalPresenceLifetimeLock;
207 u8 physicalPresenceHWEnable;
208 u8 physicalPresenceCMDEnable;
209 u8 CEKPUsed;
210 u8 TPMpost;
211 u8 TPMpostLock;
212 u8 FIPS;
213 u8 operator;
214 u8 enableRevokeEK;
215 u8 nvLocked;
216 u8 readSRKPub;
217 u8 tpmEstablished;
218 u8 maintenanceDone;
219 u8 disableFullDALogicInfo;
348df8db 220} __packed;
08837438
RA
221
222typedef union {
223 struct permanent_flags_t perm_flags;
224 struct stclear_flags_t stclear_flags;
225 bool owned;
226 __be32 num_pcrs;
227 struct tpm_version_t tpm_version;
228 struct tpm_version_1_2_t tpm_version_1_2;
229 __be32 manufacturer_id;
230 struct timeout_t timeout;
231 struct duration_t duration;
232} cap_t;
233
000a07b0
JG
234enum tpm_capabilities {
235 TPM_CAP_FLAG = cpu_to_be32(4),
236 TPM_CAP_PROP = cpu_to_be32(5),
237 CAP_VERSION_1_1 = cpu_to_be32(0x06),
238 CAP_VERSION_1_2 = cpu_to_be32(0x1A)
239};
240
241enum tpm_sub_capabilities {
242 TPM_CAP_PROP_PCR = cpu_to_be32(0x101),
243 TPM_CAP_PROP_MANUFACTURER = cpu_to_be32(0x103),
244 TPM_CAP_FLAG_PERM = cpu_to_be32(0x108),
245 TPM_CAP_FLAG_VOL = cpu_to_be32(0x109),
246 TPM_CAP_PROP_OWNER = cpu_to_be32(0x111),
247 TPM_CAP_PROP_TIS_TIMEOUT = cpu_to_be32(0x115),
248 TPM_CAP_PROP_TIS_DURATION = cpu_to_be32(0x120),
249
250};
251
08837438
RA
252struct tpm_getcap_params_in {
253 __be32 cap;
254 __be32 subcap_size;
255 __be32 subcap;
348df8db 256} __packed;
08837438
RA
257
258struct tpm_getcap_params_out {
259 __be32 cap_size;
260 cap_t cap;
348df8db 261} __packed;
08837438
RA
262
263struct tpm_readpubek_params_out {
264 u8 algorithm[4];
265 u8 encscheme[2];
266 u8 sigscheme[2];
02a077c5 267 __be32 paramsize;
08837438
RA
268 u8 parameters[12]; /*assuming RSA*/
269 __be32 keysize;
270 u8 modulus[256];
271 u8 checksum[20];
348df8db 272} __packed;
08837438
RA
273
274typedef union {
275 struct tpm_input_header in;
276 struct tpm_output_header out;
277} tpm_cmd_header;
278
659aaf2b
RA
279struct tpm_pcrread_out {
280 u8 pcr_result[TPM_DIGEST_SIZE];
348df8db 281} __packed;
659aaf2b
RA
282
283struct tpm_pcrread_in {
284 __be32 pcr_idx;
348df8db 285} __packed;
659aaf2b
RA
286
287struct tpm_pcrextend_in {
288 __be32 pcr_idx;
289 u8 hash[TPM_DIGEST_SIZE];
348df8db 290} __packed;
659aaf2b 291
41ab999c
KY
292/* 128 bytes is an arbitrary cap. This could be as large as TPM_BUFSIZE - 18
293 * bytes, but 128 is still a relatively large number of random bytes and
294 * anything much bigger causes users of struct tpm_cmd_t to start getting
295 * compiler warnings about stack frame size. */
296#define TPM_MAX_RNG_DATA 128
297
298struct tpm_getrandom_out {
299 __be32 rng_data_len;
300 u8 rng_data[TPM_MAX_RNG_DATA];
348df8db 301} __packed;
41ab999c
KY
302
303struct tpm_getrandom_in {
304 __be32 num_bytes;
348df8db 305} __packed;
41ab999c 306
c584af19
JG
307struct tpm_startup_in {
308 __be16 startup_type;
309} __packed;
310
08837438
RA
311typedef union {
312 struct tpm_getcap_params_out getcap_out;
313 struct tpm_readpubek_params_out readpubek_out;
314 u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)];
315 struct tpm_getcap_params_in getcap_in;
659aaf2b
RA
316 struct tpm_pcrread_in pcrread_in;
317 struct tpm_pcrread_out pcrread_out;
318 struct tpm_pcrextend_in pcrextend_in;
41ab999c
KY
319 struct tpm_getrandom_in getrandom_in;
320 struct tpm_getrandom_out getrandom_out;
c584af19 321 struct tpm_startup_in startup_in;
08837438
RA
322} tpm_cmd_params;
323
324struct tpm_cmd_t {
325 tpm_cmd_header header;
326 tpm_cmd_params params;
348df8db 327} __packed;
08837438
RA
328
329ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *);
afdba32e
JG
330ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
331 size_t bufsiz);
87155b73
JS
332ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd, int len,
333 const char *desc);
2b30a90f 334extern int tpm_get_timeouts(struct tpm_chip *);
08e96e48 335extern void tpm_gen_interrupt(struct tpm_chip *);
68d6e671 336extern int tpm_do_selftest(struct tpm_chip *);
9e18ee19 337extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
035e2ce8 338extern int tpm_pm_suspend(struct device *);
ce2c87d4 339extern int tpm_pm_resume(struct device *);
fd048866 340extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
78f09cc2 341 wait_queue_head_t *, bool);
f84fdff0 342
afb5abc2
JS
343struct tpm_chip *tpm_chip_find_get(int chip_num);
344extern struct tpm_chip *tpmm_chip_alloc(struct device *dev,
345 const struct tpm_class_ops *ops);
346extern int tpm_chip_register(struct tpm_chip *chip);
347extern void tpm_chip_unregister(struct tpm_chip *chip);
348
afdba32e
JG
349int tpm_dev_add_device(struct tpm_chip *chip);
350void tpm_dev_del_device(struct tpm_chip *chip);
1e3b73a9
JG
351int tpm_sysfs_add_device(struct tpm_chip *chip);
352void tpm_sysfs_del_device(struct tpm_chip *chip);
afdba32e 353
000a07b0
JG
354int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
355
f84fdff0 356#ifdef CONFIG_ACPI
0dc55365
JS
357extern int tpm_add_ppi(struct tpm_chip *chip);
358extern void tpm_remove_ppi(struct tpm_chip *chip);
f84fdff0 359#else
0dc55365 360static inline int tpm_add_ppi(struct tpm_chip *chip)
f84fdff0
XZ
361{
362 return 0;
363}
1631cfb7 364
0dc55365 365static inline void tpm_remove_ppi(struct tpm_chip *chip)
1631cfb7
GW
366{
367}
f84fdff0 368#endif