From patchwork Wed Jul 20 02:51:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Pronin X-Patchwork-Id: 9238687 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 C1C8C6075D for ; Wed, 20 Jul 2016 02:52:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4F5D200DF for ; Wed, 20 Jul 2016 02:52:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A9AB626A4D; Wed, 20 Jul 2016 02:52:04 +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 8E1D6200DF for ; Wed, 20 Jul 2016 02:52:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-3.v29.ch3.sourceforge.com) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bPhc9-0007ar-79; Wed, 20 Jul 2016 02:52:01 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-3.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1bPhc8-0007ag-4z for tpmdd-devel@lists.sourceforge.net; Wed, 20 Jul 2016 02:52:00 +0000 Received-SPF: pass (sog-mx-4.v43.ch3.sourceforge.com: domain of chromium.org designates 209.85.192.173 as permitted sender) client-ip=209.85.192.173; envelope-from=apronin@chromium.org; helo=mail-pf0-f173.google.com; Received: from mail-pf0-f173.google.com ([209.85.192.173]) by sog-mx-4.v43.ch3.sourceforge.com with esmtps (TLSv1:AES128-SHA:128) (Exim 4.76) id 1bPhc7-0001yN-38 for tpmdd-devel@lists.sourceforge.net; Wed, 20 Jul 2016 02:52:00 +0000 Received: by mail-pf0-f173.google.com with SMTP id y134so13739053pfg.0 for ; Tue, 19 Jul 2016 19:51:59 -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:in-reply-to:references; bh=m1zrnmC/L/RzVNFsYs8nDuEYPI1Mfp9yvUV8syGQ45I=; b=XEFMcAYnzM9fB7jsJtW2Nk3lnwefOz8nezR2pfRlYgZW4P1WtbbI2A0wbEN+vkF1iF NoIovF6OWD12qzrO6s2tVvxjH9N5+pjEuLcmzXtkudvUb4o0qxZywnbXMIxliEF/HVzz QVKVNlfCci4znywwPBoeyKZhDc0T3s/2QICOGAPRCPfwXa9ZQH1xEM7Z1oDH+qmg42is pmZ8H2E53GmBRE/v7VVXOFArbyPBiINmzhCBaefirVvUJss7U7FnV6Aqb9OVj8NyWLO4 yhjwlIYA2XFAtsO33cxsvuf5qdO4oQeZGrgbC0/1DUXJRtgY0VWnxJnqV9geXcgDzPIW wqJw== X-Gm-Message-State: ALyK8tLynTTZeGz1JuntfLz1kxsP+ZXgGOTLJ38psHknlnpS/3qdLF08nG+QXlF+AoKuASRJ X-Received: by 10.98.9.194 with SMTP id 63mr60946954pfj.56.1468983113416; Tue, 19 Jul 2016 19:51:53 -0700 (PDT) Received: from apronin0.mtv.corp.google.com ([172.22.64.136]) by smtp.gmail.com with ESMTPSA id sk4sm392158pac.16.2016.07.19.19.51.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 19 Jul 2016 19:51:52 -0700 (PDT) From: Andrey Pronin To: Jarkko Sakkinen Date: Tue, 19 Jul 2016 19:51:52 -0700 Message-Id: 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> 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: 1bPhc7-0001yN-38 Cc: Christophe Ricard , linux-kernel@vger.kernel.org, tpmdd-devel@lists.sourceforge.net Subject: [tpmdd-devel] [PATCH v2] 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 Add sysfs attributes in TPM2.0 case for: - TPM_PT_PERMANENT flags - TPM_PT_STARTUP_CLEAR flags - lockout-related properties v2: Dropped adding driver-specific attributes. No legacy links for TPM2 attributes. All attributes created in groups[0]. Added actual attributes for flags and lockout properties. Signed-off-by: Andrey Pronin --- drivers/char/tpm/tpm-chip.c | 4 +- drivers/char/tpm/tpm-sysfs.c | 108 +++++++++++++++++++++++++++++++++++++++++-- drivers/char/tpm/tpm.h | 30 ++++++++++++ 3 files changed, 136 insertions(+), 6 deletions(-) diff --git a/drivers/char/tpm/tpm-chip.c b/drivers/char/tpm/tpm-chip.c index e595013..ede2ca0 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; @@ -363,6 +361,8 @@ int tpm_chip_register(struct tpm_chip *chip) return 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..fcfc7e0 100644 --- a/drivers/char/tpm/tpm-sysfs.c +++ b/drivers/char/tpm/tpm-sysfs.c @@ -264,7 +264,7 @@ static ssize_t timeouts_show(struct device *dev, struct device_attribute *attr, } static DEVICE_ATTR_RO(timeouts); -static struct attribute *tpm_dev_attrs[] = { +static struct attribute *tpm1_dev_attrs[] = { &dev_attr_pubek.attr, &dev_attr_pcrs.attr, &dev_attr_enabled.attr, @@ -278,8 +278,106 @@ static struct attribute *tpm_dev_attrs[] = { NULL, }; -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 ssize_t tpm2_prop_flag_show(struct device *dev, u32 property_id, + u32 flag_mask, char *buf) +{ + u32 flags; + ssize_t rc; + + rc = tpm2_get_tpm_pt(to_tpm_chip(dev), property_id, &flags, + "reading property"); + if (rc) + return 0; + + return sprintf(buf, "%d\n", !!(flags & flag_mask)); +} + +static ssize_t tpm2_prop_u32_show(struct device *dev, u32 property_id, + char *buf) +{ + u32 value; + ssize_t rc; + + rc = tpm2_get_tpm_pt(to_tpm_chip(dev), property_id, &value, + "reading property"); + if (rc) + return 0; + + return sprintf(buf, "%u\n", value); +} + +#define DEFINE_TPM2_PROP_FLAG_ATTR(name, property_id, flag_mask) \ +static ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return tpm2_prop_flag_show(dev, property_id, flag_mask, buf); \ +} \ +static DEVICE_ATTR_RO(name) + +#define DEFINE_TPM2_PROP_U32_ATTR(name, property_id) \ +static ssize_t name##_show(struct device *dev, \ + struct device_attribute *attr, char *buf) \ +{ \ + return tpm2_prop_u32_show(dev, property_id, buf); \ +} \ +static DEVICE_ATTR_RO(name) + +DEFINE_TPM2_PROP_FLAG_ATTR(owner_auth_set, + TPM2_PT_PERMANENT, TPM2_ATTR_OWNER_AUTH_SET); +DEFINE_TPM2_PROP_FLAG_ATTR(endorsement_auth_set, + TPM2_PT_PERMANENT, TPM2_ATTR_ENDORSEMENT_AUTH_SET); +DEFINE_TPM2_PROP_FLAG_ATTR(lockout_auth_set, + TPM2_PT_PERMANENT, TPM2_ATTR_LOCKOUT_AUTH_SET); +DEFINE_TPM2_PROP_FLAG_ATTR(disable_clear, + TPM2_PT_PERMANENT, TPM2_ATTR_DISABLE_CLEAR); +DEFINE_TPM2_PROP_FLAG_ATTR(in_lockout, + TPM2_PT_PERMANENT, TPM2_ATTR_IN_LOCKOUT); +DEFINE_TPM2_PROP_FLAG_ATTR(tpm_generated_eps, + TPM2_PT_PERMANENT, TPM2_ATTR_TPM_GENERATED_EPS); + +DEFINE_TPM2_PROP_FLAG_ATTR(ph_enable, + TPM2_PT_STARTUP_CLEAR, TPM2_ATTR_PH_ENABLE); +DEFINE_TPM2_PROP_FLAG_ATTR(sh_enable, + TPM2_PT_STARTUP_CLEAR, TPM2_ATTR_SH_ENABLE); +DEFINE_TPM2_PROP_FLAG_ATTR(eh_enable, + TPM2_PT_STARTUP_CLEAR, TPM2_ATTR_EH_ENABLE); +DEFINE_TPM2_PROP_FLAG_ATTR(ph_enable_nv, + TPM2_PT_STARTUP_CLEAR, TPM2_ATTR_PH_ENABLE_NV); +DEFINE_TPM2_PROP_FLAG_ATTR(orderly, + TPM2_PT_STARTUP_CLEAR, TPM2_ATTR_ORDERLY); + +DEFINE_TPM2_PROP_U32_ATTR(lockout_counter, TPM2_PT_LOCKOUT_COUNTER); +DEFINE_TPM2_PROP_U32_ATTR(max_auth_fail, TPM2_PT_MAX_AUTH_FAIL); +DEFINE_TPM2_PROP_U32_ATTR(lockout_interval, TPM2_PT_LOCKOUT_INTERVAL); +DEFINE_TPM2_PROP_U32_ATTR(lockout_recovery, TPM2_PT_LOCKOUT_RECOVERY); + +static struct attribute *tpm2_dev_attrs[] = { + &dev_attr_owner_auth_set.attr, + &dev_attr_endorsement_auth_set.attr, + &dev_attr_lockout_auth_set.attr, + &dev_attr_disable_clear.attr, + &dev_attr_in_lockout.attr, + &dev_attr_tpm_generated_eps.attr, + &dev_attr_ph_enable.attr, + &dev_attr_sh_enable.attr, + &dev_attr_eh_enable.attr, + &dev_attr_ph_enable_nv.attr, + &dev_attr_orderly.attr, + &dev_attr_lockout_counter.attr, + &dev_attr_max_auth_fail.attr, + &dev_attr_lockout_interval.attr, + &dev_attr_lockout_recovery.attr, + &dev_attr_durations.attr, + &dev_attr_timeouts.attr, + NULL, +}; + +static const struct attribute_group tpm2_dev_group = { + .attrs = tpm2_dev_attrs, }; void tpm_sysfs_add_device(struct tpm_chip *chip) @@ -289,5 +387,7 @@ void tpm_sysfs_add_device(struct tpm_chip *chip) * removal so that no callbacks are running or can run again */ WARN_ON(chip->groups_cnt != 0); - chip->groups[chip->groups_cnt++] = &tpm_dev_group; + chip->groups[chip->groups_cnt++] = + (chip->flags & TPM_CHIP_FLAG_TPM2) ? + &tpm2_dev_group : &tpm1_dev_group; } diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index 3e32d5b..cf4359a 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -127,6 +127,36 @@ enum tpm2_capabilities { TPM2_CAP_TPM_PROPERTIES = 6, }; +enum tpm2_properties { + TPM2_PT_NONE = 0, + TPM2_PT_GROUP = 0x100, + TPM2_PT_FIXED = TPM2_PT_GROUP, + TPM2_PT_VAR = TPM2_PT_GROUP * 2, + TPM2_PT_PERMANENT = TPM2_PT_VAR + 0, + TPM2_PT_STARTUP_CLEAR = TPM2_PT_VAR + 1, + TPM2_PT_LOCKOUT_COUNTER = TPM2_PT_VAR + 14, + TPM2_PT_MAX_AUTH_FAIL = TPM2_PT_VAR + 15, + TPM2_PT_LOCKOUT_INTERVAL = TPM2_PT_VAR + 16, + TPM2_PT_LOCKOUT_RECOVERY = TPM2_PT_VAR + 17, +}; + +enum tpm2_attr_permanent { + TPM2_ATTR_OWNER_AUTH_SET = BIT(0), + TPM2_ATTR_ENDORSEMENT_AUTH_SET = BIT(1), + TPM2_ATTR_LOCKOUT_AUTH_SET = BIT(2), + TPM2_ATTR_DISABLE_CLEAR = BIT(8), + TPM2_ATTR_IN_LOCKOUT = BIT(9), + TPM2_ATTR_TPM_GENERATED_EPS = BIT(10), +}; + +enum tpm2_attr_startup_clear { + TPM2_ATTR_PH_ENABLE = BIT(0), + TPM2_ATTR_SH_ENABLE = BIT(1), + TPM2_ATTR_EH_ENABLE = BIT(2), + TPM2_ATTR_PH_ENABLE_NV = BIT(3), + TPM2_ATTR_ORDERLY = BIT(31), +}; + enum tpm2_startup_types { TPM2_SU_CLEAR = 0x0000, TPM2_SU_STATE = 0x0001,