summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/char/tpm/tpm-chip.c20
-rw-r--r--drivers/char/tpm/tpm.h2
-rw-r--r--drivers/char/tpm/tpm1-cmd.c36
-rw-r--r--drivers/char/tpm/tpm2-cmd.c6
4 files changed, 47 insertions, 17 deletions
diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c
index bf868260f435..4838c6a9f0f2 100644
--- a/drivers/char/tpm/tpm-chip.c
+++ b/drivers/char/tpm/tpm-chip.c
@@ -554,6 +554,20 @@ static int tpm_add_hwrng(struct tpm_chip *chip)
554 return hwrng_register(&chip->hwrng); 554 return hwrng_register(&chip->hwrng);
555} 555}
556 556
557static int tpm_get_pcr_allocation(struct tpm_chip *chip)
558{
559 int rc;
560
561 rc = (chip->flags & TPM_CHIP_FLAG_TPM2) ?
562 tpm2_get_pcr_allocation(chip) :
563 tpm1_get_pcr_allocation(chip);
564
565 if (rc > 0)
566 return -ENODEV;
567
568 return rc;
569}
570
557/* 571/*
558 * tpm_chip_register() - create a character device for the TPM chip 572 * tpm_chip_register() - create a character device for the TPM chip
559 * @chip: TPM chip to use. 573 * @chip: TPM chip to use.
@@ -573,6 +587,12 @@ int tpm_chip_register(struct tpm_chip *chip)
573 if (rc) 587 if (rc)
574 return rc; 588 return rc;
575 rc = tpm_auto_startup(chip); 589 rc = tpm_auto_startup(chip);
590 if (rc) {
591 tpm_chip_stop(chip);
592 return rc;
593 }
594
595 rc = tpm_get_pcr_allocation(chip);
576 tpm_chip_stop(chip); 596 tpm_chip_stop(chip);
577 if (rc) 597 if (rc)
578 return rc; 598 return rc;
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index e503ffc3aa39..a7fea3e0ca86 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -394,6 +394,7 @@ int tpm1_pcr_read(struct tpm_chip *chip, u32 pcr_idx, u8 *res_buf);
394ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap, 394ssize_t tpm1_getcap(struct tpm_chip *chip, u32 subcap_id, cap_t *cap,
395 const char *desc, size_t min_cap_length); 395 const char *desc, size_t min_cap_length);
396int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max); 396int tpm1_get_random(struct tpm_chip *chip, u8 *out, size_t max);
397int tpm1_get_pcr_allocation(struct tpm_chip *chip);
397unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); 398unsigned long tpm_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
398int tpm_pm_suspend(struct device *dev); 399int tpm_pm_suspend(struct device *dev);
399int tpm_pm_resume(struct device *dev); 400int tpm_pm_resume(struct device *dev);
@@ -449,6 +450,7 @@ int tpm2_unseal_trusted(struct tpm_chip *chip,
449ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id, 450ssize_t tpm2_get_tpm_pt(struct tpm_chip *chip, u32 property_id,
450 u32 *value, const char *desc); 451 u32 *value, const char *desc);
451 452
453ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip);
452int tpm2_auto_startup(struct tpm_chip *chip); 454int tpm2_auto_startup(struct tpm_chip *chip);
453void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type); 455void tpm2_shutdown(struct tpm_chip *chip, u16 shutdown_type);
454unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal); 456unsigned long tpm2_calc_ordinal_duration(struct tpm_chip *chip, u32 ordinal);
diff --git a/drivers/char/tpm/tpm1-cmd.c b/drivers/char/tpm/tpm1-cmd.c
index faacbe1ffa1a..149e953ca369 100644
--- a/drivers/char/tpm/tpm1-cmd.c
+++ b/drivers/char/tpm/tpm1-cmd.c
@@ -699,18 +699,6 @@ int tpm1_auto_startup(struct tpm_chip *chip)
699 goto out; 699 goto out;
700 } 700 }
701 701
702 chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks),
703 GFP_KERNEL);
704 if (!chip->allocated_banks) {
705 rc = -ENOMEM;
706 goto out;
707 }
708
709 chip->allocated_banks[0].alg_id = TPM_ALG_SHA1;
710 chip->allocated_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1];
711 chip->allocated_banks[0].crypto_id = HASH_ALGO_SHA1;
712 chip->nr_allocated_banks = 1;
713
714 return rc; 702 return rc;
715out: 703out:
716 if (rc > 0) 704 if (rc > 0)
@@ -779,3 +767,27 @@ int tpm1_pm_suspend(struct tpm_chip *chip, u32 tpm_suspend_pcr)
779 return rc; 767 return rc;
780} 768}
781 769
770/**
771 * tpm1_get_pcr_allocation() - initialize the allocated bank
772 * @chip: TPM chip to use.
773 *
774 * The function initializes the SHA1 allocated bank to extend PCR
775 *
776 * Return:
777 * * 0 on success,
778 * * < 0 on error.
779 */
780int tpm1_get_pcr_allocation(struct tpm_chip *chip)
781{
782 chip->allocated_banks = kcalloc(1, sizeof(*chip->allocated_banks),
783 GFP_KERNEL);
784 if (!chip->allocated_banks)
785 return -ENOMEM;
786
787 chip->allocated_banks[0].alg_id = TPM_ALG_SHA1;
788 chip->allocated_banks[0].digest_size = hash_digest_size[HASH_ALGO_SHA1];
789 chip->allocated_banks[0].crypto_id = HASH_ALGO_SHA1;
790 chip->nr_allocated_banks = 1;
791
792 return 0;
793}
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index d103545e4055..ba9acae83bff 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -840,7 +840,7 @@ struct tpm2_pcr_selection {
840 u8 pcr_select[3]; 840 u8 pcr_select[3];
841} __packed; 841} __packed;
842 842
843static ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip) 843ssize_t tpm2_get_pcr_allocation(struct tpm_chip *chip)
844{ 844{
845 struct tpm2_pcr_selection pcr_selection; 845 struct tpm2_pcr_selection pcr_selection;
846 struct tpm_buf buf; 846 struct tpm_buf buf;
@@ -1040,10 +1040,6 @@ int tpm2_auto_startup(struct tpm_chip *chip)
1040 goto out; 1040 goto out;
1041 } 1041 }
1042 1042
1043 rc = tpm2_get_pcr_allocation(chip);
1044 if (rc)
1045 goto out;
1046
1047 rc = tpm2_get_cc_attrs_tbl(chip); 1043 rc = tpm2_get_cc_attrs_tbl(chip);
1048 1044
1049out: 1045out: