Skip to contentSkip to conversation

tpm: Driver for next generation TPM chips

PATCH In review Kylene Jo Hall 5 participants 10 messages Apr 10, 2006 – Apr 12, 2006 TPM device driver

lore
Share & tools
lore
#0 lore raw

PATCH 7/7 tpm: Driver for next generation TPM chips

This patch contains the driver for the next generation of TPM chips version 1.2 including support for interrupts. The Trusted Computing Group has written the TPM Interface Specification (TIS) which defines a common interface for all manufacturer's 1.2 TPM's thus the name tpm_tis.

This updated version of the patch uses the new sysfs files that came about from the comments and changes in patch 6/7. It replaces the 7/7 patch from the original set.

---
 drivers/char/tpm/tpm_tis.c |  638 +++++++++++++++++++++++++++++++++++
 drivers/char/tpm/Kconfig   |   11
 drivers/char/tpm/Makefile  |    1
 drivers/char/tpm/tpm.c     |    3
 drivers/char/tpm/tpm.h     |    9
 5 files changed, 661 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm.h +9 -0
@@ -57,6 +57,8 @@ struct tpm_vendor_specific {
 	void __iomem *iobase;		/* ioremapped address */
 	unsigned long base;		/* TPM base address */
 
+	int irq;
+
 	int region_size;
 	int have_region;
 
@@ -66,8 +68,13 @@ struct tpm_vendor_specific {
 	u8 (*status) (struct tpm_chip *);
 	struct miscdevice miscdev;
 	struct attribute_group *attr_group;
+	struct list_head list;
+	int locality;
 	u32 timeout_a, timeout_b, timeout_c, timeout_d;
 	u32 duration[3];
+
+	wait_queue_head_t read_queue;
+	wait_queue_head_t int_queue;
 };
 
 struct tpm_chip {
@@ -93,6 +100,8 @@ struct tpm_chip {
 	struct list_head list;
 };
 
+#define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
+
 static inline int tpm_read_index(int base, int index)
 {
 	outb(index, base);
drivers/char/tpm/tpm.c +3 -0
@@ -391,6 +391,9 @@ static ssize_t tpm_transmit(struct tpm_c
 		goto out;
 	}
 
+	if (chip->vendor.irq)
+		goto out_recv;
+
 	stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
 	do {
 		u8 status = chip->vendor.status(chip);
drivers/char/tpm/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-$(CONFIG_TCG_TPM) += tpm.o
 ifdef CONFIG_ACPI
 	obj-$(CONFIG_TCG_TPM) += tpm_bios.o
 endif
+obj-$(CONFIG_TCG_TIS) += tpm_tis.o
 obj-$(CONFIG_TCG_NSC) += tpm_nsc.o
 obj-$(CONFIG_TCG_ATMEL) += tpm_atmel.o
 obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
drivers/char/tpm/Kconfig +10 -1
@@ -20,9 +20,18 @@ config TCG_TPM
 	  Note: For more TPM drivers enable CONFIG_PNP, CONFIG_ACPI
 	  and CONFIG_PNPACPI.
 
+config TCG_TIS
+	tristate "TPM Interface Specification 1.2 Interface"
+	depends on TCG_TPM
+	---help---
+	  If you have a TPM security chip that is compliant with the
+	  TCG TIS 1.2 TPM specification say Yes and it will be accessible
+	  from within Linux.  To compile this driver as a module, choose
+	  M here; the module will be called tpm_tis.
+
 config TCG_NSC
 	tristate "National Semiconductor TPM Interface"
-	depends on TCG_TPM
+	depends on TCG_TPM && PNPACPI
 	---help---
 	  If you have a TPM security chip from National Semicondutor 
 	  say Yes and it will be accessible from within Linux.  To 
drivers/char/tpm/tpm_tis.c +638 -0

638 lines not on this page · raw message

#1 lore raw
Quoted 7 lines · Kylene Jo Hall

This patch contains the driver for the next generation of TPM chips version 1.2 including support for interrupts. The Trusted Computing Group has written the TPM Interface Specification (TIS) which defines a common interface for all manufacturer's 1.2 TPM's thus the name tpm_tis.

Quoted 6 lines

This updated version of the patch uses the new sysfs files that came about from the comments and changes in patch 6/7. It replaces the 7/7 patch from the original set.

I've assumed that Leendert is the author of this driver. If incorrect, please let me know. If correct then the way in which we indicate that is to put a From: line right at the top of the changelog.

drivers/char/tpm/tpm_tis.c line 164

Quoted 8 lines
drivers/char/tpm/tpm_tis.c +5 -0
+		interruptible_sleep_on_timeout(&chip->vendor.int_queue,
+					       HZ *
+					       chip->vendor.timeout_a /
+					       1000);
 
...
 
+		interruptible_sleep_on_timeout(queue, HZ * timeout / 1000);

Please don't use the sleep_on functions. They are racy unless (iirc) both the waker and wakee are holding lock_kernel(). If the race hits, we miss a wakeup.

These should be converted to the not-racy wait_event_interruptible().

#2 lore raw

PATCH 1/1 tpm: update to use wait_event calls

Quoted 8 lines · Andrew Morton
Quoted 8 lines
(quoted diff) +4 -0
+		interruptible_sleep_on_timeout(&chip->vendor.int_queue,
+					       HZ *
+					       chip->vendor.timeout_a /
+					       1000);
 
...
Quoted 7 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+		interruptible_sleep_on_timeout(queue, HZ * timeout / 1000);

Please don't use the sleep_on functions. They are racy unless (iirc) both the waker and wakee are holding lock_kernel(). If the race hits, we miss a wakeup.

These should be converted to the not-racy wait_event_interruptible().

Changed in this patch.

Use wait_event_interruptible_timeout in place of interruptible_sleep_on_timeout due to its racy nature.

---
 drivers/char/tpm/tpm_tis.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_tis.c +9 -6
@@ -95,10 +95,10 @@ static int request_locality(struct tpm_c
 		 chip->vendor.iobase + TPM_ACCESS(l));
 
 	if (chip->vendor.irq) {
-		interruptible_sleep_on_timeout(&chip->vendor.int_queue,
-					       HZ *
-					       chip->vendor.timeout_a /
-					       1000);
+		wait_event_interruptible_timeout(chip->vendor.int_queue,
+						 (check_locality(chip, l) >= 0),
+						 HZ * chip->vendor.timeout_a /
+						 1000);
 		if (check_locality(chip, l) >= 0)
 			return l;
 
@@ -150,7 +150,7 @@ static int get_burstcount(struct tpm_chi
 }
 
 static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
-			 wait_queue_head_t * queue)
+			 wait_queue_head_t *queue)
 {
 	unsigned long stop;
 	u8 status;
@@ -161,7 +161,10 @@ static int wait_for_stat(struct tpm_chip
 		return 0;
 
 	if (chip->vendor.irq) {
-		interruptible_sleep_on_timeout(queue, HZ * timeout / 1000);
+		wait_event_interruptible_timeout(*queue,
+						 ((tpm_tis_status(chip) &
+						   mask) == mask),
+						 HZ * timeout / 1000);
 		status = tpm_tis_status(chip);
 		if ((status & mask) == mask)
 			return 0;
#3 lore raw

Re: [PATCH] tpm: update to use wait_event calls

Quoted 33 lines · Kylene Jo Hall
Quoted 8 lines · Andrew Morton
Quoted 8 lines
(quoted diff) +4 -0
+           interruptible_sleep_on_timeout(&chip->vendor.int_queue,
+                                          HZ *
+                                          chip->vendor.timeout_a /
+                                          1000);
 
...
Quoted 7 lines
Quoted 1 line

+ interruptible_sleep_on_timeout(queue, HZ * timeout / 1000);

Please don't use the sleep_on functions. They are racy unless (iirc) both the waker and wakee are holding lock_kernel(). If the race hits, we miss a wakeup.

These should be converted to the not-racy wait_event_interruptible().

Changed in this patch.

Use wait_event_interruptible_timeout in place of interruptible_sleep_on_timeout due to its racy nature.

---
 drivers/char/tpm/tpm_tis.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_tis.c 2006-04-11 14:00:04.341229250 -0500 renamed from drivers/char/tpm/tpm_tis.c 2006-04-11 12:18:35.573996500 -0500 +0 -0
@@ -95,10 +95,10 @@ static int request_locality(struct tpm_c
                 chip->vendor.iobase + TPM_ACCESS(l));
 
        if (chip->vendor.irq) {

drivers/char/tpm/tpm_tis.c 2006-04-11 14:00:04.341229250 -0500 static int request_locality(struct tpm_c · line 103

Quoted 10 lines
drivers/char/tpm/tpm_tis.c 2006-04-11 14:00:04.341229250 -0500 renamed from drivers/char/tpm/tpm_tis.c 2006-04-11 12:18:35.573996500 -0500 +4 -4
-               interruptible_sleep_on_timeout(&chip->vendor.int_queue,
-                                              HZ *
-                                              chip->vendor.timeout_a /
-                                              1000);
+               wait_event_interruptible_timeout(chip->vendor.int_queue,
+                                                (check_locality(chip, l) >= 0),
+                                                HZ * chip->vendor.timeout_a /
+                                                1000);
                if (check_locality(chip, l) >= 0)
                        return l;

Rather than check the condition you slept on right away, couldn't you just store the return value of wait_event_interruptible_timeout()? If it's positive, the condition should be true, if it's negative, then you got a signal, if it's 0, then you timed out. Same would go for the other change.

Thanks,
Nish

#4 lore raw

PATCH 1/1 tpm: use wait_event return code and msecs_to_jiffies

Quoted 5 lines · Nish Aravamudan

Rather than check the condition you slept on right away, couldn't you just store the return value of wait_event_interruptible_timeout()? If it's positive, the condition should be true, if it's negative, then you got a signal, if it's 0, then you timed out. Same would go for the other change.

Quoted 1 line · Ingo Oeser

what about using msecs_to_jiffies(chip->vendor.timeout_a) for this?

Great ideas, patch included below.

Update the usage of wait_event calls to utilize the return code and msecs_to_jiffies.

---
 drivers/char/tpm/tpm_tis.c |   28 +++++++++++++++++-----------
 1 files changed, 17 insertions(+), 11 deletions(-)
drivers/char/tpm/tpm_tis.c +17 -11
@@ -87,6 +87,7 @@ static void release_locality(struct tpm_
 static int request_locality(struct tpm_chip *chip, int l)
 {
 	unsigned long stop;
+	long rc;
 
 	if (check_locality(chip, l) >= 0)
 		return l;
@@ -95,11 +96,14 @@ static int request_locality(struct tpm_c
 		 chip->vendor.iobase + TPM_ACCESS(l));
 
 	if (chip->vendor.irq) {
-		wait_event_interruptible_timeout(chip->vendor.int_queue,
-						 (check_locality(chip, l) >= 0),
-						 HZ * chip->vendor.timeout_a /
-						 1000);
-		if (check_locality(chip, l) >= 0)
+		rc = wait_event_interruptible_timeout(chip->vendor.
+						      int_queue,
+						      (check_locality
+						       (chip, l) >= 0),
+						      msecs_to_jiffies
+						      (chip->vendor.
+						       timeout_a));
+		if (rc > 0)
 			return l;
 
 	} else {
@@ -153,6 +157,7 @@ static int wait_for_stat(struct tpm_chip
 			 wait_queue_head_t *queue)
 {
 	unsigned long stop;
+	long rc;
 	u8 status;
 
 	/* check current status */
@@ -161,12 +166,13 @@ static int wait_for_stat(struct tpm_chip
 		return 0;
 
 	if (chip->vendor.irq) {
-		wait_event_interruptible_timeout(*queue,
-						 ((tpm_tis_status(chip) &
-						   mask) == mask),
-						 HZ * timeout / 1000);
-		status = tpm_tis_status(chip);
-		if ((status & mask) == mask)
+		rc = wait_event_interruptible_timeout(*queue,
+						      ((tpm_tis_status
+							(chip) & mask) ==
+						       mask),
+						      msecs_to_jiffies
+						      (timeout));
+		if (rc > 0)
 			return 0;
 	} else {
 		stop = jiffies + (HZ * timeout / 1000);
#5 lore raw

Re: [PATCH] tpm: update to use wait_event calls

In reply to Kylene Jo Hall

Hi Kylene,

Quoted 11 lines · Kylene Jo Hall
---
 drivers/char/tpm/tpm_tis.c |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_tis.c +0 -0
@@ -95,10 +95,10 @@ static int request_locality(struct tpm_c
 		 chip->vendor.iobase + TPM_ACCESS(l));
 
 	if (chip->vendor.irq) {

drivers/char/tpm/tpm_tis.c static int request_locality(struct tpm_c · line 103

Quoted 10 lines
drivers/char/tpm/tpm_tis.c +4 -4
-		interruptible_sleep_on_timeout(&chip->vendor.int_queue,
-					       HZ *
-					       chip->vendor.timeout_a /
-					       1000);
+		wait_event_interruptible_timeout(chip->vendor.int_queue,
+						 (check_locality(chip, l) >= 0),
+						 HZ * chip->vendor.timeout_a /
+						 1000);
 		if (check_locality(chip, l) >= 0)
 			return l;

what about using msecs_to_jiffies(chip->vendor.timeout_a) for this?

Quoted 12 lines
drivers/char/tpm/tpm_tis.c +1 -1
@@ -150,7 +150,7 @@ static int get_burstcount(struct tpm_chi
 }
 
 static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
-			 wait_queue_head_t * queue)
+			 wait_queue_head_t *queue)
 {
 	unsigned long stop;
 	u8 status;
@@ -161,7 +161,10 @@ static int wait_for_stat(struct tpm_chip
 		return 0;

drivers/char/tpm/tpm_tis.c static int wait_for_stat(struct tpm_chip · line 170

Quoted 10 lines
drivers/char/tpm/tpm_tis.c +4 -1
 
 	if (chip->vendor.irq) {
-		interruptible_sleep_on_timeout(queue, HZ * timeout / 1000);
+		wait_event_interruptible_timeout(*queue,
+						 ((tpm_tis_status(chip) &
+						   mask) == mask),
+						 HZ * timeout / 1000);
 		status = tpm_tis_status(chip);
 		if ((status & mask) == mask)
 			return 0;

msecs_to_jiffies(timeout)?

Regards

Ingo Oeser

#6 lore raw
In reply to Kylene Jo Hall
Quoted 9 lines · Kylene Jo Hall

This patch contains the driver for the next generation of TPM chips version 1.2 including support for interrupts. The Trusted Computing Group has written the TPM Interface Specification (TIS) which defines a common interface for all manufacturer's 1.2 TPM's thus the name tpm_tis.

This updated version of the patch uses the new sysfs files that came about from the comments and changes in patch 6/7. It replaces the 7/7 patch from the original set.

<snip>

Quoted 18 lines
drivers/char/tpm/tpm_tis.c +18 -0
+static int request_locality(struct tpm_chip *chip, int l)
+{
+	unsigned long stop;
+
+	if (check_locality(chip, l) >= 0)
+		return l;
+
+	iowrite8(TPM_ACCESS_REQUEST_USE,
+		 chip->vendor.iobase + TPM_ACCESS(l));
+
+	if (chip->vendor.irq) {
+		interruptible_sleep_on_timeout(&chip->vendor.int_queue,
+					       HZ *
+					       chip->vendor.timeout_a /
+					       1000);
+		if (check_locality(chip, l) >= 0)
+			return l;
+

drivers/char/tpm/tpm_tis.c line 114

Quoted 10 lines
drivers/char/tpm/tpm_tis.c +10 -0
+	} else {
+		/* wait for burstcount */
+		stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
+		do {
+			if (check_locality(chip, l) >= 0)
+				return l;
+			msleep(TPM_TIMEOUT);
+		}
+		while (time_before(jiffies, stop));
+	}

This looks like it could take the msecs_to_jiffies() conversion as well. Might as well cache it before the if/else, as both clauses use it? Really, it is just wait_event*() without the wait-queue. Well, this is at least one more consumer potentially of the poll_event*() API I had written a while back, I'll dust it off again if I have the time.

<snip>

drivers/char/tpm/tpm_tis.c line 138

Quoted 8 lines
drivers/char/tpm/tpm_tis.c +8 -0
+static int get_burstcount(struct tpm_chip *chip)
+{
+	unsigned long stop;
+	int burstcnt;
+
+	/* wait for burstcount */
+	/* which timeout value, spec has 2 answers (c & d) */
+	stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);

msecs_to_jiffies().

<snip>

With the changes you've already made, that should clean up the sleeping code a bit, at least.

Signature · 2 lines
Nishanth Aravamudan <[email protected]>
IBM Linux Technology Center
#7 lore raw
Quoted 21 lines · Nishanth Aravamudan

return l;

drivers/char/tpm/tpm_tis.c line 114

Quoted 11 lines
drivers/char/tpm/tpm_tis.c +11 -0
+
+	} else {
+		/* wait for burstcount */
+		stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
+		do {
+			if (check_locality(chip, l) >= 0)
+				return l;
+			msleep(TPM_TIMEOUT);
+		}
+		while (time_before(jiffies, stop));
+	}

This looks like it could take the msecs_to_jiffies() conversion as well. Might as well cache it before the if/else, as both clauses use it? Really, it is just wait_event*() without the wait-queue. Well, this is at least one more consumer potentially of the poll_event*() API I had written a while back, I'll dust it off again if I have the time.

<snip>

Quoted 12 lines

drivers/char/tpm/tpm_tis.c line 138

Quoted 8 lines
drivers/char/tpm/tpm_tis.c +8 -0
+static int get_burstcount(struct tpm_chip *chip)
+{
+	unsigned long stop;
+	int burstcnt;
+
+	/* wait for burstcount */
+	/* which timeout value, spec has 2 answers (c & d) */
+	stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);

msecs_to_jiffies().

Since the timeout and duration values are always used in jiffies I think I'll just convert them to those values when I store them in the chip struct to cut way down on the number of conversions all together. Sound reasonable?

Thanks,
Kylie

#8 lore raw
Quoted 35 lines · Kylene Jo Hall
Quoted 21 lines · Nishanth Aravamudan

return l;

drivers/char/tpm/tpm_tis.c line 114

Quoted 11 lines
drivers/char/tpm/tpm_tis.c +11 -0
+
+	} else {
+		/* wait for burstcount */
+		stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
+		do {
+			if (check_locality(chip, l) >= 0)
+				return l;
+			msleep(TPM_TIMEOUT);
+		}
+		while (time_before(jiffies, stop));
+	}

This looks like it could take the msecs_to_jiffies() conversion as well. Might as well cache it before the if/else, as both clauses use it? Really, it is just wait_event*() without the wait-queue. Well, this is at least one more consumer potentially of the poll_event*() API I had written a while back, I'll dust it off again if I have the time.

<snip>

Quoted 12 lines

drivers/char/tpm/tpm_tis.c line 138

Quoted 8 lines
drivers/char/tpm/tpm_tis.c +8 -0
+static int get_burstcount(struct tpm_chip *chip)
+{
+	unsigned long stop;
+	int burstcnt;
+
+	/* wait for burstcount */
+	/* which timeout value, spec has 2 answers (c & d) */
+	stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);

msecs_to_jiffies().

Quoted 4 lines

Since the timeout and duration values are always used in jiffies I think I'll just convert them to those values when I store them in the chip struct to cut way down on the number of conversions all together. Sound reasonable?

Probably, as long as they aren't exposed to userspace in any way. I don't think userspace should do any calculations in jiffies units.

Thanks,
Nish

Signature · 2 lines
Nishanth Aravamudan <[email protected]>
IBM Linux Technology Center
#9 lore raw

PATCH 1/1 tpm: msecs_to_jiffies cleanups

Quoted 8 lines · Nishanth Aravamudan
Quoted 7 lines · Kylene Jo Hall
Quoted 6 lines · Nishanth Aravamudan

This looks like it could take the msecs_to_jiffies() conversion as well. Might as well cache it before the if/else, as both clauses use it? Really, it is just wait_event*() without the wait-queue. Well, this is at least one more consumer potentially of the poll_event*() API I had written a while back, I'll dust it off again if I have the time.

Quoted 7 lines
Quoted 4 lines

Since the timeout and duration values are always used in jiffies I think I'll just convert them to those values when I store them in the chip struct to cut way down on the number of conversions all together. Sound reasonable?

Probably, as long as they aren't exposed to userspace in any way. I don't think userspace should do any calculations in jiffies units.

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.

---
 drivers/char/tpm/tpm.c     |   22 ++++++++++++++--------
 drivers/char/tpm/tpm.h     |    4 ++--
 drivers/char/tpm/tpm_tis.c |   32 ++++++++++++++++----------------
 3 files changed, 32 insertions(+), 26 deletions(-)
drivers/char/tpm/tpm.h +2 -2
@@ -77,8 +77,8 @@ struct tpm_vendor_specific {
 	struct attribute_group *attr_group;
 	struct list_head list;
 	int locality;
-	u32 timeout_a, timeout_b, timeout_c, timeout_d;
-	u32 duration[3];
+	unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
+	unsigned long duration[3]; /* jiffies */
 
 	wait_queue_head_t read_queue;
 	wait_queue_head_t int_queue;
drivers/char/tpm/tpm.c +14 -8
@@ -354,7 +354,7 @@ unsigned long tpm_calc_ordinal_duration(
 						   TPM_PROTECTED_ORDINAL_MASK];
 
 	if (duration_idx != TPM_UNDEFINED)
-		duration = chip->vendor.duration[duration_idx] * HZ / 1000;
+		duration = chip->vendor.duration[duration_idx];
 	if (duration <= 0)
 		return 2 * 60 * HZ;
 	else
@@ -524,19 +524,19 @@ void tpm_get_timeouts(struct tpm_chip *c
 	timeout = 
 	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
 	if (timeout)
-		chip->vendor.timeout_a = timeout;
+		chip->vendor.timeout_a = msecs_to_jiffies(timeout);
 	timeout =
 	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
 	if (timeout)
-		chip->vendor.timeout_b = timeout;
+		chip->vendor.timeout_b = msecs_to_jiffies(timeout);
 	timeout =
 	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
 	if (timeout)
-		chip->vendor.timeout_c = timeout;
+		chip->vendor.timeout_c = msecs_to_jiffies(timeout);
 	timeout =
 	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
 	if (timeout)
-		chip->vendor.timeout_d = timeout;
+		chip->vendor.timeout_d = msecs_to_jiffies(timeout);
 
 duration:
 	memcpy(data, tpm_cap, sizeof(tpm_cap));
@@ -553,11 +553,17 @@ duration:
 		return;
 
 	chip->vendor.duration[TPM_SHORT] =
-	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
+	    msecs_to_jiffies(be32_to_cpu
+			     (*((__be32 *) (data +
+					    TPM_GET_CAP_RET_UINT32_1_IDX))));
 	chip->vendor.duration[TPM_MEDIUM] =
-	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
+	    msecs_to_jiffies(be32_to_cpu
+			     (*((__be32 *) (data +
+					    TPM_GET_CAP_RET_UINT32_2_IDX))));
 	chip->vendor.duration[TPM_LONG] =
-	    be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
+	    msecs_to_jiffies(be32_to_cpu
+			     (*((__be32 *) (data +
+					    TPM_GET_CAP_RET_UINT32_3_IDX))));
 }
 EXPORT_SYMBOL_GPL(tpm_get_timeouts);
 
drivers/char/tpm/tpm_tis.c +16 -16
@@ -51,6 +51,11 @@ enum tis_int_flags {
 	TPM_INTF_DATA_AVAIL_INT = 0x001,
 };
 
+enum tis_defaults {
+	TIS_SHORT_TIMEOUT = 750, /* ms */
+	TIS_LONG_TIMEOUT = 2000, /* 2 sec */
+};
+
 #define	TPM_ACCESS(l)			(0x0000 | ((l) << 12))
 #define	TPM_INT_ENABLE(l)		(0x0008 | ((l) << 12))
 #define	TPM_INT_VECTOR(l)		(0x000C | ((l) << 12))
@@ -96,19 +103,16 @@ static int request_locality(struct tpm_c
 		 chip->vendor.iobase + TPM_ACCESS(l));
 
 	if (chip->vendor.irq) {
-		rc = wait_event_interruptible_timeout(chip->vendor.
-						      int_queue,
+		rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
 						      (check_locality
 						       (chip, l) >= 0),
-						      msecs_to_jiffies
-						      (chip->vendor.
-						       timeout_a));
+						      chip->vendor.timeout_a);
 		if (rc > 0)
 			return l;
 
 	} else {
 		/* wait for burstcount */
-		stop = jiffies + (HZ * chip->vendor.timeout_a / 1000);
+		stop = jiffies + chip->vendor.timeout_a;
 		do {
 			if (check_locality(chip, l) >= 0)
 				return l;
@@ -139,7 +143,7 @@ static int get_burstcount(struct tpm_chi
 
 	/* wait for burstcount */
 	/* which timeout value, spec has 2 answers (c & d) */
-	stop = jiffies + (HZ * chip->vendor.timeout_d / 1000);
+	stop = jiffies + chip->vendor.timeout_d;
 	do {
 		burstcnt = ioread8(chip->vendor.iobase +
 				   TPM_STS(chip->vendor.locality) + 1);
@@ -153,7 +157,7 @@ static int get_burstcount(struct tpm_chi
 	return -EBUSY;
 }
 
-static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
+static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
 			 wait_queue_head_t *queue)
 {
 	unsigned long stop;
@@ -169,13 +173,11 @@ static int wait_for_stat(struct tpm_chip
 		rc = wait_event_interruptible_timeout(*queue,
 						      ((tpm_tis_status
 							(chip) & mask) ==
-						       mask),
-						      msecs_to_jiffies
-						      (timeout));
+						       mask), timeout);
 		if (rc > 0)
 			return 0;
 	} else {
-		stop = jiffies + (HZ * timeout / 1000);
+		stop = jiffies + timeout;
 		do {
 			msleep(TPM_TIMEOUT);
 			status = tpm_tis_status(chip);
@@ -453,10 +460,10 @@ static int __devinit tpm_tis_pnp_init(st
 	}
 
 	/* Default timeouts */
-	chip->vendor.timeout_a = 750;	/* ms */
-	chip->vendor.timeout_b = 2000;	/* 2 sec */
-	chip->vendor.timeout_c = 750;	/* ms */
-	chip->vendor.timeout_d = 750;	/* ms */
+	chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
+	chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
+	chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
+	chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
 
 	dev_info(&pnp_dev->dev,
 		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",