[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>

authored by Kylene Jo Hall and committed by Linus Torvalds 36b20020 27084efe

+32 -26
+14 -8
drivers/char/tpm/tpm.c
··· 354 354 TPM_PROTECTED_ORDINAL_MASK]; 355 355 356 356 if (duration_idx != TPM_UNDEFINED) 357 - duration = chip->vendor.duration[duration_idx] * HZ / 1000; 357 + duration = chip->vendor.duration[duration_idx]; 358 358 if (duration <= 0) 359 359 return 2 * 60 * HZ; 360 360 else ··· 524 524 timeout = 525 525 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))); 526 526 if (timeout) 527 - chip->vendor.timeout_a = timeout; 527 + chip->vendor.timeout_a = msecs_to_jiffies(timeout); 528 528 timeout = 529 529 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX))); 530 530 if (timeout) 531 - chip->vendor.timeout_b = timeout; 531 + chip->vendor.timeout_b = msecs_to_jiffies(timeout); 532 532 timeout = 533 533 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX))); 534 534 if (timeout) 535 - chip->vendor.timeout_c = timeout; 535 + chip->vendor.timeout_c = msecs_to_jiffies(timeout); 536 536 timeout = 537 537 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX))); 538 538 if (timeout) 539 - chip->vendor.timeout_d = timeout; 539 + chip->vendor.timeout_d = msecs_to_jiffies(timeout); 540 540 541 541 duration: 542 542 memcpy(data, tpm_cap, sizeof(tpm_cap)); ··· 553 553 return; 554 554 555 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 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 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 } 562 568 EXPORT_SYMBOL_GPL(tpm_get_timeouts); 563 569
+2 -2
drivers/char/tpm/tpm.h
··· 77 77 struct attribute_group *attr_group; 78 78 struct list_head list; 79 79 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 */ 82 82 83 83 wait_queue_head_t read_queue; 84 84 wait_queue_head_t int_queue;
+16 -16
drivers/char/tpm/tpm_tis.c
··· 51 51 TPM_INTF_DATA_AVAIL_INT = 0x001, 52 52 }; 53 53 54 + enum tis_defaults { 55 + TIS_SHORT_TIMEOUT = 750, /* ms */ 56 + TIS_LONG_TIMEOUT = 2000, /* 2 sec */ 57 + }; 58 + 54 59 #define TPM_ACCESS(l) (0x0000 | ((l) << 12)) 55 60 #define TPM_INT_ENABLE(l) (0x0008 | ((l) << 12)) 56 61 #define TPM_INT_VECTOR(l) (0x000C | ((l) << 12)) ··· 101 96 chip->vendor.iobase + TPM_ACCESS(l)); 102 97 103 98 if (chip->vendor.irq) { 104 - rc = wait_event_interruptible_timeout(chip->vendor. 105 - int_queue, 99 + rc = wait_event_interruptible_timeout(chip->vendor.int_queue, 106 100 (check_locality 107 101 (chip, l) >= 0), 108 - msecs_to_jiffies 109 - (chip->vendor. 110 - timeout_a)); 102 + chip->vendor.timeout_a); 111 103 if (rc > 0) 112 104 return l; 113 105 114 106 } else { 115 107 /* wait for burstcount */ 116 - stop = jiffies + (HZ * chip->vendor.timeout_a / 1000); 108 + stop = jiffies + chip->vendor.timeout_a; 117 109 do { 118 110 if (check_locality(chip, l) >= 0) 119 111 return l; ··· 141 139 142 140 /* wait for burstcount */ 143 141 /* which timeout value, spec has 2 answers (c & d) */ 144 - stop = jiffies + (HZ * chip->vendor.timeout_d / 1000); 142 + stop = jiffies + chip->vendor.timeout_d; 145 143 do { 146 144 burstcnt = ioread8(chip->vendor.iobase + 147 145 TPM_STS(chip->vendor.locality) + 1); ··· 155 153 return -EBUSY; 156 154 } 157 155 158 - static int wait_for_stat(struct tpm_chip *chip, u8 mask, u32 timeout, 156 + static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, 159 157 wait_queue_head_t *queue) 160 158 { 161 159 unsigned long stop; ··· 171 169 rc = wait_event_interruptible_timeout(*queue, 172 170 ((tpm_tis_status 173 171 (chip) & mask) == 174 - mask), 175 - msecs_to_jiffies 176 - (timeout)); 172 + mask), timeout); 177 173 if (rc > 0) 178 174 return 0; 179 175 } else { 180 - stop = jiffies + (HZ * timeout / 1000); 176 + stop = jiffies + timeout; 181 177 do { 182 178 msleep(TPM_TIMEOUT); 183 179 status = tpm_tis_status(chip); ··· 453 453 } 454 454 455 455 /* 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); 460 460 461 461 dev_info(&pnp_dev->dev, 462 462 "1.2 TPM (device-id 0x%X, rev-id %d)\n",