Skip to contentSkip to conversation

tpm_tis: various cleanups, and support for Intel iTPM

PATCH In review Andy Isaacson 11 participants 35 messages Jul 1, 2009 – Nov 1, 2009

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover tpm_tis: various cleanups, and support for Intel iTPM

Several patches to improve drivers/char/tpm/tpm_tis.c:

- autoload tpm_tis.ko based on acpi / pnp
- fix driver/hardware bugs observed on iTPM
- improve module probing printks
- add workaround code for iTPM

With these patches, the T500's iTPM probes ok and has reasonable contents in /sys/kernel/security/tpm0/ascii_bios_measurements:

% dmesg|grep tpm

[    8.599680] tpm_tis INTC0102:00: found 0xfed40000(0x5000)
[    8.599769] tpm_tis INTC0102:00: no IRQ found in _CRS, polling mode
[    8.608607] tpm_tis INTC0102:00: 1.2 TPM (8086:1020 rev 6)
[    8.608665] tpm_tis INTC0102:00: Intel iTPM workaround enabled

% sudo head -3 /sys/kernel/security/tpm0/ascii_bios_measurements
0 d6184a2d2e3a8bfae13a1ebb37d62e222bfab57d 08 [S-CRTM Version] 1 0f18524a0ed83806de3bab13c05e2dcc7a8e9c09 09 [CPU Microcode] 0 d9f7d65755c884f6c25680d577f348523006eed3 01 [POST CODE]

Also, I've tested that the driver still works on Dell E4300.

I'm not sure that switching to ACPI probing is either necessary or a good idea, but I wasn't able to get the pnp_driver system to load the driver on the Lenovo.

 drivers/char/tpm/Kconfig   |    2 +-
 drivers/char/tpm/tpm_tis.c |  202 +++++++++++++++++------
 2 files changed, 150 insertions(+), 54 deletions(-)

-andy

#1 lore raw

PATCH 1/6 tpm_tis: various cleanups

Avoid tabs in printk output.
Use parentheses and ARRAY_SIZE() in macro definition.

---
 drivers/char/tpm/tpm_tis.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm_tis.c +10 -10
index 717af7a..1b84441 100644
@@ -474,23 +474,23 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
 		intfcaps);
 	if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
-		dev_dbg(dev, "\tBurst Count Static\n");
+		dev_dbg(dev, "    Burst Count Static\n");
 	if (intfcaps & TPM_INTF_CMD_READY_INT)
-		dev_dbg(dev, "\tCommand Ready Int Support\n");
+		dev_dbg(dev, "    Command Ready Int Support\n");
 	if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
-		dev_dbg(dev, "\tInterrupt Edge Falling\n");
+		dev_dbg(dev, "    Interrupt Edge Falling\n");
 	if (intfcaps & TPM_INTF_INT_EDGE_RISING)
-		dev_dbg(dev, "\tInterrupt Edge Rising\n");
+		dev_dbg(dev, "    Interrupt Edge Rising\n");
 	if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
-		dev_dbg(dev, "\tInterrupt Level Low\n");
+		dev_dbg(dev, "    Interrupt Level Low\n");
 	if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
-		dev_dbg(dev, "\tInterrupt Level High\n");
+		dev_dbg(dev, "    Interrupt Level High\n");
 	if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
-		dev_dbg(dev, "\tLocality Change Int Support\n");
+		dev_dbg(dev, "    Locality Change Int Support\n");
 	if (intfcaps & TPM_INTF_STS_VALID_INT)
-		dev_dbg(dev, "\tSts Valid Int Support\n");
+		dev_dbg(dev, "    Sts Valid Int Support\n");
 	if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
-		dev_dbg(dev, "\tData Avail Int Support\n");
+		dev_dbg(dev, "    Data Avail Int Support\n");
 
 	/* INTERRUPT Setup */
 	init_waitqueue_head(&chip->vendor.read_queue);
@@ -649,7 +649,7 @@ static struct pnp_driver tis_pnp_driver = {
 	.remove = tpm_tis_pnp_remove,
 };
 
-#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
+#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2)
 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
 		    sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
Signature · 1 line
1.6.3.1
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] tpm_tis: various cleanups

Quoted 54 lines · Andy Isaacson

Avoid tabs in printk output.
Use parentheses and ARRAY_SIZE() in macro definition.

---
 drivers/char/tpm/tpm_tis.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)
drivers/char/tpm/tpm_tis.c +10 -10
index 717af7a..1b84441 100644
@@ -474,23 +474,23 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	dev_dbg(dev, "TPM interface capabilities (0x%x):\n",
 		intfcaps);
 	if (intfcaps & TPM_INTF_BURST_COUNT_STATIC)
-		dev_dbg(dev, "\tBurst Count Static\n");
+		dev_dbg(dev, "    Burst Count Static\n");
 	if (intfcaps & TPM_INTF_CMD_READY_INT)
-		dev_dbg(dev, "\tCommand Ready Int Support\n");
+		dev_dbg(dev, "    Command Ready Int Support\n");
 	if (intfcaps & TPM_INTF_INT_EDGE_FALLING)
-		dev_dbg(dev, "\tInterrupt Edge Falling\n");
+		dev_dbg(dev, "    Interrupt Edge Falling\n");
 	if (intfcaps & TPM_INTF_INT_EDGE_RISING)
-		dev_dbg(dev, "\tInterrupt Edge Rising\n");
+		dev_dbg(dev, "    Interrupt Edge Rising\n");
 	if (intfcaps & TPM_INTF_INT_LEVEL_LOW)
-		dev_dbg(dev, "\tInterrupt Level Low\n");
+		dev_dbg(dev, "    Interrupt Level Low\n");
 	if (intfcaps & TPM_INTF_INT_LEVEL_HIGH)
-		dev_dbg(dev, "\tInterrupt Level High\n");
+		dev_dbg(dev, "    Interrupt Level High\n");
 	if (intfcaps & TPM_INTF_LOCALITY_CHANGE_INT)
-		dev_dbg(dev, "\tLocality Change Int Support\n");
+		dev_dbg(dev, "    Locality Change Int Support\n");
 	if (intfcaps & TPM_INTF_STS_VALID_INT)
