Skip to content

Commit d04a248

Browse files
committed
Merge tag 'tpmdd-next-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd
Pull tpm updates from Jarkko Sakkinen: "Support for a new TPM device and fixes and Git URL change (infraded -> korg)" * tag 'tpmdd-next-v5.10' of git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd: MAINTAINERS: TPM DEVICE DRIVER: Update GIT tpm_tis: Add a check for invalid status tpm: use %*ph to print small buffer dt-bindings: Add SynQucer TPM MMIO as a trivial device tpm: tis: add support for MMIO TPM on SynQuacer
2 parents bbf5c97 + 7b9be80 commit d04a248

8 files changed

Lines changed: 246 additions & 22 deletions

File tree

Documentation/devicetree/bindings/trivial-devices.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ properties:
326326
- silabs,si7020
327327
# Skyworks SKY81452: Six-Channel White LED Driver with Touch Panel Bias Supply
328328
- skyworks,sky81452
329+
# Socionext SynQuacer TPM MMIO module
330+
- socionext,synquacer-tpm-mmio
329331
# i2c serial eeprom (24cxx)
330332
- st,24c256
331333
# Ambient Light Sensor with SMBUS/Two Wire Serial Interface

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17605,7 +17605,7 @@ L: linux-integrity@vger.kernel.org
1760517605
S: Maintained
1760617606
W: https://kernsec.org/wiki/index.php/Linux_Kernel_Integrity
1760717607
Q: https://patchwork.kernel.org/project/linux-integrity/list/
17608-
T: git git://git.infradead.org/users/jjs/linux-tpmdd.git
17608+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/jarkko/linux-tpmdd.git
1760917609
F: drivers/char/tpm/
1761017610

1761117611
TRACING

drivers/char/tpm/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ config TCG_TIS_SPI_CR50
7474
If you have a H1 secure module running Cr50 firmware on SPI bus,
7575
say Yes and it will be accessible from within Linux.
7676

77+
config TCG_TIS_SYNQUACER
78+
tristate "TPM Interface Specification 1.2 Interface / TPM 2.0 FIFO Interface (MMIO - SynQuacer)"
79+
depends on ARCH_SYNQUACER
80+
select TCG_TIS_CORE
81+
help
82+
If you have a TPM security chip that is compliant with the
83+
TCG TIS 1.2 TPM specification (TPM1.2) or the TCG PTP FIFO
84+
specification (TPM2.0) say Yes and it will be accessible from
85+
within Linux on Socionext SynQuacer platform.
86+
To compile this driver as a module, choose M here;
87+
the module will be called tpm_tis_synquacer.
88+
7789
config TCG_TIS_I2C_ATMEL
7890
tristate "TPM Interface Specification 1.2 Interface (I2C - Atmel)"
7991
depends on I2C

drivers/char/tpm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ tpm-$(CONFIG_EFI) += eventlog/efi.o
2121
tpm-$(CONFIG_OF) += eventlog/of.o
2222
obj-$(CONFIG_TCG_TIS_CORE) += tpm_tis_core.o
2323
obj-$(CONFIG_TCG_TIS) += tpm_tis.o
24+
obj-$(CONFIG_TCG_TIS_SYNQUACER) += tpm_tis_synquacer.o
2425

2526
obj-$(CONFIG_TCG_TIS_SPI) += tpm_tis_spi.o
2627
tpm_tis_spi-y := tpm_tis_spi_main.o

drivers/char/tpm/tpm-sysfs.c

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,31 +56,20 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
5656
out = (struct tpm_readpubek_out *)&tpm_buf.data[10];
5757
str +=
5858
sprintf(str,
59-
"Algorithm: %02X %02X %02X %02X\n"
60-
"Encscheme: %02X %02X\n"
61-
"Sigscheme: %02X %02X\n"
62-
"Parameters: %02X %02X %02X %02X "
63-
"%02X %02X %02X %02X "
64-
"%02X %02X %02X %02X\n"
59+
"Algorithm: %4ph\n"
60+
"Encscheme: %2ph\n"
61+
"Sigscheme: %2ph\n"
62+
"Parameters: %12ph\n"
6563
"Modulus length: %d\n"
6664
"Modulus:\n",
67-
out->algorithm[0], out->algorithm[1], out->algorithm[2],
68-
out->algorithm[3],
69-
out->encscheme[0], out->encscheme[1],
70-
out->sigscheme[0], out->sigscheme[1],
71-
out->parameters[0], out->parameters[1],
72-
out->parameters[2], out->parameters[3],
73-
out->parameters[4], out->parameters[5],
74-
out->parameters[6], out->parameters[7],
75-
out->parameters[8], out->parameters[9],
76-
out->parameters[10], out->parameters[11],
65+
out->algorithm,
66+
out->encscheme,
67+
out->sigscheme,
68+
out->parameters,
7769
be32_to_cpu(out->keysize));
7870

