Skip to contentSkip to conversation

synquacer: add TPM support

PATCH Superseded Ard Biesheuvel 2 participants 4 messages Jan 14, 2020

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover synquacer: add TPM support

This adds support for driving the TPM on Socionext SynQuacer platforms using the existing driver for a memory mapped TIS frame.

Ard Biesheuvel (2):
dt-bindings: tpm-tis-mmio: add compatible string for SynQuacer TPM
tpm: tis: add support for MMIO TPM on SynQuacer

 Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt |  1 +
 drivers/char/tpm/tpm_tis.c                                      | 31 ++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH 1/2 dt-bindings: tpm-tis-mmio: add compatible string for SynQuacer TPM

Add a compatible string for the SynQuacer TPM to the binding for a TPM exposed via a memory mapped TIS frame. The MMIO window behaves slightly differently on this hardware, so it requires its own identifier.

---
 Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt | 1 +
 1 file changed, 1 insertion(+)
Documentation/devicetree/bindings/security/tpm/tpm_tis_mmio.txt +1 -0
index 7c6304426da1..b604c8688dc8 100644
@@ -12,6 +12,7 @@ Required properties:
 - compatible: should contain a string below for the chip, followed by
               "tcg,tpm-tis-mmio". Valid chip strings are:
 	          * "atmel,at97sc3204"
+		  * "socionext,synquacer-tpm-mmio"
 - reg: The location of the MMIO registers, should be at least 0x5000 bytes
 - interrupts: An optional interrupt indicating command completion.
 
Signature · 1 line
2.20.1
#2 lore raw

PATCH 2/2 tpm: tis: add support for MMIO TPM on SynQuacer

In reply to Ard Biesheuvel

When fitted, the SynQuacer platform exposes its SPI TPM via a MMIO window that is backed by the SPI command sequencer in the SPI bus controller. This arrangement has the limitation that only byte size accesses are supported, and so we'll need to provide a separate set of read and write accessors that take this into account.

---
 drivers/char/tpm/tpm_tis.c | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_tis.c +29 -2
