The timeouts and durations files exist only for TPM 1.x chips, so a
TPM 2.0 chip exposes none of its wait limits, even when tpm.limits= or
a driver's ->adjust_limits() hook changes them.

Both files read the limits table, so add them to the TPM 2.0 attributes
too. A TPM 2.0 chip reports none of these values, so for it "[adjusted]"
means that tpm.limits= or a driver's ->adjust_limits() hook set one of
the shown values, or that validation changed one. TPM 2.0 chips get no
device/ links, so the files are /sys/class/tpm/tpmX/timeouts and
durations.

Signed-off-by: Surendran Kanagaraj <[email protected]>
---
 drivers/char/tpm/tpm-sysfs.c |  2 ++
 drivers/char/tpm/tpm2-cmd.c  | 17 +++++++++++++++++
 2 files changed, 19 insertions(+)

diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index b289a7f6f085..6bfc366fa120 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -340,6 +340,8 @@ static struct attribute *tpm1_dev_attrs[] = {
 
 static struct attribute *tpm2_dev_attrs[] = {
        &dev_attr_tpm_version_major.attr,
+       &dev_attr_durations.attr,
+       &dev_attr_timeouts.attr,
 #ifdef CONFIG_TCG_TPM2_HMAC
        &dev_attr_null_name.attr,
 #endif
diff --git a/drivers/char/tpm/tpm2-cmd.c b/drivers/char/tpm/tpm2-cmd.c
index 629caaeffa17..8cc1a262d668 100644
--- a/drivers/char/tpm/tpm2-cmd.c
+++ b/drivers/char/tpm/tpm2-cmd.c
@@ -41,9 +41,26 @@ int tpm2_find_hash_alg(unsigned int crypto_id)
 }
 EXPORT_SYMBOL_GPL(tpm2_find_hash_alg);
 
+static bool tpm2_limits_adjusted(struct tpm_chip *chip, unsigned long mask)
+{
+       const struct tpm_limit_entry *e = chip->limits.entry;
+       int limit;
+
+       for_each_set_bit(limit, &mask, TPM_NR_LIMITS) {
+               if (e[limit].src != TPM_LSRC_DEFAULT ||
+                   e[limit].flags & TPM_LF_CLAMPED)
+                       return true;
+       }
+
+       return false;
+}
+
 int tpm2_get_timeouts(struct tpm_chip *chip)
 {
        tpm_limits_update(chip, NULL);
+       chip->timeout_adjusted = tpm2_limits_adjusted(chip, 
TPM_LIMIT_INTF_MASK);
+       chip->duration_adjusted =
+               tpm2_limits_adjusted(chip, TPM1_LIMIT_DURATION_MASK);
        chip->flags |= TPM_CHIP_FLAG_HAVE_TIMEOUTS;
        return 0;
 }
-- 
2.47.3


Reply via email to