Add tpm i2c ptp driver
Subsystems (3)
cover Add tpm i2c ptp driver
This is the latest (v19) series that's been sent upstream. There is need for it on OpenBMC systems now and it's working well, so I'm sending it for inclusion in dev-5.15.
I also added the TPM to the two P10 IBM systems devicetrees.
Amir Mizinski (5):
tpm_tis: Fix expected bit handling
tpm: tpm_tis: Rewrite "tpm_tis_req_canceled()"
tpm: tpm_tis: Verify TPM_STS register is valid after locality request
tpm: tpm_tis: Add tpm_tis_i2c driver
tpm: Add YAML schema for TPM TIS I2C options
Eddie James (2):
ARM: dts: aspeed: Rainier: Add TPM device
ARM: dts: aspeed: Everest: Add TPM device
.../bindings/security/tpm/tpm-tis-i2c.yaml | 52 ++++ arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts | 5 + arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 5 + drivers/char/tpm/Kconfig | 12 + drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_tis_core.c | 72 +++-- drivers/char/tpm/tpm_tis_i2c.c | 263 ++++++++++++++++++ 7 files changed, 371 insertions(+), 39 deletions(-) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml create mode 100644 drivers/char/tpm/tpm_tis_i2c.c
Signature · 1 line
2.27.0
PATCH 1/7 tpm_tis: Fix expected bit handling
From: Amir Mizinski <[email protected]>
Currently, the driver polls the TPM_STS.stsValid field until TRUE; then it reads TPM_STS register again to verify only that TPM_STS.expect field is FALSE (i.e., it ignores TPM_STS.stsValid).
Since TPM_STS.stsValid represents the TPM_STS.expect validity, a check of only one of these fields is wrong. Fix this condition so that both fields are checked in the same TPM_STS register read.
Modify the signature of wait_for_tpm_stat() to tpm_tis_wait_for_stat(), adding an additional "expected" parameter to its call. tpm_tis_wait_for_stat() is now polling the TPM_STS with a mask and waits for the value in "expected". This modification adds the ability to check if certain TPM_STS bits have been cleared.
For example, use the new parameter to check in status that TPM_STS_VALID is set and also that TPM_STS_EXPECT is zeroed. This prevents a racy check.
--- drivers/char/tpm/tpm_tis_core.c | 61 +++++++++++++++------------------ 1 file changed, 27 insertions(+), 34 deletions(-)
drivers/char/tpm/tpm_tis_core.c +27 -34
@@ -44,9 +44,9 @@ static bool wait_for_tpm_stat_cond(struct tpm_chip *chip, u8 mask,return false; } -static int wait_for_tpm_stat (struct tpm_chip *chip,u8 mask, -unsigned long timeout,wait_queue_head_t *queue, -bool check_cancel) +static int tpm_tis_wait_for_stat (struct tpm_chip *chip,u8 mask,u8 expected, +unsigned long timeout, +wait_queue_head_t *queue,bool check_cancel) {struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);unsigned long stop;
@@ -56,7 +56,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,/* check current status */ status = chip->ops->status (chip); -if ((status & mask) == mask) +if ((status & mask) == expected)return 0 ; stop = jiffies + timeout;
@@ -84,7 +84,7 @@ static int wait_for_tpm_stat(struct tpm_chip *chip, u8 mask,usleep_range (priv->timeout_min, priv->timeout_max); status = chip->ops->status (chip); -if ((status & mask) == mask) +if ((status & mask) == expected)return 0 ; }while (time_before (jiffies, stop)); }
@@ -260,10 +260,11 @@ static int recv_data(struct tpm_chip *chip, u8 *buf, size_t count)int size =0 , burstcnt, rc;while (size < count) { - rc =wait_for_tpm_stat (chip, -TPM_STS_DATA_AVAIL |TPM_STS_VALID , - chip->timeout_c, - &priv->read_queue, true); + rc =tpm_tis_wait_for_stat (chip, +TPM_STS_DATA_AVAIL |TPM_STS_VALID , +TPM_STS_DATA_AVAIL |TPM_STS_VALID , + chip->timeout_c, &priv->read_queue, + true);if (rc <0 )return rc; burstcnt =get_burstcount (chip);
@@ -316,8 +317,9 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count) goto out; } -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { +if (tpm_tis_wait_for_stat (chip,TPM_STS_VALID ,TPM_STS_VALID , + chip->timeout_c, &priv->int_queue, + false) <0 ) { size = -ETIME ; goto out; }
@@ -343,14 +345,14 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len)struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);int rc, status, burstcnt;size_t count =0 ; -bool itpm = priv->flags &TPM_TIS_ITPM_WORKAROUND ; status =tpm_tis_status (chip);if ((status &TPM_STS_COMMAND_READY ) ==0 ) {tpm_tis_ready (chip); -if (wait_for_tpm_stat - (chip,TPM_STS_COMMAND_READY , chip->timeout_b, - &priv->int_queue, false) <0 ) { +if (tpm_tis_wait_for_stat (chip,TPM_STS_COMMAND_READY , +TPM_STS_COMMAND_READY , + chip->timeout_b, &priv->int_queue, + false) <0 ) { rc = -ETIME ; goto out_err; }
@@ -370,34 +372,24 @@ static int tpm_tis_send_data(struct tpm_chip *chip, const u8 *buf, size_t len) goto out_err; count += burstcnt; - -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { +if (tpm_tis_wait_for_stat (chip,TPM_STS_VALID |TPM_STS_DATA_EXPECT , +TPM_STS_VALID |TPM_STS_DATA_EXPECT , chip->timeout_a, + &priv->int_queue, false) <0 ) { rc = -ETIME ; goto out_err; } - status =tpm_tis_status (chip); -if (!itpm && (status &TPM_STS_DATA_EXPECT ) ==0 ) { - rc = -EIO ; - goto out_err; - } }/* write last byte */ rc =tpm_tis_write8 (priv,TPM_DATA_FIFO (priv->locality), buf[count]);if (rc <0 ) goto out_err; - -if (wait_for_tpm_stat (chip,TPM_STS_VALID , chip->timeout_c, - &priv->int_queue, false) <0 ) { +if (tpm_tis_wait_for_stat (chip,TPM_STS_VALID |TPM_STS_DATA_EXPECT , +TPM_STS_VALID , chip->timeout_a, + &priv->int_queue, false) <0 ) { rc = -ETIME ; goto out_err; } - status =tpm_tis_status (chip); -if (!itpm && (status &TPM_STS_DATA_EXPECT ) !=0 ) { - rc = -EIO ; - goto out_err; - }return 0 ;
@@ -452,9 +444,10 @@ static int tpm_tis_send_main(struct tpm_chip *chip, const u8 *buf, size_t len) ordinal =be32_to_cpu (*((__be32 *) (buf +6 ))); dur =tpm_calc_ordinal_duration (chip, ordinal); -if (wait_for_tpm_stat - (chip,TPM_STS_DATA_AVAIL |TPM_STS_VALID , dur, - &priv->read_queue, false) <0 ) { +if (tpm_tis_wait_for_stat (chip, +TPM_STS_DATA_AVAIL |TPM_STS_VALID , +TPM_STS_DATA_AVAIL |TPM_STS_VALID , + dur, &priv->read_queue, false) <0 ) { rc = -ETIME ; goto out_err; }
Signature · 1 line
2.27.0
PATCH 2/7 tpm: tpm_tis: Rewrite "tpm_tis_req_canceled()"
In reply to Eddie JamesFrom: Amir Mizinski <[email protected]>
tpm_tis_req_canceled() function is used to check if the caller requested to abort the current operation. It was found that in some cases tpm_tis_req_canceled() wrongly returned true.
Since a cancel request sets the TPM_STS.commandReady field to TRUE, the tpm_tis_req_canceled() function should check only the TPM_STS.commandReady field value.
The case for TPM_VID_WINBOND is wrong and was therefore removed.
Also, the default comparison is wrong. Only cmdReady bit needs to be compared instead of the full lower status register byte.
--- drivers/char/tpm/tpm_tis_core.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/char/tpm/tpm_tis_core.c +1 -4
@@ -662,13 +662,10 @@ static bool tpm_tis_req_canceled(struct tpm_chip *chip, u8 status)struct tpm_tis_data *priv =dev_get_drvdata (&chip->dev);switch (priv->manufacturer_id) { -case TPM_VID_WINBOND : -return ((status ==TPM_STS_VALID ) || - (status == (TPM_STS_VALID |TPM_STS_COMMAND_READY )));case TPM_VID_STM :return (status == (TPM_STS_VALID |TPM_STS_COMMAND_READY ));default : -return (status ==TPM_STS_COMMAND_READY ); +return (status &TPM_STS_COMMAND_READY ) ==TPM_STS_COMMAND_READY ; } }
Signature · 1 line
2.27.0
PATCH 3/7 tpm: tpm_tis: Verify TPM_STS register is valid after locality request
In reply to Eddie JamesFrom: Amir Mizinski <[email protected]>
An invalid TPM_STS value could be used when the following two events occur:
TPM does not update TPM_STS register after a locality request (TPM_STS Initial value = 0xFF), and a TPM_STS register read occurs in the tpm_tis_status(chip) function call.
In probe_itpm(), a call to tpm_tis_send_data() function is made after a request_locality() call, and the condition
("if ((status & TPM_STS_COMMAND_READY) == 0)") is checked. At this moment if the status value is 0xFF, then it is considered, wrongly, in “ready” state (by checking only one bit). However, at this moment the TPM is, in fact, in "Idle" state and remains in "Idle" state because "tpm_tis_ready(chip);" was not executed.
Waiting for the condition TPM_STS.tpmGo == 0, will ensure that the TPM status register has the correct value.
--- drivers/char/tpm/tpm_tis_core.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/char/tpm/tpm_tis_core.c +5 -1
@@ -178,8 +178,12 @@ static int request_locality(struct tpm_chip *chip, int l) }else {/* wait for burstcount */ do { -if (check_locality (chip, l)) +if (check_locality (chip, l)) { +if (tpm_tis_wait_for_stat (chip,TPM_STS_GO ,0 , chip->timeout_c, + &priv->int_queue, false) <0 ) +return -ETIME ;return l; + }tpm_msleep (TPM_TIMEOUT ); }while (time_before (jiffies, stop)); }
Signature · 1 line
2.27.0
PATCH 4/7 tpm: tpm_tis: Add tpm_tis_i2c driver
In reply to Eddie JamesFrom: Amir Mizinski <[email protected]>
I2C support for TPM devices on the TIS interface is currently available only as a proprietary driver implementation for each TPM vendor. This patch implements the infrastructure for a TCG-compliant TPM TIS I2C driver with the functionality required to communicate with a TPM device over I2C according to the "TCG PC Client PTP Interface Specification" and "Device Driver Design Principles for TPM 2.0"
References:
[1] "TCG PC Client Platform TPM Profile(PTP) Interface Specification for TPM 2.0" Version 01.03 Revision 22 at:
https://trustedcomputinggroup.org/resource/pc-client-platform-tpm-profile-ptp-specification/
[2] "TCG PC Client Device Driver Design Principles for TPM 2.0" Version 1.0 Revision 27 at:
https://trustedcomputinggroup.org/resource/tcg-pc-client-device-driver-design-principles-for-tpm-2-0/
--- drivers/char/tpm/Kconfig | 12 ++ drivers/char/tpm/Makefile | 1 + drivers/char/tpm/tpm_tis_i2c.c | 263 +++++++++++++++++++++++++++++++++ 3 files changed, 276 insertions(+) create mode 100644 drivers/char/tpm/tpm_tis_i2c.c
drivers/char/tpm/Kconfig +12 -0
@@ -86,6 +86,18 @@ config TCG_TIS_SYNQUACER To compile this driver as a module, choose M here; the module will be called tpm_tis_synquacer. +config TCG_TIS_I2C + tristate "TPM I2C Interface Specification" + depends on I2C + select CRC_CCITT + select TCG_TIS_CORE + help + If you have a TPM security chip, compliant with the TCG TPM PTP + (I2C interface) specification and connected to an I2C bus master, + say Yes and it will be accessible from within Linux. + To compile this driver as a module, choose M here; + the module will be called tpm_tis_i2c. + config TCG_TIS_I2C_CR50 tristate "TPM Interface Specification 2.0 Interface (I2C - CR50)" depends on I2C
drivers/char/tpm/Makefile +1 -0
@@ -29,6 +29,7 @@ tpm_tis_spi-$(CONFIG_TCG_TIS_SPI_CR50) += tpm_tis_spi_cr50.o obj-$(CONFIG_TCG_TIS_I2C_CR50) += tpm_tis_i2c_cr50.o +obj-$(CONFIG_TCG_TIS_I2C) += tpm_tis_i2c.o obj-$(CONFIG_TCG_TIS_I2C_ATMEL) += tpm_i2c_atmel.o obj-$(CONFIG_TCG_TIS_I2C_INFINEON) += tpm_i2c_infineon.o obj-$(CONFIG_TCG_TIS_I2C_NUVOTON) += tpm_i2c_nuvoton.o
drivers/char/tpm/tpm_tis_i2c.c new file +263 -0
263 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 5/7 tpm: Add YAML schema for TPM TIS I2C options
In reply to Eddie JamesFrom: Amir Mizinski <[email protected]>
Add a YAML schema to support tpm tis i2c related dt-bindings for the I2c PTP based physical layer.
This patch adds the documentation for corresponding device tree bindings of I2C based Physical TPM.
Refer to the 'I2C Interface Definition' section in
'TCG PC Client PlatformTPMProfile(PTP) Specification' publication for specification.
--- .../bindings/security/tpm/tpm-tis-i2c.yaml | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml
Documentation/devicetree/bindings/security/tpm/tpm-tis-i2c.yaml new file +52 -0
@@ -0,0 +1,52 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/security/tpm/tpm-tis-i2c.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: I2C PTP based TPM Device Tree Bindings + +maintainers: + - Amir Mizinski <[email protected]> + +description: + Device Tree Bindings for I2C based Trusted Platform Module(TPM). + +properties: + compatible: + items: + - enum: + # Nuvoton's Trusted Platform Module (TPM) (NPCT75x) + - nuvoton,npct75x + - const: tcg,tpm-tis-i2c + + reg: + maxItems: 1 + + interrupt: + maxItems: 1 + + crc-checksum: + $ref: /schemas/types.yaml#/definitions/flag + description: + Set this flag to enable CRC checksum. + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + tpm@2e { + compatible = "nuvoton,npct75x", "tcg,tpm-tis-i2c"; + reg = <0x2e>; + crc-checksum; + }; + }; +...
Signature · 1 line
2.27.0
PATCH 6/7 ARM: dts: aspeed: Rainier: Add TPM device
In reply to Eddie JamesAdd the Nuvoton NPCT75X.
--- arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/boot/dts/aspeed-bmc-ibm-rainier.dts +5 -0
@@ -2061,6 +2061,11 @@ eeprom@51 { &i2c12 { status = "okay"; + tpm@2e { + compatible = "nuvoton,npct75x"; + reg = <0x2e>; + }; + eeprom@50 { compatible = "atmel,24c64"; reg = <0x50>;
Signature · 1 line
2.27.0
PATCH 7/7 ARM: dts: aspeed: Everest: Add TPM device
In reply to Eddie JamesAdd the Nuvoton NPCT75X.
--- arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts | 5 +++++ 1 file changed, 5 insertions(+)
arch/arm/boot/dts/aspeed-bmc-ibm-everest.dts +5 -0
@@ -1881,6 +1881,11 @@ eeprom@52 { &i2c12 { status = "okay"; + + tpm@2e { + compatible = "nuvoton,npct75x"; + reg = <0x2e>; + }; }; &i2c13 {
Signature · 1 line
2.27.0