]>
Commit | Line | Data |
---|---|---|
21bbe2c0 GKH |
1 | From 9b29050f8f75916f974a2d231ae5d3cd59792296 Mon Sep 17 00:00:00 2001 |
2 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | |
3 | Date: Tue, 11 Jan 2011 14:37:29 -0500 | |
4 | Subject: tpm_tis: Use timeouts returned from TPM | |
5 | ||
6 | From: Stefan Berger <stefanb@linux.vnet.ibm.com> | |
7 | ||
8 | commit 9b29050f8f75916f974a2d231ae5d3cd59792296 upstream. | |
9 | ||
10 | The current TPM TIS driver in git discards the timeout values returned | |
11 | from the TPM. The check of the response packet needs to consider that | |
12 | the return_code field is 0 on success and the size of the expected | |
13 | packet is equivalent to the header size + u32 length indicator for the | |
14 | TPM_GetCapability() result + 3 timeout indicators of type u32. | |
15 | ||
16 | I am also adding a sysfs entry 'timeouts' showing the timeouts that are | |
17 | being used. | |
18 | ||
19 | Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com> | |
20 | Tested-by: Guillaume Chazarain <guichaz@gmail.com> | |
21 | Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com> | |
22 | Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> | |
23 | ||
24 | --- | |
25 | drivers/char/tpm/tpm.c | 18 ++++++++++++++++-- | |
26 | drivers/char/tpm/tpm.h | 2 ++ | |
27 | drivers/char/tpm/tpm_tis.c | 4 +++- | |
28 | 3 files changed, 21 insertions(+), 3 deletions(-) | |
29 | ||
30 | --- a/drivers/char/tpm/tpm.c | |
31 | +++ b/drivers/char/tpm/tpm.c | |
32 | @@ -567,9 +567,11 @@ duration: | |
33 | if (rc) | |
34 | return; | |
35 | ||
36 | - if (be32_to_cpu(tpm_cmd.header.out.return_code) | |
37 | - != 3 * sizeof(u32)) | |
38 | + if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 || | |
39 | + be32_to_cpu(tpm_cmd.header.out.length) | |
40 | + != sizeof(tpm_cmd.header.out) + sizeof(u32) + 3 * sizeof(u32)) | |
41 | return; | |
42 | + | |
43 | duration_cap = &tpm_cmd.params.getcap_out.cap.duration; | |
44 | chip->vendor.duration[TPM_SHORT] = | |
45 | usecs_to_jiffies(be32_to_cpu(duration_cap->tpm_short)); | |
46 | @@ -913,6 +915,18 @@ ssize_t tpm_show_caps_1_2(struct device | |
47 | } | |
48 | EXPORT_SYMBOL_GPL(tpm_show_caps_1_2); | |
49 | ||
50 | +ssize_t tpm_show_timeouts(struct device *dev, struct device_attribute *attr, | |
51 | + char *buf) | |
52 | +{ | |
53 | + struct tpm_chip *chip = dev_get_drvdata(dev); | |
54 | + | |
55 | + return sprintf(buf, "%d %d %d\n", | |
56 | + jiffies_to_usecs(chip->vendor.duration[TPM_SHORT]), | |
57 | + jiffies_to_usecs(chip->vendor.duration[TPM_MEDIUM]), | |
58 | + jiffies_to_usecs(chip->vendor.duration[TPM_LONG])); | |
59 | +} | |
60 | +EXPORT_SYMBOL_GPL(tpm_show_timeouts); | |
61 | + | |
62 | ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, | |
63 | const char *buf, size_t count) | |
64 | { | |
65 | --- a/drivers/char/tpm/tpm.h | |
66 | +++ b/drivers/char/tpm/tpm.h | |
67 | @@ -56,6 +56,8 @@ extern ssize_t tpm_show_owned(struct dev | |
68 | char *); | |
69 | extern ssize_t tpm_show_temp_deactivated(struct device *, | |
70 | struct device_attribute *attr, char *); | |
71 | +extern ssize_t tpm_show_timeouts(struct device *, | |
72 | + struct device_attribute *attr, char *); | |
73 | ||
74 | struct tpm_chip; | |
75 | ||
76 | --- a/drivers/char/tpm/tpm_tis.c | |
77 | +++ b/drivers/char/tpm/tpm_tis.c | |
78 | @@ -355,6 +355,7 @@ static DEVICE_ATTR(temp_deactivated, S_I | |
79 | NULL); | |
80 | static DEVICE_ATTR(caps, S_IRUGO, tpm_show_caps_1_2, NULL); | |
81 | static DEVICE_ATTR(cancel, S_IWUSR | S_IWGRP, NULL, tpm_store_cancel); | |
82 | +static DEVICE_ATTR(timeouts, S_IRUGO, tpm_show_timeouts, NULL); | |
83 | ||
84 | static struct attribute *tis_attrs[] = { | |
85 | &dev_attr_pubek.attr, | |
86 | @@ -364,7 +365,8 @@ static struct attribute *tis_attrs[] = { | |
87 | &dev_attr_owned.attr, | |
88 | &dev_attr_temp_deactivated.attr, | |
89 | &dev_attr_caps.attr, | |
90 | - &dev_attr_cancel.attr, NULL, | |
91 | + &dev_attr_cancel.attr, | |
92 | + &dev_attr_timeouts.attr, NULL, | |
93 | }; | |
94 | ||
95 | static struct attribute_group tis_attr_grp = { |