Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1235405 > unrolled thread

[PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID

Started byJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
First post2015-09-29 19:10 +0200
Last post2015-09-29 19:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> - 2015-09-29 19:10 +0200
    Re: [PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID kbuild test robot <lkp@intel.com> - 2015-09-29 19:50 +0200

#1235405 — [PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID

FromJarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
Date2015-09-29 19:10 +0200
Subject[PATCH 2/2] tpm, tpm_tis: detect TPM2 FIFO devices based on HID
Message-ID<qe6zE-4i6-5@gated-at.bofh.it>
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 <mick.saunders@gmail.com>
Reported-by: Michael Marley <michael@michaelmarley.com>
Reported-by: Jethro Beekman <kernel@jbeekman.nl>
Reported-by: Matthew Garrett <mjg59@srcf.ucam.org>
Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
---
 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 <linux/wait.h>
 #include <linux/acpi.h>
 #include <linux/freezer.h>
+#include <acpi/actbl2.h>
 #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 */
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1235439

Fromkbuild test robot <lkp@intel.com>
Date2015-09-29 19:50 +0200
Message-ID<qe7cn-50W-19@gated-at.bofh.it>
In reply to#1235405
Hi Jarkko,

[auto build test results on v4.3-rc3 -- if it's inappropriate base, please ignore]

reproduce:
  # apt-get install sparse
  make ARCH=x86_64 allmodconfig
  make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> drivers/char/tpm/tpm_tis.c:136:13: sparse: cast to restricted __le32

vim +136 drivers/char/tpm/tpm_tis.c

   120	
   121	static inline int is_tpm2_fifo(struct acpi_device *dev)
   122	{
   123		struct acpi_table_tpm2 *tbl;
   124		acpi_status st;
   125	
   126		if (!has_hid(dev, "MSFT0101"))
   127			return 0;
   128	
   129		st = acpi_get_table(ACPI_SIG_TPM2, 1,
   130				    (struct acpi_table_header **) &tbl);
   131		if (ACPI_FAILURE(st)) {
   132			dev_err(&dev->dev, "failed to get TPM2 ACPI table\n");
   133			return 0;
   134		}
   135	
 > 136		if (le32_to_cpu(tbl->start_method) != TPM2_START_FIFO)
   137			return 0;
   138	
   139		return 1;
   140	}
   141	#else
   142	static inline int is_itpm(struct acpi_device *dev)
   143	{
   144		return 0;

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web