index e7df342a317d..693e48096035 100644
@@ -32,6 +32,7 @@
 
 struct tpm_info {
 	struct resource res;
+	const struct tpm_tis_phy_ops *ops;
 	/* irq > 0 means: use irq $irq;
 	 * irq = 0 means: autoprobe for an irq;
 	 * irq = -1 means: no irq support
@@ -186,6 +187,29 @@ static const struct tpm_tis_phy_ops tpm_tcg = {
 	.write32 = tpm_tcg_write32,
 };
 
+static int tpm_tcg_read16_bw(struct tpm_tis_data *data, u32 addr, u16 *result)
+{
+	return tpm_tcg_read_bytes(data, addr, 2, (u8 *)result);
+}
+
+static int tpm_tcg_read32_bw(struct tpm_tis_data *data, u32 addr, u32 *result)
+{
+	return tpm_tcg_read_bytes(data, addr, 4, (u8 *)result);
+}
+
+static int tpm_tcg_write32_bw(struct tpm_tis_data *data, u32 addr, u32 value)
+{
+	return tpm_tcg_write_bytes(data, addr, 4, (u8 *)&value);
+}
+
+static const struct tpm_tis_phy_ops tpm_tcg_bw = {
+	.read_bytes	= tpm_tcg_read_bytes,
+	.write_bytes	= tpm_tcg_write_bytes,
+	.read16		= tpm_tcg_read16_bw,
+	.read32		= tpm_tcg_read32_bw,
+	.write32	= tpm_tcg_write32_bw,
+};
+
 static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
 {
 	struct tpm_tis_tcg_phy *phy;
@@ -210,7 +234,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
 	if (itpm || is_itpm(ACPI_COMPANION(dev)))
 		phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND;
 
-	return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg,
+	return tpm_tis_core_init(dev, &phy->priv, irq, tpm_info->ops,
 				 ACPI_HANDLE(dev));
 }
 
@@ -219,7 +243,7 @@ static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
 static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
 			    const struct pnp_device_id *pnp_id)
 {
-	struct tpm_info tpm_info = {};
+	struct tpm_info tpm_info = { .ops = &tpm_tcg };
 	struct resource *res;
 
 	res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
@@ -295,6 +319,8 @@ static int tpm_tis_plat_probe(struct platform_device *pdev)
 			tpm_info.irq = 0;
 	}
 
+	tpm_info.ops = of_device_get_match_data(&pdev->dev) ?: &tpm_tcg;
+
 	return tpm_tis_init(&pdev->dev, &tpm_info);
 }
 
@@ -311,6 +337,7 @@ static int tpm_tis_plat_remove(struct platform_device *pdev)
 #ifdef CONFIG_OF
 static const struct of_device_id tis_of_platform_match[] = {
 	{.compatible = "tcg,tpm-tis-mmio"},
+	{.compatible = "socionext,synquacer-tpm-mmio", .data = &tpm_tcg_bw},
 	{},
 };
 MODULE_DEVICE_TABLE(of, tis_of_platform_match);
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH 2/2] tpm: tis: add support for MMIO TPM on SynQuacer

Quoted 33 lines · Ard Biesheuvel

When fitted, the SynQuacer platform exposes its SPI TPM via a MMIO window that is backed by the SPI command sequencer in the SPI bus controller. This arrangement has the limitation that only byte size accesses are supported, and so we'll need to provide a separate set of read and write accessors that take this into account.

---
 drivers/char/tpm/tpm_tis.c | 31 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)
drivers/char/tpm/tpm_tis.c +6 -0
index e7df342a317d..693e48096035 100644
@@ -32,6 +32,7 @@
 
 struct tpm_info {
        struct resource res;
+       const struct tpm_tis_phy_ops *ops;
        /* irq > 0 means: use irq $irq;
         * irq = 0 means: autoprobe for an irq;
         * irq = -1 means: no irq support
@@ -186,6 +187,29 @@ static const struct tpm_tis_phy_ops tpm_tcg = {
        .write32 = tpm_tcg_write32,
 };
 
+static int tpm_tcg_read16_bw(struct tpm_tis_data *data, u32 addr, u16 *result)
+{
+       return tpm_tcg_read_bytes(data, addr, 2, (u8 *)result);
+}
+

drivers/char/tpm/tpm_tis.c static const struct tpm_tis_phy_ops tpm_tcg = { · line 204

Quoted 10 lines
drivers/char/tpm/tpm_tis.c +10 -0
+static int tpm_tcg_read32_bw(struct tpm_tis_data *data, u32 addr, u32 *result)
+{
+       return tpm_tcg_read_bytes(data, addr, 4, (u8 *)result);
+}
+
+static int tpm_tcg_write32_bw(struct tpm_tis_data *data, u32 addr, u32 value)
+{
+       return tpm_tcg_write_bytes(data, addr, 4, (u8 *)&value);
+}
+

These are wrong - I'll need to respin. Apologies for the noise.

Quoted 47 lines
drivers/char/tpm/tpm_tis.c +13 -3
+static const struct tpm_tis_phy_ops tpm_tcg_bw = {
+       .read_bytes     = tpm_tcg_read_bytes,
+       .write_bytes    = tpm_tcg_write_bytes,
+       .read16         = tpm_tcg_read16_bw,
+       .read32         = tpm_tcg_read32_bw,
+       .write32        = tpm_tcg_write32_bw,
+};
+
 static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
 {
        struct tpm_tis_tcg_phy *phy;
@@ -210,7 +234,7 @@ static int tpm_tis_init(struct device *dev, struct tpm_info *tpm_info)
        if (itpm || is_itpm(ACPI_COMPANION(dev)))
                phy->priv.flags |= TPM_TIS_ITPM_WORKAROUND;
 
-       return tpm_tis_core_init(dev, &phy->priv, irq, &tpm_tcg,
+       return tpm_tis_core_init(dev, &phy->priv, irq, tpm_info->ops,
                                 ACPI_HANDLE(dev));
 }
 
@@ -219,7 +243,7 @@ static SIMPLE_DEV_PM_OPS(tpm_tis_pm, tpm_pm_suspend, tpm_tis_resume);
 static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
                            const struct pnp_device_id *pnp_id)
 {
-       struct tpm_info tpm_info = {};
+       struct tpm_info tpm_info = { .ops = &tpm_tcg };
        struct resource *res;
 
        res = pnp_get_resource(pnp_dev, IORESOURCE_MEM, 0);
@@ -295,6 +319,8 @@ static int tpm_tis_plat_probe(struct platform_device *pdev)
                        tpm_info.irq = 0;
        }
 
+       tpm_info.ops = of_device_get_match_data(&pdev->dev) ?: &tpm_tcg;
+
        return tpm_tis_init(&pdev->dev, &tpm_info);
 }
 
@@ -311,6 +337,7 @@ static int tpm_tis_plat_remove(struct platform_device *pdev)
 #ifdef CONFIG_OF
 static const struct of_device_id tis_of_platform_match[] = {
        {.compatible = "tcg,tpm-tis-mmio"},
+       {.compatible = "socionext,synquacer-tpm-mmio", .data = &tpm_tcg_bw},
        {},
 };
 MODULE_DEVICE_TABLE(of, tis_of_platform_match);
--
Quoted 2 lines

2.20.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel