From patchwork Mon Mar 13 09:20:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Meng Li X-Patchwork-Id: 738050 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vhXR16KT6z9s73 for ; Mon, 13 Mar 2017 20:20:45 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=sfs-ml-4.v29.ch3.sourceforge.com) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cnM9f-0001og-U4; Mon, 13 Mar 2017 09:20:39 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-4.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1cnM9e-0001ob-Ss for tpmdd-devel@lists.sourceforge.net; Mon, 13 Mar 2017 09:20:38 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of windriver.com designates 147.11.146.13 as permitted sender) client-ip=147.11.146.13; envelope-from=Meng.Li@windriver.com; helo=mail1.windriver.com; Received: from mail1.windriver.com ([147.11.146.13]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) id 1cnM9c-0002ks-Qi for tpmdd-devel@lists.sourceforge.net; Mon, 13 Mar 2017 09:20:38 +0000 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id v2D9KPZx022469 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Mon, 13 Mar 2017 02:20:25 -0700 (PDT) Received: from pek-mli-d1.wrs.com (128.224.162.235) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.294.0; Mon, 13 Mar 2017 02:20:23 -0700 From: To: Date: Mon, 13 Mar 2017 17:20:17 +0800 Message-ID: <1489396817-24855-1-git-send-email-Meng.Li@windriver.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-Spam-Score: -1.9 (-) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -1.5 SPF_CHECK_PASS SPF reports sender host as permitted sender for sender-domain -0.0 SPF_PASS SPF: sender matches SPF record -0.3 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain X-Headers-End: 1cnM9c-0002ks-Qi Cc: tpmdd-devel@lists.sourceforge.net Subject: [tpmdd-devel] [PATCH] tpm: Add sysfs interface to show TPM family version X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: tpmdd-devel-bounces@lists.sourceforge.net From: Limeng So far, there is not a sysfs interface for user space code to check the TPM family version(TPM1.x or TPM2). So, add a file named description in /sys/class/tpm/tpmX/ to show it. Signed-off-by: Meng Li --- drivers/char/tpm/tpm-chip.c | 70 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index c406343..b222421 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -36,6 +36,68 @@ 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; +} + +static struct device_attribute tpm_attrs[] = { + __ATTR(description, S_IRUGO, show_description, NULL), +}; + +/** + * 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 +425,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 +451,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);