@@ -466,59 +466,6 @@ int tpm_get_timeouts(struct tpm_chip *chip)
466466}
467467EXPORT_SYMBOL_GPL (tpm_get_timeouts );
468468
469- #define TPM_ORD_CONTINUE_SELFTEST 83
470- #define CONTINUE_SELFTEST_RESULT_SIZE 10
471-
472- static 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- /**
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- */
485- static 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
499- static 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-
505- int 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-
522469/**
523470 * tpm_is_tpm2 - do we a have a TPM2 chip?
524471 * @chip: a &struct tpm_chip instance, %NULL for the default chip
@@ -559,10 +506,12 @@ int tpm_pcr_read(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
559506 chip = tpm_find_get_ops (chip );
560507 if (!chip )
561508 return - ENODEV ;
509+
562510 if (chip -> flags & TPM_CHIP_FLAG_TPM2 )
563511 rc = tpm2_pcr_read (chip , pcr_idx , res_buf );
564512 else
565- rc = tpm_pcr_read_dev (chip , pcr_idx , res_buf );
513+ rc = tpm1_pcr_read_dev (chip , pcr_idx , res_buf );
514+
566515 tpm_put_ops (chip );
567516 return rc ;
568517}
@@ -613,97 +562,6 @@ int tpm_pcr_extend(struct tpm_chip *chip, int pcr_idx, const u8 *hash)
613562}
614563EXPORT_SYMBOL_GPL (tpm_pcr_extend );
615564
616- /**
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- */
624- int 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- }
678- EXPORT_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- */
687- int 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 ;
701- out :
702- if (rc > 0 )
703- rc = - ENODEV ;
704- return rc ;
705- }
706-
707565/**
708566 * tpm_send - send a TPM command
709567 * @chip: a &struct tpm_chip instance, %NULL for the default chip
0 commit comments