-		dev_dbg(dev, "\tSts Valid Int Support\n");
+		dev_dbg(dev, "    Sts Valid Int Support\n");
 	if (intfcaps & TPM_INTF_DATA_AVAIL_INT)
-		dev_dbg(dev, "\tData Avail Int Support\n");
+		dev_dbg(dev, "    Data Avail Int Support\n");
 
 	/* INTERRUPT Setup */
 	init_waitqueue_head(&chip->vendor.read_queue);
@@ -649,7 +649,7 @@ static struct pnp_driver tis_pnp_driver = {
 	.remove = tpm_tis_pnp_remove,
 };
 
-#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
+#define TIS_HID_USR_IDX (ARRAY_SIZE(tpm_pnp_tbl) - 2)
 module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
 		    sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
 MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
#3 lore raw

PATCH 2/6 tpm_tis: add MODULE_DEVICE_TABLE to enable autoload

In reply to Andy Isaacson
---
 drivers/char/tpm/tpm_tis.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/char/tpm/tpm_tis.c +1 -0
index 1b84441..e859e0e 100644
@@ -629,6 +629,7 @@ static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
 	{"", 0},		/* User Specified */
 	{"", 0}			/* Terminator */
 };
+MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
 
 static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
 {
Signature · 1 line
1.6.3.1
Acked-by on v1 2/6
#4 lore raw

Re: [PATCH 2/6] tpm_tis: add MODULE_DEVICE_TABLE to enable autoload

Quoted 17 lines · Andy Isaacson
---
 drivers/char/tpm/tpm_tis.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/char/tpm/tpm_tis.c +1 -0
index 1b84441..e859e0e 100644
@@ -629,6 +629,7 @@ static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
 	{"", 0},		/* User Specified */
 	{"", 0}			/* Terminator */
 };
+MODULE_DEVICE_TABLE(pnp, tpm_pnp_tbl);
 
 static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
 {
#5 lore raw

PATCH 3/6 tpm_tis: set timeouts before calling request_locality

In reply to Andy Isaacson

On Intel iTPM implementations, the timeouts must be set before calling request_locality.

Based on a patch from Colin Didier and the tpmdd-devel mailing list:
http://cybione.org/~cdidier/log/data/200812020841/itpm.diff

---
 drivers/char/tpm/tpm_tis.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/char/tpm/tpm_tis.c +6 -6
index e859e0e..e0bda02 100644
@@ -450,6 +450,12 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 		goto out_err;
 	}
 