79-
for (i = 0; i < 256; i++) {
80-
str += sprintf(str, "%02X ", out->modulus[i]);
81-
if ((i + 1) % 16 == 0)
82-
str += sprintf(str, "\n");
83-
}
71+
for (i = 0; i < 256; i += 16)
72+
str += sprintf(str, "%16ph\n", &out->modulus[i]);
8473

8574
out_buf:
8675
tpm_buf_destroy(&tpm_buf);

drivers/char/tpm/tpm_tis_core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,17 @@ static u8 tpm_tis_status(struct tpm_chip *chip)
239239
if (rc < 0)
240240
return 0;
241241

242+
if (unlikely((status & TPM_STS_READ_ZERO) != 0)) {
243+
/*
244+
* If this trips, the chances are the read is
245+
* returning 0xff because the locality hasn't been
246+
* acquired. Usually because tpm_try_get_ops() hasn't
247+
* been called before doing a TPM operation.
248+
*/
249+
WARN_ONCE(1, "TPM returned invalid status\n");
250+
return 0;
251+
}
252+
242253
return status;
243254
}
244255

drivers/char/tpm/tpm_tis_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum tis_status {
3434
TPM_STS_GO = 0x20,
3535
TPM_STS_DATA_AVAIL = 0x10,
3636
TPM_STS_DATA_EXPECT = 0x08,
37+
TPM_STS_READ_ZERO = 0x23, /* bits that must be zero on read */
3738
};
3839

