Ross Philipson
unread,Sep 13, 2024, 4:13:13 PM9/13/24Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to linux-...@vger.kernel.org, x...@kernel.org, linux-i...@vger.kernel.org, linu...@vger.kernel.org, linux-...@vger.kernel.org, ke...@lists.infradead.org, linu...@vger.kernel.org, io...@lists.linux-foundation.org, ross.ph...@oracle.com, dps...@apertussolutions.com, tg...@linutronix.de, mi...@redhat.com, b...@alien8.de, h...@zytor.com, dave....@linux.intel.com, ar...@kernel.org, mj...@srcf.ucam.org, James.B...@hansenpartnership.com, peter...@gmx.de, jar...@kernel.org, j...@ziepe.ca, lu...@amacapital.net, nive...@alum.mit.edu, her...@gondor.apana.org.au, da...@davemloft.net, cor...@lwn.net, ebie...@xmission.com, dw...@infradead.org, baol...@linux.intel.com, kanth.g...@oracle.com, andrew....@citrix.com, trenchbo...@googlegroups.com
Expose a sysfs interface to allow user mode to set and query the default
locality set for the TPM chip.
Signed-off-by: Ross Philipson <
ross.ph...@oracle.com>
---
drivers/char/tpm/tpm-sysfs.c | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c
index 94231f052ea7..185a2f57d4cb 100644
--- a/drivers/char/tpm/tpm-sysfs.c
+++ b/drivers/char/tpm/tpm-sysfs.c
@@ -324,6 +324,34 @@ static ssize_t null_name_show(struct device *dev, struct device_attribute *attr,
static DEVICE_ATTR_RO(null_name);
#endif
+static ssize_t default_locality_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct tpm_chip *chip = to_tpm_chip(dev);
+
+ return sprintf(buf, "%d\n", chip->default_locality);
+}
+
+static ssize_t default_locality_store(struct device *dev, struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct tpm_chip *chip = to_tpm_chip(dev);
+ unsigned int locality;
+
+ if (kstrtouint(buf, 0, &locality))
+ return -ERANGE;
+
+ if (locality >= TPM_MAX_LOCALITY)
+ return -ERANGE;
+
+ if (tpm_chip_set_default_locality(chip, (int)locality))
+ return count;
+ else
+ return 0;
+}
+
+static DEVICE_ATTR_RW(default_locality);
+
static struct attribute *tpm1_dev_attrs[] = {
&dev_attr_pubek.attr,
&dev_attr_pcrs.attr,
@@ -336,6 +364,7 @@ static struct attribute *tpm1_dev_attrs[] = {
&dev_attr_durations.attr,
&dev_attr_timeouts.attr,
&dev_attr_tpm_version_major.attr,
+ &dev_attr_default_locality.attr,
NULL,
};
@@ -344,6 +373,7 @@ static struct attribute *tpm2_dev_attrs[] = {
#ifdef CONFIG_TCG_TPM2_HMAC
&dev_attr_null_name.attr,
#endif
+ &dev_attr_default_locality.attr,
NULL
};
--
2.39.3