+	/* Default timeouts */
+	chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
+	chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
+	chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
+	chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
+
 	if (request_locality(chip, 0) != 0) {
 		rc = -ENODEV;
 		goto out_err;
@@ -457,12 +463,6 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 
-	/* Default timeouts */
-	chip->vendor.timeout_a = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
-	chip->vendor.timeout_b = msecs_to_jiffies(TIS_LONG_TIMEOUT);
-	chip->vendor.timeout_c = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
-	chip->vendor.timeout_d = msecs_to_jiffies(TIS_SHORT_TIMEOUT);
-
 	dev_info(dev,
 		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
Signature · 1 line
1.6.3.1
#6 lore raw

PATCH 4/6 tpm_tis: print complete vendor information

In reply to Andy Isaacson

The TPM_VID field contains a vendor-id as well as a device-id, but the code only prints the device-id. Fix it.

---
 drivers/char/tpm/tpm_tis.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm_tis.c +1 -1
index e0bda02..50c2a8a 100644
@@ -464,7 +464,7 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 
 	dev_info(dev,
-		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
+		 "1.2 TPM (%04X:%04X rev %d)\n", vendor & 0xffff,
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
 	/* Figure out the capabilities */
Signature · 1 line
1.6.3.1
Acked-by on v1 4/6
#7 lore raw

Re: [PATCH 4/6] tpm_tis: print complete vendor information

Quoted 21 lines · Andy Isaacson

The TPM_VID field contains a vendor-id as well as a device-id, but the code only prints the device-id. Fix it.

---
 drivers/char/tpm/tpm_tis.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm_tis.c +1 -1
index e0bda02..50c2a8a 100644
@@ -464,7 +464,7 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 
 	dev_info(dev,
-		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
+		 "1.2 TPM (%04X:%04X rev %d)\n", vendor & 0xffff,
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
 	/* Figure out the capabilities */
#8 lore raw

PATCH 5/6 tpm_tis: convert from pnp_driver to acpi_driver

In reply to Andy Isaacson

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

Convert to acpi_driver so that we can access the _CID entry.

---
 drivers/char/tpm/Kconfig   |    2 +-
 drivers/char/tpm/tpm_tis.c |  157 +++++++++++++++++++++++++++++++++----------
 2 files changed, 121 insertions(+), 38 deletions(-)
drivers/char/tpm/Kconfig +1 -1
index f5fc64f..204b69f 100644
@@ -24,7 +24,7 @@ if TCG_TPM
 
 config TCG_TIS
 	tristate "TPM Interface Specification 1.2 Interface"
-	depends on PNP
+	depends on ACPI
 	---help---
 	  If you have a TPM security chip that is compliant with the
 	  TCG TIS 1.2 TPM specification say Yes and it will be accessible
drivers/char/tpm/tpm_tis.c +120 -37

217 lines not on this page · raw message

Signature · 1 line
1.6.3.1
#9 lore raw

Re: [PATCH 5/6] tpm_tis: convert from pnp_driver to acpi_driver

Quoted 3 lines · On Tue, 30 Jun 2009 18:04:14 -0700 Andy Isaacson <[email protected]> wrote:

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

There are a number of systems with TPMs (older laptops) that don't work very well if you enable ACPI.

This is therefore a regression - NAK

Probably the best thing to do is to provide both ACPI and PnP registration according to what is configured into the kernel. (And I guess spot duplicates although the resource should be busy anyway)

#10 lore raw

Re: [PATCH 5/6] tpm_tis: convert from pnp_driver to acpi_driver

Quoted 10 lines · Alan Cox
Quoted 3 lines · On Tue, 30 Jun 2009 18:04:14 -0700 Andy Isaacson <[email protected]> wrote:

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

There are a number of systems with TPMs (older laptops) that don't work very well if you enable ACPI.

Quoted 6 lines

This is therefore a regression - NAK

Probably the best thing to do is to provide both ACPI and PnP registration according to what is configured into the kernel. (And I guess spot duplicates although the resource should be busy anyway) --

David sent this earlier when I said that PNP didn't work with this chip:

<quote>
The problem here is acpi pnp but the fix is really simple. The current pnpacpi/core.c routine that looks for isapnp devices enumerated in acpi enforces that the acpi hid be a valid isapnp id (the formats are slightly different). But that's broken: it shoudl be enforcing that either the acpi hid or any acpi cids be valid isapnp ids. It's a one-line change to do this, see patch 2.

commit 7a553b4e7439ad0733da7da8663d32aa4865aa9e

Author: David Smith <[email protected]>
Date:   Tue Apr 28 18:52:02 2009 +0900

Update ACPI PNP to support devices with EISA PNP CIDs but non-PNP HIDs

drivers/pnp/pnpacpi/core.c +2 -2
index 9496494..8bfddfb 100644
@@ -159,8 +159,8 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 	 * driver should not be loaded.
 	 */
 	status = acpi_get_handle(device->handle, "_CRS", &temp);
-	if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
-	    is_exclusive_device(device) || (!device->status.present))
+	if (ACPI_FAILURE(status) || is_exclusive_device(device) ||
+            (!device->status.present))
 		return 0;
 
 	dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));

</quote>

If so, we can just base our DATA_EXPECT bypass on the EISA PNP CID:

Quoted 1 line

From 47516ff6b63b81d1e806148dc5e3052a001e45d0 Mon Sep 17 00:00:00 2001

From: Rajiv Andrade <[email protected]>
Date: Wed, 1 Jul 2009 09:59:55 -0300
Subject: [PATCH] TPM: DATA_EXPECT bit check bypass

Since the iTPM doesn't set the DATA_EXPECT bit when it should, we bypass this bit check in case we're running the code over this specific TPM.

---
 drivers/char/tpm/tpm.h     |    1 +
 drivers/char/tpm/tpm_tis.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm.h +1 -0
index 8e00b4d..ed4ecf0 100644
@@ -109,6 +109,7 @@ struct tpm_chip {
 
 	struct list_head list;
 	void (*release) (struct device *);
+	bool is_itpm;
 };
 
 #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
drivers/char/tpm/tpm_tis.c +10 -1
index aec1931..74a60d7 100644
@@ -27,6 +27,7 @@
 #include "tpm.h"
 
 #define TPM_HEADER_SIZE 10
+#define ITPM_ID "INTC0102"
 
 enum tis_access {
 	TPM_ACCESS_VALID = 0x80,
@@ -293,7 +294,9 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
 			      &chip->vendor.int_queue);
 		status = tpm_tis_status(chip);
-		if ((status & TPM_STS_DATA_EXPECT) == 0) {
+		/* iTPM never sets the DATA_EXPECT bit */
+		if (((status & TPM_STS_DATA_EXPECT) == 0) &&
+		     (!chip->is_itpm)) {
 			rc = -EIO;
 			goto out_err;
 		}
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	tpm_get_timeouts(chip);
 	tpm_continue_selftest(chip);
 
+	for (i=0; i < 8; i++)
+		if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+			break;
+	if (i == 8)
+		chip->is_itpm = 1;
+
 	return 0;
 out_err:
 	if (chip->vendor.iobase)
Signature · 1 line
1.6.3.1
#11 lore raw

Re: [PATCH 5/6] tpm_tis: convert from pnp_driver to acpi_driver

Realized just now that this message was stuck in my outbox and was never sent.. Anyway, here it is. The ones who own the chip, please let me know if the patches here work OK.

Rajiv

Quoted 117 lines · Rajiv Andrade
Quoted 10 lines · Alan Cox
Quoted 3 lines · On Tue, 30 Jun 2009 18:04:14 -0700 Andy Isaacson <[email protected]> wrote:

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

There are a number of systems with TPMs (older laptops) that don't work very well if you enable ACPI.

Quoted 6 lines

This is therefore a regression - NAK

Probably the best thing to do is to provide both ACPI and PnP registration according to what is configured into the kernel. (And I guess spot duplicates although the resource should be busy anyway) --

David sent this earlier when I said that PNP didn't work with this chip:

<quote>
The problem here is acpi pnp but the fix is really simple. The current pnpacpi/core.c routine that looks for isapnp devices enumerated in acpi enforces that the acpi hid be a valid isapnp id (the formats are slightly different). But that's broken: it shoudl be enforcing that either the acpi hid or any acpi cids be valid isapnp ids. It's a one-line change to do this, see patch 2.

commit 7a553b4e7439ad0733da7da8663d32aa4865aa9e

Author: David Smith <[email protected]>
Date:   Tue Apr 28 18:52:02 2009 +0900

Update ACPI PNP to support devices with EISA PNP CIDs but non-PNP HIDs

drivers/pnp/pnpacpi/core.c +2 -2
index 9496494..8bfddfb 100644
@@ -159,8 +159,8 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 	 * driver should not be loaded.
 	 */
 	status = acpi_get_handle(device->handle, "_CRS", &temp);
-	if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
-	    is_exclusive_device(device) || (!device->status.present))
+	if (ACPI_FAILURE(status) || is_exclusive_device(device) ||
+            (!device->status.present))
 		return 0;
 
 	dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));

</quote>

If so, we can just base our DATA_EXPECT bypass on the EISA PNP CID:

Quoted 1 line

From 47516ff6b63b81d1e806148dc5e3052a001e45d0 Mon Sep 17 00:00:00 2001

From: Rajiv Andrade <[email protected]>
Date: Wed, 1 Jul 2009 09:59:55 -0300
Subject: [PATCH] TPM: DATA_EXPECT bit check bypass

Since the iTPM doesn't set the DATA_EXPECT bit when it should, we bypass this bit check in case we're running the code over this specific TPM.