3940
enum tis_int_flags {
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (C) 2020 Linaro Ltd.
4+
*
5+
* This device driver implements MMIO TPM on SynQuacer Platform.
6+
*/
7+
#include <linux/acpi.h>
8+
#include <linux/init.h>
9+
#include <linux/module.h>
10+
#include <linux/slab.h>
11+
#include <linux/of.h>
12+
#include <linux/of_device.h>
13+
#include <linux/kernel.h>
14+
#include "tpm.h"
15+
#include "tpm_tis_core.h"
16+
17+
/*
18+
* irq > 0 means: use irq $irq;
19+
* irq = 0 means: autoprobe for an irq;
20+
* irq = -1 means: no irq support
21+
*/
22+
struct tpm_tis_synquacer_info {
23+
struct resource res;
24+
int irq;
25+
};
26+
27+
struct tpm_tis_synquacer_phy {
28+
struct tpm_tis_data priv;
29+
void __iomem *iobase;
30+
};
31+
32+
static inline struct tpm_tis_synquacer_phy *to_tpm_tis_tcg_phy(struct tpm_tis_data *data)
33+
{
34+
return container_of(data, struct tpm_tis_synquacer_phy, priv);
35+
}
36+
37+
static int tpm_tis_synquacer_read_bytes(struct tpm_tis_data *data, u32 addr,
38+
u16 len, u8 *result)
39+
{
40+
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
41+
42+
while (len--)
43+
*result++ = ioread8(phy->iobase + addr);
44+
45+
return 0;
46+
}
47+
48+
static int tpm_tis_synquacer_write_bytes(struct tpm_tis_data *data, u32 addr,
49+
u16 len, const u8 *value)
50+
{
51+
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
52+
53+
while (len--)
54+
iowrite8(*value++, phy->iobase + addr);
55+
56+
return 0;
57+
}
58+
59+
static int tpm_tis_synquacer_read16_bw(struct tpm_tis_data *data,
60+
u32 addr, u16 *result)
61+
{
62+
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
63+
64+
/*
65+
* Due to the limitation of SPI controller on SynQuacer,
66+
* 16/32 bits access must be done in byte-wise and descending order.
67+
*/
68+
*result = (ioread8(phy->iobase + addr + 1) << 8) |
69+
(ioread8(phy->iobase + addr));
70+
71+
return 0;
72+
}
73+
74+
static int tpm_tis_synquacer_read32_bw(struct tpm_tis_data *data,
75+
u32 addr, u32 *result)
76+
{
77+
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
78+
79+
/*
80+
* Due to the limitation of SPI controller on SynQuacer,
81+
* 16/32 bits access must be done in byte-wise and descending order.
82+
*/
83+
*result = (ioread8(phy->iobase + addr + 3) << 24) |
84+
(ioread8(phy->iobase + addr + 2) << 16) |
85+
(ioread8(phy->iobase + addr + 1) << 8) |
86+
(ioread8(phy->iobase + addr));
87+
88+
return 0;
89+
}
90+
91+
static int tpm_tis_synquacer_write32_bw(struct tpm_tis_data *data,
92+
u32 addr, u32 value)
93+
{
94+
struct tpm_tis_synquacer_phy *phy = to_tpm_tis_tcg_phy(data);
95+
96+
/*
97+
* Due to the limitation of SPI controller on SynQuacer,
98+
* 16/32 bits access must be done in byte-wise and descending order.
99+
*/
100+
iowrite8(value >> 24, phy->iobase + addr + 3);
101+
iowrite8(value >> 16, phy->iobase + addr + 2);
102+
iowrite8(value >> 8, phy->iobase + addr + 1);
103+
iowrite8(value, phy->iobase + addr);
104+
105+
return 0;
106+
}
107+
108+
static const struct tpm_tis_phy_ops tpm_tcg_bw = {
109+
.read_bytes = tpm_tis_synquacer_read_bytes,
110+
.write_bytes = tpm_tis_synquacer_write_bytes,
111+
.read16 = tpm_tis_synquacer_read16_bw,
112+
.read32 = tpm_tis_synquacer_read32_bw,
113+
.write32 = tpm_tis_synquacer_write32_bw,
114+
};
115+
116+
static int tpm_tis_synquacer_init(struct device *dev,
117+
struct tpm_tis_synquacer_info *tpm_info)
118+
{
119+
struct tpm_tis_synquacer_phy *phy;
120+
121+
phy = devm_kzalloc(dev, sizeof(struct tpm_tis_synquacer_phy), GFP_KERNEL);
122+
if (phy == NULL)
123+
return -ENOMEM;
124+
125+
phy->iobase = devm_ioremap_resource(dev, &tpm_info->res);
126+
if (IS_ERR(phy->iobase))
127+
return PTR_ERR(phy->iobase);
128+
129+
return tpm_tis_core_init(dev, &phy->priv, tpm_info->irq, &tpm_tcg_bw,
130+
ACPI_HANDLE(dev));
131+
}
132+
133+
static SIMPLE_DEV_PM_OPS(tpm_tis_synquacer_pm, tpm_pm_suspend, tpm_tis_resume);
134+
135+
static int tpm_tis_synquacer_probe(struct platform_device *pdev)
136+
{
137+
struct tpm_tis_synquacer_info tpm_info = {};
138+
struct resource *res;
139+
140+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
141+
if (res == NULL) {
142+
dev_err(&pdev->dev, "no memory resource defined\n");
143+
return -ENODEV;
144+
}
145+
tpm_info.res = *res;
146+
147+
tpm_info.irq = -1;
148+
149+
return tpm_tis_synquacer_init(&pdev->dev, &tpm_info);
150+
}
151+
152+
static int tpm_tis_synquacer_remove(struct platform_device *pdev)
153+
{
154+
struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
155+
156+
tpm_chip_unregister(chip);
157+
tpm_tis_remove(chip);
158+
159+
return 0;
160+
}
161+
162+
#ifdef CONFIG_OF
163+
static const struct of_device_id tis_synquacer_of_platform_match[] = {
164+
{.compatible = "socionext,synquacer-tpm-mmio"},
165+
{},
166+
};
167+
MODULE_DEVICE_TABLE(of, tis_synquacer_of_platform_match);
168+
#endif
169+
170+
#ifdef CONFIG_ACPI
171+
static const struct acpi_device_id tpm_synquacer_acpi_tbl[] = {
172+
{ "SCX0009" },
173+
{},
174+
};
175+
MODULE_DEVICE_TABLE(acpi, tpm_synquacer_acpi_tbl);
176+
#endif
177+
178+
static struct platform_driver tis_synquacer_drv = {
179+
.probe = tpm_tis_synquacer_probe,
180+
.remove = tpm_tis_synquacer_remove,
181+
.driver = {
182+
.name = "tpm_tis_synquacer",
183+
.pm = &tpm_tis_synquacer_pm,
184+
.of_match_table = of_match_ptr(tis_synquacer_of_platform_match),
185+
.acpi_match_table = ACPI_PTR(tpm_synquacer_acpi_tbl),
186+
},
187+
};
188+
189+
static int __init tpm_tis_synquacer_module_init(void)
190+
{
191+
int rc;
192+
193+
rc = platform_driver_register(&tis_synquacer_drv);
194+
if (rc)
195+
return rc;
196+
197+
return 0;
198+
}
199+
200+
static void __exit tpm_tis_synquacer_module_exit(void)
201+
{
202+
platform_driver_unregister(&tis_synquacer_drv);
203+
}
204+
205+
module_init(tpm_tis_synquacer_module_init);
206+
module_exit(tpm_tis_synquacer_module_exit);
207+
MODULE_DESCRIPTION("TPM MMIO Driver for Socionext SynQuacer platform");
208+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)