aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKylene Jo Hall <kjhall@us.ibm.com>2006-04-22 05:38:19 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-04-22 12:19:54 -0400
commit36b20020e537036c4f9eb5b69140c88ead5da7dc (patch)
tree71a83d0da45630fe3c3a69c446823716164fbcc1 /drivers
parent27084efee0c3dc0eb15b5ed750aa9f1adb3983c3 (diff)
[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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/tpm/tpm.c22
-rw-r--r--drivers/char/tpm/tpm.h4
-rw-r--r--drivers/char/tpm/tpm_tis.c32
3 files changed, 32 insertions, 26 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index 150c86af7809..160dc080d580 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -354,7 +354,7 @@ unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip,
354 TPM_PROTECTED_ORDINAL_MASK]; 354 TPM_PROTECTED_ORDINAL_MASK];
355 355
356 if (duration_idx != TPM_UNDEFINED) 356 if (duration_idx != TPM_UNDEFINED)
357 duration = chip->vendor.duration[duration_idx] * HZ / 1000; 357 duration = chip->vendor.duration[duration_idx];
358 if (duration <= 0) 358 if (duration <= 0)
359 return 2 * 60 * HZ; 359 return 2 * 60 * HZ;
360 else 360 else
@@ -524,19 +524,19 @@ void tpm_get_timeouts(struct tpm_chip *chip)
524 timeout = 524 timeout =
525 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))); 525 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
526 if (timeout) 526 if (timeout)
527 chip->vendor.timeout_a = timeout; 527 chip->vendor.timeout_a = msecs_to_jiffies(timeout);
528 timeout = 528 timeout =
529 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX))); 529 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
530 if (timeout) 530 if (timeout)
531 chip->vendor.timeout_b = timeout; 531 chip->vendor.timeout_b = msecs_to_jiffies(timeout);
532 timeout = 532 timeout =
533 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX))); 533 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
534 if (timeout) 534 if (timeout)
535 chip->vendor.timeout_c = timeout; 535 chip->vendor.timeout_c = msecs_to_jiffies(timeout);
536 timeout = 536 timeout =
537 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX))); 537 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
538 if (timeout) 538 if (timeout)
539 chip->vendor.timeout_d = timeout; 539 chip->vendor.timeout_d = msecs_to_jiffies(timeout);
540 540
541duration: 541duration:
542 memcpy(data, tpm_cap, sizeof(tpm_cap)); 542 memcpy(data, tpm_cap, sizeof(tpm_cap));
@@ -553,11 +553,17 @@ duration:
553 return; 553 return;
554 554
555 chip->vendor.duration[TPM_SHORT] = 555 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))));
557 chip->vendor.duration[TPM_MEDIUM] = 559 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))));
559 chip->vendor.duration[TPM_LONG] = 563 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))));
561} 567}
562EXPORT_SYMBOL_GPL(tpm_get_timeouts); 568EXPORT_SYMBOL_GPL(tpm_get_timeouts);
563 569
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index 24541a556d02..54a4c804e25f 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -77,8 +77,8 @@ struct tpm_vendor_specific {
77 struct attribute_group *attr_group; 77 struct attribute_group *attr_group;
78 struct list_head list; 78 struct list_head list;
79 int locality; 79 int locality;
80 u32 timeout_a, timeout_b, timeout_c, timeout_d; 80 unsigned long timeout_a, timeout_b, timeout_c, timeout_d; /* jiffies */
81 u32 duration[3]; 81 unsigned long duration[3]; /* jiffies */
82 82
83 wait_queue_head_t read_queue; 83 wait_queue_head_t read_queue;
84 wait_queue_head_t int_queue; 84 wait_queue_head_t int_queue;
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 02759307f736..1cb5a7f0755d 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -51,6 +51,11 @@ enum tis_int_flags {
51 TPM_INTF_DATA_AVAIL_INT = 0x001, 51 TPM_INTF_DATA_AVAIL_INT = 0x001,
52}; 52};
53 53
54enum tis_defaults {
55 TIS_SHORT_TIMEOUT = 750, /* ms */
56 TIS_LONG_TIMEOUT = 2000, /* 2 sec */
57};
58
54#define TPM_ACCESS(l) (0x0000 | ((l) << 12)) 59#define TPM_ACCESS(l) (0x0000 | ((l) << 12))
55#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) 60#define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12))
56#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) 61#define TPM_INT_VECTOR(l) (0x000C | ((l) << 12))
@@ -96,19 +101,16 @@ static int request_locality(struct tpm_chip *chip, int l)
96 chip->vendor.iobase + TPM_ACCESS(l)); 101 chip->vendor.iobase + TPM_ACCESS(l));
97 102
98 if (chip->vendor.irq) { 103 if (chip->vendor.irq) {
99 rc = wait_event_interruptible_timeout(chip->vendor. 104 rc = wait_event_interruptible_timeout(chip->vendor.int_queue,
100 int_queue,
101 (check_locality 105 (check_locality
102 (chip, l) >= 0), 106 (chip, l) >= 0),
103 msecs_to_jiffies 107 chip->vendor.timeout_a);
104 (chip->vendor.
105 timeout_a));
106 if (rc > 0) 108 if (rc > 0)
107 return l; 109 return l;
108 110
109 } else { 111 } else {
110 /* wait for burstcount */ 112 /* wait for burstcount */
111 stop = jiffies + (HZ * chip->vendor.timeout_a / 1000); 113 stop = jiffies + chip->vendor.timeout_a;
112 do { 114 do {
113 if (check_locality(chip, l) >= 0) 115 if (check_locality(chip, l) >= 0)
114 return l; 116 return l;
@@ -139,7 +141,7 @@ static int get_burstcount(struct tpm_chip *chip)
139 141
140 /* wait for burstcount */ 142 /* wait for burstcount */
141 /* which timeout value, spec has 2 answers (c & d) */ 143 /* 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;
143 do { 145 do {
144 burstcnt = ioread8(chip->vendor.iobase + 146 burstcnt = ioread8(chip->vendor.iobase +
145 TPM_STS(chip->vendor.locality) + 1); 147 TPM_STS(chip->vendor.locality) + 1);
@@ -153,7 +155,7 @@ static int get_burstcount(struct tpm_chip *chip)
153 return -EBUSY; 155 return -EBUSY;
154} 156}
155 157
156static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout, 158static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout,
157 wait_queue_head_t *queue) 159 wait_queue_head_t *queue)
158{ 160{
159 unsigned long stop; 161 unsigned long stop;
@@ -169,13 +171,11 @@ static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout,
169 rc = wait_event_interruptible_timeout(*queue, 171 rc = wait_event_interruptible_timeout(*queue,
170 ((tpm_tis_status 172 ((tpm_tis_status
171 (chip) & mask) == 173 (chip) & mask) ==
172 mask), 174 mask), timeout);
173 msecs_to_jiffies
174 (timeout));
175 if (rc > 0) 175 if (rc > 0)
176 return 0; 176 return 0;
177 } else { 177 } else {
178 stop = jiffies + (HZ * timeout / 1000); 178 stop = jiffies + timeout;
179 do { 179 do {
180 msleep(TPM_TIMEOUT); 180 msleep(TPM_TIMEOUT);
181 status = tpm_tis_status(chip); 181 status = tpm_tis_status(chip);
@@ -453,10 +453,10 @@ static int __devinit tpm_tis_pnp_init(struct pnp_dev
453 } 453 }
454 454
455 /* Default timeouts */ 455 /* Default timeouts */
456 chip->vendor.timeout_a = 750; /* ms */ 456 chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
457 chip->vendor.timeout_b = 2000; /* 2 sec */ 457 chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
458 chip->vendor.timeout_c = 750; /* ms */ 458 chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
459 chip->vendor.timeout_d = 750; /* ms */ 459 chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
460 460
461 dev_info(&pnp_dev->dev, 461 dev_info(&pnp_dev->dev,
462 "1.2 TPM (device-id 0x%X, rev-id %d)\n", 462 "1.2 TPM (device-id 0x%X, rev-id %d)\n",