---
 drivers/char/tpm/tpm.h     |    1 +
 drivers/char/tpm/tpm_tis.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm.h +1 -0
index 8e00b4d..ed4ecf0 100644
@@ -109,6 +109,7 @@ struct tpm_chip {
 
 	struct list_head list;
 	void (*release) (struct device *);
+	bool is_itpm;
 };
 
 #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
drivers/char/tpm/tpm_tis.c +10 -1
index aec1931..74a60d7 100644
@@ -27,6 +27,7 @@
 #include "tpm.h"
 
 #define TPM_HEADER_SIZE 10
+#define ITPM_ID "INTC0102"
 
 enum tis_access {
 	TPM_ACCESS_VALID = 0x80,
@@ -293,7 +294,9 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
 			      &chip->vendor.int_queue);
 		status = tpm_tis_status(chip);
-		if ((status & TPM_STS_DATA_EXPECT) == 0) {
+		/* iTPM never sets the DATA_EXPECT bit */
+		if (((status & TPM_STS_DATA_EXPECT) == 0) &&
+		     (!chip->is_itpm)) {
 			rc = -EIO;
 			goto out_err;
 		}
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	tpm_get_timeouts(chip);
 	tpm_continue_selftest(chip);
 
+	for (i=0; i < 8; i++)
+		if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+			break;
+	if (i == 8)
+		chip->is_itpm = 1;
+
 	return 0;
 out_err:
 	if (chip->vendor.iobase)
#12 lore raw

PATCH 1/1 TPM: DATA_EXPECT bit check bypass

Sending now inline in order to work ok with git-am, sorry for the flood.

This patch depends on patch http://patchwork.kernel.org/patch/33486/

Since the iTPM doesn't set the DATA_EXPECT bit when it should, we bypass this bit check in case we're running the code over this specific TPM.

---
 drivers/char/tpm/tpm.h     |    1 +
 drivers/char/tpm/tpm_tis.c |   11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm.h +1 -0
index 8e00b4d..ed4ecf0 100644
@@ -109,6 +109,7 @@ struct tpm_chip {
 
        struct list_head list;
        void (*release) (struct device *);
+       bool is_itpm;
 };
 
 #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
drivers/char/tpm/tpm_tis.c +10 -1
index aec1931..74a60d7 100644
@@ -27,6 +27,7 @@
 #include "tpm.h"
 
 #define TPM_HEADER_SIZE 10
+#define ITPM_ID "INTC0102"
 
 enum tis_access {
        TPM_ACCESS_VALID = 0x80,
@@ -293,7 +294,9 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
                wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
                              &chip->vendor.int_queue);
                status = tpm_tis_status(chip);
-               if ((status & TPM_STS_DATA_EXPECT) == 0) {
+               /* iTPM never sets the DATA_EXPECT bit */
+               if (((status & TPM_STS_DATA_EXPECT) == 0) &&
+                    (!chip->is_itpm)) {
                        rc = -EIO;
                        goto out_err;
                }
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+
        return 0;
 out_err:
        if (chip->vendor.iobase)
Signature · 1 line
1.6.3.1
#13 lore raw

Re: [PATCH] TPM: DATA_EXPECT bit check bypass

Review static int tpm_tis_init(struct device *dev, resource_siz

Quoted 1 line · Rajiv Andrade
(quoted diff) +0 -0
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_siz

e_t start,

drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 593

Quoted 9 lines
drivers/char/tpm/tpm_tis.c +6 -0
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+

strcmp() variant of some sort instead?

#14 lore raw

Re: [PATCH] TPM: DATA_EXPECT bit check bypass

Quoted 7 lines · On Thu, 2009-07-16 at 16:08 -0400, [email protected] wrote:

Review static int tpm_tis_init(struct device *dev, resource_siz

Quoted 1 line · Rajiv Andrade
(quoted diff) +0 -0
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_siz

e_t start,

Quoted 3 lines
drivers/char/tpm/tpm_tis.c +0 -0
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
Quoted 8 lines

drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 593

Quoted 6 lines
drivers/char/tpm/tpm_tis.c +6 -0
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+

strcmp() variant of some sort instead?

Much better, thanks. Forgot that lib/string.c can be handy sometimes :-)

Rajiv

#15 lore raw

Re: [PATCH] TPM: DATA_EXPECT bit check bypass

In reply to [email protected]
Quoted 7 lines · On Thu, 2009-07-16 at 16:08 -0400, [email protected] wrote:

Review static int tpm_tis_init(struct device *dev, resource_siz

Quoted 1 line · Rajiv Andrade
(quoted diff) +0 -0
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_siz

e_t start,

Quoted 3 lines
drivers/char/tpm/tpm_tis.c +0 -0
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
Quoted 8 lines

drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 593

Quoted 6 lines
drivers/char/tpm/tpm_tis.c +6 -0
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+

strcmp() variant of some sort instead?

Wait, is to_pnp_dev(dev)->id->id[i] null terminated? Maybe memcmp() fits better here..

Rajiv

#16 lore raw

Re: [PATCH] TPM: DATA_EXPECT bit check bypass

Quoted 15 lines · Rajiv Andrade
Quoted 14 lines · On Thu, 2009-07-16 at 16:08 -0400, [email protected] wrote:

Review static int tpm_tis_init(struct device *dev, resource_siz

Quoted 1 line · Rajiv Andrade
(quoted diff) +0 -0
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_siz

e_t start,

Quoted 9 lines
drivers/char/tpm/tpm_tis.c +6 -0
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+
Quoted 4 lines
Quoted 1 line

strcmp() variant of some sort instead?

Wait, is to_pnp_dev(dev)->id->id[i] null terminated? Maybe memcmp() fits better here..

Rather than checking the PNP ID at this point, I suggest something like:

(the context here depends on my earlier series, but it's fairly obvious.)

@@ -467,6 +481,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
"1.2 TPM (%04X:%04X rev %d)\n", vendor & 0xffff,
vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));

+ if (vendor == 0x10208086) {
+ dev_info(dev, "Intel iTPM workaround enabled\n");
+ chip->itpm = 1;
+ }
+
/* Figure out the capabilities */
intfcaps =
ioread32(chip->vendor.iobase +

(I suppose there should be a #define of 0x10208086 somewhere.)

I'll cook up a refreshed patch series.

-andy

#17 lore raw

Re: [PATCH] TPM: DATA_EXPECT bit check bypass

Quoted 39 lines · Andy Isaacson
Quoted 15 lines · Rajiv Andrade
Quoted 14 lines · On Thu, 2009-07-16 at 16:08 -0400, [email protected] wrote:

Review static int tpm_tis_init(struct device *dev, resource_siz

Quoted 1 line · Rajiv Andrade
(quoted diff) +0 -0
@@ -582,6 +585,12 @@ static int tpm_tis_init(struct device *dev, resource_siz

e_t start,

Quoted 9 lines
drivers/char/tpm/tpm_tis.c +6 -0
        tpm_get_timeouts(chip);
        tpm_continue_selftest(chip);
 
+       for (i=0; i < 8; i++)
+               if (ITPM_ID[i] != to_pnp_dev(dev)->id->id[i])
+                       break;
+       if (i == 8)
+               chip->is_itpm = 1;
+
Quoted 4 lines
Quoted 1 line

strcmp() variant of some sort instead?

Wait, is to_pnp_dev(dev)->id->id[i] null terminated? Maybe memcmp() fits better here..

Rather than checking the PNP ID at this point, I suggest something like:

(the context here depends on my earlier series, but it's fairly obvious.)

(quoted diff) +5 -0
@@ -467,6 +481,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 		 "1.2 TPM (%04X:%04X rev %d)\n", vendor & 0xffff,
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+	if (vendor == 0x10208086) {
+		dev_info(dev, "Intel iTPM workaround enabled\n");
+		chip->itpm = 1;
+	}
+
 	/* Figure out the capabilities */
 	intfcaps =
 	    ioread32(chip->vendor.iobase +
Quoted 2 lines

(I suppose there should be a #define of 0x10208086 somewhere.)

Much better, my patch would break everything in case force option was set.

Quoted 1 line

I'll cook up a refreshed patch series.

Great, I'll ack this one when I get it, thanks.

Rajiv
+++

#18 lore raw

Re: [PATCH 5/6] tpm_tis: convert from pnp_driver to acpi_driver

In reply to Rajiv Andrade
Quoted 51 lines · Rajiv Andrade
Quoted 10 lines · Alan Cox
Quoted 3 lines · On Tue, 30 Jun 2009 18:04:14 -0700 Andy Isaacson <[email protected]> wrote:

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

There are a number of systems with TPMs (older laptops) that don't work very well if you enable ACPI.

Quoted 6 lines

This is therefore a regression - NAK

Probably the best thing to do is to provide both ACPI and PnP registration according to what is configured into the kernel. (And I guess spot duplicates although the resource should be busy anyway) --

David sent this earlier when I said that PNP didn't work with this chip:

<quote>
The problem here is acpi pnp but the fix is really simple. The current pnpacpi/core.c routine that looks for isapnp devices enumerated in acpi enforces that the acpi hid be a valid isapnp id (the formats are slightly different). But that's broken: it shoudl be enforcing that either the acpi hid or any acpi cids be valid isapnp ids. It's a one-line change to do this, see patch 2.

commit 7a553b4e7439ad0733da7da8663d32aa4865aa9e

Author: David Smith <[email protected]>
Date:   Tue Apr 28 18:52:02 2009 +0900

Update ACPI PNP to support devices with EISA PNP CIDs but non-PNP HIDs

drivers/pnp/pnpacpi/core.c +2 -2
index 9496494..8bfddfb 100644
@@ -159,8 +159,8 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 	 * driver should not be loaded.
 	 */
 	status = acpi_get_handle(device->handle, "_CRS", &temp);
-	if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
-	    is_exclusive_device(device) || (!device->status.present))
+	if (ACPI_FAILURE(status) || is_exclusive_device(device) ||
+            (!device->status.present))
 		return 0;
 
 	dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
Quoted 1 line

</quote>

Len,

Is this an acceptable change to pnpacpi? It resolves an issue with tpm_tis but I'm concerned that it might have far-reaching impact.

I've pasted in the problematic DSDT (manually fixing up whitespace to make it more readable), and then a normal TPM simply has a _HID which is matched by a pnp_device_id table in the driver (drivers/char/tpm/tpm_tis.c).

T400:

        Device (TPM)
        {
            Method (_HID, 0, NotSerialized)
            {
                TPHY (0x00)
                If (LEqual (TPMV, 0x01)) { Return (0x0201D824) } 
                If (LEqual (TPMV, 0x02)) { Return (0x0435CF4D) } 
                If (LEqual (TPMV, 0x03)) { Return (0x02016D08) } 
                If (LEqual (TPMV, 0x04)) { Return (0x01016D08) } 
                If (LOr (LEqual (TPMV, 0x05), LEqual (TPMV, 0x06))) {
			Return (0x0010A35C)
		} 
                If (LEqual (TPMV, 0x08)) { Return (0x00128D06) } 
                If (LEqual (TPMV, 0x09)) { Return ("INTC0102") } 
                Return (0x310CD041)
            }

            Name (_CID, EisaId ("PNP0C31"))

standard TPM:

        Device (TPM)
        {
            Name (_HID, EisaId ("BCM0102"))
            Name (_CID, EisaId ("PNP0C31"))

The full thread is at
http://lkml.org/lkml/2009/7/1/265

Thanks for any insight.

-andy

#19 lore raw

Re: [PATCH 5/6] tpm_tis: convert from pnp_driver to acpi_driver

Quoted 90 lines · Andy Isaacson
Quoted 51 lines · Rajiv Andrade
Quoted 10 lines · Alan Cox
Quoted 3 lines · On Tue, 30 Jun 2009 18:04:14 -0700 Andy Isaacson <[email protected]> wrote:

Not all TIS-compatible TPM chips have a _HID method in their ACPI entry, and the TPM spec says that the _CID method should be used to enumerate the TPM chip.

There are a number of systems with TPMs (older laptops) that don't work very well if you enable ACPI.

Quoted 6 lines

This is therefore a regression - NAK

Probably the best thing to do is to provide both ACPI and PnP registration according to what is configured into the kernel. (And I guess spot duplicates although the resource should be busy anyway) --

David sent this earlier when I said that PNP didn't work with this chip:

<quote>
The problem here is acpi pnp but the fix is really simple. The current pnpacpi/core.c routine that looks for isapnp devices enumerated in acpi enforces that the acpi hid be a valid isapnp id (the formats are slightly different). But that's broken: it shoudl be enforcing that either the acpi hid or any acpi cids be valid isapnp ids. It's a one-line change to do this, see patch 2.

commit 7a553b4e7439ad0733da7da8663d32aa4865aa9e

Author: David Smith <[email protected]>
Date:   Tue Apr 28 18:52:02 2009 +0900

Update ACPI PNP to support devices with EISA PNP CIDs but non-PNP HIDs

drivers/pnp/pnpacpi/core.c +2 -2
index 9496494..8bfddfb 100644
@@ -159,8 +159,8 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
 	 * driver should not be loaded.
 	 */
 	status = acpi_get_handle(device->handle, "_CRS", &temp);
-	if (ACPI_FAILURE(status) || !ispnpidacpi(acpi_device_hid(device)) ||
-	    is_exclusive_device(device) || (!device->status.present))
+	if (ACPI_FAILURE(status) || is_exclusive_device(device) ||
+            (!device->status.present))
 		return 0;
 
 	dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
Quoted 1 line

</quote>

Len,

Is this an acceptable change to pnpacpi? It resolves an issue with tpm_tis but I'm concerned that it might have far-reaching impact.

I've pasted in the problematic DSDT (manually fixing up whitespace to make it more readable), and then a normal TPM simply has a _HID which is matched by a pnp_device_id table in the driver (drivers/char/tpm/tpm_tis.c).

T400:

        Device (TPM)
        {
            Method (_HID, 0, NotSerialized)
            {
                TPHY (0x00)
                If (LEqual (TPMV, 0x01)) { Return (0x0201D824) } 
                If (LEqual (TPMV, 0x02)) { Return (0x0435CF4D) } 
                If (LEqual (TPMV, 0x03)) { Return (0x02016D08) } 
                If (LEqual (TPMV, 0x04)) { Return (0x01016D08) } 
                If (LOr (LEqual (TPMV, 0x05), LEqual (TPMV, 0x06))) {
			Return (0x0010A35C)
		} 
                If (LEqual (TPMV, 0x08)) { Return (0x00128D06) } 
                If (LEqual (TPMV, 0x09)) { Return ("INTC0102") } 
                Return (0x310CD041)
            }

            Name (_CID, EisaId ("PNP0C31"))

standard TPM:

        Device (TPM)
        {
            Name (_HID, EisaId ("BCM0102"))
            Name (_CID, EisaId ("PNP0C31"))
Quoted 5 lines

The full thread is at
http://lkml.org/lkml/2009/7/1/265

Thanks for any insight.

We've already waited too much on this, is it acceptable to make the workaround depend on (and only on) the module parameter you've set in patch 6/6? Therefore no need to check the vendor ID.

<snip>
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)"); </snip>

It already mentions _Force_, which in many cases maps to "it's all your responsibility"...

And yes, still without PNP, but at least, working.

Rajiv

#20 lore raw

PATCH 1/1 tpm_tis: TPM_STS_DATA_EXPECT workaround

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

---

drivers/char/tpm/tpm_tis.c +9 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
 	return size;
 }
 
+static int itpm = 0;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
 /*
  * If interrupts are used (signaled by an irq set in the vendor structure)
  * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
 			      &chip->vendor.int_queue);
 		status = tpm_tis_status(chip);
-		if ((status & TPM_STS_DATA_EXPECT) == 0) {
+		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
 			rc = -EIO;
 			goto out_err;
 		}
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+	if (itpm) 
+		dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
 	/* Figure out the capabilities */
 	intfcaps =
 	    ioread32(chip->vendor.iobase +
#21 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

drivers/char/tpm/tpm_tis.c out: · line 260

Quoted 11 lines · Rajiv Andrade

---

drivers/char/tpm/tpm_tis.c +1 -0
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
 	return size;
 }
 
+static int itpm = 0;

This patch has some checkpatch issues .. Could you run it through ./script/checkpatch.pl and fix the issues that get reported?

Daniel

#22 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

Quoted 12 lines · Daniel Walker
Quoted 10 lines · Rajiv Andrade

---

drivers/char/tpm/tpm_tis.c +0 -0
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
 	return size;
 }
 
Quoted 5 lines

drivers/char/tpm/tpm_tis.c out: · line 260

Quoted 1 line
drivers/char/tpm/tpm_tis.c +1 -0
+static int itpm = 0;

This patch has some checkpatch issues .. Could you run it through ./script/checkpatch.pl and fix the issues that get reported?

Thanks for reminding me Daniel, it indeed complained about the itpm initialization to 0 and about a whitespace. Will post the fixed patch in reply to this note (avoid the quotes)

Rajiv

#23 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

In reply to Daniel Walker

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

Fixed a checkpatch issue present on the previous patch, thanks to Daniel Walker.

---

drivers/char/tpm/tpm_tis.c +9 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
 	return size;
 }
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
 /*
  * If interrupts are used (signaled by an irq set in the vendor structure)
  * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
 			      &chip->vendor.int_queue);
 		status = tpm_tis_status(chip);
-		if ((status & TPM_STS_DATA_EXPECT) == 0) {
+		if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
 			rc = -EIO;
 			goto out_err;
 		}
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+	if (itpm)
+		dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
 	/* Figure out the capabilities */
 	intfcaps =
 	    ioread32(chip->vendor.iobase +
Tested-by
#24 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

Quoted 11 lines · Rajiv Andrade

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

Quoted 8 lines

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

Fixed a checkpatch issue present on the previous patch, thanks to Daniel Walker.

As far as I know, only the intel tpm has this PNP issue, so I'm fine with it.

Quoted 39 lines

---

drivers/char/tpm/tpm_tis.c +9 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
        return size;
  }
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
  /*
  * If interrupts are used (signaled by an irq set in the vendor structure)
  * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
                wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
                              &chip->vendor.int_queue);
                status = tpm_tis_status(chip);
-               if ((status & TPM_STS_DATA_EXPECT) == 0) {
+               if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
                        rc = -EIO;
                        goto out_err;
                }
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
                 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
                 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+       if (itpm)
+               dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
        /* Figure out the capabilities */

       intfcaps =
           ioread32(chip->vendor.iobase +

#25 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

This was already tested and, given no more comments on it, finally reviewed. Can it already be merged?

Thanks,
Rajiv

Quoted 70 lines · Seiji Munetoh
Quoted 11 lines · Rajiv Andrade

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

Quoted 8 lines

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

Fixed a checkpatch issue present on the previous patch, thanks to Daniel Walker.

As far as I know, only the intel tpm has this PNP issue, so I'm fine with it.

Quoted 29 lines

---

drivers/char/tpm/tpm_tis.c +5 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
       return size;
 }
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
 /*
 * If interrupts are used (signaled by an irq set in the vendor structure)
 * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
               wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
                             &chip->vendor.int_queue);
               status = tpm_tis_status(chip);
-               if ((status & TPM_STS_DATA_EXPECT) == 0) {
+               if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
                       rc = -EIO;
                       goto out_err;
               }

drivers/char/tpm/tpm_tis.c static int tpm_tis_init(struct device *dev, resource_size_t start, · line 480

Quoted 10 lines
drivers/char/tpm/tpm_tis.c +4 -0
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
                "1.2 TPM (device-id 0x%X, rev-id %d)\n",
                vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+       if (itpm)
+               dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
       /* Figure out the capabilities */
       intfcaps =
           ioread32(chip->vendor.iobase +

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

#26 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

Hi, can this be merged, please? Using the module parameter is not optimal but it's better than the complete lack of support today.

Quoted 79 lines · Rajiv Andrade

This was already tested and, given no more comments on it, finally reviewed. Can it already be merged?

Thanks,
Rajiv

Quoted 70 lines · Seiji Munetoh
Quoted 11 lines · Rajiv Andrade

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

Quoted 8 lines

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

Fixed a checkpatch issue present on the previous patch, thanks to Daniel Walker.

As far as I know, only the intel tpm has this PNP issue, so I'm fine with it.

Quoted 34 lines

---

drivers/char/tpm/tpm_tis.c +9 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
        return size;
  }
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
  /*
  * If interrupts are used (signaled by an irq set in the vendor structure)
  * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
                wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
                              &chip->vendor.int_queue);
                status = tpm_tis_status(chip);
-               if ((status & TPM_STS_DATA_EXPECT) == 0) {
+               if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
                        rc = -EIO;
                        goto out_err;
                }
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
                 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
                 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+       if (itpm)
+               dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
        /* Figure out the capabilities */
Quoted 5 lines

       intfcaps =
           ioread32(chip->vendor.iobase +

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

Acked-by
#27 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

Quoted 7 lines · David Smith

Hi, can this be merged, please? Using the module parameter is not optimal but it's better than the complete lack of support today.

Quoted 2 lines · Rajiv Andrade

This was already tested and, given no more comments on it, finally reviewed. Can it already be merged?

James can we get this merged?

Quoted 83 lines
Quoted 77 lines

Thanks,
Rajiv

Quoted 70 lines · Seiji Munetoh
Quoted 11 lines · Rajiv Andrade

Some newer Lenovo models are shipped with a TPM that doesn't seem to set the TPM_STS_DATA_EXPECT status bit when sending it a burst of data, so the code understands it as a failure and doesn't proceed sending the chip the intended data. In this patch we bypass this bit check in case the itpm module parameter was set.

This patch is based on Andy Isaacson's one:

http://marc.info/?l=linux-kernel&m=124650185023495&w=2

It was heavily discussed how should we deal with identifying the chip in kernel space, but the required patch to do so was NACK'd:

Quoted 8 lines

http://marc.info/?l=linux-kernel&m=124650186423711&w=2

This way we let the user choose using this workaround or not based on his observations on this code behavior when trying to use the TPM.

Fixed a checkpatch issue present on the previous patch, thanks to Daniel Walker.

As far as I know, only the intel tpm has this PNP issue, so I'm fine with it.

Quoted 34 lines

---

drivers/char/tpm/tpm_tis.c +9 -1
index aec1931..c9990db 100644
@@ -257,6 +257,10 @@ out:
        return size;
  }
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
  /*
  * If interrupts are used (signaled by an irq set in the vendor structure)
  * tpm.c can skip polling for the data to be available as the interrupt is
@@ -293,7 +297,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
                wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
                              &chip->vendor.int_queue);
                status = tpm_tis_status(chip);
-               if ((status & TPM_STS_DATA_EXPECT) == 0) {
+               if (!itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
                        rc = -EIO;
                        goto out_err;
                }
@@ -467,6 +471,10 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
                 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
                 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+       if (itpm)
+               dev_info(dev, "Intel iTPM workaround enabled\n");
+
+
        /* Figure out the capabilities */
Quoted 5 lines

       intfcaps =
           ioread32(chip->vendor.iobase +

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

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

#28 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

Quoted 5 lines · Eric Paris
Quoted 3 lines · David Smith

Hi, can this be merged, please? Using the module parameter is not optimal but it's better than the complete lack of support today.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines · Rajiv Andrade

This was already tested and, given no more comments on it, finally reviewed. Can it already be merged?

James can we get this merged?

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

Signature · 2 lines
James Morris
<[email protected]>
#29 lore raw

Re: [PATCH] tpm_tis: TPM_STS_DATA_EXPECT workaround

In reply to Daniel Walker
Quoted 4 lines · Daniel Walker
Quoted 1 line

+static int itpm = 0;

This patch has some checkpatch issues .. Could you run it through ./script/checkpatch.pl and fix the issues that get reported?

Thanks for the reminder, will do.

-andy

#30 lore raw

PATCH 6/6 tpm_tis: add workarounds for iTPM

In reply to Andy Isaacson

Some Lenovo platforms (X200 and T400, maybe others) have an "iTPM" which does not quite conform to the TPM spec. With one small hack the iTPM seems to work OK.

iTPM does not set TPM_STS_DATA_EXPECT reliably during multi-burst transfers. (STS_DATA_EXPECT appears to be set after the final burst, not after each burst.) So we give up and don't attempt to report errors during write.

Based on a patch from Colin Didier and the tpmdd-devel mailing list:
http://cybione.org/~cdidier/log/data/200812020841/itpm.diff

---
 drivers/char/tpm/tpm_tis.c |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)
drivers/char/tpm/tpm_tis.c +13 -1
index 7f0cb6c..07ac7e0 100644
@@ -85,6 +85,7 @@ struct tpm_data {
 	void __iomem *tpm_address;
 	int tpm_size;
 	int tpm_irq;
+	int itpm;
 };
 
 static int check_locality(struct tpm_chip *chip, int l)
@@ -277,6 +278,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	int rc, status, burstcnt;
 	size_t count = 0;
 	u32 ordinal;
+	struct tpm_data *tpm = to_acpi_device(chip->dev)->driver_data;
 
 	if (request_locality(chip, 0) < 0)
 		return -EBUSY;
@@ -303,7 +305,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 		wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c,
 			      &chip->vendor.int_queue);
 		status = tpm_tis_status(chip);
-		if ((status & TPM_STS_DATA_EXPECT) == 0) {
+		if (!tpm->itpm && (status & TPM_STS_DATA_EXPECT) == 0) {
 			rc = -EIO;
 			goto out_err;
 		}
@@ -444,12 +446,17 @@ static int interrupts = 1;
 module_param(interrupts, bool, 0444);
 MODULE_PARM_DESC(interrupts, "Enable interrupts");
 
+static int itpm;
+module_param(itpm, bool, 0444);
+MODULE_PARM_DESC(itpm, "Force iTPM workarounds (found on some Lenovo laptops)");
+
 static int tpm_tis_init(struct device *dev, resource_size_t start,
 			resource_size_t len, unsigned int irq)
 {
 	u32 vendor, intfcaps, intmask;
 	int rc, i;
 	struct tpm_chip *chip;
+	struct tpm_data *tpm = to_acpi_device(dev)->driver_data;
 
 	if (!(chip = tpm_register_hardware(dev, &tpm_tis)))
 		return -ENODEV;
@@ -477,6 +484,11 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 		 "1.2 TPM (%04X:%04X rev %d)\n", vendor & 0xffff,
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
+	if (itpm || vendor == 0x10208086) {
+		dev_info(dev, "Intel iTPM workaround enabled\n");
+		tpm->itpm = 1;
+	}
+
 	/* Figure out the capabilities */
 	intfcaps =
 	    ioread32(chip->vendor.iobase +
Signature · 1 line
1.6.3.1
#31 lore raw

Re: [tpmdd-devel] [PATCH 6/6] tpm_tis: add workarounds for iTPM

2009/7/1 Andy Isaacson <[email protected]>:

Quoted 3 lines

Some Lenovo platforms (X200 and T400, maybe others) have an "iTPM" which does not quite conform to the TPM spec.  With one small hack the iTPM seems to work OK.

Small comment:

Intel iTPM on mobile platforms require this patch. Intel iTPM on desktop platforms works well without this patch.

--
Marcin

#32 lore raw

Re: [tpmdd-devel] [PATCH 6/6] tpm_tis: add workarounds for iTPM

Quoted 9 lines · Marcin Obara

2009/7/1 Andy Isaacson <[email protected]>:

Quoted 3 lines

Some Lenovo platforms (X200 and T400, maybe others) have an "iTPM" which does not quite conform to the TPM spec. ?With one small hack the iTPM seems to work OK.

Small comment:

Intel iTPM on mobile platforms require this patch. Intel iTPM on desktop platforms works well without this patch.

Please do expand on this -- I don't have access to any iTPM desktop platforms to verify. Can you provide information on what desktop platforms behave differently so that I can adjust the patch?

If you could simply boot a kernel with my patch series on a desktop iTPM and provide the dmesg output, that would be great!

Thanks,
-andy

#33 lore raw

Re: [tpmdd-devel] [PATCH 6/6] tpm_tis: add workarounds for iTPM

2009/7/3 Andy Isaacson <[email protected]>:

Quoted 10 lines · Marcin Obara
Quoted 2 lines

Intel iTPM on mobile platforms require this patch. Intel iTPM on desktop platforms works well without this patch.

Please do expand on this -- I don't have access to any iTPM desktop platforms to verify. Can you provide information on what desktop platforms behave differently so that I can adjust the patch?

If you could simply boot a kernel with my patch series on a desktop iTPM and provide the dmesg output, that would be great!

Intel iTPM with HID: ICO0102 does not require this patch.
(http://lkml.org/lkml/2008/6/28/143)

Currently, I don't have Q45 platform tested few months ago.

--
Marcin

#34 lore raw

Re: [tpmdd-devel] [PATCH 6/6] tpm_tis: add workarounds for iTPM

Quoted 9 lines · Marcin Obara

2009/7/3 Andy Isaacson <[email protected]>:

Quoted 8 lines · Marcin Obara
Quoted 2 lines

Intel iTPM on mobile platforms require this patch. Intel iTPM on desktop platforms works well without this patch.

Please do expand on this -- I don't have access to any iTPM desktop platforms to verify. Can you provide information on what desktop platforms behave differently so that I can adjust the patch?

Quoted 7 lines
Quoted 2 lines

If you could simply boot a kernel with my patch series on a desktop iTPM and provide the dmesg output, that would be great!

Intel iTPM with HID: ICO0102 does not require this patch.
(http://lkml.org/lkml/2008/6/28/143)

Currently, I don't have Q45 platform tested few months ago.

Ah, thanks for the reference. I may be able to find a Q45+iTPM to test on. It would still be very useful to get a dmesg (specifically with "[PATCH 4/6] tpm_tis: print complete vendor information") to verify the behavior on the Q45.

-andy