Skip to contentSkip to conversation

tpm: fix PS/2 devices not working on Braswell systems due CLKRUN enabled

PATCH In review Javier Martinez Canillas 2 participants 5 messages Dec 25, 2017 – Jan 2, 2018

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

v2 cover tpm: fix PS/2 devices not working on Braswell systems due CLKRUN enabled

Hello,

Commit 5e572cab92f0 ("tpm: Enable CLKRUN protocol for Braswell systems") added logic in the TPM TIS driver to disable the Low Pin Count CLKRUN signal during TPM transactions.

Unfortunately this breaks other devices that are attached to the LPC bus like for example PS/2 mouse and keyboards.

The bug was reported to the Fedora kernel [0] and the kernel bugzilla [1]. This issue and the propossed solution were discussed in this [2] thread, and the reporter (Jame Ettle) confirmed that his system works again after the fix in this series.

The patches are based on top or Jarkko Sakkinen's linux-tpmdd [3] tree.

Changes since v1:
- Add collected tags
- Drop patch that fixed a bug in the error path since was already fixed.

[0]: https://bugzilla.redhat.com/show_bug.cgi?id=1498987
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=197287
[2]: https://patchwork.kernel.org/patch/10119417/
[3]: git.infradead.org/users/jjs/linux-tpmdd.git

Best regards,
Javier

Javier Martinez Canillas (3):
tpm: delete the TPM_TIS_CLK_ENABLE flag
tpm: follow coding style for variable declaration in

    tpm_tis_core_init()

