tpm-interface.c (433d390f005d3a89dba5a03a87b5a6c242748de3) | tpm-interface.c (d4a317563207163ddcf677e5965ffc56ef073514) |
---|---|
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> --- 452 unchanged lines hidden (view full) --- 461 462 if (chip->flags & TPM_CHIP_FLAG_TPM2) 463 return tpm2_get_timeouts(chip); 464 else 465 return tpm1_get_timeouts(chip); 466} 467EXPORT_SYMBOL_GPL(tpm_get_timeouts); 468 | 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> --- 452 unchanged lines hidden (view full) --- 461 462 if (chip->flags & TPM_CHIP_FLAG_TPM2) 463 return tpm2_get_timeouts(chip); 464 else 465 return tpm1_get_timeouts(chip); 466} 467EXPORT_SYMBOL_GPL(tpm_get_timeouts); 468 |
469#define TPM_ORD_CONTINUE_SELFTEST 83 470#define CONTINUE_SELFTEST_RESULT_SIZE 10 471 472static const struct tpm_input_header continue_selftest_header = { 473 .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), 474 .length = cpu_to_be32(10), 475 .ordinal = cpu_to_be32(TPM_ORD_CONTINUE_SELFTEST), 476}; 477 | |
478/** | 469/** |
479 * tpm_continue_selftest -- run TPM's selftest 480 * @chip: TPM chip to use 481 * 482 * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing 483 * a TPM error code. 484 */ 485static int tpm_continue_selftest(struct tpm_chip *chip) 486{ 487 int rc; 488 struct tpm_cmd_t cmd; 489 490 cmd.header.in = continue_selftest_header; 491 rc = tpm_transmit_cmd(chip, NULL, &cmd, CONTINUE_SELFTEST_RESULT_SIZE, 492 0, 0, "continue selftest"); 493 return rc; 494} 495 496#define TPM_ORDINAL_PCRREAD 21 497#define READ_PCR_RESULT_SIZE 30 498#define READ_PCR_RESULT_BODY_SIZE 20 499static const struct tpm_input_header pcrread_header = { 500 .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), 501 .length = cpu_to_be32(14), 502 .ordinal = cpu_to_be32(TPM_ORDINAL_PCRREAD) 503}; 504 505int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) 506{ 507 int rc; 508 struct tpm_cmd_t cmd; 509 510 cmd.header.in = pcrread_header; 511 cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx); 512 rc = tpm_transmit_cmd(chip, NULL, &cmd, READ_PCR_RESULT_SIZE, 513 READ_PCR_RESULT_BODY_SIZE, 0, 514 "attempting to read a pcr value"); 515 516 if (rc == 0) 517 memcpy(res_buf, cmd.params.pcrread_out.pcr_result, 518 TPM_DIGEST_SIZE); 519 return rc; 520} 521 522/** | |
523 * tpm_is_tpm2 - do we a have a TPM2 chip? 524 * @chip: a &struct tpm_chip instance, %NULL for the default chip 525 * 526 * Return: 527 * 1 if we have a TPM2 chip. 528 * 0 if we don't have a TPM2 chip. 529 * A negative number for system errors (errno). 530 */ --- 23 unchanged lines hidden (view full) --- 554 */ 555int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) 556{ 557 int rc; 558 559 chip = tpm_find_get_ops(chip); 560 if (!chip) 561 return -ENODEV; | 470 * tpm_is_tpm2 - do we a have a TPM2 chip? 471 * @chip: a &struct tpm_chip instance, %NULL for the default chip 472 * 473 * Return: 474 * 1 if we have a TPM2 chip. 475 * 0 if we don't have a TPM2 chip. 476 * A negative number for system errors (errno). 477 */ --- 23 unchanged lines hidden (view full) --- 501 */ 502int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf) 503{ 504 int rc; 505 506 chip = tpm_find_get_ops(chip); 507 if (!chip) 508 return -ENODEV; |
509 |
|
562 if (chip->flags & TPM_CHIP_FLAG_TPM2) 563 rc = tpm2_pcr_read(chip, pcr_idx, res_buf); 564 else | 510 if (chip->flags & TPM_CHIP_FLAG_TPM2) 511 rc = tpm2_pcr_read(chip, pcr_idx, res_buf); 512 else |
565 rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf); | 513 rc = tpm1_pcr_read_dev(chip, pcr_idx, res_buf); 514 |
566 tpm_put_ops(chip); 567 return rc; 568} 569EXPORT_SYMBOL_GPL(tpm_pcr_read); 570 571/** 572 * tpm_pcr_extend - extend a PCR value in SHA1 bank. 573 * @chip: a &struct tpm_chip instance, %NULL for the default chip --- 35 unchanged lines hidden (view full) --- 609 rc = tpm1_pcr_extend(chip, pcr_idx, hash, 610 "attempting extend a PCR value"); 611 tpm_put_ops(chip); 612 return rc; 613} 614EXPORT_SYMBOL_GPL(tpm_pcr_extend); 615 616/** | 515 tpm_put_ops(chip); 516 return rc; 517} 518EXPORT_SYMBOL_GPL(tpm_pcr_read); 519 520/** 521 * tpm_pcr_extend - extend a PCR value in SHA1 bank. 522 * @chip: a &struct tpm_chip instance, %NULL for the default chip --- 35 unchanged lines hidden (view full) --- 558 rc = tpm1_pcr_extend(chip, pcr_idx, hash, 559 "attempting extend a PCR value"); 560 tpm_put_ops(chip); 561 return rc; 562} 563EXPORT_SYMBOL_GPL(tpm_pcr_extend); 564 565/** |
617 * tpm_do_selftest - have the TPM continue its selftest and wait until it 618 * can receive further commands 619 * @chip: TPM chip to use 620 * 621 * Returns 0 on success, < 0 in case of fatal error or a value > 0 representing 622 * a TPM error code. 623 */ 624int tpm_do_selftest(struct tpm_chip *chip) 625{ 626 int rc; 627 unsigned int loops; 628 unsigned int delay_msec = 100; 629 unsigned long duration; 630 u8 dummy[TPM_DIGEST_SIZE]; 631 632 duration = tpm1_calc_ordinal_duration(chip, TPM_ORD_CONTINUE_SELFTEST); 633 634 loops = jiffies_to_msecs(duration) / delay_msec; 635 636 rc = tpm_continue_selftest(chip); 637 if (rc == TPM_ERR_INVALID_POSTINIT) { 638 chip->flags |= TPM_CHIP_FLAG_ALWAYS_POWERED; 639 dev_info(&chip->dev, "TPM not ready (%d)\n", rc); 640 } 641 /* This may fail if there was no TPM driver during a suspend/resume 642 * cycle; some may return 10 (BAD_ORDINAL), others 28 (FAILEDSELFTEST) 643 */ 644 if (rc) 645 return rc; 646 647 do { 648 /* Attempt to read a PCR value */ 649 rc = tpm_pcr_read_dev(chip, 0, dummy); 650 651 /* Some buggy TPMs will not respond to tpm_tis_ready() for 652 * around 300ms while the self test is ongoing, keep trying 653 * until the self test duration expires. */ 654 if (rc == -ETIME) { 655 dev_info( 656 &chip->dev, HW_ERR 657 "TPM command timed out during continue self test"); 658 tpm_msleep(delay_msec); 659 continue; 660 } 661 662 if (rc == TPM_ERR_DISABLED || rc == TPM_ERR_DEACTIVATED) { 663 dev_info(&chip->dev, 664 "TPM is disabled/deactivated (0x%X)\n", rc); 665 /* TPM is disabled and/or deactivated; driver can 666 * proceed and TPM does handle commands for 667 * suspend/resume correctly 668 */ 669 return 0; 670 } 671 if (rc != TPM_WARN_DOING_SELFTEST) 672 return rc; 673 tpm_msleep(delay_msec); 674 } while (--loops > 0); 675 676 return rc; 677} 678EXPORT_SYMBOL_GPL(tpm_do_selftest); 679 680/** 681 * tpm1_auto_startup - Perform the standard automatic TPM initialization 682 * sequence 683 * @chip: TPM chip to use 684 * 685 * Returns 0 on success, < 0 in case of fatal error. 686 */ 687int tpm1_auto_startup(struct tpm_chip *chip) 688{ 689 int rc; 690 691 rc = tpm_get_timeouts(chip); 692 if (rc) 693 goto out; 694 rc = tpm_do_selftest(chip); 695 if (rc) { 696 dev_err(&chip->dev, "TPM self test failed\n"); 697 goto out; 698 } 699 700 return rc; 701out: 702 if (rc > 0) 703 rc = -ENODEV; 704 return rc; 705} 706 707/** | |
708 * tpm_send - send a TPM command 709 * @chip: a &struct tpm_chip instance, %NULL for the default chip 710 * @cmd: a TPM command buffer 711 * @buflen: the length of the TPM command buffer 712 * 713 * Return: same as with tpm_transmit_cmd() 714 */ 715int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) --- 240 unchanged lines hidden --- | 566 * tpm_send - send a TPM command 567 * @chip: a &struct tpm_chip instance, %NULL for the default chip 568 * @cmd: a TPM command buffer 569 * @buflen: the length of the TPM command buffer 570 * 571 * Return: same as with tpm_transmit_cmd() 572 */ 573int tpm_send(struct tpm_chip *chip, void *cmd, size_t buflen) --- 240 unchanged lines hidden --- |