diff options
author | Rajiv Andrade <srajiv@linux.vnet.ibm.com> | 2011-09-16 13:39:40 -0400 |
---|---|---|
committer | Rajiv Andrade <srajiv@linux.vnet.ibm.com> | 2011-11-16 06:44:55 -0500 |
commit | fd04886660208ab2e35baaca55588afa57d52c9c (patch) | |
tree | 200fd2b5a472317472f36cd452f60b1e5b42874f /drivers/char | |
parent | 9efa54f002cc03fdb4e9d8d508aa996af01c48d0 (diff) |
TPM: Export wait_for_stat for other vendor specific drivers
Moved wait_for_stat to tpm.c so that other drivers can use it.
Also renamed it to avoid future namespace conflicts.
Signed-off-by: Rajiv Andrade <srajiv@linux.vnet.ibm.com>
Diffstat (limited to 'drivers/char')
-rw-r--r-- | drivers/char/tpm/tpm.c | 41 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.h | 3 | ||||
-rw-r--r-- | drivers/char/tpm/tpm_tis.c | 64 |
3 files changed, 55 insertions, 53 deletions
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c index 2e12b3f98139..efd24bbb5cb1 100644 --- a/drivers/char/tpm/tpm.c +++ b/drivers/char/tpm/tpm.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/mutex.h> | 28 | #include <linux/mutex.h> |
29 | #include <linux/spinlock.h> | 29 | #include <linux/spinlock.h> |
30 | #include <linux/freezer.h> | ||
30 | 31 | ||
31 | #include "tpm.h" | 32 | #include "tpm.h" |
32 | 33 | ||
@@ -1057,6 +1058,46 @@ ssize_t tpm_store_cancel(struct device *dev, struct device_attribute *attr, | |||
1057 | } | 1058 | } |
1058 | EXPORT_SYMBOL_GPL(tpm_store_cancel); | 1059 | EXPORT_SYMBOL_GPL(tpm_store_cancel); |
1059 | 1060 | ||
1061 | int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, | ||
1062 | wait_queue_head_t *queue) | ||
1063 | { | ||
1064 | unsigned long stop; | ||
1065 | long rc; | ||
1066 | u8 status; | ||
1067 | |||
1068 | /* check current status */ | ||
1069 | status = chip->vendor.status(chip); | ||
1070 | if ((status & mask) == mask) | ||
1071 | return 0; | ||
1072 | |||
1073 | stop = jiffies + timeout; | ||
1074 | |||
1075 | if (chip->vendor.irq) { | ||
1076 | again: | ||
1077 | timeout = stop - jiffies; | ||
1078 | if ((long)timeout <= 0) | ||
1079 | return -ETIME; | ||
1080 | rc = wait_event_interruptible_timeout(*queue, | ||
1081 | ((chip->vendor.status(chip) | ||
1082 | & mask) == mask), | ||
1083 | timeout); | ||
1084 | if (rc > 0) | ||
1085 | return 0; | ||
1086 | if (rc == -ERESTARTSYS && freezing(current)) { | ||
1087 | clear_thread_flag(TIF_SIGPENDING); | ||
1088 | goto again; | ||
1089 | } | ||
1090 | } else { | ||
1091 | do { | ||
1092 | msleep(TPM_TIMEOUT); | ||
1093 | status = chip->vendor.status(chip); | ||
1094 | if ((status & mask) == mask) | ||
1095 | return 0; | ||
1096 | } while (time_before(jiffies, stop)); | ||
1097 | } | ||
1098 | return -ETIME; | ||
1099 | } | ||
1100 | EXPORT_SYMBOL_GPL(wait_for_tpm_stat); | ||
1060 | /* | 1101 | /* |
1061 | * Device file system interface to the TPM | 1102 | * Device file system interface to the TPM |
1062 | * | 1103 | * |
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index e264de16285f..9deb65c0ab61 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
@@ -296,7 +296,8 @@ extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); | |||
296 | extern void tpm_remove_hardware(struct device *); | 296 | extern void tpm_remove_hardware(struct device *); |
297 | extern int tpm_pm_suspend(struct device *, pm_message_t); | 297 | extern int tpm_pm_suspend(struct device *, pm_message_t); |
298 | extern int tpm_pm_resume(struct device *); | 298 | extern int tpm_pm_resume(struct device *); |
299 | 299 | extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long, | |
300 | wait_queue_head_t *); | ||
300 | #ifdef CONFIG_ACPI | 301 | #ifdef CONFIG_ACPI |
301 | extern struct dentry ** tpm_bios_log_setup(char *); | 302 | extern struct dentry ** tpm_bios_log_setup(char *); |
302 | extern void tpm_bios_log_teardown(struct dentry **); | 303 | extern void tpm_bios_log_teardown(struct dentry **); |
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index e4553eb6e542..92f9f34e88f7 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c | |||
@@ -193,54 +193,14 @@ static int get_burstcount(struct tpm_chip *chip) | |||
193 | return -EBUSY; | 193 | return -EBUSY; |
194 | } | 194 | } |
195 | 195 | ||
196 | static int wait_for_stat(struct tpm_chip *chip, u8 mask, unsigned long timeout, | ||
197 | wait_queue_head_t *queue) | ||
198 | { | ||
199 | unsigned long stop; | ||
200 | long rc; | ||
201 | u8 status; | ||
202 | |||
203 | /* check current status */ | ||
204 | status = chip->vendor.status(chip); | ||
205 | if ((status & mask) == mask) | ||
206 | return 0; | ||
207 | |||
208 | stop = jiffies + timeout; | ||
209 | |||
210 | if (chip->vendor.irq) { | ||
211 | again: | ||
212 | timeout = stop - jiffies; | ||
213 | if ((long)timeout <= 0) | ||
214 | return -ETIME; | ||
215 | rc = wait_event_interruptible_timeout(*queue, | ||
216 | ((chip->vendor.status(chip) | ||
217 | & mask) == mask), | ||
218 | timeout); | ||
219 | if (rc > 0) | ||
220 | return 0; | ||
221 | if (rc == -ERESTARTSYS && freezing(current)) { | ||
222 | clear_thread_flag(TIF_SIGPENDING); | ||
223 | goto again; | ||
224 | } | ||
225 | } else { | ||
226 | do { | ||
227 | msleep(TPM_TIMEOUT); | ||
228 | status = chip->vendor.status(chip); | ||
229 | if ((status & mask) == mask) | ||
230 | return 0; | ||
231 | } while (time_before(jiffies, stop)); | ||
232 | } | ||
233 | return -ETIME; | ||
234 | } | ||
235 | |||
236 | static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) | 196 | static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) |
237 | { | 197 | { |
238 | int size = 0, burstcnt; | 198 | int size = 0, burstcnt; |
239 | while (size < count && | 199 | while (size < count && |
240 | wait_for_stat(chip, | 200 | wait_for_tpm_stat(chip, |
241 | TPM_STS_DATA_AVAIL | TPM_STS_VALID, | 201 | TPM_STS_DATA_AVAIL | TPM_STS_VALID, |
242 | chip->vendor.timeout_c, | 202 | chip->vendor.timeout_c, |
243 | &chip->vendor.read_queue) | 203 | &chip->vendor.read_queue) |
244 | == 0) { | 204 | == 0) { |
245 | burstcnt = get_burstcount(chip); | 205 | burstcnt = get_burstcount(chip); |
246 | for (; burstcnt > 0 && size < count; burstcnt--) | 206 | for (; burstcnt > 0 && size < count; burstcnt--) |
@@ -282,8 +242,8 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) | |||
282 | goto out; | 242 | goto out; |
283 | } | 243 | } |
284 | 244 | ||
285 | wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, | 245 | wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, |
286 | &chip->vendor.int_queue); | 246 | &chip->vendor.int_queue); |
287 | status = tpm_tis_status(chip); | 247 | status = tpm_tis_status(chip); |
288 | if (status & TPM_STS_DATA_AVAIL) { /* retry? */ | 248 | if (status & TPM_STS_DATA_AVAIL) { /* retry? */ |
289 | dev_err(chip->dev, "Error left over data\n"); | 249 | dev_err(chip->dev, "Error left over data\n"); |
@@ -317,7 +277,7 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) | |||
317 | status = tpm_tis_status(chip); | 277 | status = tpm_tis_status(chip); |
318 | if ((status & TPM_STS_COMMAND_READY) == 0) { | 278 | if ((status & TPM_STS_COMMAND_READY) == 0) { |
319 | tpm_tis_ready(chip); | 279 | tpm_tis_ready(chip); |
320 | if (wait_for_stat | 280 | if (wait_for_tpm_stat |
321 | (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, | 281 | (chip, TPM_STS_COMMAND_READY, chip->vendor.timeout_b, |
322 | &chip->vendor.int_queue) < 0) { | 282 | &chip->vendor.int_queue) < 0) { |
323 | rc = -ETIME; | 283 | rc = -ETIME; |
@@ -333,8 +293,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) | |||
333 | count++; | 293 | count++; |
334 | } | 294 | } |
335 | 295 | ||
336 | wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, | 296 | wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, |
337 | &chip->vendor.int_queue); | 297 | &chip->vendor.int_queue); |
338 | status = tpm_tis_status(chip); | 298 | status = tpm_tis_status(chip); |
339 | if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { | 299 | if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) { |
340 | rc = -EIO; | 300 | rc = -EIO; |
@@ -345,8 +305,8 @@ static int tpm_tis_send_data(struct tpm_chip *chip, u8 *buf, size_t len) | |||
345 | /* write last byte */ | 305 | /* write last byte */ |
346 | iowrite8(buf[count], | 306 | iowrite8(buf[count], |
347 | chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality)); | 307 | chip->vendor.iobase + TPM_DATA_FIFO(chip->vendor.locality)); |
348 | wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, | 308 | wait_for_tpm_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, |
349 | &chip->vendor.int_queue); | 309 | &chip->vendor.int_queue); |
350 | status = tpm_tis_status(chip); | 310 | status = tpm_tis_status(chip); |
351 | if ((status & TPM_STS_DATA_EXPECT) != 0) { | 311 | if ((status & TPM_STS_DATA_EXPECT) != 0) { |
352 | rc = -EIO; | 312 | rc = -EIO; |
@@ -381,7 +341,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len) | |||
381 | 341 | ||
382 | if (chip->vendor.irq) { | 342 | if (chip->vendor.irq) { |
383 | ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); | 343 | ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); |
384 | if (wait_for_stat | 344 | if (wait_for_tpm_stat |
385 | (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, | 345 | (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, |
386 | tpm_calc_ordinal_duration(chip, ordinal), | 346 | tpm_calc_ordinal_duration(chip, ordinal), |
387 | &chip->vendor.read_queue) < 0) { | 347 | &chip->vendor.read_queue) < 0) { |