aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tpm
diff options
context:
space:
mode:
authorKylene Jo Hall <kjhall@us.ibm.com>2006-04-22 05:37:15 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-22 12:19:53 -0400
commit90dda520c1962d55a0e1d2571deed0d75fd6d6f1 (patch)
tree38d0da2fbeabb595f248f6029e470a1f2acd763a /drivers/char/tpm
parentbeed53a1aaeaae4eb93297c23f1598a726716adf (diff)
[PATCH] tpm: chip struct update
To assist with chip management and better support the possibility of having multiple TPMs in the system of the same kind, the struct tpm_vendor_specific member of the tpm_chip was changed from a pointer to an instance. This patch changes that declaration and fixes up all accesses to the structure member except in tpm_infineon which is coming in a patch from Marcel Selhorst. Signed-off-by: Kylene Hall <kjhall@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'drivers/char/tpm')
-rw-r--r--drivers/char/tpm/tpm.c48
-rw-r--r--drivers/char/tpm/tpm.h2
-rw-r--r--drivers/char/tpm/tpm_atmel.c26
-rw-r--r--drivers/char/tpm/tpm_nsc.c32
4 files changed, 53 insertions, 55 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 187bcdaf7bf6..50013eb8cf1e 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -78,7 +78,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
78 78
79 down(&chip->tpm_mutex); 79 down(&chip->tpm_mutex);
80 80
81 if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { 81 if ((rc = chip->vendor.send(chip, (u8 *) buf, count)) < 0) {
82 dev_err(chip->dev, 82 dev_err(chip->dev,
83 "tpm_transmit: tpm_send: error %zd\n", rc); 83 "tpm_transmit: tpm_send: error %zd\n", rc);
84 goto out; 84 goto out;
@@ -86,13 +86,12 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
86 86
87 stop = jiffies + 2 * 60 * HZ; 87 stop = jiffies + 2 * 60 * HZ;
88 do { 88 do {
89 u8 status = chip->vendor->status(chip); 89 u8 status = chip->vendor.status(chip);
90 if ((status & chip->vendor->req_complete_mask) == 90 if ((status & chip->vendor.req_complete_mask) ==
91 chip->vendor->req_complete_val) { 91 chip->vendor.req_complete_val)
92 goto out_recv; 92 goto out_recv;
93 }
94 93
95 if ((status == chip->vendor->req_canceled)) { 94 if ((status == chip->vendor.req_canceled)) {
96 dev_err(chip->dev, "Operation Canceled\n"); 95 dev_err(chip->dev, "Operation Canceled\n");
97 rc = -ECANCELED; 96 rc = -ECANCELED;
98 goto out; 97 goto out;
@@ -102,14 +101,13 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
102 rmb(); 101 rmb();
103 } while (time_before(jiffies, stop)); 102 } while (time_before(jiffies, stop));
104 103
105 104 chip->vendor.cancel(chip);
106 chip->vendor->cancel(chip);
107 dev_err(chip->dev, "Operation Timed out\n"); 105 dev_err(chip->dev, "Operation Timed out\n");
108 rc = -ETIME; 106 rc = -ETIME;
109 goto out; 107 goto out;
110 108
111out_recv: 109out_recv:
112 rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); 110 rc = chip->vendor.recv(chip, (u8 *) buf, bufsiz);
113 if (rc < 0) 111 if (rc < 0)
114 dev_err(chip->dev, 112 dev_err(chip->dev,
115 "tpm_transmit: tpm_recv: error %zd\n", rc); 113 "tpm_transmit: tpm_recv: error %zd\n", rc);
@@ -340,7 +338,7 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr,
340 if (chip == NULL) 338 if (chip == NULL)
341 return 0; 339 return 0;
342 340
343 chip->vendor->cancel(chip); 341 chip->vendor.cancel(chip);
344 return count; 342 return count;
345} 343}
346EXPORT_SYMBOL_GPL(tpm_store_cancel); 344EXPORT_SYMBOL_GPL(tpm_store_cancel);
@@ -356,7 +354,7 @@ int tpm_open(struct inode *inode, struct file *file)
356 spin_lock(&driver_lock); 354 spin_lock(&driver_lock);
357 355
358 list_for_each_entry(pos, &tpm_chip_list, list) { 356 list_for_each_entry(pos, &tpm_chip_list, list) {
359 if (pos->vendor->miscdev.minor == minor) { 357 if (pos->vendor.miscdev.minor == minor) {
360 chip = pos; 358 chip = pos;
361 break; 359 break;
362 } 360 }
@@ -488,14 +486,14 @@ void tpm_remove_hardware(struct device *dev)
488 spin_unlock(&driver_lock); 486 spin_unlock(&driver_lock);
489 487
490 dev_set_drvdata(dev, NULL); 488 dev_set_drvdata(dev, NULL);
491 misc_deregister(&chip->vendor->miscdev); 489 misc_deregister(&chip->vendor.miscdev);
492 kfree(chip->vendor->miscdev.name); 490 kfree(chip->vendor.miscdev.name);
493 491
494 sysfs_remove_group(&dev->kobj, chip->vendor->attr_group); 492 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
495 tpm_bios_log_teardown(chip->bios_dir); 493 tpm_bios_log_teardown(chip->bios_dir);
496 494
497 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= 495 dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES] &=
498 ~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); 496 ~(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES));
499 497
500 kfree(chip); 498 kfree(chip);
501 499
@@ -569,7 +567,7 @@ int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
569 chip->user_read_timer.function = user_reader_timeout; 567 chip->user_read_timer.function = user_reader_timeout;
570 chip->user_read_timer.data = (unsigned long) chip; 568 chip->user_read_timer.data = (unsigned long) chip;
571 569
572 chip->vendor = entry; 570 memcpy(&chip->vendor, entry, sizeof(struct tpm_vendor_specific));
573 571
574 chip->dev_num = -1; 572 chip->dev_num = -1;
575 573
@@ -588,22 +586,22 @@ dev_num_search_complete:
588 kfree(chip); 586 kfree(chip);
589 return -ENODEV; 587 return -ENODEV;
590 } else if (chip->dev_num == 0) 588 } else if (chip->dev_num == 0)
591 chip->vendor->miscdev.minor = TPM_MINOR; 589 chip->vendor.miscdev.minor = TPM_MINOR;
592 else 590 else
593 chip->vendor->miscdev.minor = MISC_DYNAMIC_MINOR; 591 chip->vendor.miscdev.minor = MISC_DYNAMIC_MINOR;
594 592
595 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); 593 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
596 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); 594 scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num);
597 chip->vendor->miscdev.name = devname; 595 chip->vendor.miscdev.name = devname;
598 596
599 chip->vendor->miscdev.dev = dev; 597 chip->vendor.miscdev.dev = dev;
600 chip->dev = get_device(dev); 598 chip->dev = get_device(dev);
601 599
602 if (misc_register(&chip->vendor->miscdev)) { 600 if (misc_register(&chip->vendor.miscdev)) {
603 dev_err(chip->dev, 601 dev_err(chip->dev,
604 "unable to misc_register %s, minor %d\n", 602 "unable to misc_register %s, minor %d\n",
605 chip->vendor->miscdev.name, 603 chip->vendor.miscdev.name,
606 chip->vendor->miscdev.minor); 604 chip->vendor.miscdev.minor);
607 put_device(dev); 605 put_device(dev);
608 kfree(chip); 606 kfree(chip);
609 dev_mask[i] &= !(1 << j); 607 dev_mask[i] &= !(1 << j);
@@ -618,7 +616,7 @@ dev_num_search_complete:
618 616
619 spin_unlock(&driver_lock); 617 spin_unlock(&driver_lock);
620 618
621 sysfs_create_group(&dev->kobj, chip->vendor->attr_group); 619 sysfs_create_group(&dev->kobj, chip->vendor.attr_group);
622 620
623 chip->bios_dir = tpm_bios_log_setup(devname); 621 chip->bios_dir = tpm_bios_log_setup(devname);
624 622
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index dec0224b4478..a203963efaab 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -81,7 +81,7 @@ struct tpm_chip {
81 struct work_struct work; 81 struct work_struct work;
82 struct semaphore tpm_mutex; /* tpm is processing */ 82 struct semaphore tpm_mutex; /* tpm is processing */
83 83
84 struct tpm_vendor_specific *vendor; 84 struct tpm_vendor_specific vendor;
85 85
86 struct dentry **bios_dir; 86 struct dentry **bios_dir;
87 87
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index ff3654964fe3..26787976ef1a 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -47,12 +47,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
47 return -EIO; 47 return -EIO;
48 48
49 for (i = 0; i < 6; i++) { 49 for (i = 0; i < 6; i++) {
50 status = ioread8(chip->vendor->iobase + 1); 50 status = ioread8(chip->vendor.iobase + 1);
51 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 51 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
52 dev_err(chip->dev, "error reading header\n"); 52 dev_err(chip->dev, "error reading header\n");
53 return -EIO; 53 return -EIO;
54 } 54 }
55 *buf++ = ioread8(chip->vendor->iobase); 55 *buf++ = ioread8(chip->vendor.iobase);
56 } 56 }
57 57
58 /* size of the data received */ 58 /* size of the data received */
@@ -63,7 +63,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
63 dev_err(chip->dev, 63 dev_err(chip->dev,
64 "Recv size(%d) less than available space\n", size); 64 "Recv size(%d) less than available space\n", size);
65 for (; i < size; i++) { /* clear the waiting data anyway */ 65 for (; i < size; i++) { /* clear the waiting data anyway */
66 status = ioread8(chip->vendor->iobase + 1); 66 status = ioread8(chip->vendor.iobase + 1);
67 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 67 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
68 dev_err(chip->dev, "error reading data\n"); 68 dev_err(chip->dev, "error reading data\n");
69 return -EIO; 69 return -EIO;
@@ -74,16 +74,16 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
74 74
75 /* read all the data available */ 75 /* read all the data available */
76 for (; i < size; i++) { 76 for (; i < size; i++) {
77 status = ioread8(chip->vendor->iobase + 1); 77 status = ioread8(chip->vendor.iobase + 1);
78 if ((status & ATML_STATUS_DATA_AVAIL) == 0) { 78 if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
79 dev_err(chip->dev, "error reading data\n"); 79 dev_err(chip->dev, "error reading data\n");
80 return -EIO; 80 return -EIO;
81 } 81 }
82 *buf++ = ioread8(chip->vendor->iobase); 82 *buf++ = ioread8(chip->vendor.iobase);
83 } 83 }
84 84
85 /* make sure data available is gone */ 85 /* make sure data available is gone */
86 status = ioread8(chip->vendor->iobase + 1); 86 status = ioread8(chip->vendor.iobase + 1);
87 87
88 if (status & ATML_STATUS_DATA_AVAIL) { 88 if (status & ATML_STATUS_DATA_AVAIL) {
89 dev_err(chip->dev, "data available is stuck\n"); 89 dev_err(chip->dev, "data available is stuck\n");
@@ -100,7 +100,7 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
100 dev_dbg(chip->dev, "tpm_atml_send:\n"); 100 dev_dbg(chip->dev, "tpm_atml_send:\n");
101 for (i = 0; i < count; i++) { 101 for (i = 0; i < count; i++) {
102 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]); 102 dev_dbg(chip->dev, "%d 0x%x(%d)\n", i, buf[i], buf[i]);
103 iowrite8(buf[i], chip->vendor->iobase); 103 iowrite8(buf[i], chip->vendor.iobase);
104 } 104 }
105 105
106 return count; 106 return count;
@@ -108,12 +108,12 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
108 108
109static void tpm_atml_cancel(struct tpm_chip *chip) 109static void tpm_atml_cancel(struct tpm_chip *chip)
110{ 110{
111 iowrite8(ATML_STATUS_ABORT, chip->vendor->iobase + 1); 111 iowrite8(ATML_STATUS_ABORT, chip->vendor.iobase + 1);
112} 112}
113 113
114static u8 tpm_atml_status(struct tpm_chip *chip) 114static u8 tpm_atml_status(struct tpm_chip *chip)
115{ 115{
116 return ioread8(chip->vendor->iobase + 1); 116 return ioread8(chip->vendor.iobase + 1);
117} 117}
118 118
119static struct file_operations atmel_ops = { 119static struct file_operations atmel_ops = {
@@ -159,10 +159,10 @@ static void atml_plat_remove(void)
159 struct tpm_chip *chip = dev_get_drvdata(&pdev->dev); 159 struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
160 160
161 if (chip) { 161 if (chip) {
162 if (chip->vendor->have_region) 162 if (chip->vendor.have_region)
163 atmel_release_region(chip->vendor->base, 163 atmel_release_region(chip->vendor.base,
164 chip->vendor->region_size); 164 chip->vendor.region_size);
165 atmel_put_base_addr(chip->vendor); 165 atmel_put_base_addr(chip->vendor.iobase);
166 tpm_remove_hardware(chip->dev); 166 tpm_remove_hardware(chip->dev);
167 platform_device_unregister(pdev); 167 platform_device_unregister(pdev);
168 } 168 }
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 680a8e331887..3dbbe9686c76 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -71,7 +71,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
71 unsigned long stop; 71 unsigned long stop;
72 72
73 /* status immediately available check */ 73 /* status immediately available check */
74 *data = inb(chip->vendor->base + NSC_STATUS); 74 *data = inb(chip->vendor.base + NSC_STATUS);
75 if ((*data & mask) == val) 75 if ((*data & mask) == val)
76 return 0; 76 return 0;
77 77
@@ -79,7 +79,7 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u8 val, u8 * data)
79 stop = jiffies + 10 * HZ; 79 stop = jiffies + 10 * HZ;
80 do { 80 do {
81 msleep(TPM_TIMEOUT); 81 msleep(TPM_TIMEOUT);
82 *data = inb(chip->vendor->base + 1); 82 *data = inb(chip->vendor.base + 1);
83 if ((*data & mask) == val) 83 if ((*data & mask) == val)
84 return 0; 84 return 0;
85 } 85 }
@@ -94,9 +94,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
94 unsigned long stop; 94 unsigned long stop;
95 95
96 /* status immediately available check */ 96 /* status immediately available check */
97 status = inb(chip->vendor->base + NSC_STATUS); 97 status = inb(chip->vendor.base + NSC_STATUS);
98 if (status & NSC_STATUS_OBF) 98 if (status & NSC_STATUS_OBF)
99 status = inb(chip->vendor->base + NSC_DATA); 99 status = inb(chip->vendor.base + NSC_DATA);
100 if (status & NSC_STATUS_RDY) 100 if (status & NSC_STATUS_RDY)
101 return 0; 101 return 0;
102 102
@@ -104,9 +104,9 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
104 stop = jiffies + 100; 104 stop = jiffies + 100;
105 do { 105 do {
106 msleep(TPM_TIMEOUT); 106 msleep(TPM_TIMEOUT);
107 status = inb(chip->vendor->base + NSC_STATUS); 107 status = inb(chip->vendor.base + NSC_STATUS);
108 if (status & NSC_STATUS_OBF) 108 if (status & NSC_STATUS_OBF)
109 status = inb(chip->vendor->base + NSC_DATA); 109 status = inb(chip->vendor.base + NSC_DATA);
110 if (status & NSC_STATUS_RDY) 110 if (status & NSC_STATUS_RDY)
111 return 0; 111 return 0;
112 } 112 }
@@ -132,7 +132,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
132 return -EIO; 132 return -EIO;
133 } 133 }
134 if ((data = 134 if ((data =
135 inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_NORMAL) { 135 inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
136 dev_err(chip->dev, "not in normal mode (0x%x)\n", 136 dev_err(chip->dev, "not in normal mode (0x%x)\n",
137 data); 137 data);
138 return -EIO; 138 return -EIO;
@@ -148,7 +148,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
148 } 148 }
149 if (data & NSC_STATUS_F0) 149 if (data & NSC_STATUS_F0)
150 break; 150 break;
151 *p = inb(chip->vendor->base + NSC_DATA); 151 *p = inb(chip->vendor.base + NSC_DATA);
152 } 152 }
153 153
154 if ((data & NSC_STATUS_F0) == 0 && 154 if ((data & NSC_STATUS_F0) == 0 &&
@@ -156,7 +156,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
156 dev_err(chip->dev, "F0 not set\n"); 156 dev_err(chip->dev, "F0 not set\n");
157 return -EIO; 157 return -EIO;
158 } 158 }
159 if ((data = inb(chip->vendor->base + NSC_DATA)) != NSC_COMMAND_EOC) { 159 if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
160 dev_err(chip->dev, 160 dev_err(chip->dev,
161 "expected end of command(0x%x)\n", data); 161 "expected end of command(0x%x)\n", data);
162 return -EIO; 162 return -EIO;
@@ -182,7 +182,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
182 * fix it. Not sure why this is needed, we followed the flow 182 * fix it. Not sure why this is needed, we followed the flow
183 * chart in the manual to the letter. 183 * chart in the manual to the letter.
184 */ 184 */
185 outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND); 185 outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
186 186
187 if (nsc_wait_for_ready(chip) != 0) 187 if (nsc_wait_for_ready(chip) != 0)
188 return -EIO; 188 return -EIO;
@@ -192,7 +192,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
192 return -EIO; 192 return -EIO;
193 } 193 }
194 194
195 outb(NSC_COMMAND_NORMAL, chip->vendor->base + NSC_COMMAND); 195 outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
196 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) { 196 if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
197 dev_err(chip->dev, "IBR timeout\n"); 197 dev_err(chip->dev, "IBR timeout\n");
198 return -EIO; 198 return -EIO;
@@ -204,26 +204,26 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
204 "IBF timeout (while writing data)\n"); 204 "IBF timeout (while writing data)\n");
205 return -EIO; 205 return -EIO;
206 } 206 }
207 outb(buf[i], chip->vendor->base + NSC_DATA); 207 outb(buf[i], chip->vendor.base + NSC_DATA);
208 } 208 }
209 209
210 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) { 210 if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
211 dev_err(chip->dev, "IBF timeout\n"); 211 dev_err(chip->dev, "IBF timeout\n");
212 return -EIO; 212 return -EIO;
213 } 213 }
214 outb(NSC_COMMAND_EOC, chip->vendor->base + NSC_COMMAND); 214 outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
215 215
216 return count; 216 return count;
217} 217}
218 218
219static void tpm_nsc_cancel(struct tpm_chip *chip) 219static void tpm_nsc_cancel(struct tpm_chip *chip)
220{ 220{
221 outb(NSC_COMMAND_CANCEL, chip->vendor->base + NSC_COMMAND); 221 outb(NSC_COMMAND_CANCEL, chip->vendor.base + NSC_COMMAND);
222} 222}
223 223
224static u8 tpm_nsc_status(struct tpm_chip *chip) 224static u8 tpm_nsc_status(struct tpm_chip *chip)
225{ 225{
226 return inb(chip->vendor->base + NSC_STATUS); 226 return inb(chip->vendor.base + NSC_STATUS);
227} 227}
228 228
229static struct file_operations nsc_ops = { 229static struct file_operations nsc_ops = {
@@ -268,7 +268,7 @@ static void __devexit tpm_nsc_remove(struct device *dev)
268{ 268{
269 struct tpm_chip *chip = dev_get_drvdata(dev); 269 struct tpm_chip *chip = dev_get_drvdata(dev);
270 if ( chip ) { 270 if ( chip ) {
271 release_region(chip->vendor->base, 2); 271 release_region(chip->vendor.base, 2);
272 tpm_remove_hardware(chip->dev); 272 tpm_remove_hardware(chip->dev);
273 } 273 }
274} 274}