diff options
author | Jason Gunthorpe <jgunthorpe@obsidianresearch.com> | 2015-11-25 16:05:32 -0500 |
---|---|---|
committer | Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> | 2015-12-20 08:23:46 -0500 |
commit | 25112048cd59930e23775cafb88e18cfb484892c (patch) | |
tree | 12847b70d58372af1d44c69cc83d9821cd773e91 | |
parent | 036bb38ffb3e4c92361108f324364b0341cd9e31 (diff) |
tpm: rework tpm_get_timeouts()
IRQ probing needs to know that the TPM is working before trying to
probe, so move tpm_get_timeouts() to the top of the tpm_tis_init().
This has the advantage of also getting the correct timeouts loaded
before doing IRQ probing.
All the timeout handling code is moved to tpm_get_timeouts() in order to
remove duplicate code in tpm_tis and tpm_crb.
[jarkko.sakkinen@linux.intel.com: squashed two patches together and
improved the commit message.]
Signed-off-by: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Tested-by: Martin Wilck <Martin.Wilck@ts.fujitsu.com>
Tested-by: Scot Doyle <lkml14@scotdoyle.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Acked-by: Peter Huewe <peterhuewe@gmx.de>
-rw-r--r-- | drivers/char/tpm/tpm-interface.c | 15 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_crb.c | 14 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_tis.c | 33 |
3 files changed, 34 insertions, 28 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index afdc83602e9f..e2fa89c88304 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c | |||
@@ -503,6 +503,21 @@ int tpm_get_timeouts(struct tpm_chip *chip) | |||
503 | struct duration_t *duration_cap; | 503 | struct duration_t *duration_cap; |
504 | ssize_t rc; | 504 | ssize_t rc; |
505 | 505 | ||
506 | if (chip->flags & TPM_CHIP_FLAG_TPM2) { | ||
507 | /* Fixed timeouts for TPM2 */ | ||
508 | chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); | ||
509 | chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); | ||
510 | chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); | ||
511 | chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); | ||
512 | chip->vendor.duration[TPM_SHORT] = | ||
513 | msecs_to_jiffies(TPM2_DURATION_SHORT); | ||
514 | chip->vendor.duration[TPM_MEDIUM] = | ||
515 | msecs_to_jiffies(TPM2_DURATION_MEDIUM); | ||
516 | chip->vendor.duration[TPM_LONG] = | ||
517 | msecs_to_jiffies(TPM2_DURATION_LONG); | ||
518 | return 0; | ||
519 | } | ||
520 | |||
506 | tpm_cmd.header.in = tpm_getcap_header; | 521 | tpm_cmd.header.in = tpm_getcap_header; |
507 | tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; | 522 | tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; |
508 | tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); | 523 | tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); |
diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 4bb9727c1047..8342cf51ffdc 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c | |||
@@ -284,17 +284,9 @@ static int crb_acpi_add(struct acpi_device *device) | |||
284 | 284 | ||
285 | chip->vendor.priv = priv; | 285 | chip->vendor.priv = priv; |
286 | 286 | ||
287 | /* Default timeouts and durations */ | 287 | rc = tpm_get_timeouts(chip); |
288 | chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); | 288 | if (rc) |
289 | chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); | 289 | return rc; |
290 | chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); | ||
291 | chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); | ||
292 | chip->vendor.duration[TPM_SHORT] = | ||
293 | msecs_to_jiffies(TPM2_DURATION_SHORT); | ||
294 | chip->vendor.duration[TPM_MEDIUM] = | ||
295 | msecs_to_jiffies(TPM2_DURATION_MEDIUM); | ||
296 | chip->vendor.duration[TPM_LONG] = | ||
297 | msecs_to_jiffies(TPM2_DURATION_LONG); | ||
298 | 290 | ||
299 | chip->acpi_dev_handle = device->handle; | 291 | chip->acpi_dev_handle = device->handle; |
300 | 292 | ||
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 513f30efd9d3..56a295d328c7 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c | |||
@@ -740,6 +740,16 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, | |||
740 | if (intfcaps & TPM_INTF_DATA_AVAIL_INT) | 740 | if (intfcaps & TPM_INTF_DATA_AVAIL_INT) |
741 | dev_dbg(dev, "\tData Avail Int Support\n"); | 741 | dev_dbg(dev, "\tData Avail Int Support\n"); |
742 | 742 | ||
743 | /* Very early on issue a command to the TPM in polling mode to make | ||
744 | * sure it works. May as well use that command to set the proper | ||
745 | * timeouts for the driver. | ||
746 | */ | ||
747 | if (tpm_get_timeouts(chip)) { | ||
748 | dev_err(dev, "Could not get TPM timeouts and durations\n"); | ||
749 | rc = -ENODEV; | ||
750 | goto out_err; | ||
751 | } | ||
752 | |||
743 | /* INTERRUPT Setup */ | 753 | /* INTERRUPT Setup */ |
744 | init_waitqueue_head(&chip->vendor.read_queue); | 754 | init_waitqueue_head(&chip->vendor.read_queue); |
745 | init_waitqueue_head(&chip->vendor.int_queue); | 755 | init_waitqueue_head(&chip->vendor.int_queue); |
@@ -837,18 +847,13 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, | |||
837 | iowrite8(irq_r, chip->vendor.iobase + | 847 | iowrite8(irq_r, chip->vendor.iobase + |
838 | TPM_INT_VECTOR(chip->vendor.locality)); | 848 | TPM_INT_VECTOR(chip->vendor.locality)); |
839 | 849 | ||
840 | if (chip->flags & TPM_CHIP_FLAG_TPM2) { | 850 | if (tpm_get_timeouts(chip)) { |
841 | chip->vendor.timeout_a = msecs_to_jiffies(TPM2_TIMEOUT_A); | 851 | dev_err(dev, "Could not get TPM timeouts and durations\n"); |
842 | chip->vendor.timeout_b = msecs_to_jiffies(TPM2_TIMEOUT_B); | 852 | rc = -ENODEV; |
843 | chip->vendor.timeout_c = msecs_to_jiffies(TPM2_TIMEOUT_C); | 853 | goto out_err; |
844 | chip->vendor.timeout_d = msecs_to_jiffies(TPM2_TIMEOUT_D); | 854 | } |
845 | chip->vendor.duration[TPM_SHORT] = | ||
846 | msecs_to_jiffies(TPM2_DURATION_SHORT); | ||
847 | chip->vendor.duration[TPM_MEDIUM] = | ||
848 | msecs_to_jiffies(TPM2_DURATION_MEDIUM); | ||
849 | chip->vendor.duration[TPM_LONG] = | ||
850 | msecs_to_jiffies(TPM2_DURATION_LONG); | ||
851 | 855 | ||
856 | if (chip->flags & TPM_CHIP_FLAG_TPM2) { | ||
852 | rc = tpm2_do_selftest(chip); | 857 | rc = tpm2_do_selftest(chip); |
853 | if (rc == TPM2_RC_INITIALIZE) { | 858 | if (rc == TPM2_RC_INITIALIZE) { |
854 | dev_warn(dev, "Firmware has not started TPM\n"); | 859 | dev_warn(dev, "Firmware has not started TPM\n"); |
@@ -864,12 +869,6 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info, | |||
864 | goto out_err; | 869 | goto out_err; |
865 | } | 870 | } |
866 | } else { | 871 | } else { |
867 | if (tpm_get_timeouts(chip)) { | ||
868 | dev_err(dev, "Could not get TPM timeouts and durations\n"); | ||
869 | rc = -ENODEV; | ||
870 | goto out_err; | ||
871 | } | ||
872 | |||
873 | if (tpm_do_selftest(chip)) { | 872 | if (tpm_do_selftest(chip)) { |
874 | dev_err(dev, "TPM self test failed\n"); | 873 | dev_err(dev, "TPM self test failed\n"); |
875 | rc = -ENODEV; | 874 | rc = -ENODEV; |