Skip to content

Commit 7084edd

Browse files
snitsJarkko Sakkinen
authored andcommitted
tpm: Add tpm_version_major sysfs file
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 <[email protected]> Cc: Mimi Zohar <[email protected]> Cc: Peter Huewe <[email protected]> Cc: Jason Gunthorpe <[email protected]> Cc: [email protected] Signed-off-by: Jerry Snitselaar <[email protected]> Reviewed-by: Mimi Zohar <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> Signed-off-by: Jarkko Sakkinen <[email protected]>
1 parent c269e87 commit 7084edd

File tree

2 files changed

+38
-7
lines changed

2 files changed

+38
-7
lines changed

Documentation/ABI/stable/sysfs-class-tpm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,14 @@ Description: The "timeouts" property shows the 4 vendor-specific values
183183
The four timeout values are shown in usecs, with a trailing
184184
"[original]" or "[adjusted]" depending on whether the values
185185
were scaled by the driver to be reported in usec from msecs.
186+
187+
What: /sys/class/tpm/tpmX/tpm_version_major
188+
Date: October 2019
189+
KernelVersion: 5.5
190+
191+
Description: The "tpm_version_major" property shows the TCG spec major version
192+
implemented by the TPM device.
193+
194+
Example output:
195+
196+
2

drivers/char/tpm/tpm-sysfs.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,17 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr,
310310
}
311311
static DEVICE_ATTR_RO(timeouts);
312312

313-
static struct attribute *tpm_dev_attrs[] = {
313+
static ssize_t tpm_version_major_show(struct device *dev,
314+
struct device_attribute *attr, char *buf)
315+
{
316+
struct tpm_chip *chip = to_tpm_chip(dev);
317+
318+
return sprintf(buf, "%s\n", chip->flags & TPM_CHIP_FLAG_TPM2
319+
? "2" : "1");
320+
}
321+
static DEVICE_ATTR_RO(tpm_version_major);
322+
323+
static struct attribute *tpm1_dev_attrs[] = {
314324
&dev_attr_pubek.attr,
315325
&dev_attr_pcrs.attr,
316326
&dev_attr_enabled.attr,
@@ -321,18 +331,28 @@ static struct attribute *tpm_dev_attrs[] = {
321331
&dev_attr_cancel.attr,
322332
&dev_attr_durations.attr,
323333
&dev_attr_timeouts.attr,
334+
&dev_attr_tpm_version_major.attr,
324335
NULL,
325336
};
326337

327-
static const struct attribute_group tpm_dev_group = {
328-
.attrs = tpm_dev_attrs,
338+
static struct attribute *tpm2_dev_attrs[] = {
339+
&dev_attr_tpm_version_major.attr,
340+
NULL
341+
};
342+
343+
static const struct attribute_group tpm1_dev_group = {
344+
.attrs = tpm1_dev_attrs,
345+
};
346+
347+
static const struct attribute_group tpm2_dev_group = {
348+
.attrs = tpm2_dev_attrs,
329349
};
330350

331351
void tpm_sysfs_add_device(struct tpm_chip *chip)
332352
{
333-
if (chip->flags & TPM_CHIP_FLAG_TPM2)
334-
return;
335-
336353
WARN_ON(chip->groups_cnt != 0);
337-
chip->groups[chip->groups_cnt++] = &tpm_dev_group;
354+
if (chip->flags & TPM_CHIP_FLAG_TPM2)
355+
chip->groups[chip->groups_cnt++] = &tpm2_dev_group;
356+
else
357+
chip->groups[chip->groups_cnt++] = &tpm1_dev_group;
338358
}

0 commit comments

Comments
 (0)