aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tpm
diff options
context:
space:
mode:
authorJason Gunthorpe <jgunthorpe@obsidianresearch.com>2013-11-26 15:30:40 -0500
committerPeter Huewe <peterhuewe@gmx.de>2014-01-06 08:37:24 -0500
commitafdba32e2a9ea729a9f9f280dbf6c718773c7ded (patch)
treed77cca8a096e5320f3194d4a6ca1b4fef2dc9b99 /drivers/char/tpm
parentd65e55d4999b394e37ffe12543ecd2a17b7c44fc (diff)
tpm: Pull everything related to /dev/tpmX into tpm-dev.c
CLASS-dev.c is a common idiom for Linux subsystems This pulls all the code related to the miscdev into tpm-dev.c and makes it static. The identical file_operation structs in the drivers are purged and the tpm common code unconditionally creates the miscdev. Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com> Reviewed-by: Joel Schopp <jschopp@linux.vnet.ibm.com> Reviewed-by: Ashley Lai <adlai@linux.vnet.ibm.com> [phuewe: tpm_dev_release is now used only in this file, thus the EXPORT_SYMBOL can be dropped and the function be marked as static. It has no other in-kernel users] Signed-off-by: Peter Huewe <peterhuewe@gmx.de>
Diffstat (limited to 'drivers/char/tpm')
-rw-r--r--drivers/char/tpm/Makefile2
-rw-r--r--drivers/char/tpm/tpm-dev.c199
-rw-r--r--drivers/char/tpm/tpm-interface.c181
-rw-r--r--drivers/char/tpm/tpm.h11
-rw-r--r--drivers/char/tpm/tpm_atmel.c10
-rw-r--r--drivers/char/tpm/tpm_i2c_atmel.c10
-rw-r--r--drivers/char/tpm/tpm_i2c_infineon.c10
-rw-r--r--drivers/char/tpm/tpm_i2c_nuvoton.c10
-rw-r--r--drivers/char/tpm/tpm_i2c_stm_st33.c10
-rw-r--r--drivers/char/tpm/tpm_ibmvtpm.c10
-rw-r--r--drivers/char/tpm/tpm_infineon.c10
-rw-r--r--drivers/char/tpm/tpm_nsc.c10
-rw-r--r--drivers/char/tpm/tpm_tis.c11
-rw-r--r--drivers/char/tpm/xen-tpmfront.c12
14 files changed, 217 insertions, 279 deletions
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index b80a4000daee..d835e87d2d38 100644
--- a/drivers/char/tpm/Makefile
+++ b/drivers/char/tpm/Makefile
@@ -2,7 +2,7 @@
2# Makefile for the kernel tpm device drivers. 2# Makefile for the kernel tpm device drivers.
3# 3#
4obj-$(CONFIG_TCG_TPM) += tpm.o 4obj-$(CONFIG_TCG_TPM) += tpm.o
5tpm-y := tpm-interface.o 5tpm-y := tpm-interface.o tpm-dev.o
6tpm-$(CONFIG_ACPI) += tpm_ppi.o 6tpm-$(CONFIG_ACPI) += tpm_ppi.o
7 7
8ifdef CONFIG_ACPI 8ifdef CONFIG_ACPI
diff --git a/drivers/char/tpm/tpm-dev.c b/drivers/char/tpm/tpm-dev.c
new file mode 100644
index 000000000000..4f0cf2b6fc67
--- /dev/null
+++ b/drivers/char/tpm/tpm-dev.c
@@ -0,0 +1,199 @@
1/*
2 * Copyright (C) 2004 IBM Corporation
3 * Authors:
4 * Leendert van Doorn <leendert@watson.ibm.com>
5 * Dave Safford <safford@watson.ibm.com>
6 * Reiner Sailer <sailer@watson.ibm.com>
7 * Kylene Hall <kjhall@us.ibm.com>
8 *
9 * Copyright (C) 2013 Obsidian Research Corp
10 * Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
11 *
12 * Device file system interface to the TPM
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation, version 2 of the
17 * License.
18 *
19 */
20#include <linux/miscdevice.h>
21#include <linux/slab.h>
22#include <linux/uaccess.h>
23#include "tpm.h"
24
25static void user_reader_timeout(unsigned long ptr)
26{
27 struct tpm_chip *chip = (struct tpm_chip *) ptr;
28
29 schedule_work(&chip->work);
30}
31
32static void timeout_work(struct work_struct *work)
33{
34 struct tpm_chip *chip = container_of(work, struct tpm_chip, work);
35
36 mutex_lock(&chip->buffer_mutex);
37 atomic_set(&chip->data_pending, 0);
38 memset(chip->data_buffer, 0, TPM_BUFSIZE);
39 mutex_unlock(&chip->buffer_mutex);
40}
41
42static int tpm_open(struct inode *inode, struct file *file)
43{
44 struct miscdevice *misc = file->private_data;
45 struct tpm_chip *chip = container_of(misc, struct tpm_chip,
46 vendor.miscdev);
47
48 /* It's assured that the chip will be opened just once,
49 * by the check of is_open variable, which is protected
50 * by driver_lock. */
51 if (test_and_set_bit(0, &chip->is_open)) {
52 dev_dbg(chip->dev, "Another process owns this TPM\n");
53 return -EBUSY;
54 }
55
56 chip->data_buffer = kzalloc(TPM_BUFSIZE, GFP_KERNEL);
57 if (chip->data_buffer == NULL) {
58 clear_bit(0, &chip->is_open);
59 return -ENOMEM;
60 }
61
62 atomic_set(&chip->data_pending, 0);
63
64 file->private_data = chip;
65 get_device(chip->dev);
66 return 0;
67}
68
69static ssize_t tpm_read(struct file *file, char __user *buf,
70 size_t size, loff_t *off)
71{
72 struct tpm_chip *chip = file->private_data;
73 ssize_t ret_size;
74 int rc;
75
76 del_singleshot_timer_sync(&chip->user_read_timer);
77 flush_work(&chip->work);
78 ret_size = atomic_read(&chip->data_pending);
79 if (ret_size > 0) { /* relay data */
80 ssize_t orig_ret_size = ret_size;
81 if (size < ret_size)
82 ret_size = size;
83
84 mutex_lock(&chip->buffer_mutex);
85 rc = copy_to_user(buf, chip->data_buffer, ret_size);
86 memset(chip->data_buffer, 0, orig_ret_size);
87 if (rc)
88 ret_size = -EFAULT;
89
90 mutex_unlock(&chip->buffer_mutex);
91 }
92
93 atomic_set(&chip->data_pending, 0);
94
95 return ret_size;
96}
97
98static ssize_t tpm_write(struct file *file, const char __user *buf,
99 size_t size, loff_t *off)
100{
101 struct tpm_chip *chip = file->private_data;
102 size_t in_size = size;
103 ssize_t out_size;
104
105 /* cannot perform a write until the read has cleared
106 either via tpm_read or a user_read_timer timeout.
107 This also prevents splitted buffered writes from blocking here.
108 */
109 if (atomic_read(&chip->data_pending) != 0)
110 return -EBUSY;
111
112 if (in_size > TPM_BUFSIZE)
113 return -E2BIG;
114
115 mutex_lock(&chip->buffer_mutex);
116
117 if (copy_from_user
118 (chip->data_buffer, (void __user *) buf, in_size)) {
119 mutex_unlock(&chip->buffer_mutex);
120 return -EFAULT;
121 }
122
123 /* atomic tpm command send and result receive */
124 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
125 if (out_size < 0) {
126 mutex_unlock(&chip->buffer_mutex);
127 return out_size;
128 }
129
130 atomic_set(&chip->data_pending, out_size);
131 mutex_unlock(&chip->buffer_mutex);
132
133 /* Set a timeout by which the reader must come claim the result */
134 mod_timer(&chip->user_read_timer, jiffies + (60 * HZ));
135
136 return in_size;
137}
138
139/*
140 * Called on file close
141 */
142static int tpm_release(struct inode *inode, struct file *file)
143{
144 struct tpm_chip *chip = file->private_data;
145
146 del_singleshot_timer_sync(&chip->user_read_timer);
147 flush_work(&chip->work);
148 file->private_data = NULL;
149 atomic_set(&chip->data_pending, 0);
150 kzfree(chip->data_buffer);
151 clear_bit(0, &chip->is_open);
152 put_device(chip->dev);
153 return 0;
154}
155
156static const struct file_operations tpm_fops = {
157 .owner = THIS_MODULE,
158 .llseek = no_llseek,
159 .open = tpm_open,
160 .read = tpm_read,
161 .write = tpm_write,
162 .release = tpm_release,
163};
164
165int tpm_dev_add_device(struct tpm_chip *chip)
166{
167 int rc;
168
169 mutex_init(&chip->buffer_mutex);
170 INIT_WORK(&chip->work, timeout_work);
171
172 setup_timer(&chip->user_read_timer, user_reader_timeout,
173 (unsigned long)chip);
174
175 chip->vendor.miscdev.fops = &tpm_fops;
176 if (chip->dev_num == 0)
177 chip->vendor.miscdev.minor = TPM_MINOR;
178 else
179 chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
180
181 chip->vendor.miscdev.name = chip->devname;
182 chip->vendor.miscdev.parent = chip->dev;
183
184 rc = misc_register(&chip->vendor.miscdev);
185 if (rc) {
186 chip->vendor.miscdev.name = NULL;
187 dev_err(chip->dev,
188 "unable to misc_register %s, minor %d err=%d\n",
189 chip->vendor.miscdev.name,
190 chip->vendor.miscdev.minor, rc);
191 }
192 return rc;
193}
194
195void tpm_dev_del_device(struct tpm_chip *chip)
196{
197 if (chip->vendor.miscdev.name)
198 misc_deregister(&chip->vendor.miscdev);
199}
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c
index 6ae41d337630..0b9e9ca05ef3 100644
--- a/drivers/char/tpm/tpm-interface.c
+++ b/drivers/char/tpm/tpm-interface.c
@@ -312,23 +312,6 @@ static const u8 tpm_ordinal_duration[TPM_MAX_ORDINAL] = {
312 TPM_MEDIUM, 312 TPM_MEDIUM,
313}; 313};
314 314
315static void user_reader_timeout(unsigned long ptr)
316{
317 struct tpm_chip *chip = (struct tpm_chip *) ptr;
318
319 schedule_work(&chip->work);
320}
321
322static void timeout_work(struct work_struct *work)
323{
324 struct tpm_chip *chip = container_of(work, struct tpm_chip, work);
325
326 mutex_lock(&chip->buffer_mutex);
327 atomic_set(&chip->data_pending, 0);
328 memset(chip->data_buffer, 0, TPM_BUFSIZE);
329 mutex_unlock(&chip->buffer_mutex);
330}
331
332/* 315/*
333 * Returns max number of jiffies to wait 316 * Returns max number of jiffies to wait
334 */ 317 */
@@ -355,8 +338,8 @@ EXPORT_SYMBOL_GPL(tpm_calc_ordinal_duration);
355/* 338/*
356 * Internal kernel interface to transmit TPM commands 339 * Internal kernel interface to transmit TPM commands
357 */ 340 */
358static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, 341ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
359 size_t bufsiz) 342 size_t bufsiz)
360{ 343{
361 ssize_t rc; 344 ssize_t rc;
362 u32 count, ordinal; 345 u32 count, ordinal;
@@ -1151,127 +1134,6 @@ again:
1151 return -ETIME; 1134 return -ETIME;
1152} 1135}
1153EXPORT_SYMBOL_GPL(wait_for_tpm_stat); 1136EXPORT_SYMBOL_GPL(wait_for_tpm_stat);
1154/*
1155 * Device file system interface to the TPM
1156 *
1157 * It's assured that the chip will be opened just once,
1158 * by the check of is_open variable, which is protected
1159 * by driver_lock.
1160 */
1161int tpm_open(struct inode *inode, struct file *file)
1162{
1163 struct miscdevice *misc = file->private_data;
1164 struct tpm_chip *chip = container_of(misc, struct tpm_chip,
1165 vendor.miscdev);
1166
1167 if (test_and_set_bit(0, &chip->is_open)) {
1168 dev_dbg(chip->dev, "Another process owns this TPM\n");
1169 return -EBUSY;
1170 }
1171
1172 chip->data_buffer = kzalloc(TPM_BUFSIZE, GFP_KERNEL);
1173 if (chip->data_buffer == NULL) {
1174 clear_bit(0, &chip->is_open);
1175 return -ENOMEM;
1176 }
1177
1178 atomic_set(&chip->data_pending, 0);
1179
1180 file->private_data = chip;
1181 get_device(chip->dev);
1182 return 0;
1183}
1184EXPORT_SYMBOL_GPL(tpm_open);
1185
1186/*
1187 * Called on file close
1188 */
1189int tpm_release(struct inode *inode, struct file *file)
1190{
1191 struct tpm_chip *chip = file->private_data;
1192
1193 del_singleshot_timer_sync(&chip->user_read_timer);
1194 flush_work(&chip->work);
1195 file->private_data = NULL;
1196 atomic_set(&chip->data_pending, 0);
1197 kzfree(chip->data_buffer);
1198 clear_bit(0, &chip->is_open);
1199 put_device(chip->dev);
1200 return 0;
1201}
1202EXPORT_SYMBOL_GPL(tpm_release);
1203
1204ssize_t tpm_write(struct file *file, const char __user *buf,
1205 size_t size, loff_t *off)
1206{
1207 struct tpm_chip *chip = file->private_data;
1208 size_t in_size = size;
1209 ssize_t out_size;
1210
1211 /* cannot perform a write until the read has cleared
1212 either via tpm_read or a user_read_timer timeout.
1213 This also prevents splitted buffered writes from blocking here.
1214 */
1215 if (atomic_read(&chip->data_pending) != 0)
1216 return -EBUSY;
1217
1218 if (in_size > TPM_BUFSIZE)
1219 return -E2BIG;
1220
1221 mutex_lock(&chip->buffer_mutex);
1222
1223 if (copy_from_user
1224 (chip->data_buffer, (void __user *) buf, in_size)) {
1225 mutex_unlock(&chip->buffer_mutex);
1226 return -EFAULT;
1227 }
1228
1229 /* atomic tpm command send and result receive */
1230 out_size = tpm_transmit(chip, chip->data_buffer, TPM_BUFSIZE);
1231 if (out_size < 0) {
1232 mutex_unlock(&chip->buffer_mutex);
1233 return out_size;
1234 }
1235
1236 atomic_set(&chip->data_pending, out_size);
1237 mutex_unlock(&chip->buffer_mutex);
1238
1239 /* Set a timeout by which the reader must come claim the result */
1240 mod_timer(&chip->user_read_timer, jiffies + (60 * HZ));
1241
1242 return in_size;
1243}
1244EXPORT_SYMBOL_GPL(tpm_write);
1245
1246ssize_t tpm_read(struct file *file, char __user *buf,
1247 size_t size, loff_t *off)
1248{
1249 struct tpm_chip *chip = file->private_data;
1250 ssize_t ret_size;
1251 int rc;
1252
1253 del_singleshot_timer_sync(&chip->user_read_timer);
1254 flush_work(&chip->work);
1255 ret_size = atomic_read(&chip->data_pending);
1256 if (ret_size > 0) { /* relay data */
1257 ssize_t orig_ret_size = ret_size;
1258 if (size < ret_size)
1259 ret_size = size;
1260
1261 mutex_lock(&chip->buffer_mutex);
1262 rc = copy_to_user(buf, chip->data_buffer, ret_size);
1263 memset(chip->data_buffer, 0, orig_ret_size);
1264 if (rc)
1265 ret_size = -EFAULT;
1266
1267 mutex_unlock(&chip->buffer_mutex);
1268 }
1269
1270 atomic_set(&chip->data_pending, 0);
1271
1272 return ret_size;
1273}
1274EXPORT_SYMBOL_GPL(tpm_read);
1275 1137
1276void tpm_remove_hardware(struct device *dev) 1138void tpm_remove_hardware(struct device *dev)
1277{ 1139{
@@ -1287,7 +1149,7 @@ void tpm_remove_hardware(struct device *dev)
1287 spin_unlock(&driver_lock); 1149 spin_unlock(&driver_lock);
1288 synchronize_rcu(); 1150 synchronize_rcu();
1289 1151
1290 misc_deregister(&chip->vendor.miscdev); 1152 tpm_dev_del_device(chip);
1291 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group); 1153 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
1292 tpm_remove_ppi(&dev->kobj); 1154 tpm_remove_ppi(&dev->kobj);
1293 tpm_bios_log_teardown(chip->bios_dir); 1155 tpm_bios_log_teardown(chip->bios_dir);
@@ -1448,7 +1310,7 @@ EXPORT_SYMBOL_GPL(tpm_dev_vendor_release);
1448 * Once all references to platform device are down to 0, 1310 * Once all references to platform device are down to 0,
1449 * release all allocated structures. 1311 * release all allocated structures.
1450 */ 1312 */
1451void tpm_dev_release(struct device *dev) 1313static void tpm_dev_release(struct device *dev)
1452{ 1314{
1453 struct tpm_chip *chip = dev_get_drvdata(dev); 1315 struct tpm_chip *chip = dev_get_drvdata(dev);
1454 1316
@@ -1460,7 +1322,6 @@ void tpm_dev_release(struct device *dev)
1460 chip->release(dev); 1322 chip->release(dev);
1461 kfree(chip); 1323 kfree(chip);
1462} 1324}
1463EXPORT_SYMBOL_GPL(tpm_dev_release);
1464 1325
1465/* 1326/*
1466 * Called from tpm_<specific>.c probe function only for devices 1327 * Called from tpm_<specific>.c probe function only for devices
@@ -1480,15 +1341,9 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
1480 if (chip == NULL) 1341 if (chip == NULL)
1481 return NULL; 1342 return NULL;
1482 1343
1483 mutex_init(&chip->buffer_mutex);
1484 mutex_init(&chip->tpm_mutex); 1344 mutex_init(&chip->tpm_mutex);
1485 INIT_LIST_HEAD(&chip->list); 1345 INIT_LIST_HEAD(&chip->list);
1486 1346
1487 INIT_WORK(&chip->work, timeout_work);
1488
1489 setup_timer(&chip->user_read_timer, user_reader_timeout,
1490 (unsigned long)chip);
1491
1492 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific)); 1347 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
1493 1348
1494 chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES); 1349 chip->dev_num = find_first_zero_bit(dev_mask, TPM_NUM_DEVICES);
@@ -1496,40 +1351,26 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
1496 if (chip->dev_num >= TPM_NUM_DEVICES) { 1351 if (chip->dev_num >= TPM_NUM_DEVICES) {
1497 dev_err(dev, "No available tpm device numbers\n"); 1352 dev_err(dev, "No available tpm device numbers\n");
1498 goto out_free; 1353 goto out_free;
1499 } else if (chip->dev_num == 0) 1354 }
1500 chip->vendor.miscdev.minor = TPM_MINOR;
1501 else
1502 chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
1503 1355
1504 set_bit(chip->dev_num, dev_mask); 1356 set_bit(chip->dev_num, dev_mask);
1505 1357
1506 scnprintf(chip->devname, sizeof(chip->devname), "%s%d", "tpm", 1358 scnprintf(chip->devname, sizeof(chip->devname), "%s%d", "tpm",
1507 chip->dev_num); 1359 chip->dev_num);
1508 chip->vendor.miscdev.name = chip->devname;
1509 1360
1510 chip->vendor.miscdev.parent = dev;
1511 chip->dev = get_device(dev); 1361 chip->dev = get_device(dev);
1512 chip->release = dev->release; 1362 chip->release = dev->release;
1513 dev->release = tpm_dev_release; 1363 dev->release = tpm_dev_release;
1514 dev_set_drvdata(dev, chip); 1364 dev_set_drvdata(dev, chip);
1515 1365
1516 if (misc_register(&chip->vendor.miscdev)) { 1366 if (tpm_dev_add_device(chip))
1517 dev_err(chip->dev,
1518 "unable to misc_register %s, minor %d\n",
1519 chip->vendor.miscdev.name,
1520 chip->vendor.miscdev.minor);
1521 goto put_device; 1367 goto put_device;
1522 }
1523 1368
1524 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { 1369 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group))
1525 misc_deregister(&chip->vendor.miscdev); 1370 goto del_misc;
1526 goto put_device;
1527 }
1528 1371
1529 if (tpm_add_ppi(&dev->kobj)) { 1372 if (tpm_add_ppi(&dev->kobj))
1530 misc_deregister(&chip->vendor.miscdev); 1373 goto del_misc;
1531 goto put_device;
1532 }
1533 1374
1534 chip->bios_dir = tpm_bios_log_setup(chip->devname); 1375 chip->bios_dir = tpm_bios_log_setup(chip->devname);
1535 1376
@@ -1540,6 +1381,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev,
1540 1381
1541 return chip; 1382 return chip;
1542 1383
1384del_misc:
1385 tpm_dev_del_device(chip);
1543put_device: 1386put_device:
1544 put_device(chip->dev); 1387 put_device(chip->dev);
1545out_free: 1388out_free:
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index f32847872193..496228cf1d81 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -323,25 +323,24 @@ struct tpm_cmd_t {
323 323
324ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *); 324ssize_t tpm_getcap(struct device *, __be32, cap_t *, const char *);
325 325
326ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
327 size_t bufsiz);
326extern int tpm_get_timeouts(struct tpm_chip *); 328extern int tpm_get_timeouts(struct tpm_chip *);
327extern void tpm_gen_interrupt(struct tpm_chip *); 329extern void tpm_gen_interrupt(struct tpm_chip *);
328extern int tpm_do_selftest(struct tpm_chip *); 330extern int tpm_do_selftest(struct tpm_chip *);
329extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32); 331extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
330extern struct tpm_chip* tpm_register_hardware(struct device *, 332extern struct tpm_chip* tpm_register_hardware(struct device *,
331 const struct tpm_vendor_specific *); 333 const struct tpm_vendor_specific *);
332extern int tpm_open(struct inode *, struct file *);
333extern int tpm_release(struct inode *, struct file *);
334extern void tpm_dev_release(struct device *dev);
335extern void tpm_dev_vendor_release(struct tpm_chip *); 334extern void tpm_dev_vendor_release(struct tpm_chip *);
336extern ssize_t tpm_write(struct file *, const char __user *, size_t,
337 loff_t *);
338extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
339extern void tpm_remove_hardware(struct device *); 335extern void tpm_remove_hardware(struct device *);
340extern int tpm_pm_suspend(struct device *); 336extern int tpm_pm_suspend(struct device *);
341extern int tpm_pm_resume(struct device *); 337extern int tpm_pm_resume(struct device *);
342extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long, 338extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
343 wait_queue_head_t *, bool); 339 wait_queue_head_t *, bool);
344 340
341int tpm_dev_add_device(struct tpm_chip *chip);
342void tpm_dev_del_device(struct tpm_chip *chip);
343
345#ifdef CONFIG_ACPI 344#ifdef CONFIG_ACPI
346extern int tpm_add_ppi(struct kobject *); 345extern int tpm_add_ppi(struct kobject *);
347extern void tpm_remove_ppi(struct kobject *); 346extern void tpm_remove_ppi(struct kobject *);
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index c9a528d25d22..9692e2f252e0 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -121,15 +121,6 @@ static bool tpm_atml_req_canceled(struct tpm_chip *chip, u8 status)
121 return (status == ATML_STATUS_READY); 121 return (status == ATML_STATUS_READY);
122} 122}
123 123
124static const struct file_operations atmel_ops = {
125 .owner = THIS_MODULE,
126 .llseek = no_llseek,
127 .open = tpm_open,
128 .read = tpm_read,
129 .write = tpm_write,
130 .release = tpm_release,
131};
132
133static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 124static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
134static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 125static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
135static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL); 126static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
@@ -154,7 +145,6 @@ static const struct tpm_vendor_specific tpm_atmel = {
154 .req_complete_val = ATML_STATUS_DATA_AVAIL, 145 .req_complete_val = ATML_STATUS_DATA_AVAIL,
155 .req_canceled = tpm_atml_req_canceled, 146 .req_canceled = tpm_atml_req_canceled,
156 .attr_group = &atmel_attr_grp, 147 .attr_group = &atmel_attr_grp,
157 .miscdev = { .fops = &atmel_ops, },
158}; 148};
159 149
160static struct platform_device *pdev; 150static struct platform_device *pdev;
diff --git a/drivers/char/tpm/tpm_i2c_atmel.c b/drivers/char/tpm/tpm_i2c_atmel.c
index af6805b06f57..079c19d31187 100644
--- a/drivers/char/tpm/tpm_i2c_atmel.c
+++ b/drivers/char/tpm/tpm_i2c_atmel.c
@@ -135,15 +135,6 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
135 return ATMEL_STS_OK; 135 return ATMEL_STS_OK;
136} 136}
137 137
138static const struct file_operations i2c_atmel_ops = {
139 .owner = THIS_MODULE,
140 .llseek = no_llseek,
141 .open = tpm_open,
142 .read = tpm_read,
143 .write = tpm_write,
144 .release = tpm_release,
145};
146
147static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 138static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
148static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 139static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
149static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 140static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -187,7 +178,6 @@ static const struct tpm_vendor_specific i2c_atmel = {
187 .req_complete_val = ATMEL_STS_OK, 178 .req_complete_val = ATMEL_STS_OK,
188 .req_canceled = i2c_atmel_req_canceled, 179 .req_canceled = i2c_atmel_req_canceled,
189 .attr_group = &i2c_atmel_attr_grp, 180 .attr_group = &i2c_atmel_attr_grp,
190 .miscdev.fops = &i2c_atmel_ops,
191}; 181};
192 182
193static int i2c_atmel_probe(struct i2c_client *client, 183static int i2c_atmel_probe(struct i2c_client *client,
diff --git a/drivers/char/tpm/tpm_i2c_infineon.c b/drivers/char/tpm/tpm_i2c_infineon.c
index fefd2aa5c81e..c1ba7fa6830c 100644
--- a/drivers/char/tpm/tpm_i2c_infineon.c
+++ b/drivers/char/tpm/tpm_i2c_infineon.c
@@ -566,15 +566,6 @@ static bool tpm_tis_i2c_req_canceled(struct tpm_chip *chip, u8 status)
566 return (status == TPM_STS_COMMAND_READY); 566 return (status == TPM_STS_COMMAND_READY);
567} 567}
568 568
569static const struct file_operations tis_ops = {
570 .owner = THIS_MODULE,
571 .llseek = no_llseek,
572 .open = tpm_open,
573 .read = tpm_read,
574 .write = tpm_write,
575 .release = tpm_release,
576};
577
578static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 569static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
579static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 570static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
580static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 571static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -613,7 +604,6 @@ static struct tpm_vendor_specific tpm_tis_i2c = {
613 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 604 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
614 .req_canceled = tpm_tis_i2c_req_canceled, 605 .req_canceled = tpm_tis_i2c_req_canceled,
615 .attr_group = &tis_attr_grp, 606 .attr_group = &tis_attr_grp,
616 .miscdev.fops = &tis_ops,
617}; 607};
618 608
619static int tpm_tis_i2c_init(struct device *dev) 609static int tpm_tis_i2c_init(struct device *dev)
diff --git a/drivers/char/tpm/tpm_i2c_nuvoton.c b/drivers/char/tpm/tpm_i2c_nuvoton.c
index 4f5ac251ae1e..c9bb60e45cb0 100644
--- a/drivers/char/tpm/tpm_i2c_nuvoton.c
+++ b/drivers/char/tpm/tpm_i2c_nuvoton.c
@@ -455,15 +455,6 @@ static bool i2c_nuvoton_req_canceled(struct tpm_chip *chip, u8 status)
455 return (status == TPM_STS_COMMAND_READY); 455 return (status == TPM_STS_COMMAND_READY);
456} 456}
457 457
458static const struct file_operations i2c_nuvoton_ops = {
459 .owner = THIS_MODULE,
460 .llseek = no_llseek,
461 .open = tpm_open,
462 .read = tpm_read,
463 .write = tpm_write,
464 .release = tpm_release,
465};
466
467static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 458static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
468static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 459static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
469static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 460static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -502,7 +493,6 @@ static const struct tpm_vendor_specific tpm_i2c = {
502 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 493 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
503 .req_canceled = i2c_nuvoton_req_canceled, 494 .req_canceled = i2c_nuvoton_req_canceled,
504 .attr_group = &i2c_nuvoton_attr_grp, 495 .attr_group = &i2c_nuvoton_attr_grp,
505 .miscdev.fops = &i2c_nuvoton_ops,
506}; 496};
507 497
508/* The only purpose for the handler is to signal to any waiting threads that 498/* The only purpose for the handler is to signal to any waiting threads that
diff --git a/drivers/char/tpm/tpm_i2c_stm_st33.c b/drivers/char/tpm/tpm_i2c_stm_st33.c
index cf6840385483..e519e6815780 100644
--- a/drivers/char/tpm/tpm_i2c_stm_st33.c
+++ b/drivers/char/tpm/tpm_i2c_stm_st33.c
@@ -574,15 +574,6 @@ static bool tpm_st33_i2c_req_canceled(struct tpm_chip *chip, u8 status)
574 return (status == TPM_STS_COMMAND_READY); 574 return (status == TPM_STS_COMMAND_READY);
575} 575}
576 576
577static const struct file_operations tpm_st33_i2c_fops = {
578 .owner = THIS_MODULE,
579 .llseek = no_llseek,
580 .read = tpm_read,
581 .write = tpm_write,
582 .open = tpm_open,
583 .release = tpm_release,
584};
585
586static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 577static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
587static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 578static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
588static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 579static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -616,7 +607,6 @@ static struct tpm_vendor_specific st_i2c_tpm = {
616 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 607 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
617 .req_canceled = tpm_st33_i2c_req_canceled, 608 .req_canceled = tpm_st33_i2c_req_canceled,
618 .attr_group = &stm_tpm_attr_grp, 609 .attr_group = &stm_tpm_attr_grp,
619 .miscdev = {.fops = &tpm_st33_i2c_fops,},
620}; 610};
621 611
622static int interrupts; 612static int interrupts;
diff --git a/drivers/char/tpm/tpm_ibmvtpm.c b/drivers/char/tpm/tpm_ibmvtpm.c
index cab8d098095c..2ee43093066f 100644
--- a/drivers/char/tpm/tpm_ibmvtpm.c
+++ b/drivers/char/tpm/tpm_ibmvtpm.c
@@ -403,15 +403,6 @@ static bool tpm_ibmvtpm_req_canceled(struct tpm_chip *chip, u8 status)
403 return (status == 0); 403 return (status == 0);
404} 404}
405 405
406static const struct file_operations ibmvtpm_ops = {
407 .owner = THIS_MODULE,
408 .llseek = no_llseek,
409 .open = tpm_open,
410 .read = tpm_read,
411 .write = tpm_write,
412 .release = tpm_release,
413};
414
415static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 406static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
416static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 407static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
417static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 408static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -448,7 +439,6 @@ static const struct tpm_vendor_specific tpm_ibmvtpm = {
448 .req_complete_val = 0, 439 .req_complete_val = 0,
449 .req_canceled = tpm_ibmvtpm_req_canceled, 440 .req_canceled = tpm_ibmvtpm_req_canceled,
450 .attr_group = &ibmvtpm_attr_grp, 441 .attr_group = &ibmvtpm_attr_grp,
451 .miscdev = { .fops = &ibmvtpm_ops, },
452}; 442};
453 443
454static const struct dev_pm_ops tpm_ibmvtpm_pm_ops = { 444static const struct dev_pm_ops tpm_ibmvtpm_pm_ops = {
diff --git a/drivers/char/tpm/tpm_infineon.c b/drivers/char/tpm/tpm_infineon.c
index 2b480c2960bb..c75c10ca2660 100644
--- a/drivers/char/tpm/tpm_infineon.c
+++ b/drivers/char/tpm/tpm_infineon.c
@@ -386,15 +386,6 @@ static struct attribute *inf_attrs[] = {
386 386
387static struct attribute_group inf_attr_grp = {.attrs = inf_attrs }; 387static struct attribute_group inf_attr_grp = {.attrs = inf_attrs };
388 388
389static const struct file_operations inf_ops = {
390 .owner = THIS_MODULE,
391 .llseek = no_llseek,
392 .open = tpm_open,
393 .read = tpm_read,
394 .write = tpm_write,
395 .release = tpm_release,
396};
397
398static const struct tpm_vendor_specific tpm_inf = { 389static const struct tpm_vendor_specific tpm_inf = {
399 .recv = tpm_inf_recv, 390 .recv = tpm_inf_recv,
400 .send = tpm_inf_send, 391 .send = tpm_inf_send,
@@ -403,7 +394,6 @@ static const struct tpm_vendor_specific tpm_inf = {
403 .req_complete_mask = 0, 394 .req_complete_mask = 0,
404 .req_complete_val = 0, 395 .req_complete_val = 0,
405 .attr_group = &inf_attr_grp, 396 .attr_group = &inf_attr_grp,
406 .miscdev = {.fops = &inf_ops,},
407}; 397};
408 398
409static const struct pnp_device_id tpm_inf_pnp_tbl[] = { 399static const struct pnp_device_id tpm_inf_pnp_tbl[] = {
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 770c46f8eb30..a4acac9008f7 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -232,15 +232,6 @@ static bool tpm_nsc_req_canceled(struct tpm_chip *chip, u8 status)
232 return (status == NSC_STATUS_RDY); 232 return (status == NSC_STATUS_RDY);
233} 233}
234 234
235static const struct file_operations nsc_ops = {
236 .owner = THIS_MODULE,
237 .llseek = no_llseek,
238 .open = tpm_open,
239 .read = tpm_read,
240 .write = tpm_write,
241 .release = tpm_release,
242};
243
244static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 235static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
245static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 236static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
246static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL); 237static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps, NULL);
@@ -265,7 +256,6 @@ static const struct tpm_vendor_specific tpm_nsc = {
265 .req_complete_val = NSC_STATUS_OBF, 256 .req_complete_val = NSC_STATUS_OBF,
266 .req_canceled = tpm_nsc_req_canceled, 257 .req_canceled = tpm_nsc_req_canceled,
267 .attr_group = &nsc_attr_grp, 258 .attr_group = &nsc_attr_grp,
268 .miscdev = { .fops = &nsc_ops, },
269}; 259};
270 260
271static struct platform_device *pdev = NULL; 261static struct platform_device *pdev = NULL;
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 1b74459c0723..46f57f5dda7d 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -432,15 +432,6 @@ static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)
432 } 432 }
433} 433}
434 434
435static const struct file_operations tis_ops = {
436 .owner = THIS_MODULE,
437 .llseek = no_llseek,
438 .open = tpm_open,
439 .read = tpm_read,
440 .write = tpm_write,
441 .release = tpm_release,
442};
443
444static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 435static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
445static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 436static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
446static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 437static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -479,8 +470,6 @@ static struct tpm_vendor_specific tpm_tis = {
479 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID, 470 .req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID,
480 .req_canceled = tpm_tis_req_canceled, 471 .req_canceled = tpm_tis_req_canceled,
481 .attr_group = &tis_attr_grp, 472 .attr_group = &tis_attr_grp,
482 .miscdev = {
483 .fops = &tis_ops,},
484}; 473};
485 474
486static irqreturn_t tis_int_probe(int irq, void *dev_id) 475static irqreturn_t tis_int_probe(int irq, void *dev_id)
diff --git a/drivers/char/tpm/xen-tpmfront.c b/drivers/char/tpm/xen-tpmfront.c
index c8ff4df81779..e3c7c0154515 100644
--- a/drivers/char/tpm/xen-tpmfront.c
+++ b/drivers/char/tpm/xen-tpmfront.c
@@ -143,15 +143,6 @@ static int vtpm_recv(struct tpm_chip *chip, u8 *buf, size_t count)
143 return length; 143 return length;
144} 144}
145 145
146static const struct file_operations vtpm_ops = {
147 .owner = THIS_MODULE,
148 .llseek = no_llseek,
149 .open = tpm_open,
150 .read = tpm_read,
151 .write = tpm_write,
152 .release = tpm_release,
153};
154
155static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL); 146static DEVICE_ATTR(pubek, S_IRUGO, tpm_show_pubek, NULL);
156static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL); 147static DEVICE_ATTR(pcrs, S_IRUGO, tpm_show_pcrs, NULL);
157static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL); 148static DEVICE_ATTR(enabled, S_IRUGO, tpm_show_enabled, NULL);
@@ -191,9 +182,6 @@ static const struct tpm_vendor_specific tpm_vtpm = {
191 .req_complete_val = VTPM_STATUS_IDLE | VTPM_STATUS_RESULT, 182 .req_complete_val = VTPM_STATUS_IDLE | VTPM_STATUS_RESULT,
192 .req_canceled = vtpm_req_canceled, 183 .req_canceled = vtpm_req_canceled,
193 .attr_group = &vtpm_attr_grp, 184 .attr_group = &vtpm_attr_grp,
194 .miscdev = {
195 .fops = &vtpm_ops,
196 },
197}; 185};
198 186
199static irqreturn_t tpmif_interrupt(int dummy, void *dev_id) 187static irqreturn_t tpmif_interrupt(int dummy, void *dev_id)