From patchwork Tue Sep 29 17:07:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 7288641 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6AB7BBEEA4 for ; Tue, 29 Sep 2015 17:08:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5CF5620681 for ; Tue, 29 Sep 2015 17:08:01 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 4F82B20678 for ; Tue, 29 Sep 2015 17:07:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZgyNh-0000R0-3v; Tue, 29 Sep 2015 17:07:57 +0000 Received: from sog-mx-3.v43.ch3.sourceforge.com ([172.29.43.193] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1ZgyNg-0000Qv-9o for tpmdd-devel@lists.sourceforge.net; Tue, 29 Sep 2015 17:07:56 +0000 X-ACL-Warn: Received: from mga09.intel.com ([134.134.136.24]) by sog-mx-3.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1ZgyNe-0005aT-PA for tpmdd-devel@lists.sourceforge.net; Tue, 29 Sep 2015 17:07:56 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP; 29 Sep 2015 10:07:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,609,1437462000"; d="scan'208";a="654470442" Received: from christep-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.4.37]) by orsmga003.jf.intel.com with ESMTP; 29 Sep 2015 10:07:23 -0700 From: Jarkko Sakkinen To: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Date: Tue, 29 Sep 2015 20:07:11 +0300 Message-Id: <1443546431-14948-3-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1443546431-14948-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1443546431-14948-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -0.0 (/) X-Headers-End: 1ZgyNe-0005aT-PA Cc: gregkh@linuxfoundation.org, akpm@linux-foundation.org Subject: [tpmdd-devel] [PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID 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-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It turned out that the root cause in b371616b8 was not correct for https://bugzilla.kernel.org/show_bug.cgi?id=98181. All TPM 2.0 FIFO and CRB devices have the same HID. For FIFO devices the start method is always 6. This patch changes FIFO and CRB drivers so that they check start method value and initialize only if the start method has a proper value for that particular interface. Reported-by: Michael Saunders Reported-by: Michael Marley Reported-by: Jethro Beekman Reported-by: Matthew Garrett Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm.h | 7 +++++++ drivers/char/tpm/tpm_crb.c | 20 +++++--------------- drivers/char/tpm/tpm_tis.c | 40 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h index f8319a0..39be5ac 100644 --- a/drivers/char/tpm/tpm.h +++ b/drivers/char/tpm/tpm.h @@ -115,6 +115,13 @@ enum tpm2_startup_types { TPM2_SU_STATE = 0x0001, }; +enum tpm2_start_method { + TPM2_START_ACPI = 2, + TPM2_START_FIFO = 6, + TPM2_START_CRB = 7, + TPM2_START_CRB_WITH_ACPI = 8, +}; + struct tpm_chip; struct tpm_vendor_specific { diff --git a/drivers/char/tpm/tpm_crb.c b/drivers/char/tpm/tpm_crb.c index 1267322..b4564b6 100644 --- a/drivers/char/tpm/tpm_crb.c +++ b/drivers/char/tpm/tpm_crb.c @@ -34,12 +34,6 @@ enum crb_defaults { CRB_ACPI_START_INDEX = 1, }; -enum crb_start_method { - CRB_SM_ACPI_START = 2, - CRB_SM_CRB = 7, - CRB_SM_CRB_WITH_ACPI_START = 8, -}; - struct acpi_tpm2 { struct acpi_table_header hdr; u16 platform_class; @@ -233,13 +227,9 @@ static int crb_acpi_add(struct acpi_device *device) return -ENODEV; } - /* At least some versions of AMI BIOS have a bug that TPM2 table has - * zero address for the control area and therefore we must fail. - */ - if (!buf->control_area_pa) { - dev_err(dev, "TPM2 ACPI table has a zero address for the control area\n"); - return -EINVAL; - } + /* Should the FIFO driver handle this? */ + if (buf->start_method == TPM2_START_FIFO) + return -ENODEV; if (buf->hdr.length < sizeof(struct acpi_tpm2)) { dev_err(dev, "TPM2 ACPI table has wrong size"); @@ -259,11 +249,11 @@ static int crb_acpi_add(struct acpi_device *device) * report only ACPI start but in practice seems to require both * ACPI start and CRB start. */ - if (sm == CRB_SM_CRB || sm == CRB_SM_CRB_WITH_ACPI_START || + if (sm == TPM2_START_CRB || sm == TPM2_START_FIFO || !strcmp(acpi_device_hid(device), "MSFT0101")) priv->flags |= CRB_FL_CRB_START; - if (sm == CRB_SM_ACPI_START || sm == CRB_SM_CRB_WITH_ACPI_START) + if (sm == TPM2_START_ACPI || sm == TPM2_START_CRB_WITH_ACPI) priv->flags |= CRB_FL_ACPI_START; priv->cca = (struct crb_control_area __iomem *) diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c index 87581b2..545a38e 100644 --- a/drivers/char/tpm/tpm_tis.c +++ b/drivers/char/tpm/tpm_tis.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "tpm.h" enum tis_access { @@ -101,21 +102,52 @@ struct priv_data { }; #if defined(CONFIG_ACPI) -static int is_itpm(struct acpi_device *dev) +static int has_hid(struct acpi_device *dev, const char *hid) { struct acpi_hardware_id *id; list_for_each_entry(id, &dev->pnp.ids, list) - if (!strcmp("INTC0102", id->id)) + if (!strcmp(hid, id->id)) return 1; return 0; } + +static inline int is_itpm(struct acpi_device *dev) +{ + return has_hid(dev, "INTC0102"); +} + +static inline int is_tpm2_fifo(struct acpi_device *dev) +{ + struct acpi_table_tpm2 *tbl; + acpi_status st; + + if (!has_hid(dev, "MSFT0101")) + return 0; + + st = acpi_get_table(ACPI_SIG_TPM2, 1, + (struct acpi_table_header **) &tbl); + if (ACPI_FAILURE(st)) { + dev_err(&dev->dev, "failed to get TPM2 ACPI table\n"); + return 0; + } + + if (le32_to_cpu(tbl->start_method) != TPM2_START_FIFO) + return 0; + + return 1; +} #else static inline int is_itpm(struct acpi_device *dev) { return 0; } + +static inline int is_tpm2_fifo(struct acpi_device *dev) +{ + return 0; +} #endif /* Before we attempt to access the TPM we must see that the valid bit is set. @@ -912,6 +944,9 @@ static int tpm_tis_acpi_init(struct acpi_device *acpi_dev) struct tpm_info tpm_info = tis_default_info; int ret; + if (!is_tpm2_fifo(acpi_dev)) + return -ENODEV; + INIT_LIST_HEAD(&resources); ret = acpi_dev_get_resources(acpi_dev, &resources, tpm_check_resource, &tpm_info); @@ -937,6 +972,7 @@ static struct acpi_device_id tpm_acpi_tbl[] = { {"BCM0102", 0}, /* Broadcom */ {"NSC1200", 0}, /* National */ {"ICO0102", 0}, /* Intel */ + {"MSFT0101", 0}, /* TPM 2.0 */ /* Add new here */ {"", 0}, /* User Specified */ {"", 0} /* Terminator */