blob: ceaa627cc9c57102e3a37db72e2b5d9de95cdd0e [file] [log] [blame]
From e5c36cf8236c221c1d7357548ec85a41482c50a8 Mon Sep 17 00:00:00 2001
From: Yi Chou <yich@google.com>
Date: Mon, 9 Aug 2021 16:13:08 +0800
Subject: [PATCH] Reland "CHROMIUM: tpm: expose the DID_VID information"
This relands commit 40eedf6399b7 ("CHROMIUM: tpm: expose the DID_VID information")
Diff: Increased the size of attribute_groups of tpm_chip.
Original change's description:
> CHROMIUM: tpm: expose the DID_VID information
>
> This patch exposes tht DID_VID to userspace, so userspace program could
> use this file to get the DID_VID information.
>
> BUG=b:191499174
> TEST=check the content of /sys/class/tpm/tpm0/did_vid
>
> Signed-off-by: Yi Chou <yich@google.com>
> Change-Id: I1eaa727f43ac372ddb3f9cd0049ca0a054f4064a
> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3106049
> Reviewed-by: Nicholas Bishop <nicholasbishop@google.com>
> Reviewed-by: Andrey Pronin <apronin@chromium.org>
BUG=b:191499174
TEST=check the content of /sys/class/tpm/tpm0/did_vid on ACPI TPM device
Signed-off-by: Yi Chou <yich@google.com>
Change-Id: I5f5901cf137ab7c93f26c4376738aa10b62d2cb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/3116425
Reviewed-by: Andrey Pronin <apronin@chromium.org>
---
drivers/char/tpm/tpm_tis_core.c | 28 ++++++++++++++++++++++++++++
include/linux/tpm.h | 2 +-
2 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/drivers/char/tpm/tpm_tis_core.c b/drivers/char/tpm/tpm_tis_core.c
--- a/drivers/char/tpm/tpm_tis_core.c
+++ b/drivers/char/tpm/tpm_tis_core.c
@@ -925,6 +925,31 @@ static const struct tpm_class_ops tpm_tis = {
.clk_enable = tpm_tis_clkrun_enable,
};
+static ssize_t did_vid_show(struct device *dev, struct device_attribute *attr,
+ char *buf)
+{
+ struct tpm_tis_data *priv = dev_get_drvdata(dev);
+ u32 did_vid = 0;
+ int rc;
+
+ rc = tpm_tis_read32(priv, TPM_DID_VID(0), &did_vid);
+ if (rc < 0) {
+ dev_warn(dev, "%s: failed to read did_vid: %d\n", __func__, rc);
+ return rc;
+ }
+ return sprintf(buf, "0x%08X\n", did_vid);
+}
+static DEVICE_ATTR_RO(did_vid);
+
+static struct attribute *tpm_tis_attrs[] = {
+ &dev_attr_did_vid.attr,
+ NULL,
+};
+
+static const struct attribute_group tpm_tis_group = {
+ .attrs = tpm_tis_attrs,
+};
+
int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
const struct tpm_tis_phy_ops *phy_ops,
acpi_handle acpi_dev_handle)
@@ -1009,6 +1034,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
(chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
vendor >> 16, rid);
+ /* Expose the DID_VID information to userspace */
+ chip->groups[chip->groups_cnt++] = &tpm_tis_group;
+
probe = probe_itpm(chip);
if (probe < 0) {
rc = -ENODEV;
diff --git a/include/linux/tpm.h b/include/linux/tpm.h
--- a/include/linux/tpm.h
+++ b/include/linux/tpm.h
@@ -155,7 +155,7 @@ struct tpm_chip {
struct dentry *bios_dir[TPM_NUM_EVENT_LOG_FILES];
- const struct attribute_group *groups[3 + TPM_MAX_HASHES];
+ const struct attribute_group *groups[4 + TPM_MAX_HASHES];
unsigned int groups_cnt;
u32 nr_allocated_banks;
--
2.33.0.259.gc128427fd7-goog