aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tpm
diff options
context:
space:
mode:
authorKylene Jo Hall <kjhall@us.ibm.com>2006-04-22 05:37:26 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-22 12:19:53 -0400
commite0dd03caf20d040a0a86b6bd74028ec9bda545f5 (patch)
treefe65a043531f3b896f5dba08bbb8ae385332f7d1 /drivers/char/tpm
parent90dda520c1962d55a0e1d2571deed0d75fd6d6f1 (diff)
[PATCH] tpm: return chip from tpm_register_hardware
Changes in the 1.2 TPM Specification make it necessary to update some fields of the chip structure in the initialization function after it is registered with tpm.c thus tpm_register_hardware was modified to return a pointer to the structure. This patch makes that change and the associated changes in tpm_atmel and tpm_nsc. The changes to tpm_infineon will be 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.c11
-rw-r--r--drivers/char/tpm/tpm.h10
-rw-r--r--drivers/char/tpm/tpm_atmel.c32
-rw-r--r--drivers/char/tpm/tpm_atmel.h25
-rw-r--r--drivers/char/tpm/tpm_nsc.c17
5 files changed, 55 insertions, 40 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 50013eb8cf1e..5e58296f2832 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -544,7 +544,8 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume);
544 * upon errant exit from this function specific probe function should call 544 * upon errant exit from this function specific probe function should call
545 * pci_disable_device 545 * pci_disable_device
546 */ 546 */
547int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry) 547struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vendor_specific
548 *entry)
548{ 549{
549#define DEVNAME_SIZE 7 550#define DEVNAME_SIZE 7
550 551
@@ -555,7 +556,7 @@ int tpm_register_hardware(struct device *dev, struct tpm_vendor_specific *entry)
555 /* Driver specific per-device data */ 556 /* Driver specific per-device data */
556 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 557 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
557 if (chip == NULL) 558 if (chip == NULL)
558 return -ENOMEM; 559 return NULL;
559 560
560 init_MUTEX(&chip->buffer_mutex); 561 init_MUTEX(&chip->buffer_mutex);
561 init_MUTEX(&chip->tpm_mutex); 562 init_MUTEX(&chip->tpm_mutex);
@@ -584,7 +585,7 @@ dev_num_search_complete:
584 if (chip->dev_num < 0) { 585 if (chip->dev_num < 0) {
585 dev_err(dev, "No available tpm device numbers\n"); 586 dev_err(dev, "No available tpm device numbers\n");
586 kfree(chip); 587 kfree(chip);
587 return -ENODEV; 588 return NULL;
588 } else if (chip->dev_num == 0) 589 } else if (chip->dev_num == 0)
589 chip->vendor.miscdev.minor = TPM_MINOR; 590 chip->vendor.miscdev.minor = TPM_MINOR;
590 else 591 else
@@ -605,7 +606,7 @@ dev_num_search_complete:
605 put_device(dev); 606 put_device(dev);
606 kfree(chip); 607 kfree(chip);
607 dev_mask[i] &= !(1 << j); 608 dev_mask[i] &= !(1 << j);
608 return -ENODEV; 609 return NULL;
609 } 610 }
610 611
611 spin_lock(&driver_lock); 612 spin_lock(&driver_lock);
@@ -620,7 +621,7 @@ dev_num_search_complete:
620 621
621 chip->bios_dir = tpm_bios_log_setup(devname); 622 chip->bios_dir = tpm_bios_log_setup(devname);
622 623
623 return 0; 624 return chip;
624} 625}
625EXPORT_SYMBOL_GPL(tpm_register_hardware); 626EXPORT_SYMBOL_GPL(tpm_register_hardware);
626 627
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index a203963efaab..4f005345bf37 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -48,9 +48,9 @@ extern ssize_t tpm_store_cancel(struct device *, struct device_attribute *attr,
48struct tpm_chip; 48struct tpm_chip;
49 49
50struct tpm_vendor_specific { 50struct tpm_vendor_specific {
51 u8 req_complete_mask; 51 const u8 req_complete_mask;
52 u8 req_complete_val; 52 const u8 req_complete_val;
53 u8 req_canceled; 53 const u8 req_canceled;
54 void __iomem *iobase; /* ioremapped address */ 54 void __iomem *iobase; /* ioremapped address */
55 unsigned long base; /* TPM base address */ 55 unsigned long base; /* TPM base address */
56 56
@@ -100,8 +100,8 @@ static inline void tpm_write_index(int base, int index, int value)
100 outb(value & 0xFF, base+1); 100 outb(value & 0xFF, base+1);
101} 101}
102 102
103extern int tpm_register_hardware(struct device *, 103extern struct tpm_chip* tpm_register_hardware(struct device *,
104 struct tpm_vendor_specific *); 104 const struct tpm_vendor_specific *);
105extern int tpm_open(struct inode *, struct file *); 105extern int tpm_open(struct inode *, struct file *);
106extern int tpm_release(struct inode *, struct file *); 106extern int tpm_release(struct inode *, struct file *);
107extern ssize_t tpm_write(struct file *, const char __user *, size_t, 107extern ssize_t tpm_write(struct file *, const char __user *, size_t,
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index 26787976ef1a..58a258cec153 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -140,7 +140,7 @@ static struct attribute* atmel_attrs[] = {
140 140
141static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs }; 141static struct attribute_group atmel_attr_grp = { .attrs = atmel_attrs };
142 142
143static struct tpm_vendor_specific tpm_atmel = { 143static const struct tpm_vendor_specific tpm_atmel = {
144 .recv = tpm_atml_recv, 144 .recv = tpm_atml_recv,
145 .send = tpm_atml_send, 145 .send = tpm_atml_send,
146 .cancel = tpm_atml_cancel, 146 .cancel = tpm_atml_cancel,
@@ -179,18 +179,22 @@ static struct device_driver atml_drv = {
179static int __init init_atmel(void) 179static int __init init_atmel(void)
180{ 180{
181 int rc = 0; 181 int rc = 0;
182 void __iomem *iobase = NULL;
183 int have_region, region_size;
184 unsigned long base;
185 struct tpm_chip *chip;
182 186
183 driver_register(&atml_drv); 187 driver_register(&atml_drv);
184 188
185 if ((tpm_atmel.iobase = atmel_get_base_addr(&tpm_atmel)) == NULL) { 189 if ((iobase = atmel_get_base_addr(&base, &region_size)) == NULL) {
186 rc = -ENODEV; 190 rc = -ENODEV;
187 goto err_unreg_drv; 191 goto err_unreg_drv;
188 } 192 }
189 193
190 tpm_atmel.have_region = 194 have_region =
191 (atmel_request_region 195 (atmel_request_region
192 (tpm_atmel.base, tpm_atmel.region_size, 196 (tpm_atmel.base, region_size, "tpm_atmel0") == NULL) ? 0 : 1;
193 "tpm_atmel0") == NULL) ? 0 : 1; 197
194 198
195 if (IS_ERR 199 if (IS_ERR
196 (pdev = 200 (pdev =
@@ -199,17 +203,25 @@ static int __init init_atmel(void)
199 goto err_rel_reg; 203 goto err_rel_reg;
200 } 204 }
201 205
202 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_atmel)) < 0) 206 if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_atmel))) {
207 rc = -ENODEV;
203 goto err_unreg_dev; 208 goto err_unreg_dev;
209 }
210
211 chip->vendor.iobase = iobase;
212 chip->vendor.base = base;
213 chip->vendor.have_region = have_region;
214 chip->vendor.region_size = region_size;
215
204 return 0; 216 return 0;
205 217
206err_unreg_dev: 218err_unreg_dev:
207 platform_device_unregister(pdev); 219 platform_device_unregister(pdev);
208err_rel_reg: 220err_rel_reg:
209 atmel_put_base_addr(&tpm_atmel); 221 atmel_put_base_addr(iobase);
210 if (tpm_atmel.have_region) 222 if (have_region)
211 atmel_release_region(tpm_atmel.base, 223 atmel_release_region(base,
212 tpm_atmel.region_size); 224 region_size);
213err_unreg_drv: 225err_unreg_drv:
214 driver_unregister(&atml_drv); 226 driver_unregister(&atml_drv);
215 return rc; 227 return rc;
diff --git a/drivers/char/tpm/tpm_atmel.h b/drivers/char/tpm/tpm_atmel.h
index d3478aaadd77..2e68eeb8a2cd 100644
--- a/drivers/char/tpm/tpm_atmel.h
+++ b/drivers/char/tpm/tpm_atmel.h
@@ -28,13 +28,12 @@
28#define atmel_request_region request_mem_region 28#define atmel_request_region request_mem_region
29#define atmel_release_region release_mem_region 29#define atmel_release_region release_mem_region
30 30
31static inline void atmel_put_base_addr(struct tpm_vendor_specific 31static inline void atmel_put_base_addr(void __iomem *iobase)
32 *vendor)
33{ 32{
34 iounmap(vendor->iobase); 33 iounmap(iobase);
35} 34}
36 35
37static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific *vendor) 36static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
38{ 37{
39 struct device_node *dn; 38 struct device_node *dn;
40 unsigned long address, size; 39 unsigned long address, size;
@@ -71,9 +70,9 @@ static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific *vendor)
71 else 70 else
72 size = reg[naddrc]; 71 size = reg[naddrc];
73 72
74 vendor->base = address; 73 *base = address;
75 vendor->region_size = size; 74 *region_size = size;
76 return ioremap(vendor->base, vendor->region_size); 75 return ioremap(*base, *region_size);
77} 76}
78#else 77#else
79#define atmel_getb(chip, offset) inb(chip->vendor->base + offset) 78#define atmel_getb(chip, offset) inb(chip->vendor->base + offset)
@@ -106,14 +105,12 @@ static int atmel_verify_tpm11(void)
106 return 0; 105 return 0;
107} 106}
108 107
109static inline void atmel_put_base_addr(struct tpm_vendor_specific 108static inline void atmel_put_base_addr(void __iomem *iobase)
110 *vendor)
111{ 109{
112} 110}
113 111
114/* Determine where to talk to device */ 112/* Determine where to talk to device */
115static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific 113static void __iomem * atmel_get_base_addr(unsigned long *base, int *region_size)
116 *vendor)
117{ 114{
118 int lo, hi; 115 int lo, hi;
119 116
@@ -123,9 +120,9 @@ static void __iomem * atmel_get_base_addr(struct tpm_vendor_specific
123 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO); 120 lo = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_LO);
124 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI); 121 hi = tpm_read_index(TPM_ADDR, TPM_ATMEL_BASE_ADDR_HI);
125 122
126 vendor->base = (hi << 8) | lo; 123 *base = (hi << 8) | lo;
127 vendor->region_size = 2; 124 *region_size = 2;
128 125
129 return ioport_map(vendor->base, vendor->region_size); 126 return ioport_map(*base, *region_size);
130} 127}
131#endif 128#endif
diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
index 3dbbe9686c76..4c8bc06c7d95 100644
--- a/drivers/char/tpm/tpm_nsc.c
+++ b/drivers/char/tpm/tpm_nsc.c
@@ -250,7 +250,7 @@ static struct attribute * nsc_attrs[] = {
250 250
251static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs }; 251static struct attribute_group nsc_attr_grp = { .attrs = nsc_attrs };
252 252
253static struct tpm_vendor_specific tpm_nsc = { 253static const struct tpm_vendor_specific tpm_nsc = {
254 .recv = tpm_nsc_recv, 254 .recv = tpm_nsc_recv,
255 .send = tpm_nsc_send, 255 .send = tpm_nsc_send,
256 .cancel = tpm_nsc_cancel, 256 .cancel = tpm_nsc_cancel,
@@ -286,7 +286,8 @@ static int __init init_nsc(void)
286 int rc = 0; 286 int rc = 0;
287 int lo, hi; 287 int lo, hi;
288 int nscAddrBase = TPM_ADDR; 288 int nscAddrBase = TPM_ADDR;
289 289 struct tpm_chip *chip;
290 unsigned long base;
290 291
291 /* verify that it is a National part (SID) */ 292 /* verify that it is a National part (SID) */
292 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) { 293 if (tpm_read_index(TPM_ADDR, NSC_SID_INDEX) != 0xEF) {
@@ -300,7 +301,7 @@ static int __init init_nsc(void)
300 301
301 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI); 302 hi = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_HI);
302 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO); 303 lo = tpm_read_index(nscAddrBase, TPM_NSC_BASE0_LO);
303 tpm_nsc.base = (hi<<8) | lo; 304 base = (hi<<8) | lo;
304 305
305 /* enable the DPM module */ 306 /* enable the DPM module */
306 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01); 307 tpm_write_index(nscAddrBase, NSC_LDC_INDEX, 0x01);
@@ -320,13 +321,15 @@ static int __init init_nsc(void)
320 if ((rc = platform_device_register(pdev)) < 0) 321 if ((rc = platform_device_register(pdev)) < 0)
321 goto err_free_dev; 322 goto err_free_dev;
322 323
323 if (request_region(tpm_nsc.base, 2, "tpm_nsc0") == NULL ) { 324 if (request_region(base, 2, "tpm_nsc0") == NULL ) {
324 rc = -EBUSY; 325 rc = -EBUSY;
325 goto err_unreg_dev; 326 goto err_unreg_dev;
326 } 327 }
327 328
328 if ((rc = tpm_register_hardware(&pdev->dev, &tpm_nsc)) < 0) 329 if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) {
330 rc = -ENODEV;
329 goto err_rel_reg; 331 goto err_rel_reg;
332 }
330 333
331 dev_dbg(&pdev->dev, "NSC TPM detected\n"); 334 dev_dbg(&pdev->dev, "NSC TPM detected\n");
332 dev_dbg(&pdev->dev, 335 dev_dbg(&pdev->dev,
@@ -361,10 +364,12 @@ static int __init init_nsc(void)
361 "NSC TPM revision %d\n", 364 "NSC TPM revision %d\n",
362 tpm_read_index(nscAddrBase, 0x27) & 0x1F); 365 tpm_read_index(nscAddrBase, 0x27) & 0x1F);
363 366
367 chip->vendor.base = base;
368
364 return 0; 369 return 0;
365 370
366err_rel_reg: 371err_rel_reg:
367 release_region(tpm_nsc.base, 2); 372 release_region(base, 2);
368err_unreg_dev: 373err_unreg_dev:
369 platform_device_unregister(pdev); 374 platform_device_unregister(pdev);
370err_free_dev: 375err_free_dev: