diff options
-rw-r--r-- | drivers/char/tpm/tpm-interface.c | 67 | ||||
-rw-r--r-- | drivers/char/tpm/tpm.h | 6 | ||||
-rw-r--r-- | drivers/char/tpm/tpm2-cmd.c | 32 |
3 files changed, 44 insertions, 61 deletions
diff --git a/drivers/char/tpm/tpm-interface.c b/drivers/char/tpm/tpm-interface.c index d2b4df6d9894..3123a6e44687 100644 --- a/drivers/char/tpm/tpm-interface.c +++ b/drivers/char/tpm/tpm-interface.c | |||
@@ -540,6 +540,47 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, | |||
540 | } | 540 | } |
541 | EXPORT_SYMBOL_GPL(tpm_transmit_cmd); | 541 | EXPORT_SYMBOL_GPL(tpm_transmit_cmd); |
542 | 542 | ||
543 | #define TPM_ORD_STARTUP 153 | ||
544 | #define TPM_ST_CLEAR 1 | ||
545 | |||
546 | /** | ||
547 | * tpm_startup - turn on the TPM | ||
548 | * @chip: TPM chip to use | ||
549 | * | ||
550 | * Normally the firmware should start the TPM. This function is provided as a | ||
551 | * workaround if this does not happen. A legal case for this could be for | ||
552 | * example when a TPM emulator is used. | ||
553 | * | ||
554 | * Return: same as tpm_transmit_cmd() | ||
555 | */ | ||
556 | int tpm_startup(struct tpm_chip *chip) | ||
557 | { | ||
558 | struct tpm_buf buf; | ||
559 | int rc; | ||
560 | |||
561 | dev_info(&chip->dev, "starting up the TPM manually\n"); | ||
562 | |||
563 | if (chip->flags & TPM_CHIP_FLAG_TPM2) { | ||
564 | rc = tpm_buf_init(&buf, TPM2_ST_NO_SESSIONS, TPM2_CC_STARTUP); | ||
565 | if (rc < 0) | ||
566 | return rc; | ||
567 | |||
568 | tpm_buf_append_u16(&buf, TPM2_SU_CLEAR); | ||
569 | } else { | ||
570 | rc = tpm_buf_init(&buf, TPM_TAG_RQU_COMMAND, TPM_ORD_STARTUP); | ||
571 | if (rc < 0) | ||
572 | return rc; | ||
573 | |||
574 | tpm_buf_append_u16(&buf, TPM_ST_CLEAR); | ||
575 | } | ||
576 | |||
577 | rc = tpm_transmit_cmd(chip, NULL, buf.data, PAGE_SIZE, 0, 0, | ||
578 | "attempting to start the TPM"); | ||
579 | |||
580 | tpm_buf_destroy(&buf); | ||
581 | return rc; | ||
582 | } | ||
583 | |||
543 | #define TPM_DIGEST_SIZE 20 | 584 | #define TPM_DIGEST_SIZE 20 |
544 | #define TPM_RET_CODE_IDX 6 | 585 | #define TPM_RET_CODE_IDX 6 |
545 | #define TPM_INTERNAL_RESULT_SIZE 200 | 586 | #define TPM_INTERNAL_RESULT_SIZE 200 |
@@ -586,27 +627,6 @@ ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, | |||
586 | } | 627 | } |
587 | EXPORT_SYMBOL_GPL(tpm_getcap); | 628 | EXPORT_SYMBOL_GPL(tpm_getcap); |
588 | 629 | ||
589 | #define TPM_ORD_STARTUP 153 | ||
590 | #define TPM_ST_CLEAR cpu_to_be16(1) | ||
591 | #define TPM_ST_STATE cpu_to_be16(2) | ||
592 | #define TPM_ST_DEACTIVATED cpu_to_be16(3) | ||
593 | static const struct tpm_input_header tpm_startup_header = { | ||
594 | .tag = cpu_to_be16(TPM_TAG_RQU_COMMAND), | ||
595 | .length = cpu_to_be32(12), | ||
596 | .ordinal = cpu_to_be32(TPM_ORD_STARTUP) | ||
597 | }; | ||
598 | |||
599 | static int tpm_startup(struct tpm_chip *chip, __be16 startup_type) | ||
600 | { | ||
601 | struct tpm_cmd_t start_cmd; | ||
602 | start_cmd.header.in = tpm_startup_header; | ||
603 | |||
604 | start_cmd.params.startup_in.startup_type = startup_type; | ||
605 | return tpm_transmit_cmd(chip, NULL, &start_cmd, | ||
606 | TPM_INTERNAL_RESULT_SIZE, 0, | ||
607 | 0, "attempting to start the TPM"); | ||
608 | } | ||
609 | |||
610 | int tpm_get_timeouts(struct tpm_chip *chip) | 630 | int tpm_get_timeouts(struct tpm_chip *chip) |
611 | { | 631 | { |
612 | cap_t cap; | 632 | cap_t cap; |
@@ -636,10 +656,7 @@ int tpm_get_timeouts(struct tpm_chip *chip) | |||
636 | rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, NULL, | 656 | rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, NULL, |
637 | sizeof(cap.timeout)); | 657 | sizeof(cap.timeout)); |
638 | if (rc == TPM_ERR_INVALID_POSTINIT) { | 658 | if (rc == TPM_ERR_INVALID_POSTINIT) { |
639 | /* The TPM is not started, we are the first to talk to it. | 659 | if (tpm_startup(chip)) |
640 | Execute a startup command. */ | ||
641 | dev_info(&chip->dev, "Issuing TPM_STARTUP\n"); | ||
642 | if (tpm_startup(chip, TPM_ST_CLEAR)) | ||
643 | return rc; | 660 | return rc; |
644 | 661 | ||
645 | rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, | 662 | rc = tpm_getcap(chip, TPM_CAP_PROP_TIS_TIMEOUT, &cap, |
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index cdd261383dea..71d661a60df2 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h | |||
@@ -382,10 +382,6 @@ struct tpm_getrandom_in { | |||
382 | __be32 num_bytes; | 382 | __be32 num_bytes; |
383 | } __packed; | 383 | } __packed; |
384 | 384 | ||
385 | struct tpm_startup_in { | ||
386 | __be16 startup_type; | ||
387 | } __packed; | ||
388 | |||
389 | typedef union { | 385 | typedef union { |
390 | struct tpm_readpubek_params_out readpubek_out; | 386 | struct tpm_readpubek_params_out readpubek_out; |
391 | u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; | 387 | u8 readpubek_out_buffer[sizeof(struct tpm_readpubek_params_out)]; |
@@ -393,7 +389,6 @@ typedef union { | |||
393 | struct tpm_pcrread_out pcrread_out; | 389 | struct tpm_pcrread_out pcrread_out; |
394 | struct tpm_getrandom_in getrandom_in; | 390 | struct tpm_getrandom_in getrandom_in; |
395 | struct tpm_getrandom_out getrandom_out; | 391 | struct tpm_getrandom_out getrandom_out; |
396 | struct tpm_startup_in startup_in; | ||
397 | } tpm_cmd_params; | 392 | } tpm_cmd_params; |
398 | 393 | ||
399 | struct tpm_cmd_t { | 394 | struct tpm_cmd_t { |
@@ -519,6 +514,7 @@ ssize_t tpm_transmit_cmd(struct tpm_chip *chip, struct tpm_space *space, | |||
519 | const void *buf, size_t bufsiz, | 514 | const void *buf, size_t bufsiz, |
520 | size_t min_rsp_body_length, unsigned int flags, | 515 | size_t min_rsp_body_length, unsigned int flags, |
521 | const char *desc); | 516 | const char *desc); |
517 | int tpm_startup(struct tpm_chip *chip); | ||
522 | ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, | 518 | ssize_t tpm_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, |
523 | const char *desc, size_t min_cap_length); | 519 | const char *desc, size_t min_cap_length); |
524 | int tpm_get_timeouts(struct tpm_chip *); | 520 | int tpm_get_timeouts(struct tpm_chip *); |
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c index 3a9964326279..1962c9b15cd5 100644 --- a/drivers/char/tpm/tpm2-cmd.c +++ b/drivers/char/tpm/tpm2-cmd.c | |||
@@ -779,36 +779,6 @@ ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, u32 *value, | |||
779 | } | 779 | } |
780 | EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt); | 780 | EXPORT_SYMBOL_GPL(tpm2_get_tpm_pt); |
781 | 781 | ||
782 | #define TPM2_STARTUP_IN_SIZE \ | ||
783 | (sizeof(struct tpm_input_header) + \ | ||
784 | sizeof(struct tpm2_startup_in)) | ||
785 | |||
786 | static const struct tpm_input_header tpm2_startup_header = { | ||
787 | .tag = cpu_to_be16(TPM2_ST_NO_SESSIONS), | ||
788 | .length = cpu_to_be32(TPM2_STARTUP_IN_SIZE), | ||
789 | .ordinal = cpu_to_be32(TPM2_CC_STARTUP) | ||
790 | }; | ||
791 | |||
792 | /** | ||
793 | * tpm2_startup() - send startup command to the TPM chip | ||
794 | * | ||
795 | * @chip: TPM chip to use. | ||
796 | * @startup_type: startup type. The value is either | ||
797 | * TPM_SU_CLEAR or TPM_SU_STATE. | ||
798 | * | ||
799 | * Return: Same as with tpm_transmit_cmd. | ||
800 | */ | ||
801 | static int tpm2_startup(struct tpm_chip *chip, u16 startup_type) | ||
802 | { | ||
803 | struct tpm2_cmd cmd; | ||
804 | |||
805 | cmd.header.in = tpm2_startup_header; | ||
806 | |||
807 | cmd.params.startup_in.startup_type = cpu_to_be16(startup_type); | ||
808 | return tpm_transmit_cmd(chip, NULL, &cmd, sizeof(cmd), 0, 0, | ||
809 | "attempting to start the TPM"); | ||
810 | } | ||
811 | |||
812 | #define TPM2_SHUTDOWN_IN_SIZE \ | 782 | #define TPM2_SHUTDOWN_IN_SIZE \ |
813 | (sizeof(struct tpm_input_header) + \ | 783 | (sizeof(struct tpm_input_header) + \ |
814 | sizeof(struct tpm2_startup_in)) | 784 | sizeof(struct tpm2_startup_in)) |
@@ -1150,7 +1120,7 @@ int tpm2_auto_startup(struct tpm_chip *chip) | |||
1150 | } | 1120 | } |
1151 | 1121 | ||
1152 | if (rc == TPM2_RC_INITIALIZE) { | 1122 | if (rc == TPM2_RC_INITIALIZE) { |
1153 | rc = tpm2_startup(chip, TPM2_SU_CLEAR); | 1123 | rc = tpm_startup(chip); |
1154 | if (rc) | 1124 | if (rc) |
1155 | goto out; | 1125 | goto out; |
1156 | 1126 | ||