Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751411AbdCMHLk convert rfc822-to-8bit (ORCPT ); Mon, 13 Mar 2017 03:11:40 -0400 Received: from mout.gmx.net ([212.227.17.21]:55917 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751191AbdCMHLc (ORCPT ); Mon, 13 Mar 2017 03:11:32 -0400 Date: Mon, 13 Mar 2017 08:10:53 +0100 User-Agent: K-9 Mail for Android In-Reply-To: <1489382517-9078-1-git-send-email-Meng.Li@windriver.com> References: <1489382517-9078-1-git-send-email-Meng.Li@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: Re: [PATCH] tpm: Add sysfs interface to show TPM hardware version To: Meng.Li@windriver.com, linux-kernel@vger.kernel.org CC: tpmdd@selhorst.net, jarkko.sakkinen@linux.intel.com, jgunthorpe@obsidianresearch.com, tpmdd-devel@lists.sourceforge.net From: Peter Huewe Message-ID: <29B2C361-A0C0-410E-ACCA-07AFA382A251@gmx.de> X-Provags-ID: V03:K0:l23bRgFQsm4EhMJtR5VyZLD2BjBWySzDXk2W4XXd08BQo0+3r63 RzEf1LMmshtmUO1rk1LFpTM+/Ko8bRe5uqEAa4QtjWOjOt/U4Qudv6cUjv5hupJzqsqhzsf iS8VAiWiZ/ALb0ojuOEzpg6KszCWPdsqD75TfNS684v06lgZQZdIIFF2+6940L7435/HTED O/uDRI9xvBHUC8rRulRhw== X-UI-Out-Filterresults: notjunk:1;V01:K0:BvK7YPJU1Ds=:F2/Kj2inTc+NN4y/mMdXm2 /7J2LC7qINQd2yRvjOh8kHN1adcX7N7bhlOqe4Omx517ya2UbtZtX9DEydBisSMcKkxFUi0mc qr2JIQd25vUzm555GTEwslxXwgkDletLa5MOuPudkK3rI8nVZT7Z3M0/MSDVWplQs+d8wOAJ3 GK46RWahmXiC4YYz3zugZRwSegYFAL5XJaDbql6ndDnF0MfX6LLOQcwfHGhFpqWtFOTKkwquZ tFWx+qD9rR5/kK7BS5IaJDCDFa0EICGiEk8R73AIyKc4kQwNIWFQL71aI57/Tyv97VAkqn897 7loYZKsI+7EvG6QAZnmKLM4ha7iSPAhdyZuyruv4VKxzkx/XH1jQHhn/cr4oNNy6cCFSsCyZT 2Zl0IC5FsiJlNR18ojLfNT0WQXNDXV6bRFShoxExyKvrEcahPUNhTyucQwA3uyLqQk1juSKt/ hTg/pR5z7tPy2FhymApX8xI1ijjACfPG9+APRWusPZVmWAs6gecaXB0XXFEbg7qJWOIvgax36 hCgiY3F+GE/Z09b4PAeMVVX1WnxvFVb0dJ8kK+92bm2PKOR5nEggAY14qswq5oPaD5Z987LWy 6pejPtqicHVJ7rDqxx8fKjc7Dhfu8EMSpbNkXd0QuVT+yTkx38MnLOB0FJdw0BHxgRMO0/8G0 1uR3shQL8aJIrA49BiT5PrVnhW/wkCb/Kbp6U1lArybSQvPULI9eK9SufPgkQj2VefyOEXK0H 9rnLjOT9+2bx+9a+YMQwnVytV4Xn3Kb+SkvLNcrBxVsqwr+aKJSpx9p+pxbHF3HxI16G8CCrU CqOTkrc Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3665 Lines: 140 Hi, Thanks for your patch. Am 13. März 2017 06:21:57 MEZ schrieb Meng.Li@windriver.com: >From: Limeng > >So far, there is not a sysfs interface for user space code to >check the TPM hardware version(TPM1.x or TPM2). So, add a >file named description in /sys/class/tpm/tpmX/ to show it. It's not really the hardware version but the "TPM Family" according to tcg. And yes you are right there is currently no way, except for trial and error, for the userspace to determine this. So an interface to get this information makes sense to me. > >Signed-off-by: Meng Li >--- >drivers/char/tpm/tpm-chip.c | 85 >+++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 85 insertions(+) > >diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c >index c406343..da2cd69 100644 >--- a/drivers/char/tpm/tpm-chip.c >+++ b/drivers/char/tpm/tpm-chip.c >@@ -36,6 +36,83 @@ > dev_t tpm_devt; > > /** >+ * show_description - sysfs interface for checking current TPM >hardware version. >+ * @dev: pointer to tpm chip device >+ * @attr: unused >+ * @buf: char buffer to be filled with TPM hardware version info >+ * >+ * Provides sysfs interface for showing current TPM hardware version. >+ */ >+static ssize_t show_description(struct device *dev, >+ struct device_attribute *attr, char *buf) >+{ >+ struct tpm_chip *chip = (struct tpm_chip *)container_of(dev,struct >tpm_chip,dev); >+ int ret; >+ >+ if (chip->flags & TPM_CHIP_FLAG_TPM2) >+ ret = sprintf(buf, "TPM 2.0"); >+ else >+ ret = sprintf(buf, "TPM 1.x"); >+ >+ return ret; >+} >+ >+/** >+ * store_description - interface for manually setting data. >+ * @dev: unused >+ * @attr: unused >+ * @buf: unused >+ * @count: unused >+ * >+ * There is not any process in this function, reserve for feature. >+ */ >+static ssize_t store_description(struct device *dev, struct >device_attribute *attr, >+ const char *buf, size_t count) >+{ >+ return count; >+} Since it does not do anything I would not create this function and leave the sysfs node as S_IRUGO. >+ >+static struct device_attribute tpm_attrs[] = { >+ __ATTR(description, S_IRUGO | S_IWUSR, show_description, >store_description), >+}; >+ >+/** >+ * tpm_create_sysfs - Create tpm sysfs interface. >+ * @dev: pointer to tpm chip device >+ * >+ * Create sysfs interface for checking current TPM hardware version. >+ */ >+static int tpm_create_sysfs(struct device *dev) >+{ >+ int r, t; >+ >+ for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) { >+ r = device_create_file(dev, &tpm_attrs[t]); >+ if (r) { >+ dev_err(dev, "failed to create sysfs file\n"); >+ return r; >+ } >+ } >+ >+ return 0; >+} >+ >+/** >+ * tpm_remove_sysfs - Remove tpm sysfs interface. >+ * @dev: pointer to tpm chip device >+ * >+ * Remove sysfs interface for checking current TPM hardware version. >+ */ >+static void tpm_remove_sysfs(struct device *dev) >+{ >+ int t; >+ >+ for (t = 0; t < ARRAY_SIZE(tpm_attrs); t++) { >+ device_remove_file(dev, &tpm_attrs[t]); >+ } >+} >+ >+/** > * tpm_try_get_ops() - Get a ref to the tpm_chip > * @chip: Chip to ref > * >@@ -363,6 +440,13 @@ int tpm_chip_register(struct tpm_chip *chip) > return rc; > } > >+ rc = tpm_create_sysfs(&chip->dev); >+ if (rc) { >+ tpm_del_legacy_sysfs(chip); >+ tpm_chip_unregister(chip); >+ return rc; >+ } >+ > return 0; > } > EXPORT_SYMBOL_GPL(tpm_chip_register); >@@ -382,6 +466,7 @@ int tpm_chip_register(struct tpm_chip *chip) > */ > void tpm_chip_unregister(struct tpm_chip *chip) > { >+ tpm_remove_sysfs(&chip->dev); > tpm_del_legacy_sysfs(chip); > tpm_bios_log_teardown(chip); > tpm_del_char_device(chip); -- Sent from my mobile