From patchwork Fri Jul 15 01:51:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Pronin X-Patchwork-Id: 9231007 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CA72C60572 for ; Fri, 15 Jul 2016 01:51:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7EF02830A for ; Fri, 15 Jul 2016 01:51:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC9A028326; Fri, 15 Jul 2016 01:51:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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 mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2FD232830A for ; Fri, 15 Jul 2016 01:51:49 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bNsI7-0002fV-2I; Fri, 15 Jul 2016 01:51:47 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bNsI6-0002fM-5P for tpmdd-devel@lists.sourceforge.net; Fri, 15 Jul 2016 01:51:46 +0000 Received-SPF: pass (sog-mx-3.v43.ch3.sourceforge.com: domain of chromium.org designates 209.85.192.182 as permitted sender) client-ip=209.85.192.182; envelope-from=apronin@chromium.org; helo=mail-pf0-f182.google.com; Received: from mail-pf0-f182.google.com ([209.85.192.182]) by sog-mx-3.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bNsI5-0007DU-4d for tpmdd-devel@lists.sourceforge.net; Fri, 15 Jul 2016 01:51:46 +0000 Received: by mail-pf0-f182.google.com with SMTP id c2so35892777pfa.2 for ; Thu, 14 Jul 2016 18:51:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=1Rcuxm52beuhGCyoNqN2MTiDpdhwPPvDA5Crwxd04n0=; b=YGE6nM8tCFoc8v4t3mnXCDYuC0g+DtPKfnqoSJAB61PFN+XvxFM5WsRX2wDq7CMuow e+wvl4QGSLQ9vQDwrOkASSFBPErBMWVwyja65EdXp7P0oLuqUEQB7GeArMd/iOQNPFCe H+W0M6Pgo5WIqcpGi0jVURX79qeeABBxloupn4jY1Ez0iYmfJ3AvaEhBAsfr0nPCgy+S XjwnfB05uHQyQ/hr60l8L3CFCiw+JX6A/fAfZI5cN5dndXiOhcnNFQzIpjWO1JVU/e5O SUavTdb1LCvLSgE5A9mBN4OfqMK7PZGoxGIxnfc5BbrKb+oke1YOcvd3x958QoM3qtdp CvWA== X-Gm-Message-State: ALyK8tLbii5Kn5HdsNRe27QO6EW2COTxz0EcW+CTMv5KcUjNUEiwsAaqA8K3PrNHVuTo/dR4 X-Received: by 10.98.155.17 with SMTP id r17mr17466430pfd.24.1468547499436; Thu, 14 Jul 2016 18:51:39 -0700 (PDT) Received: from apronin0.mtv.corp.google.com ([172.22.64.136]) by smtp.gmail.com with ESMTPSA id g189sm6789777pfc.46.2016.07.14.18.51.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Jul 2016 18:51:39 -0700 (PDT) From: Andrey Pronin To: Jarkko Sakkinen Date: Thu, 14 Jul 2016 18:51:35 -0700 Message-Id: <1468547496-16215-2-git-send-email-apronin@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1468547496-16215-1-git-send-email-apronin@chromium.org> References: <1468547496-16215-1-git-send-email-apronin@chromium.org> X-Headers-End: 1bNsI5-0007DU-4d Cc: dianders@chromium.org, linux-kernel@vger.kernel.org, smbarber@chromium.org, tpmdd-devel@lists.sourceforge.net, groeck@chromium.org Subject: [tpmdd-devel] [PATCH 1/2] tpm: add sysfs attributes for tpm2 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: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Virus-Scanned: ClamAV using ClamSMTP Break sysfs attributes into common and TPM 1.2/2.0-specific, and create sysfs groups for TPM2.0. Signed-off-by: Andrey Pronin --- drivers/char/tpm/tpm-chip.c | 48 ++++++++++++++++++++++++++++---------------- drivers/char/tpm/tpm-sysfs.c | 24 ++++++++++++++++++++-- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index 5a2f043..6c72671 100644 --- a/drivers/char/tpm/tpm-chip.c +++ b/drivers/char/tpm/tpm-chip.c @@ -281,8 +281,6 @@ static int tpm1_chip_register(struct tpm_chip *chip) if (chip->flags & TPM_CHIP_FLAG_TPM2) return 0; - tpm_sysfs_add_device(chip); - chip->bios_dir = tpm_bios_log_setup(dev_name(&chip->dev)); return 0; @@ -300,14 +298,21 @@ static void tpm1_chip_unregister(struct tpm_chip *chip) static void tpm_del_legacy_sysfs(struct tpm_chip *chip) { struct attribute **i; + int ngrp; - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL) return; - sysfs_remove_link(&chip->dev.parent->kobj, "ppi"); - - for (i = chip->groups[0]->attrs; *i != NULL; ++i) - sysfs_remove_link(&chip->dev.parent->kobj, (*i)->name); + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) { + if (chip->groups[ngrp]->name) { + sysfs_remove_link(&chip->dev.parent->kobj, + chip->groups[ngrp]->name); + } else { + for (i = chip->groups[ngrp]->attrs; *i != NULL; ++i) + sysfs_remove_link(&chip->dev.parent->kobj, + (*i)->name); + } + } } /* For compatibility with legacy sysfs paths we provide symlinks from the @@ -317,20 +322,27 @@ static void tpm_del_legacy_sysfs(struct tpm_chip *chip) static int tpm_add_legacy_sysfs(struct tpm_chip *chip) { struct attribute **i; - int rc; + int rc = 0; + int ngrp; - if (chip->flags & (TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_VIRTUAL)) + if (chip->flags & TPM_CHIP_FLAG_VIRTUAL) return 0; - rc = __compat_only_sysfs_link_entry_to_kobj( - &chip->dev.parent->kobj, &chip->dev.kobj, "ppi"); - if (rc && rc != -ENOENT) - return rc; - /* All the names from tpm-sysfs */ - for (i = chip->groups[0]->attrs; *i != NULL; ++i) { - rc = __compat_only_sysfs_link_entry_to_kobj( - &chip->dev.parent->kobj, &chip->dev.kobj, (*i)->name); + for (ngrp = 0; ngrp < chip->groups_cnt; ++ngrp) { + if (chip->groups[ngrp]->name) { + rc = __compat_only_sysfs_link_entry_to_kobj( + &chip->dev.parent->kobj, &chip->dev.kobj, + chip->groups[ngrp]->name); + } else { + for (i = chip->groups[ngrp]->attrs; + (*i != NULL) && !rc; + ++i) + rc = __compat_only_sysfs_link_entry_to_kobj( + &chip->dev.parent->kobj, + &chip->dev.kobj, + (*i)->name); + } if (rc) { tpm_del_legacy_sysfs(chip); return rc; @@ -354,6 +366,8 @@ int tpm_chip_register(struct tpm_chip *chip) { int rc; + tpm_sysfs_add_device(chip); + rc = tpm1_chip_register(chip); if (rc) return rc; diff --git a/drivers/char/tpm/tpm-sysfs.c b/drivers/char/tpm/tpm-sysfs.c index b46cf70..95ce90d 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -265,6 +265,12 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RO(timeouts); static struct attribute *tpm_dev_attrs[] = { + &dev_attr_durations.attr, + &dev_attr_timeouts.attr, + NULL, +}; + +static struct attribute *tpm1_dev_attrs[] = { &dev_attr_pubek.attr, &dev_attr_pcrs.attr, &dev_attr_enabled.attr, @@ -273,8 +279,10 @@ static struct attribute *tpm_dev_attrs[] = { &dev_attr_temp_deactivated.attr, &dev_attr_caps.attr, &dev_attr_cancel.attr, - &dev_attr_durations.attr, - &dev_attr_timeouts.attr, + NULL, +}; + +static struct attribute *tpm2_dev_attrs[] = { NULL, }; @@ -282,6 +290,14 @@ static const struct attribute_group tpm_dev_group = { .attrs = tpm_dev_attrs, }; +static const struct attribute_group tpm1_dev_group = { + .attrs = tpm1_dev_attrs, +}; + +static const struct attribute_group tpm2_dev_group = { + .attrs = tpm2_dev_attrs, +}; + void tpm_sysfs_add_device(struct tpm_chip *chip) { /* The sysfs routines rely on an implicit tpm_try_get_ops, device_del @@ -290,4 +306,8 @@ void tpm_sysfs_add_device(struct tpm_chip *chip) */ WARN_ON(chip->groups_cnt != 0); chip->groups[chip->groups_cnt++] = &tpm_dev_group; + if (chip->flags & TPM_CHIP_FLAG_TPM2) + chip->groups[chip->groups_cnt++] = &tpm2_dev_group; + else + chip->groups[chip->groups_cnt++] = &tpm1_dev_group; }