tpm: only attempt to disable the LPC CLKRUN if is already enabled

 drivers/char/tpm/tpm_tis.c      | 15 ---------------
 drivers/char/tpm/tpm_tis_core.c | 17 +++++++++++++----
 drivers/char/tpm/tpm_tis_core.h |  1 -
 3 files changed, 13 insertions(+), 20 deletions(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH v2 1/3 tpm: delete the TPM_TIS_CLK_ENABLE flag

This flag is only used to warn if CLKRUN_EN wasn't disabled on Braswell systems, but the only way this can happen is if the code is not correct.

So it's an unnecessary check that just makes the code harder to read.

---

 drivers/char/tpm/tpm_tis.c      | 15 ---------------
 drivers/char/tpm/tpm_tis_core.c |  2 --
 drivers/char/tpm/tpm_tis_core.h |  1 -
 3 files changed, 18 deletions(-)
drivers/char/tpm/tpm_tis.c +0 -15
index c847fc69a2fc..4b73e28458e3 100644
@@ -138,9 +138,6 @@ static int tpm_tcg_read_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
-		WARN(1, "CLKRUN not enabled!\n");
-
 	while (len--)
 		*result++ = ioread8(phy->iobase + addr);
 
@@ -152,9 +149,6 @@ static int tpm_tcg_write_bytes(struct tpm_tis_data *data, u32 addr, u16 len,
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
-		WARN(1, "CLKRUN not enabled!\n");
-
 	while (len--)
 		iowrite8(*value++, phy->iobase + addr);
 
@@ -165,9 +159,6 @@ static int tpm_tcg_read16(struct tpm_tis_data *data, u32 addr, u16 *result)
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
-		WARN(1, "CLKRUN not enabled!\n");
-
 	*result = ioread16(phy->iobase + addr);
 
 	return 0;
@@ -177,9 +168,6 @@ static int tpm_tcg_read32(struct tpm_tis_data *data, u32 addr, u32 *result)
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
-		WARN(1, "CLKRUN not enabled!\n");
-
 	*result = ioread32(phy->iobase + addr);
 
 	return 0;
@@ -189,9 +177,6 @@ static int tpm_tcg_write32(struct tpm_tis_data *data, u32 addr, u32 value)
 {
 	struct tpm_tis_tcg_phy *phy = to_tpm_tis_tcg_phy(data);
 
-	if (is_bsw() && !(data->flags & TPM_TIS_CLK_ENABLE))
-		WARN(1, "CLKRUN not enabled!\n");
-
 	iowrite32(value, phy->iobase + addr);
 
 	return 0;
drivers/char/tpm/tpm_tis_core.c +0 -2
index dc3600fc79b7..f2bd99fa8352 100644
@@ -751,7 +751,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
 		return;
 
 	if (value) {
-		data->flags |= TPM_TIS_CLK_ENABLE;
 		data->clkrun_enabled++;
 		if (data->clkrun_enabled > 1)
 			return;
@@ -782,7 +781,6 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
 		 * sure LPC clock is running before sending any TPM command.
 		 */
 		outb(0xCC, 0x80);
-		data->flags &= ~TPM_TIS_CLK_ENABLE;
 	}
 }
 
drivers/char/tpm/tpm_tis_core.h +0 -1
index afc50cde1ba6..d5c6a2e952b3 100644
@@ -86,7 +86,6 @@ enum tis_defaults {
 
 enum tpm_tis_flags {
 	TPM_TIS_ITPM_WORKAROUND		= BIT(0),
-	TPM_TIS_CLK_ENABLE		= BIT(1),
 };
 
 struct tpm_tis_data {
Signature · 1 line
2.14.3
#2 lore raw

PATCH v2 2/3 tpm: follow coding style for variable declaration in tpm_tis_core_init()

In reply to Javier Martinez Canillas

The coding style says "use just one data declaration per line (no commas for multiple data declarations)" so follow this convention.

---

 drivers/char/tpm/tpm_tis_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +3 -1
index f2bd99fa8352..03daf7017e0f 100644
@@ -803,7 +803,9 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 		      const struct tpm_tis_phy_ops *phy_ops,
 		      acpi_handle acpi_dev_handle)
 {
-	u32 vendor, intfcaps, intmask;
+	u32 vendor;
+	u32 intfcaps;
+	u32 intmask;
 	u8 rid;
 	int rc, probe;
 	struct tpm_chip *chip;
Signature · 1 line
2.14.3
#3 lore raw

PATCH v2 3/3 tpm: only attempt to disable the LPC CLKRUN if is already enabled

In reply to Javier Martinez Canillas

Commit 5e572cab92f0 ("tpm: Enable CLKRUN protocol for Braswell systems") added logic in the TPM TIS driver to disable the Low Pin Count CLKRUN signal during TPM transactions.

Unfortunately this breaks other devices that are attached to the LPC bus like for example PS/2 mouse and keyboards.

One flaw with the logic is that it assumes that the CLKRUN is always enabled, and so it unconditionally enables it after a TPM transaction.

But it could be that the CLKRUN# signal was already disabled in the LPC bus and so after the driver probes, CLKRUN_EN will remain enabled which may break other devices that are attached to the LPC bus but don't have support for the CLKRUN protocol.

Fixes 5e572cab92f0 ("tpm: Enable CLKRUN protocol for Braswell systems")

---

This patch fixes the bug reported for the Fedora kernel [0] and the kernel bugzilla [1]. The issue and the propossed solution were discussed in this
[2] thread.

[0]: https://bugzilla.redhat.com/show_bug.cgi?id=1498987
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=197287
[2]: https://patchwork.kernel.org/patch/10119417/

 drivers/char/tpm/tpm_tis_core.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +10 -1
index 03daf7017e0f..a72a9f03286d 100644
@@ -747,7 +747,8 @@ static void tpm_tis_clkrun_enable(struct tpm_chip *chip, bool value)
 	struct tpm_tis_data *data = dev_get_drvdata(&chip->dev);
 	u32 clkrun_val;
 
-	if (!IS_ENABLED(CONFIG_X86) || !is_bsw())
+	if (!IS_ENABLED(CONFIG_X86) || !is_bsw() ||
+	    !data->ilb_base_addr)
 		return;
 
 	if (value) {
@@ -806,6 +807,7 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 	u32 vendor;
 	u32 intfcaps;
 	u32 intmask;
+	u32 clkrun_val;
 	u8 rid;
 	int rc, probe;
 	struct tpm_chip *chip;
@@ -831,6 +833,13 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
 					ILB_REMAP_SIZE);
 		if (!priv->ilb_base_addr)
 			return -ENOMEM;
+
+		clkrun_val = ioread32(priv->ilb_base_addr + LPC_CNTRL_OFFSET);
+		/* Check if CLKRUN# is already not enabled in the LPC bus */
+		if (!(clkrun_val & LPC_CLKRUN_EN)) {
+			iounmap(priv->ilb_base_addr);
+			priv->ilb_base_addr = NULL;
+		}
 	}
 
 	if (chip->ops->clk_enable != NULL)
Signature · 1 line
2.14.3
#4 lore raw
In reply to Javier Martinez Canillas
Quoted 32 lines · Javier Martinez Canillas

Hello,

Commit 5e572cab92f0 ("tpm: Enable CLKRUN protocol for Braswell systems") added logic in the TPM TIS driver to disable the Low Pin Count CLKRUN signal during TPM transactions.

Unfortunately this breaks other devices that are attached to the LPC bus like for example PS/2 mouse and keyboards.

The bug was reported to the Fedora kernel [0] and the kernel bugzilla [1]. This issue and the propossed solution were discussed in this [2] thread, and the reporter (Jame Ettle) confirmed that his system works again after the fix in this series.

The patches are based on top or Jarkko Sakkinen's linux-tpmdd [3] tree.

Changes since v1:
- Add collected tags
- Drop patch that fixed a bug in the error path since was already fixed.

[0]: https://bugzilla.redhat.com/show_bug.cgi?id=1498987
[1]: https://bugzilla.kernel.org/show_bug.cgi?id=197287
[2]: https://patchwork.kernel.org/patch/10119417/
[3]: git.infradead.org/users/jjs/linux-tpmdd.git

Best regards,
Javier

Javier Martinez Canillas (3):
tpm: delete the TPM_TIS_CLK_ENABLE flag
tpm: follow coding style for variable declaration in

Quoted 11 lines
    tpm_tis_core_init()

tpm: only attempt to disable the LPC CLKRUN if is already enabled

 drivers/char/tpm/tpm_tis.c      | 15 ---------------
 drivers/char/tpm/tpm_tis_core.c | 17 +++++++++++++----
 drivers/char/tpm/tpm_tis_core.h |  1 -
 3 files changed, 13 insertions(+), 20 deletions(-)
Signature · 1 line
2.14.3

Thanks, these are now applied.

/Jarkko