aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/tpm/tpm_tis.c
diff options
context:
space:
mode:
authorRajiv Andrade <srajiv@linux.vnet.ibm.com>2011-09-16 13:39:40 -0400
committerRajiv Andrade <srajiv@linux.vnet.ibm.com>2011-11-16 06:44:55 -0500
commitfd04886660208ab2e35baaca55588afa57d52c9c (patch)
tree200fd2b5a472317472f36cd452f60b1e5b42874f /drivers/char/tpm/tpm_tis.c
parent9efa54f002cc03fdb4e9d8d508aa996af01c48d0 (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/tpm/tpm_tis.c')
-rw-r--r--drivers/char/tpm/tpm_tis.c64
1 files changed, 12 insertions, 52 deletions
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
196static 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) {
211again:
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
236static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count) 196static 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) {