diff options
Diffstat (limited to 'drivers/char/tpm/tpm.c')
-rw-r--r-- | drivers/char/tpm/tpm.c | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 328f2a97916e..75f949b53177 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -64,7 +64,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
64 | if (count == 0) | 64 | if (count == 0) |
65 | return -ENODATA; | 65 | return -ENODATA; |
66 | if (count > bufsiz) { | 66 | if (count > bufsiz) { |
67 | dev_err(&chip->pci_dev->dev, | 67 | dev_err(chip->dev, |
68 | "invalid count value %x %zx \n", count, bufsiz); | 68 | "invalid count value %x %zx \n", count, bufsiz); |
69 | return -E2BIG; | 69 | return -E2BIG; |
70 | } | 70 | } |
@@ -72,7 +72,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
72 | down(&chip->tpm_mutex); | 72 | down(&chip->tpm_mutex); |
73 | 73 | ||
74 | if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { | 74 | if ((rc = chip->vendor->send(chip, (u8 *) buf, count)) < 0) { |
75 | dev_err(&chip->pci_dev->dev, | 75 | dev_err(chip->dev, |
76 | "tpm_transmit: tpm_send: error %zd\n", rc); | 76 | "tpm_transmit: tpm_send: error %zd\n", rc); |
77 | goto out; | 77 | goto out; |
78 | } | 78 | } |
@@ -86,7 +86,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
86 | } | 86 | } |
87 | 87 | ||
88 | if ((status == chip->vendor->req_canceled)) { | 88 | if ((status == chip->vendor->req_canceled)) { |
89 | dev_err(&chip->pci_dev->dev, "Operation Canceled\n"); | 89 | dev_err(chip->dev, "Operation Canceled\n"); |
90 | rc = -ECANCELED; | 90 | rc = -ECANCELED; |
91 | goto out; | 91 | goto out; |
92 | } | 92 | } |
@@ -97,14 +97,14 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf, | |||
97 | 97 | ||
98 | 98 | ||
99 | chip->vendor->cancel(chip); | 99 | chip->vendor->cancel(chip); |
100 | dev_err(&chip->pci_dev->dev, "Operation Timed out\n"); | 100 | dev_err(chip->dev, "Operation Timed out\n"); |
101 | rc = -ETIME; | 101 | rc = -ETIME; |
102 | goto out; | 102 | goto out; |
103 | 103 | ||
104 | out_recv: | 104 | out_recv: |
105 | rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); | 105 | rc = chip->vendor->recv(chip, (u8 *) buf, bufsiz); |
106 | if (rc < 0) | 106 | if (rc < 0) |
107 | dev_err(&chip->pci_dev->dev, | 107 | dev_err(chip->dev, |
108 | "tpm_transmit: tpm_recv: error %zd\n", rc); | 108 | "tpm_transmit: tpm_recv: error %zd\n", rc); |
109 | out: | 109 | out: |
110 | up(&chip->tpm_mutex); | 110 | up(&chip->tpm_mutex); |
@@ -139,15 +139,14 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr, | |||
139 | __be32 index; | 139 | __be32 index; |
140 | char *str = buf; | 140 | char *str = buf; |
141 | 141 | ||
142 | struct tpm_chip *chip = | 142 | struct tpm_chip *chip = dev_get_drvdata(dev); |
143 | pci_get_drvdata(to_pci_dev(dev)); | ||
144 | if (chip == NULL) | 143 | if (chip == NULL) |
145 | return -ENODEV; | 144 | return -ENODEV; |
146 | 145 | ||
147 | memcpy(data, cap_pcr, sizeof(cap_pcr)); | 146 | memcpy(data, cap_pcr, sizeof(cap_pcr)); |
148 | if ((len = tpm_transmit(chip, data, sizeof(data))) | 147 | if ((len = tpm_transmit(chip, data, sizeof(data))) |
149 | < CAP_PCR_RESULT_SIZE) { | 148 | < CAP_PCR_RESULT_SIZE) { |
150 | dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " | 149 | dev_dbg(chip->dev, "A TPM error (%d) occurred " |
151 | "attempting to determine the number of PCRS\n", | 150 | "attempting to determine the number of PCRS\n", |
152 | be32_to_cpu(*((__be32 *) (data + 6)))); | 151 | be32_to_cpu(*((__be32 *) (data + 6)))); |
153 | return 0; | 152 | return 0; |
@@ -161,7 +160,7 @@ ssize_t tpm_show_pcrs(struct device *dev, struct device_attribute *attr, | |||
161 | memcpy(data + 10, &index, 4); | 160 | memcpy(data + 10, &index, 4); |
162 | if ((len = tpm_transmit(chip, data, sizeof(data))) | 161 | if ((len = tpm_transmit(chip, data, sizeof(data))) |
163 | < READ_PCR_RESULT_SIZE){ | 162 | < READ_PCR_RESULT_SIZE){ |
164 | dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred" | 163 | dev_dbg(chip->dev, "A TPM error (%d) occurred" |
165 | " attempting to read PCR %d of %d\n", | 164 | " attempting to read PCR %d of %d\n", |
166 | be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs); | 165 | be32_to_cpu(*((__be32 *) (data + 6))), i, num_pcrs); |
167 | goto out; | 166 | goto out; |
@@ -191,8 +190,7 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr, | |||
191 | int i, rc; | 190 | int i, rc; |
192 | char *str = buf; | 191 | char *str = buf; |
193 | 192 | ||
194 | struct tpm_chip *chip = | 193 | struct tpm_chip *chip = dev_get_drvdata(dev); |
195 | pci_get_drvdata(to_pci_dev(dev)); | ||
196 | if (chip == NULL) | 194 | if (chip == NULL) |
197 | return -ENODEV; | 195 | return -ENODEV; |
198 | 196 | ||
@@ -205,7 +203,7 @@ ssize_t tpm_show_pubek(struct device *dev, struct device_attribute *attr, | |||
205 | 203 | ||
206 | if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) < | 204 | if ((len = tpm_transmit(chip, data, READ_PUBEK_RESULT_SIZE)) < |
207 | READ_PUBEK_RESULT_SIZE) { | 205 | READ_PUBEK_RESULT_SIZE) { |
208 | dev_dbg(&chip->pci_dev->dev, "A TPM error (%d) occurred " | 206 | dev_dbg(chip->dev, "A TPM error (%d) occurred " |
209 | "attempting to read the PUBEK\n", | 207 | "attempting to read the PUBEK\n", |
210 | be32_to_cpu(*((__be32 *) (data + 6)))); | 208 | be32_to_cpu(*((__be32 *) (data + 6)))); |
211 | rc = 0; | 209 | rc = 0; |
@@ -274,8 +272,7 @@ ssize_t tpm_show_caps(struct device *dev, struct device_attribute *attr, | |||
274 | ssize_t len; | 272 | ssize_t len; |
275 | char *str = buf; | 273 | char *str = buf; |
276 | 274 | ||
277 | struct tpm_chip *chip = | 275 | struct tpm_chip *chip = dev_get_drvdata(dev); |
278 | pci_get_drvdata(to_pci_dev(dev)); | ||
279 | if (chip == NULL) | 276 | if (chip == NULL) |
280 | return -ENODEV; | 277 | return -ENODEV; |
281 | 278 | ||
@@ -339,21 +336,21 @@ int tpm_open(struct inode *inode, struct file *file) | |||
339 | } | 336 | } |
340 | 337 | ||
341 | if (chip->num_opens) { | 338 | if (chip->num_opens) { |
342 | dev_dbg(&chip->pci_dev->dev, | 339 | dev_dbg(chip->dev, |
343 | "Another process owns this TPM\n"); | 340 | "Another process owns this TPM\n"); |
344 | rc = -EBUSY; | 341 | rc = -EBUSY; |
345 | goto err_out; | 342 | goto err_out; |
346 | } | 343 | } |
347 | 344 | ||
348 | chip->num_opens++; | 345 | chip->num_opens++; |
349 | pci_dev_get(chip->pci_dev); | 346 | get_device(chip->dev); |
350 | 347 | ||
351 | spin_unlock(&driver_lock); | 348 | spin_unlock(&driver_lock); |
352 | 349 | ||
353 | chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); | 350 | chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); |
354 | if (chip->data_buffer == NULL) { | 351 | if (chip->data_buffer == NULL) { |
355 | chip->num_opens--; | 352 | chip->num_opens--; |
356 | pci_dev_put(chip->pci_dev); | 353 | put_device(chip->dev); |
357 | return -ENOMEM; | 354 | return -ENOMEM; |
358 | } | 355 | } |
359 | 356 | ||
@@ -378,7 +375,7 @@ int tpm_release(struct inode *inode, struct file *file) | |||
378 | chip->num_opens--; | 375 | chip->num_opens--; |
379 | del_singleshot_timer_sync(&chip->user_read_timer); | 376 | del_singleshot_timer_sync(&chip->user_read_timer); |
380 | atomic_set(&chip->data_pending, 0); | 377 | atomic_set(&chip->data_pending, 0); |
381 | pci_dev_put(chip->pci_dev); | 378 | put_device(chip->dev); |
382 | kfree(chip->data_buffer); | 379 | kfree(chip->data_buffer); |
383 | spin_unlock(&driver_lock); | 380 | spin_unlock(&driver_lock); |
384 | return 0; | 381 | return 0; |
@@ -447,12 +444,12 @@ ssize_t tpm_read(struct file * file, char __user * buf, | |||
447 | 444 | ||
448 | EXPORT_SYMBOL_GPL(tpm_read); | 445 | EXPORT_SYMBOL_GPL(tpm_read); |
449 | 446 | ||
450 | void __devexit tpm_remove(struct pci_dev *pci_dev) | 447 | void tpm_remove_hardware(struct device *dev) |
451 | { | 448 | { |
452 | struct tpm_chip *chip = pci_get_drvdata(pci_dev); | 449 | struct tpm_chip *chip = dev_get_drvdata(dev); |
453 | 450 | ||
454 | if (chip == NULL) { | 451 | if (chip == NULL) { |
455 | dev_err(&pci_dev->dev, "No device data found\n"); | 452 | dev_err(dev, "No device data found\n"); |
456 | return; | 453 | return; |
457 | } | 454 | } |
458 | 455 | ||
@@ -462,22 +459,20 @@ void __devexit tpm_remove(struct pci_dev *pci_dev) | |||
462 | 459 | ||
463 | spin_unlock(&driver_lock); | 460 | spin_unlock(&driver_lock); |
464 | 461 | ||
465 | pci_set_drvdata(pci_dev, NULL); | 462 | dev_set_drvdata(dev, NULL); |
466 | misc_deregister(&chip->vendor->miscdev); | 463 | misc_deregister(&chip->vendor->miscdev); |
467 | kfree(chip->vendor->miscdev.name); | 464 | kfree(chip->vendor->miscdev.name); |
468 | 465 | ||
469 | sysfs_remove_group(&pci_dev->dev.kobj, chip->vendor->attr_group); | 466 | sysfs_remove_group(&dev->kobj, chip->vendor->attr_group); |
470 | |||
471 | pci_disable_device(pci_dev); | ||
472 | 467 | ||
473 | dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); | 468 | dev_mask[chip->dev_num / TPM_NUM_MASK_ENTRIES ] &= !(1 << (chip->dev_num % TPM_NUM_MASK_ENTRIES)); |
474 | 469 | ||
475 | kfree(chip); | 470 | kfree(chip); |
476 | 471 | ||
477 | pci_dev_put(pci_dev); | 472 | put_device(dev); |
478 | } | 473 | } |
479 | 474 | ||
480 | EXPORT_SYMBOL_GPL(tpm_remove); | 475 | EXPORT_SYMBOL_GPL(tpm_remove_hardware); |
481 | 476 | ||
482 | static u8 savestate[] = { | 477 | static u8 savestate[] = { |
483 | 0, 193, /* TPM_TAG_RQU_COMMAND */ | 478 | 0, 193, /* TPM_TAG_RQU_COMMAND */ |
@@ -524,7 +519,7 @@ EXPORT_SYMBOL_GPL(tpm_pm_resume); | |||
524 | * upon errant exit from this function specific probe function should call | 519 | * upon errant exit from this function specific probe function should call |
525 | * pci_disable_device | 520 | * pci_disable_device |
526 | */ | 521 | */ |
527 | int tpm_register_hardware(struct pci_dev *pci_dev, | 522 | int tpm_register_hardware(struct device *dev, |
528 | struct tpm_vendor_specific *entry) | 523 | struct tpm_vendor_specific *entry) |
529 | { | 524 | { |
530 | #define DEVNAME_SIZE 7 | 525 | #define DEVNAME_SIZE 7 |
@@ -563,7 +558,7 @@ int tpm_register_hardware(struct pci_dev *pci_dev, | |||
563 | 558 | ||
564 | dev_num_search_complete: | 559 | dev_num_search_complete: |
565 | if (chip->dev_num < 0) { | 560 | if (chip->dev_num < 0) { |
566 | dev_err(&pci_dev->dev, | 561 | dev_err(dev, |
567 | "No available tpm device numbers\n"); | 562 | "No available tpm device numbers\n"); |
568 | kfree(chip); | 563 | kfree(chip); |
569 | return -ENODEV; | 564 | return -ENODEV; |
@@ -576,15 +571,15 @@ dev_num_search_complete: | |||
576 | scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); | 571 | scnprintf(devname, DEVNAME_SIZE, "%s%d", "tpm", chip->dev_num); |
577 | chip->vendor->miscdev.name = devname; | 572 | chip->vendor->miscdev.name = devname; |
578 | 573 | ||
579 | chip->vendor->miscdev.dev = &(pci_dev->dev); | 574 | chip->vendor->miscdev.dev = dev; |
580 | chip->pci_dev = pci_dev_get(pci_dev); | 575 | chip->dev = get_device(dev); |
581 | 576 | ||
582 | if (misc_register(&chip->vendor->miscdev)) { | 577 | if (misc_register(&chip->vendor->miscdev)) { |
583 | dev_err(&chip->pci_dev->dev, | 578 | dev_err(chip->dev, |
584 | "unable to misc_register %s, minor %d\n", | 579 | "unable to misc_register %s, minor %d\n", |
585 | chip->vendor->miscdev.name, | 580 | chip->vendor->miscdev.name, |
586 | chip->vendor->miscdev.minor); | 581 | chip->vendor->miscdev.minor); |
587 | pci_dev_put(pci_dev); | 582 | put_device(dev); |
588 | kfree(chip); | 583 | kfree(chip); |
589 | dev_mask[i] &= !(1 << j); | 584 | dev_mask[i] &= !(1 << j); |
590 | return -ENODEV; | 585 | return -ENODEV; |
@@ -592,13 +587,13 @@ dev_num_search_complete: | |||
592 | 587 | ||
593 | spin_lock(&driver_lock); | 588 | spin_lock(&driver_lock); |
594 | 589 | ||
595 | pci_set_drvdata(pci_dev, chip); | 590 | dev_set_drvdata(dev, chip); |
596 | 591 | ||
597 | list_add(&chip->list, &tpm_chip_list); | 592 | list_add(&chip->list, &tpm_chip_list); |
598 | 593 | ||
599 | spin_unlock(&driver_lock); | 594 | spin_unlock(&driver_lock); |
600 | 595 | ||
601 | sysfs_create_group(&pci_dev->dev.kobj, chip->vendor->attr_group); | 596 | sysfs_create_group(&dev->kobj, chip->vendor->attr_group); |
602 | 597 | ||
603 | return 0; | 598 | return 0; |
604 | } | 599 | } |