Skip to content

Commit 36b2002

Browse files
Kylene Jo HallLinus Torvalds
authored andcommitted
[PATCH] tpm: msecs_to_jiffies cleanups
The timeout and duration values used in the tpm driver are not exposed to userspace. This patch converts the storage units to jiffies with msecs_to_jiffies. They were always being used in jiffies so this simplifies things removing the need for calculation all over the place. The change necessitated a type change in the tpm_chip struct to hold jiffies. Signed-off-by: Kylie Hall <kjhall@us.ibm.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 27084ef commit 36b2002

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

drivers/char/tpm/tpm.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
354354
TPM_PROTECTED_ORDINAL_MASK];
355355

356356
if (duration_idx != TPM_UNDEFINED)
357-
duration = chip->vendor.duration[duration_idx] * HZ / 1000;
357+
duration = chip->vendor.duration[duration_idx];
358358
if (duration <= 0)
359359
return 2 * 60 * HZ;
360360
else
@@ -524,19 +524,19 @@ void tpm_get_timeouts(struct tpm_chip *chip)
524524
timeout =
525525
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
526526
if (timeout)
527-
chip->vendor.timeout_a = timeout;
527+
chip->vendor.timeout_a = msecs_to_jiffies(timeout);
528528
timeout =
529529
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
530530
if (timeout)
531-
chip->vendor.timeout_b = timeout;
531+
chip->vendor.timeout_b = msecs_to_jiffies(timeout);
532532
timeout =
533533
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
534534
if (timeout)
535-
chip->vendor.timeout_c = timeout;
535+
chip->vendor.timeout_c = msecs_to_jiffies(timeout);
536536
timeout =
537537
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
538538
if (timeout)
539-
chip->vendor.timeout_d = timeout;
539+
chip->vendor.timeout_d = msecs_to_jiffies(timeout);
540540

541541
duration:
542542
memcpy(data, tpm_cap, sizeof(tpm_cap));
@@ -553,11 +553,17 @@ void tpm_get_timeouts(struct tpm_chip *chip)
553553
return;
554554

555555
chip->vendor.duration[TPM_SHORT] =
556-
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
556+
msecs_to_jiffies(be32_to_cpu
557+
(*((__be32 *) (data +
558+
TPM_GET_CAP_RET_UINT32_1_IDX))));
557559
chip->vendor.duration[TPM_MEDIUM] =
558-
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
560+
msecs_to_jiffies(be32_to_cpu
561+
(*((__be32 *) (data +
562+
TPM_GET_CAP_RET_UINT32_2_IDX))));
559563
chip->vendor.duration[TPM_LONG] =
560-
be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
564+
msecs_to_jiffies(be32_to_cpu
565+
(*((__be32 *) (data +
566+
TPM_GET_CAP_RET_UINT32_3_IDX))));
561567
}
562568
EXPORT_SYMBOL_GPL(tpm_get_timeouts);
563569

drivers/char/tpm/tpm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ struct tpm_vendor_specific {
7777
struct attribute_group *attr_group;
7878
struct list_head list;
7979
int locality;
80-
u32 timeout_a, timeout_b, timeout_c, timeout_d;
81-
u32 duration[3];
80+
unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
81+
unsigned long duration[3]; /* jiffies */
8282

8383
wait_queue_head_t read_queue;
8484
wait_queue_head_t int_queue;

drivers/char/tpm/tpm_tis.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ enum tis_int_flags {
5151
TPM_INTF_DATA_AVAIL_INT = 0x001,
5252
};
5353

54+
enum tis_defaults {
55+
TIS_SHORT_TIMEOUT = 750, /* ms */
56+
TIS_LONG_TIMEOUT = 2000, /* 2 sec */
57+
};
58+
5459
#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
5560
#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
5661
#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
@@ -96,19 +101,16 @@ static int request_locality(struct tpm_chip *chip, int l)
96101
chip->vendor.iobase + TPM_ACCESS(l));
97102

98103
if (chip->vendor.irq) {
99-
rc = wait_event_interruptible_timeout(chip->vendor.
100-
int_queue,
104+
rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
101105
(check_locality
102106
(chip, l) >= 0),
103-
msecs_to_jiffies
104-
(chip->vendor.
105-
timeout_a));
107+
chip->vendor.timeout_a);
106108
if (rc > 0)
107109
return l;
108110

109111
} else {
110112
/* wait for burstcount */
111-
stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
113+
stop = jiffies + chip->vendor.timeout_a;
112114
do {
113115
if (check_locality(chip, l) >= 0)
114116
return l;
@@ -139,7 +141,7 @@ static int get_burstcount(struct tpm_chip *chip)
139141

140142
/* wait for burstcount */
141143
/* which timeout value, spec has 2 answers (c & d) */
142-
stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);
144+
stop = jiffies + chip->vendor.timeout_d;
143145
do {
144146
burstcnt = ioread8(chip->vendor.iobase +
145147
TPM_STS(chip->vendor.locality) + 1);
@@ -153,7 +155,7 @@ static int get_burstcount(struct tpm_chip *chip)
153155
return -EBUSY;
154156
}
155157

156-
static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
158+
static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
157159
wait_queue_head_t *queue)
158160
{
159161
unsigned long stop;
@@ -169,13 +171,11 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
169171
rc = wait_event_interruptible_timeout(*queue,
170172
((tpm_tis_status
171173
(chip) & mask) ==
172-
mask),
173-
msecs_to_jiffies
174-
(timeout));
174+
mask), timeout);
175175
if (rc > 0)
176176
return 0;
177177
} else {
178-
stop = jiffies + (HZ * timeout / 1000);
178+
stop = jiffies + timeout;
179179
do {
180180
msleep(TPM_TIMEOUT);
181181
status = tpm_tis_status(chip);
@@ -453,10 +453,10 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev
453453
}
454454

455455
/* Default timeouts */
456-
chip->vendor.timeout_a = 750; /* ms */
457-
chip->vendor.timeout_b = 2000; /* 2 sec */
458-
chip->vendor.timeout_c = 750; /* ms */
459-
chip->vendor.timeout_d = 750; /* ms */
456+
chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
457+
chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
458+
chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
459+
chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
460460

461461
dev_info(&pnp_dev->dev,
462462
"1.2 TPM (device-id 0x%X, rev-id %d)\n",

0 commit comments

Comments
 (0)