tpm-interface.c (9938b04472d5c59f8bd8152a548533a8599596a2) | tpm-interface.c (8cfffc9d4d3786d3b496a021d7224e06328bac7d) |
---|---|
1/* 2 * Copyright (C) 2004 IBM Corporation 3 * Copyright (C) 2014 Intel Corporation 4 * 5 * Authors: 6 * Leendert van Doorn <leendert@watson.ibm.com> 7 * Dave Safford <safford@watson.ibm.com> 8 * Reiner Sailer <sailer@watson.ibm.com> --- 331 unchanged lines hidden (view full) --- 340 if (bufsiz > TPM_BUFSIZE) 341 bufsiz = TPM_BUFSIZE; 342 343 count = be32_to_cpu(*((__be32 *) (buf + 2))); 344 ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); 345 if (count == 0) 346 return -ENODATA; 347 if (count > bufsiz) { | 1/* 2 * Copyright (C) 2004 IBM Corporation 3 * Copyright (C) 2014 Intel Corporation 4 * 5 * Authors: 6 * Leendert van Doorn <leendert@watson.ibm.com> 7 * Dave Safford <safford@watson.ibm.com> 8 * Reiner Sailer <sailer@watson.ibm.com> --- 331 unchanged lines hidden (view full) --- 340 if (bufsiz > TPM_BUFSIZE) 341 bufsiz = TPM_BUFSIZE; 342 343 count = be32_to_cpu(*((__be32 *) (buf + 2))); 344 ordinal = be32_to_cpu(*((__be32 *) (buf + 6))); 345 if (count == 0) 346 return -ENODATA; 347 if (count > bufsiz) { |
348 dev_err(chip->pdev, | 348 dev_err(&chip->dev, |
349 "invalid count value %x %zx\n", count, bufsiz); 350 return -E2BIG; 351 } 352 353 mutex_lock(&chip->tpm_mutex); 354 355 rc = chip->ops->send(chip, (u8 *) buf, count); 356 if (rc < 0) { | 349 "invalid count value %x %zx\n", count, bufsiz); 350 return -E2BIG; 351 } 352 353 mutex_lock(&chip->tpm_mutex); 354 355 rc = chip->ops->send(chip, (u8 *) buf, count); 356 if (rc < 0) { |
357 dev_err(chip->pdev, | 357 dev_err(&chip->dev, |
358 "tpm_transmit: tpm_send: error %zd\n", rc); 359 goto out; 360 } 361 362 if (chip->vendor.irq) 363 goto out_recv; 364 365 if (chip->flags & TPM_CHIP_FLAG_TPM2) 366 stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal); 367 else 368 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); 369 do { 370 u8 status = chip->ops->status(chip); 371 if ((status & chip->ops->req_complete_mask) == 372 chip->ops->req_complete_val) 373 goto out_recv; 374 375 if (chip->ops->req_canceled(chip, status)) { | 358 "tpm_transmit: tpm_send: error %zd\n", rc); 359 goto out; 360 } 361 362 if (chip->vendor.irq) 363 goto out_recv; 364 365 if (chip->flags & TPM_CHIP_FLAG_TPM2) 366 stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal); 367 else 368 stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal); 369 do { 370 u8 status = chip->ops->status(chip); 371 if ((status & chip->ops->req_complete_mask) == 372 chip->ops->req_complete_val) 373 goto out_recv; 374 375 if (chip->ops->req_canceled(chip, status)) { |
376 dev_err(chip->pdev, "Operation Canceled\n"); | 376 dev_err(&chip->dev, "Operation Canceled\n"); |
377 rc = -ECANCELED; 378 goto out; 379 } 380 381 msleep(TPM_TIMEOUT); /* CHECK */ 382 rmb(); 383 } while (time_before(jiffies, stop)); 384 385 chip->ops->cancel(chip); | 377 rc = -ECANCELED; 378 goto out; 379 } 380 381 msleep(TPM_TIMEOUT); /* CHECK */ 382 rmb(); 383 } while (time_before(jiffies, stop)); 384 385 chip->ops->cancel(chip); |
386 dev_err(chip->pdev, "Operation Timed out\n"); | 386 dev_err(&chip->dev, "Operation Timed out\n"); |
387 rc = -ETIME; 388 goto out; 389 390out_recv: 391 rc = chip->ops->recv(chip, (u8 *) buf, bufsiz); 392 if (rc < 0) | 387 rc = -ETIME; 388 goto out; 389 390out_recv: 391 rc = chip->ops->recv(chip, (u8 *) buf, bufsiz); 392 if (rc < 0) |
393 dev_err(chip->pdev, | 393 dev_err(&chip->dev, |
394 "tpm_transmit: tpm_recv: error %zd\n", rc); 395out: 396 mutex_unlock(&chip->tpm_mutex); 397 return rc; 398} 399 400#define TPM_DIGEST_SIZE 20 401#define TPM_RET_CODE_IDX 6 --- 9 unchanged lines hidden (view full) --- 411 return len; 412 else if (len < TPM_HEADER_SIZE) 413 return -EFAULT; 414 415 header = cmd; 416 417 err = be32_to_cpu(header->return_code); 418 if (err != 0 && desc) | 394 "tpm_transmit: tpm_recv: error %zd\n", rc); 395out: 396 mutex_unlock(&chip->tpm_mutex); 397 return rc; 398} 399 400#define TPM_DIGEST_SIZE 20 401#define TPM_RET_CODE_IDX 6 --- 9 unchanged lines hidden (view full) --- 411 return len; 412 else if (len < TPM_HEADER_SIZE) 413 return -EFAULT; 414 415 header = cmd; 416 417 err = be32_to_cpu(header->return_code); 418 if (err != 0 && desc) |
419 dev_err(chip->pdev, "A TPM error (%d) occurred %s\n", err, | 419 dev_err(&chip->dev, "A TPM error (%d) occurred %s\n", err, |
420 desc); 421 422 return err; 423} 424 425#define TPM_INTERNAL_RESULT_SIZE 200 426#define TPM_ORD_GET_CAP cpu_to_be32(101) 427#define TPM_ORD_GET_RANDOM cpu_to_be32(70) --- 94 unchanged lines hidden (view full) --- 522 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 523 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); 524 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; 525 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL); 526 527 if (rc == TPM_ERR_INVALID_POSTINIT) { 528 /* The TPM is not started, we are the first to talk to it. 529 Execute a startup command. */ | 420 desc); 421 422 return err; 423} 424 425#define TPM_INTERNAL_RESULT_SIZE 200 426#define TPM_ORD_GET_CAP cpu_to_be32(101) 427#define TPM_ORD_GET_RANDOM cpu_to_be32(70) --- 94 unchanged lines hidden (view full) --- 522 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 523 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); 524 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; 525 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL); 526 527 if (rc == TPM_ERR_INVALID_POSTINIT) { 528 /* The TPM is not started, we are the first to talk to it. 529 Execute a startup command. */ |
530 dev_info(chip->pdev, "Issuing TPM_STARTUP"); | 530 dev_info(&chip->dev, "Issuing TPM_STARTUP"); |
531 if (tpm_startup(chip, TPM_ST_CLEAR)) 532 return rc; 533 534 tpm_cmd.header.in = tpm_getcap_header; 535 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 536 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); 537 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; 538 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 539 NULL); 540 } 541 if (rc) { | 531 if (tpm_startup(chip, TPM_ST_CLEAR)) 532 return rc; 533 534 tpm_cmd.header.in = tpm_getcap_header; 535 tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP; 536 tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4); 537 tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT; 538 rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, 539 NULL); 540 } 541 if (rc) { |
542 dev_err(chip->pdev, | 542 dev_err(&chip->dev, |
543 "A TPM error (%zd) occurred attempting to determine the timeouts\n", 544 rc); 545 goto duration; 546 } 547 548 if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 || 549 be32_to_cpu(tpm_cmd.header.out.length) 550 != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32)) --- 22 unchanged lines hidden (view full) --- 573 for (i = 0; i != ARRAY_SIZE(new_timeout); i++) 574 new_timeout[i] *= 1000; 575 chip->vendor.timeout_adjusted = true; 576 } 577 } 578 579 /* Report adjusted timeouts */ 580 if (chip->vendor.timeout_adjusted) { | 543 "A TPM error (%zd) occurred attempting to determine the timeouts\n", 544 rc); 545 goto duration; 546 } 547 548 if (be32_to_cpu(tpm_cmd.header.out.return_code) != 0 || 549 be32_to_cpu(tpm_cmd.header.out.length) 550 != sizeof(tpm_cmd.header.out) + sizeof(u32) + 4 * sizeof(u32)) --- 22 unchanged lines hidden (view full) --- 573 for (i = 0; i != ARRAY_SIZE(new_timeout); i++) 574 new_timeout[i] *= 1000; 575 chip->vendor.timeout_adjusted = true; 576 } 577 } 578 579 /* Report adjusted timeouts */ 580 if (chip->vendor.timeout_adjusted) { |
581 dev_info(chip->pdev, | 581 dev_info(&chip->dev, |
582 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n", 583 old_timeout[0], new_timeout[0], 584 old_timeout[1], new_timeout[1], 585 old_timeout[2], new_timeout[2], 586 old_timeout[3], new_timeout[3]); 587 } 588 589 chip->vendor.timeout_a = usecs_to_jiffies(new_timeout[0]); --- 30 unchanged lines hidden (view full) --- 620 * fix up the resulting too-small TPM_SHORT value to make things work. 621 * We also scale the TPM_MEDIUM and -_LONG values by 1000. 622 */ 623 if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) { 624 chip->vendor.duration[TPM_SHORT] = HZ; 625 chip->vendor.duration[TPM_MEDIUM] *= 1000; 626 chip->vendor.duration[TPM_LONG] *= 1000; 627 chip->vendor.duration_adjusted = true; | 582 HW_ERR "Adjusting reported timeouts: A %lu->%luus B %lu->%luus C %lu->%luus D %lu->%luus\n", 583 old_timeout[0], new_timeout[0], 584 old_timeout[1], new_timeout[1], 585 old_timeout[2], new_timeout[2], 586 old_timeout[3], new_timeout[3]); 587 } 588 589 chip->vendor.timeout_a = usecs_to_jiffies(new_timeout[0]); --- 30 unchanged lines hidden (view full) --- 620 * fix up the resulting too-small TPM_SHORT value to make things work. 621 * We also scale the TPM_MEDIUM and -_LONG values by 1000. 622 */ 623 if (chip->vendor.duration[TPM_SHORT] < (HZ / 100)) { 624 chip->vendor.duration[TPM_SHORT] = HZ; 625 chip->vendor.duration[TPM_MEDIUM] *= 1000; 626 chip->vendor.duration[TPM_LONG] *= 1000; 627 chip->vendor.duration_adjusted = true; |
628 dev_info(chip->pdev, "Adjusting TPM timeout parameters."); | 628 dev_info(&chip->dev, "Adjusting TPM timeout parameters."); |
629 } 630 return 0; 631} 632EXPORT_SYMBOL_GPL(tpm_get_timeouts); 633 634#define TPM_ORD_CONTINUE_SELFTEST 83 635#define CONTINUE_SELFTEST_RESULT_SIZE 10 636 --- 173 unchanged lines hidden (view full) --- 810 /* Attempt to read a PCR value */ 811 cmd.header.in = pcrread_header; 812 cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0); 813 rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); 814 /* Some buggy TPMs will not respond to tpm_tis_ready() for 815 * around 300ms while the self test is ongoing, keep trying 816 * until the self test duration expires. */ 817 if (rc == -ETIME) { | 629 } 630 return 0; 631} 632EXPORT_SYMBOL_GPL(tpm_get_timeouts); 633 634#define TPM_ORD_CONTINUE_SELFTEST 83 635#define CONTINUE_SELFTEST_RESULT_SIZE 10 636 --- 173 unchanged lines hidden (view full) --- 810 /* Attempt to read a PCR value */ 811 cmd.header.in = pcrread_header; 812 cmd.params.pcrread_in.pcr_idx = cpu_to_be32(0); 813 rc = tpm_transmit(chip, (u8 *) &cmd, READ_PCR_RESULT_SIZE); 814 /* Some buggy TPMs will not respond to tpm_tis_ready() for 815 * around 300ms while the self test is ongoing, keep trying 816 * until the self test duration expires. */ 817 if (rc == -ETIME) { |
818 dev_info(chip->pdev, HW_ERR "TPM command timed out during continue self test"); | 818 dev_info( 819 &chip->dev, HW_ERR 820 "TPM command timed out during continue self test"); |
819 msleep(delay_msec); 820 continue; 821 } 822 823 if (rc < TPM_HEADER_SIZE) 824 return -EFAULT; 825 826 rc = be32_to_cpu(cmd.header.out.return_code); 827 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { | 821 msleep(delay_msec); 822 continue; 823 } 824 825 if (rc < TPM_HEADER_SIZE) 826 return -EFAULT; 827 828 rc = be32_to_cpu(cmd.header.out.return_code); 829 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { |
828 dev_info(chip->pdev, | 830 dev_info(&chip->dev, |
829 "TPM is disabled/deactivated (0x%X)\n", rc); 830 /* TPM is disabled and/or deactivated; driver can 831 * proceed and TPM does handle commands for 832 * suspend/resume correctly 833 */ 834 return 0; 835 } 836 if (rc != TPM_WARN_DOING_SELFTEST) --- 136 unchanged lines hidden (view full) --- 973 * may cause the TPM to invalidate previously saved state. 974 */ 975 if (rc != TPM_WARN_RETRY) 976 break; 977 msleep(TPM_TIMEOUT_RETRY); 978 } 979 980 if (rc) | 831 "TPM is disabled/deactivated (0x%X)\n", rc); 832 /* TPM is disabled and/or deactivated; driver can 833 * proceed and TPM does handle commands for 834 * suspend/resume correctly 835 */ 836 return 0; 837 } 838 if (rc != TPM_WARN_DOING_SELFTEST) --- 136 unchanged lines hidden (view full) --- 975 * may cause the TPM to invalidate previously saved state. 976 */ 977 if (rc != TPM_WARN_RETRY) 978 break; 979 msleep(TPM_TIMEOUT_RETRY); 980 } 981 982 if (rc) |
981 dev_err(chip->pdev, | 983 dev_err(&chip->dev, |
982 "Error (%d) sending savestate before suspend\n", rc); 983 else if (try > 0) | 984 "Error (%d) sending savestate before suspend\n", rc); 985 else if (try > 0) |
984 dev_warn(chip->pdev, "TPM savestate took %dms\n", | 986 dev_warn(&chip->dev, "TPM savestate took %dms\n", |
985 try * TPM_TIMEOUT_RETRY); 986 987 return rc; 988} 989EXPORT_SYMBOL_GPL(tpm_pm_suspend); 990 991/* 992 * Resume from a power safe. The BIOS already restored --- 157 unchanged lines hidden --- | 987 try * TPM_TIMEOUT_RETRY); 988 989 return rc; 990} 991EXPORT_SYMBOL_GPL(tpm_pm_suspend); 992 993/* 994 * Resume from a power safe. The BIOS already restored --- 157 unchanged lines hidden --- |