]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
tpm: Add tpm_version_major sysfs file
authorJerry Snitselaar <jsnitsel@redhat.com>
Wed, 30 Oct 2019 22:58:43 +0000 (15:58 -0700)
committerJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Wed, 22 Jan 2020 08:46:51 +0000 (10:46 +0200)
Easily determining what TCG version a tpm device implements
has been a pain point for userspace for a long time, so
add a sysfs file to report the TCG major version of a tpm device.

Also add an entry to Documentation/ABI/stable/sysfs-class-tpm
describing the new file.

Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Cc: Mimi Zohar <zohar@linux.ibm.com>
Cc: Peter Huewe <peterhuewe@gmx.de>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: linux-integrity@vger.kernel.org
Signed-off-by: Jerry Snitselaar <jsnitsel@redhat.com>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Documentation/ABI/stable/sysfs-class-tpm
drivers/char/tpm/tpm-sysfs.c

index 2881626fefa363ba26c20fda24564cb7b8130864..58e94e7d55be5f8ec949545c677b148f0ec46868 100644 (file)
@@ -183,3 +183,14 @@ Description:       The "timeouts" property shows the 4 vendor-specific values
                The four timeout values are shown in usecs, with a trailing
                "[original]" or "[adjusted]" depending on whether the values
                were scaled by the driver to be reported in usec from msecs.
+
+What:          /sys/class/tpm/tpmX/tpm_version_major
+Date:          October 2019
+KernelVersion: 5.5
+Contact:       linux-integrity@vger.kernel.org
+Description:   The "tpm_version_major" property shows the TCG spec major version
+               implemented by the TPM device.
+
+               Example output:
+
+               2
index 3b53b3e5ec3e7caad780fad060ca99a8e6333c8f..d52bf4df0bca96d83a1233f4b3f870c3365805a2 100644 (file)
@@ -310,7 +310,17 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR_RO(timeouts);
 
-static struct attribute *tpm_dev_attrs[] = {
+static ssize_t tpm_version_major_show(struct device *dev,
+                                 struct device_attribute *attr, char *buf)
+{
+       struct tpm_chip *chip = to_tpm_chip(dev);
+
+       return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
+                      ? "2" : "1");
+}
+static DEVICE_ATTR_RO(tpm_version_major);
+
+static struct attribute *tpm1_dev_attrs[] = {
        &dev_attr_pubek.attr,
        &dev_attr_pcrs.attr,
        &dev_attr_enabled.attr,
@@ -321,18 +331,28 @@ static struct attribute *tpm_dev_attrs[] = {
        &dev_attr_cancel.attr,
        &dev_attr_durations.attr,
        &dev_attr_timeouts.attr,
+       &dev_attr_tpm_version_major.attr,
        NULL,
 };
 
-static const struct attribute_group tpm_dev_group = {
-       .attrs = tpm_dev_attrs,
+static struct attribute *tpm2_dev_attrs[] = {
+       &dev_attr_tpm_version_major.attr,
+       NULL
+};
+
+static const struct attribute_group tpm1_dev_group = {
+       .attrs = tpm1_dev_attrs,
+};
+
+static const struct attribute_group tpm2_dev_group = {
+       .attrs = tpm2_dev_attrs,
 };
 
 void tpm_sysfs_add_device(struct tpm_chip *chip)
 {
-       if (chip->flags & TPM_CHIP_FLAG_TPM2)
-               return;
-
        WARN_ON(chip->groups_cnt != 0);
-       chip->groups[chip->groups_cnt++] = &tpm_dev_group;
+       if (chip->flags & TPM_CHIP_FLAG_TPM2)
+               chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
+       else
+               chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
 }