Skip to contentSkip to conversation

TPM 2.0 support

PATCH Superseded Jarkko Sakkinen 2 participants 21 messages Nov 1, 2014 – Nov 6, 2014

Subsystems (4)

v5 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v5 cover TPM 2.0 support

This patch set enables TPM2 protocol and provides drivers for FIFO and CRB interfaces.

Major changes since v1:

- Improved struct tpm_chip life-cycle by taking advantage of devres API.
- Refined sysfs attributes as simple key-values thereby not repeating mistakes in TPM1 sysfs attributes.
- Documented functions in tpm-chip.c and tpm2-cmd.c.
- Documented sysfs attributes.

Major changes since v2:

- Lots of fixes in calling order in device drivers (thanks to Jason Gunthorpe for pointing these out!).
- Attach sysfs attributes to the misc device because it represents TPM device to the user space.

Major changes since v3:

- Disable sysfs attibutes for TPM 2.0 for until we can sort out the best approach for them.
- Fixed all the style issues found with checkpatch.pl.

Major changes since v4:

- missing EXPORT_SYMBOL_GPL()
- own class for TPM devices used for TPM 2.0 devices and onwards.

Jarkko Sakkinen (6):
tpm: merge duplicate transmit_cmd() functions
tpm: two-phase chip management functions
tpm: fix multiple race conditions in tpm_ppi.c
tpm: TPM 2.0 baseline support
tpm: TPM 2.0 CRB Interface
tpm: create TPM 2.0 devices using own device class

Will Arthur (1):
tpm: TPM 2.0 FIFO Interface

 drivers/char/tpm/Kconfig            |   9 +
 drivers/char/tpm/Makefile           |   3 +-
 drivers/char/tpm/tpm-chip.c         | 209 +++++++++++++
 drivers/char/tpm/tpm-dev.c          |  77 ++++-
 drivers/char/tpm/tpm-interface.c    | 256 +++++-----------
 drivers/char/tpm/tpm-sysfs.c        |  29 +-
 drivers/char/tpm/tpm.h              | 113 ++++++-
 drivers/char/tpm/tpm2-cmd.c         | 566 ++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_atmel.c        |  26 +-
 drivers/char/tpm/tpm_crb.c          | 334 +++++++++++++++++++++
 drivers/char/tpm/tpm_i2c_atmel.c    |  49 ++--
 drivers/char/tpm/tpm_i2c_infineon.c |  43 +--
 drivers/char/tpm/tpm_i2c_nuvoton.c  |  66 ++---
 drivers/char/tpm/tpm_i2c_stm_st33.c |  44 ++-
 drivers/char/tpm/tpm_ibmvtpm.c      |  17 +-
 drivers/char/tpm/tpm_infineon.c     |  51 ++--
 drivers/char/tpm/tpm_nsc.c          |  34 ++-
 drivers/char/tpm/tpm_ppi.c          | 136 +++++----
 drivers/char/tpm/tpm_tis.c          | 177 ++++++-----
 drivers/char/tpm/xen-tpmfront.c     |  14 +-
 20 files changed, 1711 insertions(+), 542 deletions(-)
 create mode 100644 drivers/char/tpm/tpm-chip.c
 create mode 100644 drivers/char/tpm/tpm2-cmd.c
 create mode 100644 drivers/char/tpm/tpm_crb.c
Signature · 1 line
2.1.0
#1 lore raw

PATCH v5 1/7 tpm: merge duplicate transmit_cmd() functions

Merged transmit_cmd() functions in tpm-interface.c and tpm-sysfs.c. Added "tpm_" prefix for consistency sake. Changed cmd parameter as opaque. This enables to use separate command structures for TPM1 and TPM2 commands in future. Loose coupling works fine here.

---
 drivers/char/tpm/tpm-interface.c | 49 +++++++++++++++++++++-------------------
 drivers/char/tpm/tpm-sysfs.c     | 23 ++-----------------
 drivers/char/tpm/tpm.h           |  3 ++-
 3 files changed, 30 insertions(+), 45 deletions(-)
drivers/char/tpm/tpm-interface.c +26 -23
index 6af1700..0150b7c 100644
@@ -398,9 +398,10 @@ out:
 #define TPM_DIGEST_SIZE 20
 #define TPM_RET_CODE_IDX 6
 
-static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
-			    int len, const char *desc)
+ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd,
+			 int len, const char *desc)
 {
+	struct tpm_output_header *header;
 	int err;
 
 	len = tpm_transmit(chip, (u8 *) cmd, len);
@@ -409,7 +410,9 @@ static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
 	else if (len < TPM_HEADER_SIZE)
 		return -EFAULT;
 
-	err = be32_to_cpu(cmd->header.out.return_code);
+	header = (struct tpm_output_header *) cmd;
+
+	err = be32_to_cpu(header->return_code);
 	if (err != 0 && desc)
 		dev_err(chip->dev, "A TPM error (%d) occurred %s\n", err, desc);
 
@@ -448,7 +451,7 @@ ssize_t tpm_getcap(struct device *dev, __be32 subcap_id, cap_t *cap,
 		tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
 		tpm_cmd.params.getcap_in.subcap = subcap_id;
 	}
-	rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc);
+	rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, desc);
 	if (!rc)
 		*cap = tpm_cmd.params.getcap_out.cap;
 	return rc;
@@ -464,8 +467,8 @@ void tpm_gen_interrupt(struct tpm_chip *chip)
 	tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
 	tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
 
-	rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
-			"attempting to determine the timeouts");
+	rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+			      "attempting to determine the timeouts");
 }
 EXPORT_SYMBOL_GPL(tpm_gen_interrupt);
 
@@ -484,8 +487,8 @@ static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
 	struct tpm_cmd_t start_cmd;
 	start_cmd.header.in = tpm_startup_header;
 	start_cmd.params.startup_in.startup_type = startup_type;
-	return transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE,
-			    "attempting to start the TPM");
+	return tpm_transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE,
+				"attempting to start the TPM");
 }
 
 int tpm_get_timeouts(struct tpm_chip *chip)
@@ -500,7 +503,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 	tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
 	tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
 	tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
-	rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL);
+	rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE, NULL);
 
 	if (rc == TPM_ERR_INVALID_POSTINIT) {
 		/* The TPM is not started, we are the first to talk to it.
@@ -513,7 +516,7 @@ int tpm_get_timeouts(struct tpm_chip *chip)
 		tpm_cmd.params.getcap_in.cap = TPM_CAP_PROP;
 		tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
 		tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_TIMEOUT;
-		rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+		rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
 				  NULL);
 	}
 	if (rc) {
@@ -575,8 +578,8 @@ duration:
 	tpm_cmd.params.getcap_in.subcap_size = cpu_to_be32(4);
 	tpm_cmd.params.getcap_in.subcap = TPM_CAP_PROP_TIS_DURATION;
 
-	rc = transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
-			"attempting to determine the durations");
+	rc = tpm_transmit_cmd(chip, &tpm_cmd, TPM_INTERNAL_RESULT_SIZE,
+			      "attempting to determine the durations");
 	if (rc)
 		return rc;
 
@@ -631,8 +634,8 @@ static int tpm_continue_selftest(struct tpm_chip *chip)
 	struct tpm_cmd_t cmd;
 
 	cmd.header.in = continue_selftest_header;
-	rc = transmit_cmd(chip, &cmd, CONTINUE_SELFTEST_RESULT_SIZE,
-			  "continue selftest");
+	rc = tpm_transmit_cmd(chip, &cmd, CONTINUE_SELFTEST_RESULT_SIZE,
+			      "continue selftest");
 	return rc;
 }
 
@@ -672,8 +675,8 @@ int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf)
 
 	cmd.header.in = pcrread_header;
 	cmd.params.pcrread_in.pcr_idx = cpu_to_be32(pcr_idx);
-	rc = transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
-			  "attempting to read a pcr value");
+	rc = tpm_transmit_cmd(chip, &cmd, READ_PCR_RESULT_SIZE,
+			      "attempting to read a pcr value");
 
 	if (rc == 0)
 		memcpy(res_buf, cmd.params.pcrread_out.pcr_result,
@@ -737,8 +740,8 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 	cmd.header.in = pcrextend_header;
 	cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(pcr_idx);
 	memcpy(cmd.params.pcrextend_in.hash, hash, TPM_DIGEST_SIZE);
-	rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
-			  "attempting extend a PCR value");
+	rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
+			      "attempting extend a PCR value");
 
 	tpm_chip_put(chip);
 	return rc;
@@ -817,7 +820,7 @@ int tpm_send(u32 chip_num, void *cmd, size_t buflen)
 	if (chip == NULL)
 		return -ENODEV;
 
-	rc = transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd");
+	rc = tpm_transmit_cmd(chip, cmd, buflen, "attempting tpm_cmd");
 
 	tpm_chip_put(chip);
 	return rc;
@@ -938,14 +941,14 @@ int tpm_pm_suspend(struct device *dev)
 		cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(tpm_suspend_pcr);
 		memcpy(cmd.params.pcrextend_in.hash, dummy_hash,
 		       TPM_DIGEST_SIZE);
-		rc = transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
-				  "extending dummy pcr before suspend");
+		rc = tpm_transmit_cmd(chip, &cmd, EXTEND_PCR_RESULT_SIZE,
+				      "extending dummy pcr before suspend");
 	}
 
 	/* now do the actual savestate */
 	for (try = 0; try < TPM_RETRY; try++) {
 		cmd.header.in = savestate_header;
-		rc = transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE, NULL);
+		rc = tpm_transmit_cmd(chip, &cmd, SAVESTATE_RESULT_SIZE, NULL);
 
 		/*
 		 * If the TPM indicates that it is too busy to respond to
@@ -1022,7 +1025,7 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
 		tpm_cmd.header.in = tpm_getrandom_header;
 		tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
 
-		err = transmit_cmd(chip, &tpm_cmd,
+		err = tpm_transmit_cmd(chip, &tpm_cmd,
 				   TPM_GETRANDOM_RESULT_SIZE + num_bytes,
 				   "attempting get random");
 		if (err)
drivers/char/tpm/tpm-sysfs.c +2 -21
index 01730a2..8ecb052 100644
@@ -20,25 +20,6 @@
 #include <linux/device.h>
 #include "tpm.h"
 
-/* XXX for now this helper is duplicated in tpm-interface.c */
-static ssize_t transmit_cmd(struct tpm_chip *chip, struct tpm_cmd_t *cmd,
-			    int len, const char *desc)
-{
-	int err;
-
-	len = tpm_transmit(chip, (u8 *) cmd, len);
-	if (len <  0)
-		return len;
-	else if (len < TPM_HEADER_SIZE)
-		return -EFAULT;
-
-	err = be32_to_cpu(cmd->header.out.return_code);
-	if (err != 0 && desc)
-		dev_err(chip->dev, "A TPM error (%d) occurred %s\n", err, desc);
-
-	return err;
-}
-
 #define READ_PUBEK_RESULT_SIZE 314
 #define TPM_ORD_READPUBEK cpu_to_be32(124)
 static struct tpm_input_header tpm_readpubek_header = {
@@ -58,8 +39,8 @@ static ssize_t pubek_show(struct device *dev, struct device_attribute *attr,
 	struct tpm_chip *chip = dev_get_drvdata(dev);
 
 	tpm_cmd.header.in = tpm_readpubek_header;
-	err = transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
-			   "attempting to read the PUBEK");
+	err = tpm_transmit_cmd(chip, &tpm_cmd, READ_PUBEK_RESULT_SIZE,
+			       "attempting to read the PUBEK");
 	if (err)
 		goto out;
 
drivers/char/tpm/tpm.h +2 -1
index e4d0888..e638eb0 100644
@@ -314,9 +314,10 @@ struct tpm_cmd_t {
 } __packed;
 
 ssize_t	tpm_getcap(struct device *, __be32, cap_t *, const char *);
-
 ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
 		     size_t bufsiz);
+ssize_t tpm_transmit_cmd(struct tpm_chip *chip, void *cmd, int len,
+			 const char *desc);
 extern int tpm_get_timeouts(struct tpm_chip *);
 extern void tpm_gen_interrupt(struct tpm_chip *);
 extern int tpm_do_selftest(struct tpm_chip *);
Signature · 1 line
2.1.0
#2 lore raw

PATCH v5 2/7 tpm: two-phase chip management functions

In reply to Jarkko Sakkinen

tpm_register_hardware() and tpm_remove_hardware() are called often before initializing the device. This is wrong order since it could be that main TPM driver needs a fully initialized chip to be able to do its job. For example, now it is impossible to move common startup functions such as tpm_do_selftest() to tpm_register_hardware().

Added tpmm_chip_alloc() and tpm_chip_register() where tpm_chip_alloc() reserves memory resources and tpm_chip_register() initializes the device driver. This way it is possible to alter struct tpm_chip attributes and initialize the device driver before passing it to tpm_chip_register().

The framework takes care of freeing struct tpm_chip by using devres API. The broken release callback has been wiped. For example, ACPI drivers do not ever get this callback.

This is a interm step to get proper life-cycle for TPM device drivers. The next steps are adding proper ref counting and locking to tpm_chip that is used in every place in the TPM driver.

Big thank you to Jason Gunthorpe for carefully reviewing this part of the code. Without his contribution reaching the best quality would not have been possible.

---
 drivers/char/tpm/Makefile           |   2 +-
 drivers/char/tpm/tpm-chip.c         | 196 ++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm-interface.c    | 148 +--------------------------
 drivers/char/tpm/tpm.h              |  11 +-
 drivers/char/tpm/tpm_atmel.c        |  12 ++-
 drivers/char/tpm/tpm_i2c_atmel.c    |  33 ++----
 drivers/char/tpm/tpm_i2c_infineon.c |  37 ++-----
 drivers/char/tpm/tpm_i2c_nuvoton.c  |  44 +++-----
 drivers/char/tpm/tpm_i2c_stm_st33.c |  38 +++----
 drivers/char/tpm/tpm_ibmvtpm.c      |  17 ++--
 drivers/char/tpm/tpm_infineon.c     |  29 +++---
 drivers/char/tpm/tpm_nsc.c          |  14 ++-
 drivers/char/tpm/tpm_tis.c          |  79 ++++++---------
 drivers/char/tpm/xen-tpmfront.c     |  14 +--
 14 files changed, 331 insertions(+), 343 deletions(-)
 create mode 100644 drivers/char/tpm/tpm-chip.c
drivers/char/tpm/Makefile +1 -1
index 4d85dd6..837da04 100644
@@ -2,7 +2,7 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
-tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o
+tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o
 
 ifdef CONFIG_ACPI
drivers/char/tpm/tpm-chip.c new file +196 -0

196 lines not on this page · raw message

drivers/char/tpm/tpm-interface.c +1 -147

177 lines not on this page · raw message

drivers/char/tpm/tpm.h +6 -5
index e638eb0..9880681 100644
@@ -110,7 +110,6 @@ struct tpm_chip {
 	struct dentry **bios_dir;
 
 	struct list_head list;
-	void (*release) (struct device *);
 };
 
 #define to_tpm_chip(n) container_of(n, struct tpm_chip, vendor)
@@ -322,15 +321,17 @@ extern int tpm_get_timeouts(struct tpm_chip *);
 extern void tpm_gen_interrupt(struct tpm_chip *);
 extern int tpm_do_selftest(struct tpm_chip *);
 extern unsigned long tpm_calc_ordinal_duration(struct tpm_chip *, u32);
-extern struct tpm_chip* tpm_register_hardware(struct device *,
-					      const struct tpm_class_ops *ops);
-extern void tpm_dev_vendor_release(struct tpm_chip *);
-extern void tpm_remove_hardware(struct device *);
 extern int tpm_pm_suspend(struct device *);
 extern int tpm_pm_resume(struct device *);
 extern int wait_for_tpm_stat(struct tpm_chip *, u8, unsigned long,
 			     wait_queue_head_t *, bool);
 
+struct tpm_chip *tpm_chip_find_get(int chip_num);
+extern struct tpm_chip *tpmm_chip_alloc(struct device *dev,
+				       const struct tpm_class_ops *ops);
+extern int tpm_chip_register(struct tpm_chip *chip);
+extern void tpm_chip_unregister(struct tpm_chip *chip);
+
 int tpm_dev_add_device(struct tpm_chip *chip);
 void tpm_dev_del_device(struct tpm_chip *chip);
 int tpm_sysfs_add_device(struct tpm_chip *chip);
drivers/char/tpm/tpm_atmel.c +9 -3
index 6069d13..fb2f921 100644
@@ -138,11 +138,12 @@ static void atml_plat_remove(void)
 	struct tpm_chip *chip = dev_get_drvdata(&pdev->dev);
 
 	if (chip) {
+		/* FIXME might be broken when using force */
+		tpm_chip_unregister(chip);
 		if (chip->vendor.have_region)
 			atmel_release_region(chip->vendor.base,
 					     chip->vendor.region_size);
 		atmel_put_base_addr(chip->vendor.iobase);
-		tpm_remove_hardware(chip->dev);
 		platform_device_unregister(pdev);
 	}
 }
@@ -184,8 +185,9 @@ static int __init init_atmel(void)
 		goto err_rel_reg;
 	}
 
-	if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_atmel))) {
-		rc = -ENODEV;
+	chip = tpmm_chip_alloc(&pdev->dev, &tpm_atmel);
+	if (IS_ERR(chip)) {
+		rc = PTR_ERR(chip);
 		goto err_unreg_dev;
 	}
 
@@ -194,6 +196,10 @@ static int __init init_atmel(void)
 	chip->vendor.have_region = have_region;
 	chip->vendor.region_size = region_size;
 
+	rc = tpm_chip_register(chip);
+	if (rc)
+		goto err_unreg_dev;
+
 	return 0;
 
 err_unreg_dev:
drivers/char/tpm/tpm_i2c_atmel.c +11 -22
index 7727292..8af3b4a 100644
@@ -160,11 +160,9 @@ static int i2c_atmel_probe(struct i2c_client *client,
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
 		return -ENODEV;
 
-	chip = tpm_register_hardware(dev, &i2c_atmel);
-	if (!chip) {
-		dev_err(dev, "%s() error in tpm_register_hardware\n", __func__);
-		return -ENODEV;
-	}
+	chip = tpmm_chip_alloc(dev, &i2c_atmel);
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
 
 	chip->vendor.priv = devm_kzalloc(dev, sizeof(struct priv_data),
 					 GFP_KERNEL);
@@ -179,21 +177,16 @@ static int i2c_atmel_probe(struct i2c_client *client,
 	/* There is no known way to probe for this device, and all version
 	 * information seems to be read via TPM commands. Thus we rely on the
 	 * TPM startup process in the common code to detect the device. */
-	if (tpm_get_timeouts(chip)) {
-		rc = -ENODEV;
-		goto out_err;
-	}
+	if (tpm_get_timeouts(chip))
+		return -ENODEV;
 
-	if (tpm_do_selftest(chip)) {
-		rc = -ENODEV;
-		goto out_err;
-	}
+	if (tpm_do_selftest(chip))
+		return -ENODEV;
 
-	return 0;
+	rc = tpm_chip_register(chip);
+	if (rc)
+		return rc;
 
-out_err:
-	tpm_dev_vendor_release(chip);
-	tpm_remove_hardware(chip->dev);
 	return rc;
 }
 
@@ -201,11 +194,7 @@ static int i2c_atmel_remove(struct i2c_client *client)
 {
 	struct device *dev = &(client->dev);
 	struct tpm_chip *chip = dev_get_drvdata(dev);
-
-	if (chip)
-		tpm_dev_vendor_release(chip);
-	tpm_remove_hardware(dev);
-	kfree(chip);
+	tpm_chip_unregister(chip);
 	return 0;
 }
 
drivers/char/tpm/tpm_i2c_infineon.c +7 -30
index 472af4b..03708e6 100644
@@ -581,12 +581,9 @@ static int tpm_tis_i2c_init(struct device *dev)
 	int rc = 0;
 	struct tpm_chip *chip;
 
-	chip = tpm_register_hardware(dev, &tpm_tis_i2c);
-	if (!chip) {
-		dev_err(dev, "could not register hardware\n");
-		rc = -ENODEV;
-		goto out_err;
-	}
+	chip = tpmm_chip_alloc(dev, &tpm_tis_i2c);
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
 
 	/* Disable interrupts */
 	chip->vendor.irq = 0;
@@ -600,7 +597,7 @@ static int tpm_tis_i2c_init(struct device *dev)
 	if (request_locality(chip, 0) != 0) {
 		dev_err(dev, "could not request locality\n");
 		rc = -ENODEV;
-		goto out_vendor;
+		goto out_err;
 	}
 
 	/* read four bytes from DID_VID register */
@@ -628,21 +625,9 @@ static int tpm_tis_i2c_init(struct device *dev)
 	tpm_get_timeouts(chip);
 	tpm_do_selftest(chip);
 
-	return 0;
-
+	return tpm_chip_register(chip);
 out_release:
 	release_locality(chip, chip->vendor.locality, 1);
-
-out_vendor:
-	/* close file handles */
-	tpm_dev_vendor_release(chip);
-
-	/* remove hardware */
-	tpm_remove_hardware(chip->dev);
-
-	/* reset these pointers, otherwise we oops */
-	chip->dev->release = NULL;
-	chip->release = NULL;
 	tpm_dev.client = NULL;
 out_err:
 	return rc;
@@ -712,17 +697,9 @@ static int tpm_tis_i2c_probe(struct i2c_client *client,
 static int tpm_tis_i2c_remove(struct i2c_client *client)
 {
 	struct tpm_chip *chip = tpm_dev.chip;
-	release_locality(chip, chip->vendor.locality, 1);
 
-	/* close file handles */
-	tpm_dev_vendor_release(chip);
-
-	/* remove hardware */
-	tpm_remove_hardware(chip->dev);
-
-	/* reset these pointers, otherwise we oops */
-	chip->dev->release = NULL;
-	chip->release = NULL;
+	tpm_chip_unregister(chip);
+	release_locality(chip, chip->vendor.locality, 1);
 	tpm_dev.client = NULL;
 
 	return 0;
drivers/char/tpm/tpm_i2c_nuvoton.c +15 -29

78 lines not on this page · raw message

drivers/char/tpm/tpm_i2c_stm_st33.c +14 -24
index 4669e37..b9d1a38 100644
@@ -609,37 +609,29 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	if (client == NULL) {
 		pr_info("%s: i2c client is NULL. Device not accessible.\n",
 			__func__);
-		err = -ENODEV;
-		goto end;
+		return -ENODEV;
 	}
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		dev_info(&client->dev, "client not i2c capable\n");
-		err = -ENODEV;
-		goto end;
+		return -ENODEV;
 	}
 
-	chip = tpm_register_hardware(&client->dev, &st_i2c_tpm);
-	if (!chip) {
-		dev_info(&client->dev, "fail chip\n");
-		err = -ENODEV;
-		goto end;
-	}
+	chip = tpmm_chip_alloc(&client->dev, &st_i2c_tpm);
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
 
 	platform_data = client->dev.platform_data;
 
 	if (!platform_data) {
 		dev_info(&client->dev, "chip not available\n");
-		err = -ENODEV;
-		goto _tpm_clean_answer;
+		return -ENODEV;
 	}
 
 	platform_data->tpm_i2c_buffer[0] =
 	    kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
-	if (platform_data->tpm_i2c_buffer[0] == NULL) {
-		err = -ENOMEM;
-		goto _tpm_clean_answer;
-	}
+	if (platform_data->tpm_i2c_buffer[0] == NULL)
+		return -ENOMEM;
 	platform_data->tpm_i2c_buffer[1] =
 	    kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
 	if (platform_data->tpm_i2c_buffer[1] == NULL) {
@@ -716,8 +708,10 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	tpm_get_timeouts(chip);
 	tpm_do_selftest(chip);
 
-	dev_info(chip->dev, "TPM I2C Initialized\n");
-	return 0;
+	err = tpm_chip_register(chip);
+	if (!err)
+		return 0;
+
 _irq_set:
 	free_irq(gpio_to_irq(platform_data->io_serirq), (void *)chip);
 _gpio_init2:
@@ -732,10 +726,6 @@ _tpm_clean_response2:
 _tpm_clean_response1:
 	kzfree(platform_data->tpm_i2c_buffer[0]);
 	platform_data->tpm_i2c_buffer[0] = NULL;
-_tpm_clean_answer:
-	tpm_remove_hardware(chip->dev);
-end:
-	pr_info("TPM I2C initialisation fail\n");
 	return err;
 }
 
@@ -752,13 +742,13 @@ static int tpm_st33_i2c_remove(struct i2c_client *client)
 		((struct i2c_client *)TPM_VPRIV(chip))->dev.platform_data;
 
 	if (pin_infos != NULL) {
+		tpm_chip_unregister(chip);
+
 		free_irq(pin_infos->io_serirq, chip);
 
 		gpio_free(pin_infos->io_serirq);
 		gpio_free(pin_infos->io_lpcpd);
 
-		tpm_remove_hardware(chip->dev);
-
 		if (pin_infos->tpm_i2c_buffer[1] != NULL) {
 			kzfree(pin_infos->tpm_i2c_buffer[1]);
 			pin_infos->tpm_i2c_buffer[1] = NULL;
drivers/char/tpm/tpm_ibmvtpm.c +7 -10
index af74c57..eb95796 100644
@@ -270,8 +270,11 @@ static int ibmvtpm_crq_send_init(struct ibmvtpm_dev *ibmvtpm)
 static int tpm_ibmvtpm_remove(struct vio_dev *vdev)
 {
 	struct ibmvtpm_dev *ibmvtpm = ibmvtpm_get_data(&vdev->dev);
+	struct tpm_chip *chip = dev_get_drvdata(ibmvtpm->dev);
 	int rc = 0;
 
+	tpm_chip_unregister(chip);
+
 	free_irq(vdev->irq, ibmvtpm);
 
 	do {
@@ -290,8 +293,6 @@ static int tpm_ibmvtpm_remove(struct vio_dev *vdev)
 		kfree(ibmvtpm->rtce_buf);
 	}
 
-	tpm_remove_hardware(ibmvtpm->dev);
-
 	kfree(ibmvtpm);
 
 	return 0;
@@ -555,11 +556,9 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
 	struct tpm_chip *chip;
 	int rc = -ENOMEM, rc1;
 
-	chip = tpm_register_hardware(dev, &tpm_ibmvtpm);
-	if (!chip) {
-		dev_err(dev, "tpm_register_hardware failed\n");
-		return -ENODEV;
-	}
+	chip = tpmm_chip_alloc(dev, &tpm_ibmvtpm);
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
 
 	ibmvtpm = kzalloc(sizeof(struct ibmvtpm_dev), GFP_KERNEL);
 	if (!ibmvtpm) {
@@ -629,7 +628,7 @@ static int tpm_ibmvtpm_probe(struct vio_dev *vio_dev,
 	if (rc)
 		goto init_irq_cleanup;
 
-	return rc;
+	return tpm_chip_register(chip);
 init_irq_cleanup:
 	do {
 		rc1 = plpar_hcall_norets(H_FREE_CRQ, vio_dev->unit_address);
@@ -644,8 +643,6 @@ cleanup:
 		kfree(ibmvtpm);
 	}
 
-	tpm_remove_hardware(dev);
-
 	return rc;
 }
 
drivers/char/tpm/tpm_infineon.c +17 -12
index dc0a255..dcdb671 100644
@@ -546,7 +546,14 @@ static int tpm_inf_pnp_probe(struct pnp_dev *dev,
 			 vendorid[0], vendorid[1],
 			 productid[0], productid[1], chipname);
 
-		if (!(chip = tpm_register_hardware(&dev->dev, &tpm_inf)))
+		chip = tpmm_chip_alloc(&dev->dev, &tpm_inf);
+		if (IS_ERR(chip)) {
+			rc = PTR_ERR(chip);
+			goto err_release_region;
+		}
+
+		rc = tpm_chip_register(chip);
+		if (rc)
 			goto err_release_region;
 
 		return 0;
@@ -572,17 +579,15 @@ static void tpm_inf_pnp_remove(struct pnp_dev *dev)
 {
 	struct tpm_chip *chip = pnp_get_drvdata(dev);
 
-	if (chip) {
-		if (tpm_dev.iotype == TPM_INF_IO_PORT) {
-			release_region(tpm_dev.data_regs, tpm_dev.data_size);
-			release_region(tpm_dev.config_port,
-				       tpm_dev.config_size);
-		} else {
-			iounmap(tpm_dev.mem_base);
-			release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
-		}
-		tpm_dev_vendor_release(chip);
-		tpm_remove_hardware(chip->dev);
+	tpm_chip_unregister(chip);
+
+	if (tpm_dev.iotype == TPM_INF_IO_PORT) {
+		release_region(tpm_dev.data_regs, tpm_dev.data_size);
+		release_region(tpm_dev.config_port,
+			       tpm_dev.config_size);
+	} else {
+		iounmap(tpm_dev.mem_base);
+		release_mem_region(tpm_dev.map_base, tpm_dev.map_size);
 	}
 }
 
drivers/char/tpm/tpm_nsc.c +9 -5
index 3179ec9..00c5470 100644
@@ -247,10 +247,9 @@ static struct platform_device *pdev = NULL;
 static void tpm_nsc_remove(struct device *dev)
 {
 	struct tpm_chip *chip = dev_get_drvdata(dev);
-	if ( chip ) {
-		release_region(chip->vendor.base, 2);
-		tpm_remove_hardware(chip->dev);
-	}
+
+	tpm_chip_unregister(chip);
+	release_region(chip->vendor.base, 2);
 }
 
 static SIMPLE_DEV_PM_OPS(tpm_nsc_pm, tpm_pm_suspend, tpm_pm_resume);
@@ -308,11 +307,16 @@ static int __init init_nsc(void)
 		goto err_del_dev;
 	}
 
-	if (!(chip = tpm_register_hardware(&pdev->dev, &tpm_nsc))) {
+	chip = tpmm_chip_alloc(&pdev->dev, &tpm_nsc);
+	if (IS_ERR(chip)) {
 		rc = -ENODEV;
 		goto err_rel_reg;
 	}
 
+	rc = tpm_chip_register(chip);
+	if (rc)
+		goto err_rel_reg;
+
 	dev_dbg(&pdev->dev, "NSC TPM detected\n");
 	dev_dbg(&pdev->dev,
 		"NSC LDN 0x%x, SID 0x%x, SRID 0x%x\n",
drivers/char/tpm/tpm_tis.c +30 -49

150 lines not on this page · raw message

drivers/char/tpm/xen-tpmfront.c +8 -6
index 441b44e..c3b4f5a 100644
@@ -175,9 +175,9 @@ static int setup_chip(struct device *dev, struct tpm_private *priv)
 {
 	struct tpm_chip *chip;
 
-	chip = tpm_register_hardware(dev, &tpm_vtpm);
-	if (!chip)
-		return -ENODEV;
+	chip = tpmm_chip_alloc(dev, &tpm_vtpm);
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
 
 	init_waitqueue_head(&chip->vendor.read_queue);
 
@@ -286,6 +286,7 @@ static int tpmfront_probe(struct xenbus_device *dev,
 		const struct xenbus_device_id *id)
 {
 	struct tpm_private *priv;
+	struct tpm_chip *chip;
 	int rv;
 
 	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -302,21 +303,22 @@ static int tpmfront_probe(struct xenbus_device *dev,
 
 	rv = setup_ring(dev, priv);
 	if (rv) {
-		tpm_remove_hardware(&dev->dev);
+		chip = dev_get_drvdata(&dev->dev);
+		tpm_chip_unregister(chip);
 		ring_free(priv);
 		return rv;
 	}
 
 	tpm_get_timeouts(priv->chip);
 
-	return rv;
+	return tpm_chip_register(priv->chip);
 }
 
 static int tpmfront_remove(struct xenbus_device *dev)
 {
 	struct tpm_chip *chip = dev_get_drvdata(&dev->dev);
 	struct tpm_private *priv = TPM_VPRIV(chip);
-	tpm_remove_hardware(&dev->dev);
+	tpm_chip_unregister(chip);
 	ring_free(priv);
 	TPM_VPRIV(chip) = NULL;
 	return 0;
Signature · 1 line
2.1.0
#3 lore raw

PATCH v5 3/7 tpm: fix multiple race conditions in tpm_ppi.c

In reply to Jarkko Sakkinen

Traversal of the ACPI device tree was not done right. It should lookup PPI only under the ACPI device that it is associated. Otherwise, it could match to a wrong PPI interface if there are two TPM devices in the device tree.

Removed global ACPI handle and version string from tpm_ppi.c as this is racy. Instead they should be associated with the chip.

Additionally, added the missing copyright platter to tpm_ppi.c.

---
 drivers/char/tpm/tpm-chip.c |   4 +-
 drivers/char/tpm/tpm.h      |  16 ++++--
 drivers/char/tpm/tpm_ppi.c  | 136 +++++++++++++++++++++++++++-----------------
 drivers/char/tpm/tpm_tis.c  |  15 +++--
 4 files changed, 108 insertions(+), 63 deletions(-)
drivers/char/tpm/tpm-chip.c +2 -2
index bf85114..fdff9e7 100644
@@ -148,7 +148,7 @@ int tpm_chip_register(struct tpm_chip *chip)
 	if (rc)
 		goto del_misc;
 
-	rc = tpm_add_ppi(&chip->dev->kobj);
+	rc = tpm_add_ppi(chip);
 	if (rc)
 		goto del_sysfs;
 
@@ -186,7 +186,7 @@ void tpm_chip_unregister(struct tpm_chip *chip)
 	synchronize_rcu();
 
 	tpm_sysfs_del_device(chip);
-	tpm_remove_ppi(&chip->dev->kobj);
+	tpm_remove_ppi(chip);
 
 	if (chip->bios_dir)
 		tpm_bios_log_teardown(chip->bios_dir);
drivers/char/tpm/tpm.h +12 -4
index 9880681..69f4003 100644
@@ -27,6 +27,7 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/tpm.h>
+#include <linux/acpi.h>
 
 enum tpm_const {
 	TPM_MINOR = 224,	/* officially assigned */
@@ -94,6 +95,8 @@ struct tpm_vendor_specific {
 #define TPM_VID_WINBOND  0x1050
 #define TPM_VID_STM      0x104A
 
+#define TPM_PPI_VERSION_LEN		3
+
 struct tpm_chip {
 	struct device *dev;	/* Device stuff */
 	const struct tpm_class_ops *ops;
@@ -109,6 +112,11 @@ struct tpm_chip {
 
 	struct dentry **bios_dir;
 
+#ifdef CONFIG_ACPI
+	acpi_handle acpi_dev_handle;
+	char ppi_version[TPM_PPI_VERSION_LEN + 1];
+#endif /* CONFIG_ACPI */
+
 	struct list_head list;
 };
 
@@ -340,15 +348,15 @@ void tpm_sysfs_del_device(struct tpm_chip *chip);
 int tpm_pcr_read_dev(struct tpm_chip *chip, int pcr_idx, u8 *res_buf);
 
 #ifdef CONFIG_ACPI
-extern int tpm_add_ppi(struct kobject *);
-extern void tpm_remove_ppi(struct kobject *);
+extern int tpm_add_ppi(struct tpm_chip *chip);
+extern void tpm_remove_ppi(struct tpm_chip *chip);
 #else
-static inline int tpm_add_ppi(struct kobject *parent)
+static inline int tpm_add_ppi(struct tpm_chip *chip)
 {
 	return 0;
 }
 
-static inline void tpm_remove_ppi(struct kobject *parent)
+static inline void tpm_remove_ppi(struct tpm_chip *chip)
 {
 }
 #endif
drivers/char/tpm/tpm_ppi.c +83 -53

241 lines not on this page · raw message

drivers/char/tpm/tpm_tis.c +11 -4
index e2cb04d..1b51aeb 100644
@@ -536,8 +536,9 @@ static void tpm_tis_remove(struct tpm_chip *chip)
 	release_locality(chip, chip->vendor.locality, 1);
 }
 
-static int tpm_tis_init(struct device *dev, resource_size_t start,
-			resource_size_t len, unsigned int irq)
+static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
+			resource_size_t start, resource_size_t len,
+			unsigned int irq)
 {
 	u32 vendor, intfcaps, intmask;
 	int rc, i, irq_s, irq_e, probe;
@@ -547,6 +548,8 @@ static int tpm_tis_init(struct device *dev, resource_size_t start,
 	if (IS_ERR(chip))
 		return PTR_ERR(chip);
 
+	chip->acpi_dev_handle = acpi_dev_handle;
+
 	chip->vendor.iobase = devm_ioremap(dev, start, len);
 	if (!chip->vendor.iobase)
 		return -EIO;
@@ -777,6 +780,7 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
 {
 	resource_size_t start, len;
 	unsigned int irq = 0;
+	acpi_handle acpi_dev_handle = NULL;
 
 	start = pnp_mem_start(pnp_dev, 0);
 	len = pnp_mem_len(pnp_dev, 0);
@@ -789,7 +793,10 @@ static int tpm_tis_pnp_init(struct pnp_dev *pnp_dev,
 	if (is_itpm(pnp_dev))
 		itpm = true;
 
-	return tpm_tis_init(&pnp_dev->dev, start, len, irq);
+	if (pnp_acpi_device(pnp_dev))
+		acpi_dev_handle = pnp_acpi_device(pnp_dev)->handle;
+
+	return tpm_tis_init(&pnp_dev->dev, acpi_dev_handle, start, len, irq);
 }
 
 static struct pnp_device_id tpm_pnp_tbl[] = {
@@ -858,7 +865,7 @@ static int __init init_tis(void)
 		rc = PTR_ERR(pdev);
 		goto err_dev;
 	}
-	rc = tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0);
+	rc = tpm_tis_init(&pdev->dev, NULL, TIS_MEM_BASE, TIS_MEM_LEN, 0);
 	if (rc)
 		goto err_init;
 	return 0;
Signature · 1 line
2.1.0
#4 lore raw

PATCH v5 4/7 tpm: TPM 2.0 baseline support

In reply to Jarkko Sakkinen

TPM 2.0 devices are separated by adding a field 'flags' to struct tpm_chip and defining a flag TPM_CHIP_FLAG_TPM2 for tagging them.

This patch adds the following internal functions:

- tpm2_get_random()
- tpm2_get_tpm_pt()
- tpm2_pcr_extend()
- tpm2_pcr_read()
- tpm2_startup()

Additionally, the following exported functions are implemented for implementing TPM 2.0 device drivers:

- tpm2_do_selftest()
- tpm2_calc_ordinal_durations()
- tpm2_gen_interrupt()

The existing functions that are exported for the use for existing subsystems have been changed to check the flags field in struct tpm_chip and use appropriate TPM 2.0 counterpart if TPM_CHIP_FLAG_TPM2 is est.

The code for tpm2_calc_ordinal_duration() and tpm2_startup() were originally written by Will Arthur.

---
 drivers/char/tpm/Makefile        |   2 +-
 drivers/char/tpm/tpm-chip.c      |  31 ++-
 drivers/char/tpm/tpm-interface.c |  24 +-
 drivers/char/tpm/tpm.h           |  67 +++++
 drivers/char/tpm/tpm2-cmd.c      | 566 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 674 insertions(+), 16 deletions(-)
 create mode 100644 drivers/char/tpm/tpm2-cmd.c
drivers/char/tpm/Makefile +1 -1
index 837da04..ae56af9 100644
@@ -2,7 +2,7 @@
 # Makefile for the kernel tpm device drivers.
 #
 obj-$(CONFIG_TCG_TPM) += tpm.o
-tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o
+tpm-y := tpm-interface.o tpm-dev.o tpm-sysfs.o tpm-chip.o tpm2-cmd.o
 tpm-$(CONFIG_ACPI) += tpm_ppi.o
 
 ifdef CONFIG_ACPI
drivers/char/tpm/tpm-chip.c +19 -12
index fdff9e7..9d2038b 100644
@@ -144,15 +144,18 @@ int tpm_chip_register(struct tpm_chip *chip)
 	if (rc)
 		return rc;
 
-	rc = tpm_sysfs_add_device(chip);
-	if (rc)
-		goto del_misc;
+	/* Populate sysfs for TPM1 devices. */
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
+		rc = tpm_sysfs_add_device(chip);
+		if (rc)
+			goto del_misc;
 
-	rc = tpm_add_ppi(chip);
-	if (rc)
-		goto del_sysfs;
+		rc = tpm_add_ppi(chip);
+		if (rc)
+			goto del_sysfs;
 
-	chip->bios_dir = tpm_bios_log_setup(chip->devname);
+		chip->bios_dir = tpm_bios_log_setup(chip->devname);
+	}
 
 	/* Make the chip available. */
 	spin_lock(&driver_lock);
@@ -161,7 +164,8 @@ int tpm_chip_register(struct tpm_chip *chip)
 
 	return 0;
 del_sysfs:
-	tpm_sysfs_del_device(chip);
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2))
+		tpm_sysfs_del_device(chip);
 del_misc:
 	tpm_dev_del_device(chip);
 	return rc;
@@ -185,11 +189,14 @@ void tpm_chip_unregister(struct tpm_chip *chip)
 	spin_unlock(&driver_lock);
 	synchronize_rcu();
 
-	tpm_sysfs_del_device(chip);
-	tpm_remove_ppi(chip);
+	/* Clean up sysfs for TPM1 devices. */
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2)) {
+		if (chip->bios_dir)
+			tpm_bios_log_teardown(chip->bios_dir);
 
-	if (chip->bios_dir)
-		tpm_bios_log_teardown(chip->bios_dir);
+		tpm_remove_ppi(chip);
+		tpm_sysfs_del_device(chip);
+	}
 
 	tpm_dev_del_device(chip);
 }
drivers/char/tpm/tpm-interface.c +21 -3
index 915c610..a98532f 100644
@@ -360,7 +360,10 @@ ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
 	if (chip->vendor.irq)
 		goto out_recv;
 
-	stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		stop = jiffies + tpm2_calc_ordinal_duration(chip, ordinal);
+	else
+		stop = jiffies + tpm_calc_ordinal_duration(chip, ordinal);
 	do {
 		u8 status = chip->ops->status(chip);
 		if ((status & chip->ops->req_complete_mask) ==
@@ -482,7 +485,7 @@ static const struct tpm_input_header tpm_startup_header = {
 static int tpm_startup(struct tpm_chip *chip, __be16 startup_type)
 {
 	struct tpm_cmd_t start_cmd;
-	start_cmd.header.in = tpm_startup_header;
+
 	start_cmd.params.startup_in.startup_type = startup_type;
 	return tpm_transmit_cmd(chip, &start_cmd, TPM_INTERNAL_RESULT_SIZE,
 				"attempting to start the TPM");
@@ -679,7 +682,10 @@ int tpm_pcr_read(u32 chip_num, int pcr_idx, u8 *res_buf)
 	chip = tpm_chip_find_get(chip_num);
 	if (chip == NULL)
 		return -ENODEV;
-	rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		rc = tpm2_pcr_read(chip, pcr_idx, res_buf);
+	else
+		rc = tpm_pcr_read_dev(chip, pcr_idx, res_buf);
 	tpm_chip_put(chip);
 	return rc;
 }
@@ -713,6 +719,12 @@ int tpm_pcr_extend(u32 chip_num, int pcr_idx, const u8 *hash)
 	if (chip == NULL)
 		return -ENODEV;
 
+	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+		rc = tpm2_pcr_extend(chip, pcr_idx, hash);
+		tpm_chip_put(chip);
+		return rc;
+	}
+
 	cmd.header.in = pcrextend_header;
 	cmd.params.pcrextend_in.pcr_idx = cpu_to_be32(pcr_idx);
 	memcpy(cmd.params.pcrextend_in.hash, hash, TPM_DIGEST_SIZE);
@@ -973,6 +985,12 @@ int tpm_get_random(u32 chip_num, u8 *out, size_t max)
 	if (chip == NULL)
 		return -ENODEV;
 
+	if (chip->flags & TPM_CHIP_FLAG_TPM2) {
+		err = tpm2_get_random(chip, out, max);
+		tpm_chip_put(chip);
+		return err;
+	}
+
 	do {
 		tpm_cmd.header.in = tpm_getrandom_header;
 		tpm_cmd.params.getrandom_in.num_bytes = cpu_to_be32(num_bytes);
drivers/char/tpm/tpm.h +67 -0

85 lines not on this page · raw message

drivers/char/tpm/tpm2-cmd.c new file +566 -0

566 lines not on this page · raw message

Signature · 1 line
2.1.0
#5 lore raw

PATCH v5 5/7 tpm: TPM 2.0 CRB Interface

In reply to Jarkko Sakkinen

tpm_crb is a driver for TPM 2.0 Command Response Buffer (CRB) Interface as defined in PC Client Platform TPM Profile (PTP) Specification.

Only polling and single locality is supported as these are the limitations of the available hardware, Platform Trust Techonlogy (PTT) in Haswell CPUs.

The driver always applies CRB with ACPI start because PTT reports using only ACPI start as start method but as a result of my testing it requires also CRB start.

---
 drivers/char/tpm/Kconfig   |   9 ++
 drivers/char/tpm/Makefile  |   1 +
 drivers/char/tpm/tpm_crb.c | 334 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 344 insertions(+)
 create mode 100644 drivers/char/tpm/tpm_crb.c
drivers/char/tpm/Kconfig +9 -0
index c54cac3..10c9419 100644
@@ -122,4 +122,13 @@ config TCG_XEN
 	  To compile this driver as a module, choose M here; the module
 	  will be called xen-tpmfront.
 
+config TCG_CRB
+	tristate "TPM 2.0 CRB Interface"
+	depends on X86 && ACPI
+	---help---
+	  If you have a TPM security chip that is compliant with the
+	  TCG CRB 2.0 TPM specification 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_crb.
+
 endif # TCG_TPM
drivers/char/tpm/Makefile +1 -0
index ae56af9..e6d26dd 100644
@@ -22,3 +22,4 @@ obj-$(CONFIG_TCG_INFINEON) += tpm_infineon.o
 obj-$(CONFIG_TCG_IBMVTPM) += tpm_ibmvtpm.o
 obj-$(CONFIG_TCG_ST33_I2C) += tpm_i2c_stm_st33.o
 obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
+obj-$(CONFIG_TCG_CRB) += tpm_crb.o
drivers/char/tpm/tpm_crb.c new file +334 -0

334 lines not on this page · raw message

Signature · 1 line
2.1.0
#6 lore raw

PATCH v5 6/7 tpm: TPM 2.0 FIFO Interface

In reply to Jarkko Sakkinen

From: Will Arthur <[email protected]>

Detect TPM 2.0 by using the extended STS (STS3) register. For TPM 2.0, instead of calling tpm_get_timeouts(), assign duration and timeout values defined in the TPM 2.0 PTP specification.

---
 drivers/char/tpm/tpm_tis.c | 71 ++++++++++++++++++++++++++++++++++++----------
 1 file changed, 56 insertions(+), 15 deletions(-)
drivers/char/tpm/tpm_tis.c +56 -15
index 1b51aeb..4d4bff1 100644
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2005, 2006 IBM Corporation
+ * Copyright (C) 2014 Intel Corporation
  *
  * Authors:
  * Leendert van Doorn <[email protected]>
@@ -44,6 +45,10 @@ enum tis_status {
 	TPM_STS_DATA_EXPECT = 0x08,
 };
 
+enum tis_status3 {
+	TPM_STS3_TPM2_FAM = 0x04,
+};
+
 enum tis_int_flags {
 	TPM_GLOBAL_INT_ENABLE = 0x80000000,
 	TPM_INTF_BURST_COUNT_STATIC = 0x100,
@@ -70,6 +75,7 @@ enum tis_defaults {
 #define	TPM_INT_STATUS(l)		(0x0010 | ((l) << 12))
 #define	TPM_INTF_CAPS(l)		(0x0014 | ((l) << 12))
 #define	TPM_STS(l)			(0x0018 | ((l) << 12))
+#define	TPM_STS3(l)			(0x001b | ((l) << 12))
 #define	TPM_DATA_FIFO(l)		(0x0024 | ((l) << 12))
 
 #define	TPM_DID_VID(l)			(0x0F00 | ((l) << 12))
@@ -344,6 +350,7 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	int rc;
 	u32 ordinal;
+	unsigned long dur;
 
 	rc = tpm_tis_send_data(chip, buf, len);
 	if (rc < 0)
@@ -355,9 +362,14 @@ static int tpm_tis_send(struct tpm_chip *chip, u8 *buf, size_t len)
 
 	if (chip->vendor.irq) {
 		ordinal = be32_to_cpu(*((__be32 *) (buf + 6)));
+
+		if (chip->flags & TPM_CHIP_FLAG_TPM2)
+			dur = tpm_calc_ordinal_duration(chip, ordinal);
+		else
+			dur = tpm_calc_ordinal_duration(chip, ordinal);
+
 		if (wait_for_tpm_stat
-		    (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID,
-		     tpm_calc_ordinal_duration(chip, ordinal),
+		    (chip, TPM_STS_DATA_AVAIL | TPM_STS_VALID, dur,
 		     &chip->vendor.read_queue, false) < 0) {
 			rc = -ETIME;
 			goto out_err;
@@ -543,6 +555,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 	u32 vendor, intfcaps, intmask;
 	int rc, i, irq_s, irq_e, probe;
 	struct tpm_chip *chip;
+	u8 sts3;
 
 	chip = tpmm_chip_alloc(dev, &tpm_tis);
 	if (IS_ERR(chip))
@@ -554,11 +567,28 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 	if (!chip->vendor.iobase)
 		return -EIO;
 
+	sts3 = ioread8(chip->vendor.iobase + TPM_STS3(1));
+	if (sts3 & TPM_STS3_TPM2_FAM)
+		chip->flags = TPM_CHIP_FLAG_TPM2;
+
 	/* 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 (chip->flags & TPM_CHIP_FLAG_TPM2) {
+		chip->vendor.timeout_a = usecs_to_jiffies(TPM2_TIMEOUT_A);
+		chip->vendor.timeout_b = usecs_to_jiffies(TPM2_TIMEOUT_B);
+		chip->vendor.timeout_c = usecs_to_jiffies(TPM2_TIMEOUT_C);
+		chip->vendor.timeout_d = usecs_to_jiffies(TPM2_TIMEOUT_D);
+		chip->vendor.duration[TPM_SHORT] =
+			usecs_to_jiffies(TPM2_DURATION_SHORT);
+		chip->vendor.duration[TPM_MEDIUM] =
+			usecs_to_jiffies(TPM2_DURATION_MEDIUM);
+		chip->vendor.duration[TPM_LONG] =
+			usecs_to_jiffies(TPM2_DURATION_LONG);
+	} else {
+		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 (wait_startup(chip, 0) != 0) {
 		rc = -ENODEV;
@@ -573,8 +603,8 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 	vendor = ioread32(chip->vendor.iobase + TPM_DID_VID(0));
 	chip->vendor.manufacturer_id = vendor;
 
-	dev_info(dev,
-		 "1.2 TPM (device-id 0x%X, rev-id %d)\n",
+	dev_info(dev, "%s TPM (device-id 0x%X, rev-id %d)\n",
+		 (chip->flags & TPM_CHIP_FLAG_TPM2) ? "2.0" : "1.2",
 		 vendor >> 16, ioread8(chip->vendor.iobase + TPM_RID(0)));
 
 	if (!itpm) {
@@ -616,13 +646,17 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 		dev_dbg(dev, "\tData Avail Int Support\n");
 
 	/* get the timeouts before testing for irqs */
-	if (tpm_get_timeouts(chip)) {
+	if (!(chip->flags & TPM_CHIP_FLAG_TPM2) && tpm_get_timeouts(chip)) {
 		dev_err(dev, "Could not get TPM timeouts and durations\n");
 		rc = -ENODEV;
 		goto out_err;
 	}
 
-	if (tpm_do_selftest(chip)) {
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		rc = tpm2_do_selftest(chip);
+	else
+		rc = tpm_do_selftest(chip);
+	if (rc) {
 		dev_err(dev, "TPM self test failed\n");
 		rc = -ENODEV;
 		goto out_err;
@@ -683,7 +717,10 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 			chip->vendor.probed_irq = 0;
 
 			/* Generate Interrupts */
-			tpm_gen_interrupt(chip);
+			if (chip->flags & TPM_CHIP_FLAG_TPM2)
+				tpm2_gen_interrupt(chip);
+			else
+				tpm_gen_interrupt(chip);
 
 			chip->vendor.irq = chip->vendor.probed_irq;
 
@@ -759,14 +796,18 @@ static void tpm_tis_reenable_interrupts(struct tpm_chip *chip)
 static int tpm_tis_resume(struct device *dev)
 {
 	struct tpm_chip *chip = dev_get_drvdata(dev);
-	int ret;
+	int ret = 0;
 
 	if (chip->vendor.irq)
 		tpm_tis_reenable_interrupts(chip);
 
-	ret = tpm_pm_resume(dev);
-	if (!ret)
-		tpm_do_selftest(chip);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		tpm2_do_selftest(chip);
+	else {
+		ret = tpm_pm_resume(dev);
+		if (!ret)
+			tpm_do_selftest(chip);
+	}
 
 	return ret;
 }
Signature · 1 line
2.1.0
#7 lore raw

PATCH v5 7/7 tpm: create TPM 2.0 devices using own device class

In reply to Jarkko Sakkinen

Added own class for TPM devices that is used for TPM 2.0 and onwards. For TPM1 old device structure is kept for backwards compatibility.

Each struct tpm_chip represents a character device that is associated to the tpm device class.

---
 drivers/char/tpm/tpm-chip.c         | 14 +++++--
 drivers/char/tpm/tpm-dev.c          | 77 ++++++++++++++++++++++++++++++++++---
 drivers/char/tpm/tpm-interface.c    | 51 +++++++++++++++++-------
 drivers/char/tpm/tpm-sysfs.c        |  6 +--
 drivers/char/tpm/tpm.h              | 16 +++++++-
 drivers/char/tpm/tpm_atmel.c        | 14 +++----
 drivers/char/tpm/tpm_crb.c          |  4 +-
 drivers/char/tpm/tpm_i2c_atmel.c    | 16 ++++----
 drivers/char/tpm/tpm_i2c_infineon.c |  6 +--
 drivers/char/tpm/tpm_i2c_nuvoton.c  | 22 +++++------
 drivers/char/tpm/tpm_i2c_stm_st33.c |  6 +--
 drivers/char/tpm/tpm_infineon.c     | 22 +++++------
 drivers/char/tpm/tpm_nsc.c          | 20 +++++-----
 drivers/char/tpm/tpm_ppi.c          |  4 +-
 drivers/char/tpm/tpm_tis.c          | 12 +++---
 15 files changed, 199 insertions(+), 91 deletions(-)
drivers/char/tpm/tpm-chip.c +10 -4
index 9d2038b..9cc3ccf 100644
@@ -45,7 +45,7 @@ struct tpm_chip *tpm_chip_find_get(int chip_num)
 		if (chip_num != TPM_ANY_NUM && chip_num != pos->dev_num)
 			continue;
 
-		if (try_module_get(pos->dev->driver->owner)) {
+		if (try_module_get(pos->pdev->driver->owner)) {
 			chip = pos;
 			break;
 		}
@@ -111,7 +111,7 @@ struct tpm_chip *tpmm_chip_alloc(struct device *dev,
 	scnprintf(chip->devname, sizeof(chip->devname), "%s%d", "tpm",
 		  chip->dev_num);
 
-	chip->dev = dev;
+	chip->pdev = dev;
 	devm_add_action(dev, tpmm_chip_remove, chip);
 	dev_set_drvdata(dev, chip);
 
@@ -140,7 +140,10 @@ int tpm_chip_register(struct tpm_chip *chip)
 {
 	int rc;
 
-	rc = tpm_dev_add_device(chip);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		rc = tpm2_dev_add_device(chip);
+	else
+		rc = tpm_dev_add_device(chip);
 	if (rc)
 		return rc;
 
@@ -198,6 +201,9 @@ void tpm_chip_unregister(struct tpm_chip *chip)
 		tpm_sysfs_del_device(chip);
 	}
 
-	tpm_dev_del_device(chip);
+	if (chip->flags & TPM_CHIP_FLAG_TPM2)
+		tpm2_dev_del_device(chip);
+	else
+		tpm_dev_del_device(chip);
 }
 EXPORT_SYMBOL_GPL(tpm_chip_unregister);
drivers/char/tpm/tpm-dev.c +72 -5

114 lines not on this page · raw message

drivers/char/tpm/tpm-interface.c +37 -14

143 lines not on this page · raw message

drivers/char/tpm/tpm-sysfs.c +3 -3
index 8ecb052..ee66fd4 100644
@@ -284,16 +284,16 @@ static const struct attribute_group tpm_dev_group = {
 int tpm_sysfs_add_device(struct tpm_chip *chip)
 {
 	int err;
-	err = sysfs_create_group(&chip->dev->kobj,
+	err = sysfs_create_group(&chip->pdev->kobj,
 				 &tpm_dev_group);
 
 	if (err)
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"failed to create sysfs attributes, %d\n", err);
 	return err;
 }
 
 void tpm_sysfs_del_device(struct tpm_chip *chip)
 {
-	sysfs_remove_group(&chip->dev->kobj, &tpm_dev_group);
+	sysfs_remove_group(&chip->pdev->kobj, &tpm_dev_group);
 }
drivers/char/tpm/tpm.h +14 -2
index 076456a..97963d3 100644
@@ -28,6 +28,7 @@
 #include <linux/io.h>
 #include <linux/tpm.h>
 #include <linux/acpi.h>
+#include <linux/cdev.h>
 
 enum tpm_const {
 	TPM_MINOR = 224,	/* officially assigned */
@@ -153,7 +154,11 @@ enum tpm_chip_flags {
 };
 
 struct tpm_chip {
-	struct device *dev;	/* Device stuff */
+	/* Device associations */
+	struct device *pdev;
+	struct device dev;
+	struct cdev cdev;
+
 	const struct tpm_class_ops *ops;
 	unsigned int flags;
 
@@ -180,7 +185,7 @@ struct tpm_chip {
 
 static inline void tpm_chip_put(struct tpm_chip *chip)
 {
-	module_put(chip->dev->driver->owner);
+	module_put(chip->pdev->driver->owner);
 }
 
 static inline int tpm_read_index(int base, int index)
@@ -376,6 +381,8 @@ struct tpm_cmd_t {
 	tpm_cmd_params	params;
 } __packed;
 
+extern struct class *tpm_class;
+
 ssize_t	tpm_getcap(struct device *, __be32, cap_t *, const char *);
 ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
 		     size_t bufsiz);
@@ -398,6 +405,11 @@ extern void tpm_chip_unregister(struct tpm_chip *chip);
 
 int tpm_dev_add_device(struct tpm_chip *chip);
 void tpm_dev_del_device(struct tpm_chip *chip);
+int tpm2_dev_add_device(struct tpm_chip *chip);
+void tpm2_dev_del_device(struct tpm_chip *chip);
+void tpm_dev_init(void);
+void tpm_dev_exit(void);
+
 int tpm_sysfs_add_device(struct tpm_chip *chip);
 void tpm_sysfs_del_device(struct tpm_chip *chip);
 
drivers/char/tpm/tpm_atmel.c +7 -7
index fb2f921..387b0c0 100644
@@ -49,7 +49,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	for (i = 0; i < 6; i++) {
 		status = ioread8(chip->vendor.iobase + 1);
 		if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-			dev_err(chip->dev, "error reading header\n");
+			dev_err(chip->pdev, "error reading header\n");
 			return -EIO;
 		}
 		*buf++ = ioread8(chip->vendor.iobase);
@@ -60,12 +60,12 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	size = be32_to_cpu(*native_size);
 
 	if (count < size) {
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"Recv size(%d) less than available space\n", size);
 		for (; i < size; i++) {	/* clear the waiting data anyway */
 			status = ioread8(chip->vendor.iobase + 1);
 			if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-				dev_err(chip->dev, "error reading data\n");
+				dev_err(chip->pdev, "error reading data\n");
 				return -EIO;
 			}
 		}
@@ -76,7 +76,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	for (; i < size; i++) {
 		status = ioread8(chip->vendor.iobase + 1);
 		if ((status & ATML_STATUS_DATA_AVAIL) == 0) {
-			dev_err(chip->dev, "error reading data\n");
+			dev_err(chip->pdev, "error reading data\n");
 			return -EIO;
 		}
 		*buf++ = ioread8(chip->vendor.iobase);
@@ -86,7 +86,7 @@ static int tpm_atml_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	status = ioread8(chip->vendor.iobase + 1);
 
 	if (status & ATML_STATUS_DATA_AVAIL) {
-		dev_err(chip->dev, "data available is stuck\n");
+		dev_err(chip->pdev, "data available is stuck\n");
 		return -EIO;
 	}
 
@@ -97,9 +97,9 @@ static int tpm_atml_send(struct tpm_chip *chip, u8 *buf, size_t count)
 {
 	int i;
 
-	dev_dbg(chip->dev, "tpm_atml_send:\n");
+	dev_dbg(chip->pdev, "tpm_atml_send:\n");
 	for (i = 0; i < count; i++) {
-		dev_dbg(chip->dev, "%d 0x%x(%d)\n",  i, buf[i], buf[i]);
+		dev_dbg(chip->pdev, "%d 0x%x(%d)\n",  i, buf[i], buf[i]);
  		iowrite8(buf[i], chip->vendor.iobase);
 	}
 
drivers/char/tpm/tpm_crb.c +2 -2
index 3b7202c..c95ddc9 100644
@@ -169,7 +169,7 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
 	cca = priv->cca;
 
 	if (len > le32_to_cpu(cca->cmd_size)) {
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"invalid command count value %x %zx\n",
 			(unsigned int) len,
 			(size_t) le32_to_cpu(cca->cmd_size));
@@ -200,7 +200,7 @@ static void crb_cancel(struct tpm_chip *chip)
 	wmb();
 
 	if (crb_do_acpi_start(chip))
-		dev_err(chip->dev, "ACPI Start failed\n");
+		dev_err(chip->pdev, "ACPI Start failed\n");
 
 	cca->cancel = 0;
 }
drivers/char/tpm/tpm_i2c_atmel.c +8 -8
index 8af3b4a..dfef1ae 100644
@@ -52,7 +52,7 @@ struct priv_data {
 static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
 {
 	struct priv_data *priv = chip->vendor.priv;
-	struct i2c_client *client = to_i2c_client(chip->dev);
+	struct i2c_client *client = to_i2c_client(chip->pdev);
 	s32 status;
 
 	priv->len = 0;
@@ -62,7 +62,7 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
 
 	status = i2c_master_send(client, buf, len);
 
-	dev_dbg(chip->dev,
+	dev_dbg(chip->pdev,
 		"%s(buf=%*ph len=%0zx) -> sts=%d\n", __func__,
 		(int)min_t(size_t, 64, len), buf, len, status);
 	return status;
@@ -71,7 +71,7 @@ static int i2c_atmel_send(struct tpm_chip *chip, u8 *buf, size_t len)
 static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 {
 	struct priv_data *priv = chip->vendor.priv;
-	struct i2c_client *client = to_i2c_client(chip->dev);
+	struct i2c_client *client = to_i2c_client(chip->pdev);
 	struct tpm_output_header *hdr =
 		(struct tpm_output_header *)priv->buffer;
 	u32 expected_len;
@@ -88,7 +88,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 		return -ENOMEM;
 
 	if (priv->len >= expected_len) {
-		dev_dbg(chip->dev,
+		dev_dbg(chip->pdev,
 			"%s early(buf=%*ph count=%0zx) -> ret=%d\n", __func__,
 			(int)min_t(size_t, 64, expected_len), buf, count,
 			expected_len);
@@ -97,7 +97,7 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	}
 
 	rc = i2c_master_recv(client, buf, expected_len);
-	dev_dbg(chip->dev,
+	dev_dbg(chip->pdev,
 		"%s reread(buf=%*ph count=%0zx) -> ret=%d\n", __func__,
 		(int)min_t(size_t, 64, expected_len), buf, count,
 		expected_len);
@@ -106,13 +106,13 @@ static int i2c_atmel_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 
 static void i2c_atmel_cancel(struct tpm_chip *chip)
 {
-	dev_err(chip->dev, "TPM operation cancellation was requested, but is not supported");
+	dev_err(chip->pdev, "TPM operation cancellation was requested, but is not supported");
 }
 
 static u8 i2c_atmel_read_status(struct tpm_chip *chip)
 {
 	struct priv_data *priv = chip->vendor.priv;
-	struct i2c_client *client = to_i2c_client(chip->dev);
+	struct i2c_client *client = to_i2c_client(chip->pdev);
 	int rc;
 
 	/* The TPM fails the I2C read until it is ready, so we do the entire
@@ -125,7 +125,7 @@ static u8 i2c_atmel_read_status(struct tpm_chip *chip)
 	/* Once the TPM has completed the command the command remains readable
 	 * until another command is issued. */
 	rc = i2c_master_recv(client, priv->buffer, sizeof(priv->buffer));
-	dev_dbg(chip->dev,
+	dev_dbg(chip->pdev,
 		"%s: sts=%d", __func__, rc);
 	if (rc <= 0)
 		return 0;
drivers/char/tpm/tpm_i2c_infineon.c +3 -3
index 03708e6..33c5f36 100644
@@ -446,7 +446,7 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	/* read first 10 bytes, including tag, paramsize, and result */
 	size = recv_data(chip, buf, TPM_HEADER_SIZE);
 	if (size < TPM_HEADER_SIZE) {
-		dev_err(chip->dev, "Unable to read header\n");
+		dev_err(chip->pdev, "Unable to read header\n");
 		goto out;
 	}
 
@@ -459,14 +459,14 @@ static int tpm_tis_i2c_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	size += recv_data(chip, &buf[TPM_HEADER_SIZE],
 			  expected - TPM_HEADER_SIZE);
 	if (size < expected) {
-		dev_err(chip->dev, "Unable to read remainder of result\n");
+		dev_err(chip->pdev, "Unable to read remainder of result\n");
 		size = -ETIME;
 		goto out;
 	}
 
 	wait_for_stat(chip, TPM_STS_VALID, chip->vendor.timeout_c, &status);
 	if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
-		dev_err(chip->dev, "Error left over data\n");
+		dev_err(chip->pdev, "Error left over data\n");
 		size = -EIO;
 		goto out;
 	}
drivers/char/tpm/tpm_i2c_nuvoton.c +11 -11
index 09f0c46..92ee9fa 100644
@@ -96,13 +96,13 @@ static s32 i2c_nuvoton_write_buf(struct i2c_client *client, u8 offset, u8 size,
 /* read TPM_STS register */
 static u8 i2c_nuvoton_read_status(struct tpm_chip *chip)
 {
-	struct i2c_client *client = to_i2c_client(chip->dev);
+	struct i2c_client *client = to_i2c_client(chip->pdev);
 	s32 status;
 	u8 data;
 
 	status = i2c_nuvoton_read_buf(client, TPM_STS, 1, &data);
 	if (status <= 0) {
-		dev_err(chip->dev, "%s() error return %d\n", __func__,
+		dev_err(chip->pdev, "%s() error return %d\n", __func__,
 			status);
 		data = TPM_STS_ERR_VAL;
 	}
@@ -127,13 +127,13 @@ static s32 i2c_nuvoton_write_status(struct i2c_client *client, u8 data)
 /* write commandReady to TPM_STS register */
 static void i2c_nuvoton_ready(struct tpm_chip *chip)
 {
-	struct i2c_client *client = to_i2c_client(chip->dev);
+	struct i2c_client *client = to_i2c_client(chip->pdev);
 	s32 status;
 
 	/* this causes the current command to be aborted */
 	status = i2c_nuvoton_write_status(client, TPM_STS_COMMAND_READY);
 	if (status < 0)
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"%s() fail to write TPM_STS.commandReady\n", __func__);
 }
 
@@ -212,7 +212,7 @@ static int i2c_nuvoton_wait_for_stat(struct tpm_chip *chip, u8 mask, u8 value,
 				return 0;
 		} while (time_before(jiffies, stop));
 	}
-	dev_err(chip->dev, "%s(%02x, %02x) -> timeout\n", __func__, mask,
+	dev_err(chip->pdev, "%s(%02x, %02x) -> timeout\n", __func__, mask,
 		value);
 	return -ETIMEDOUT;
 }
@@ -240,7 +240,7 @@ static int i2c_nuvoton_recv_data(struct i2c_client *client,
 					       &chip->vendor.read_queue) == 0) {
 		burst_count = i2c_nuvoton_get_burstcount(client, chip);
 		if (burst_count < 0) {
-			dev_err(chip->dev,
+			dev_err(chip->pdev,
 				"%s() fail to read burstCount=%d\n", __func__,
 				burst_count);
 			return -EIO;
@@ -249,12 +249,12 @@ static int i2c_nuvoton_recv_data(struct i2c_client *client,
 		rc = i2c_nuvoton_read_buf(client, TPM_DATA_FIFO_R,
 					  bytes2read, &buf[size]);
 		if (rc < 0) {
-			dev_err(chip->dev,
+			dev_err(chip->pdev,
 				"%s() fail on i2c_nuvoton_read_buf()=%d\n",
 				__func__, rc);
 			return -EIO;
 		}
-		dev_dbg(chip->dev, "%s(%d):", __func__, bytes2read);
+		dev_dbg(chip->pdev, "%s(%d):", __func__, bytes2read);
 		size += bytes2read;
 	}
 
@@ -264,7 +264,7 @@ static int i2c_nuvoton_recv_data(struct i2c_client *client,
 /* Read TPM command results */
 static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 {
-	struct device *dev = chip->dev;
+	struct device *dev = chip->pdev;
 	struct i2c_client *client = to_i2c_client(dev);
 	s32 rc;
 	int expected, status, burst_count, retries, size = 0;
@@ -334,7 +334,7 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 		break;
 	}
 	i2c_nuvoton_ready(chip);
-	dev_dbg(chip->dev, "%s() -> %d\n", __func__, size);
+	dev_dbg(chip->pdev, "%s() -> %d\n", __func__, size);
 	return size;
 }
 
@@ -347,7 +347,7 @@ static int i2c_nuvoton_recv(struct tpm_chip *chip, u8 *buf, size_t count)
  */
 static int i2c_nuvoton_send(struct tpm_chip *chip, u8 *buf, size_t len)
 {
-	struct device *dev = chip->dev;
+	struct device *dev = chip->pdev;
 	struct i2c_client *client = to_i2c_client(dev);
 	u32 ordinal;
 	size_t count = 0;
drivers/char/tpm/tpm_i2c_stm_st33.c +3 -3
index b9d1a38..64ef510 100644
@@ -544,7 +544,7 @@ static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
 
 	size = recv_data(chip, buf, TPM_HEADER_SIZE);
 	if (size < TPM_HEADER_SIZE) {
-		dev_err(chip->dev, "Unable to read header\n");
+		dev_err(chip->pdev, "Unable to read header\n");
 		goto out;
 	}
 
@@ -557,7 +557,7 @@ static int tpm_stm_i2c_recv(struct tpm_chip *chip, unsigned char *buf,
 	size += recv_data(chip, &buf[TPM_HEADER_SIZE],
 					expected - TPM_HEADER_SIZE);
 	if (size < expected) {
-		dev_err(chip->dev, "Unable to read remainder of result\n");
+		dev_err(chip->pdev, "Unable to read remainder of result\n");
 		size = -ETIME;
 		goto out;
 	}
@@ -671,7 +671,7 @@ tpm_st33_i2c_probe(struct i2c_client *client, const struct i2c_device_id *id)
 				IRQF_TRIGGER_HIGH,
 				"TPM SERIRQ management", chip);
 		if (err < 0) {
-			dev_err(chip->dev , "TPM SERIRQ signals %d not available\n",
+			dev_err(chip->pdev , "TPM SERIRQ signals %d not available\n",
 				gpio_to_irq(platform_data->io_serirq));
 			goto _irq_set;
 		}
drivers/char/tpm/tpm_infineon.c +11 -11
index dcdb671..6d49213 100644
@@ -195,9 +195,9 @@ static int wait(struct tpm_chip *chip, int wait_for_bit)
 	}
 	if (i == TPM_MAX_TRIES) {	/* timeout occurs */
 		if (wait_for_bit == STAT_XFE)
-			dev_err(chip->dev, "Timeout in wait(STAT_XFE)\n");
+			dev_err(chip->pdev, "Timeout in wait(STAT_XFE)\n");
 		if (wait_for_bit == STAT_RDA)
-			dev_err(chip->dev, "Timeout in wait(STAT_RDA)\n");
+			dev_err(chip->pdev, "Timeout in wait(STAT_RDA)\n");
 		return -EIO;
 	}
 	return 0;
@@ -220,7 +220,7 @@ static void wait_and_send(struct tpm_chip *chip, u8 sendbyte)
 static void tpm_wtx(struct tpm_chip *chip)
 {
 	number_of_wtx++;
-	dev_info(chip->dev, "Granting WTX (%02d / %02d)\n",
+	dev_info(chip->pdev, "Granting WTX (%02d / %02d)\n",
 		 number_of_wtx, TPM_MAX_WTX_PACKAGES);
 	wait_and_send(chip, TPM_VL_VER);
 	wait_and_send(chip, TPM_CTRL_WTX);
@@ -231,7 +231,7 @@ static void tpm_wtx(struct tpm_chip *chip)
 
 static void tpm_wtx_abort(struct tpm_chip *chip)
 {
-	dev_info(chip->dev, "Aborting WTX\n");
+	dev_info(chip->pdev, "Aborting WTX\n");
 	wait_and_send(chip, TPM_VL_VER);
 	wait_and_send(chip, TPM_CTRL_WTX_ABORT);
 	wait_and_send(chip, 0x00);
@@ -257,7 +257,7 @@ recv_begin:
 	}
 
 	if (buf[0] != TPM_VL_VER) {
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"Wrong transport protocol implementation!\n");
 		return -EIO;
 	}
@@ -272,7 +272,7 @@ recv_begin:
 		}
 
 		if ((size == 0x6D00) && (buf[1] == 0x80)) {
-			dev_err(chip->dev, "Error handling on vendor layer!\n");
+			dev_err(chip->pdev, "Error handling on vendor layer!\n");
 			return -EIO;
 		}
 
@@ -284,7 +284,7 @@ recv_begin:
 	}
 
 	if (buf[1] == TPM_CTRL_WTX) {
-		dev_info(chip->dev, "WTX-package received\n");
+		dev_info(chip->pdev, "WTX-package received\n");
 		if (number_of_wtx < TPM_MAX_WTX_PACKAGES) {
 			tpm_wtx(chip);
 			goto recv_begin;
@@ -295,14 +295,14 @@ recv_begin:
 	}
 
 	if (buf[1] == TPM_CTRL_WTX_ABORT_ACK) {
-		dev_info(chip->dev, "WTX-abort acknowledged\n");
+		dev_info(chip->pdev, "WTX-abort acknowledged\n");
 		return size;
 	}
 
 	if (buf[1] == TPM_CTRL_ERROR) {
-		dev_err(chip->dev, "ERROR-package received:\n");
+		dev_err(chip->pdev, "ERROR-package received:\n");
 		if (buf[4] == TPM_INF_NAK)
-			dev_err(chip->dev,
+			dev_err(chip->pdev,
 				"-> Negative acknowledgement"
 				" - retransmit command!\n");
 		return -EIO;
@@ -321,7 +321,7 @@ static int tpm_inf_send(struct tpm_chip *chip, u8 * buf, size_t count)
 
 	ret = empty_fifo(chip, 1);
 	if (ret) {
-		dev_err(chip->dev, "Timeout while clearing FIFO\n");
+		dev_err(chip->pdev, "Timeout while clearing FIFO\n");
 		return -EIO;
 	}
 
drivers/char/tpm/tpm_nsc.c +10 -10
index 00c5470..072c298 100644
@@ -113,7 +113,7 @@ static int nsc_wait_for_ready(struct tpm_chip *chip)
 	}
 	while (time_before(jiffies, stop));
 
-	dev_info(chip->dev, "wait for ready failed\n");
+	dev_info(chip->pdev, "wait for ready failed\n");
 	return -EBUSY;
 }
 
@@ -129,12 +129,12 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
 		return -EIO;
 
 	if (wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0) {
-		dev_err(chip->dev, "F0 timeout\n");
+		dev_err(chip->pdev, "F0 timeout\n");
 		return -EIO;
 	}
 	if ((data =
 	     inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_NORMAL) {
-		dev_err(chip->dev, "not in normal mode (0x%x)\n",
+		dev_err(chip->pdev, "not in normal mode (0x%x)\n",
 			data);
 		return -EIO;
 	}
@@ -143,7 +143,7 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
 	for (p = buffer; p < &buffer[count]; p++) {
 		if (wait_for_stat
 		    (chip, NSC_STATUS_OBF, NSC_STATUS_OBF, &data) < 0) {
-			dev_err(chip->dev,
+			dev_err(chip->pdev,
 				"OBF timeout (while reading data)\n");
 			return -EIO;
 		}
@@ -154,11 +154,11 @@ static int tpm_nsc_recv(struct tpm_chip *chip, u8 * buf, size_t count)
 
 	if ((data & NSC_STATUS_F0) == 0 &&
 	(wait_for_stat(chip, NSC_STATUS_F0, NSC_STATUS_F0, &data) < 0)) {
-		dev_err(chip->dev, "F0 not set\n");
+		dev_err(chip->pdev, "F0 not set\n");
 		return -EIO;
 	}
 	if ((data = inb(chip->vendor.base + NSC_DATA)) != NSC_COMMAND_EOC) {
-		dev_err(chip->dev,
+		dev_err(chip->pdev,
 			"expected end of command(0x%x)\n", data);
 		return -EIO;
 	}
@@ -189,19 +189,19 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
 		return -EIO;
 
 	if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
-		dev_err(chip->dev, "IBF timeout\n");
+		dev_err(chip->pdev, "IBF timeout\n");
 		return -EIO;
 	}
 
 	outb(NSC_COMMAND_NORMAL, chip->vendor.base + NSC_COMMAND);
 	if (wait_for_stat(chip, NSC_STATUS_IBR, NSC_STATUS_IBR, &data) < 0) {
-		dev_err(chip->dev, "IBR timeout\n");
+		dev_err(chip->pdev, "IBR timeout\n");
 		return -EIO;
 	}
 
 	for (i = 0; i < count; i++) {
 		if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
-			dev_err(chip->dev,
+			dev_err(chip->pdev,
 				"IBF timeout (while writing data)\n");
 			return -EIO;
 		}
@@ -209,7 +209,7 @@ static int tpm_nsc_send(struct tpm_chip *chip, u8 * buf, size_t count)
 	}
 
 	if (wait_for_stat(chip, NSC_STATUS_IBF, 0, &data) < 0) {
-		dev_err(chip->dev, "IBF timeout\n");
+		dev_err(chip->pdev, "IBF timeout\n");
 		return -EIO;
 	}
 	outb(NSC_COMMAND_EOC, chip->vendor.base + NSC_COMMAND);
drivers/char/tpm/tpm_ppi.c +2 -2
index 6acdb17..659de61 100644
@@ -358,11 +358,11 @@ int tpm_add_ppi(struct tpm_chip *chip)
 
 	ACPI_FREE(obj);
 
-	return sysfs_create_group(&chip->dev->kobj, &ppi_attr_grp);
+	return sysfs_create_group(&chip->pdev->kobj, &ppi_attr_grp);
 }
 
 void tpm_remove_ppi(struct tpm_chip *chip)
 {
 	if (chip->ppi_version[0] != '\0')
-		sysfs_remove_group(&chip->dev->kobj, &ppi_attr_grp);
+		sysfs_remove_group(&chip->pdev->kobj, &ppi_attr_grp);
 }
drivers/char/tpm/tpm_tis.c +6 -6
index 4d4bff1..66780ba 100644
@@ -244,7 +244,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	/* read first 10 bytes, including tag, paramsize, and result */
 	if ((size =
 	     recv_data(chip, buf, TPM_HEADER_SIZE)) < TPM_HEADER_SIZE) {
-		dev_err(chip->dev, "Unable to read header\n");
+		dev_err(chip->pdev, "Unable to read header\n");
 		goto out;
 	}
 
@@ -257,7 +257,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 	if ((size +=
 	     recv_data(chip, &buf[TPM_HEADER_SIZE],
 		       expected - TPM_HEADER_SIZE)) < expected) {
-		dev_err(chip->dev, "Unable to read remainder of result\n");
+		dev_err(chip->pdev, "Unable to read remainder of result\n");
 		size = -ETIME;
 		goto out;
 	}
@@ -266,7 +266,7 @@ static int tpm_tis_recv(struct tpm_chip *chip, u8 *buf, size_t count)
 			  &chip->vendor.int_queue, false);
 	status = tpm_tis_status(chip);
 	if (status & TPM_STS_DATA_AVAIL) {	/* retry? */
-		dev_err(chip->dev, "Error left over data\n");
+		dev_err(chip->pdev, "Error left over data\n");
 		size = -EIO;
 		goto out;
 	}
@@ -445,7 +445,7 @@ static int probe_itpm(struct tpm_chip *chip)
 
 	rc = tpm_tis_send_data(chip, cmd_getticks, len);
 	if (rc == 0) {
-		dev_info(chip->dev, "Detected an iTPM.\n");
+		dev_info(chip->pdev, "Detected an iTPM.\n");
 		rc = 1;
 	} else
 		rc = -EFAULT;
@@ -696,7 +696,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 			if (devm_request_irq
 			    (dev, i, tis_int_probe, IRQF_SHARED,
 			     chip->vendor.miscdev.name, chip) != 0) {
-				dev_info(chip->dev,
+				dev_info(chip->pdev,
 					 "Unable to request irq: %d for probe\n",
 					 i);
 				continue;
@@ -746,7 +746,7 @@ static int tpm_tis_init(struct device *dev, acpi_handle acpi_dev_handle,
 		if (devm_request_irq
 		    (dev, chip->vendor.irq, tis_int_handler, IRQF_SHARED,
 		     chip->vendor.miscdev.name, chip) != 0) {
-			dev_info(chip->dev,
+			dev_info(chip->pdev,
 				 "Unable to request irq: %d for use\n",
 				 chip->vendor.irq);
 			chip->vendor.irq = 0;
Signature · 1 line
2.1.0
#8 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 5 lines · Jarkko Sakkinen

Added own class for TPM devices that is used for TPM 2.0 and onwards. For TPM1 old device structure is kept for backwards compatibility.

Each struct tpm_chip represents a character device that is associated to the tpm device class.

I think we should hang back on this untill we can answer a few questions..

I certainly thing both TPM1 and TPM2 should create the class, at the worst only tpm2 uses it for the chardev?

drivers/char/tpm/tpm-dev.c static int tpm_open(struct inode *inode, struct file *file) · line 69

Quoted 7 lines
drivers/char/tpm/tpm-dev.c +1 -1
@@ -63,7 +65,7 @@ static int tpm_open(struct inode *inode, struct file *file)
 	 * by the check of is_open variable, which is protected
 	 * by driver_lock. */
 	if (test_and_set_bit(0, &chip->is_open)) {
-		dev_dbg(chip->dev, "Another process owns this TPM\n");
+		dev_dbg(chip->pdev, "Another process owns this TPM\n");
 		return -EBUSY;

I actually think these are mostly wrong, and are part of why I think tpm1 should create the class too.

Except for the probe and remove function everything should log using the TPM device name (eg tpm0) and not the platform device name, so all of these debug statements should stay chip->dev...

And considering the volume of changes it might be better to leave 'dev' as a pointer to the tpm class rather than try and tackle that in this giant patch..

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 219

Quoted 3 lines
drivers/char/tpm/tpm-dev.c +3 -0
+static void tpm_dev_release(struct device *dev)
+{
+}

And all of this is upside down, the devm interm stuff should hold a get_device() on the struct device and the kfree should live here.

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 234

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	chip->cdev.owner = chip->pdev->driver->owner;

Is that right? the cdev fops is in this module, not the driver's module..

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 246

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	rc = cdev_add(&chip->cdev, chip->dev.devt, 1);

Can we/should we re-use the misc dev minor number assigned to TPM for tpm0?

To me altering the dev major:minor a far more visible change than moving the 'dev' file in sysfs. udev will handle the latter transparently, but the former will break non-udev systems..

Jason

#9 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 4 lines · Jason Gunthorpe
Quoted 3 lines · Jarkko Sakkinen

Added own class for TPM devices that is used for TPM 2.0 and onwards. For TPM1 old device structure is kept for backwards compatibility.

Quoted 8 lines
Quoted 2 lines

Each struct tpm_chip represents a character device that is associated to the tpm device class.

I think we should hang back on this untill we can answer a few questions..

I certainly thing both TPM1 and TPM2 should create the class, at the worst only tpm2 uses it for the chardev?

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

Quoted 12 lines

drivers/char/tpm/tpm-dev.c static int tpm_open(struct inode *inode, struct file *file) · line 69

Quoted 8 lines
drivers/char/tpm/tpm-dev.c +1 -1
@@ -63,7 +65,7 @@ static int tpm_open(struct inode *inode, struct file *file)
 	 * by the check of is_open variable, which is protected
 	 * by driver_lock. */
 	if (test_and_set_bit(0, &chip->is_open)) {
-		dev_dbg(chip->dev, "Another process owns this TPM\n");
+		dev_dbg(chip->pdev, "Another process owns this TPM\n");
 		return -EBUSY;

I actually think these are mostly wrong, and are part of why I think tpm1 should create the class too.

Quoted 3 lines

Except for the probe and remove function everything should log using the TPM device name (eg tpm0) and not the platform device name, so all of these debug statements should stay chip->dev...

I tend to agree but here applies my previous comment.

Quoted 3 lines

And considering the volume of changes it might be better to leave 'dev' as a pointer to the tpm class rather than try and tackle that in this giant patch..

Maybe, or maybe I could make the rename a separate patch?

It's fairly mechanical, just a matter of replacing string "chip->dev" with "chip->pdev".

Quoted 7 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 219

Quoted 4 lines
drivers/char/tpm/tpm-dev.c +3 -0
+static void tpm_dev_release(struct device *dev)
+{
+}

And all of this is upside down, the devm interm stuff should hold a get_device() on the struct device and the kfree should live here.

Agreed but didn't want diverge from TPM1 sequences (yet!). I think FIXME comment might be appropriate.

Quoted 4 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 234

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	chip->cdev.owner = chip->pdev->driver->owner;

Is that right? the cdev fops is in this module, not the driver's module..

tpm.ko defines the interface but TPM device driver module owns the character device. I think this is right and similar logic is also for example rtc_device_register().

Quoted 8 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 246

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	rc = cdev_add(&chip->cdev, chip->dev.devt, 1);

Can we/should we re-use the misc dev minor number assigned to TPM for tpm0?

To me altering the dev major:minor a far more visible change than moving the 'dev' file in sysfs. udev will handle the latter transparently, but the former will break non-udev systems..

I could understand in the context of a misc device but don't really when TPM 2.0 devices have their own device class. Using a 'tpm' class would in all cases break non-udev systems because major number is no longer 10 (misc).

Quoted 1 line

Jason

/Jarkko

#10 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 4 lines · Jarkko Sakkinen

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

Quoted 5 lines
Quoted 3 lines

And considering the volume of changes it might be better to leave 'dev' as a pointer to the tpm class rather than try and tackle that in this giant patch..

Maybe, or maybe I could make the rename a separate patch?

Pointer then rename?

Quoted 2 lines

It's fairly mechanical, just a matter of replacing string "chip->dev" with "chip->pdev".

Not everyone should be replaced :|

Quoted 8 lines
Quoted 4 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 234

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	chip->cdev.owner = chip->pdev->driver->owner;

Is that right? the cdev fops is in this module, not the driver's module..

tpm.ko defines the interface but TPM device driver module owns the character device. I think this is right and similar logic is also for example rtc_device_register().

Hmm, yes, I see that in rtc_dev_prepare - but I don't have time to figure out why that might be :)

On the surface, it doesn't seem to make sense: The cdev layer never calls into a function that goes to the chip module - all functions go to the fops in tpm.ko, and tmp.ko is (eventually) responsible for ensuring that ops never points to an unloaded module.

So why should it care what the driver module is??

Quoted 4 lines

I could understand in the context of a misc device but don't really when TPM 2.0 devices have their own device class. Using a 'tpm' class would in all cases break non-udev systems because major number is no longer 10 (misc).

I'm just saying it would be nice to force the major/minor to misc.tpm for tmp0.

No idea if that is OK or not.

Jason

#11 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 11 lines · Jason Gunthorpe
Quoted 4 lines · Jarkko Sakkinen

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

I have to admit that I'm not quite following here but I assume that you restated this below in more verbose way and this is basically the same argument :)

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

And considering the volume of changes it might be better to leave 'dev' as a pointer to the tpm class rather than try and tackle that in this giant patch..

Quoted 8 lines
Quoted 1 line

Maybe, or maybe I could make the rename a separate patch?

Pointer then rename?

Quoted 2 lines

It's fairly mechanical, just a matter of replacing string "chip->dev" with "chip->pdev".

Not everyone should be replaced :|

I think the current variable name "dev" is miss-leading. The use of "pdev" would document better the appropriate use for that field (i.e. for the most cases DON'T use it).

Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 234

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	chip->cdev.owner = chip->pdev->driver->owner;

Is that right? the cdev fops is in this module, not the driver's module..

tpm.ko defines the interface but TPM device driver module owns the character device. I think this is right and similar logic is also for example rtc_device_register().

Hmm, yes, I see that in rtc_dev_prepare - but I don't have time to figure out why that might be :)

Quoted 6 lines

On the surface, it doesn't seem to make sense: The cdev layer never calls into a function that goes to the chip module - all functions go to the fops in tpm.ko, and tmp.ko is (eventually) responsible for ensuring that ops never points to an unloaded module.

So why should it care what the driver module is??

Fully agreed, I think you got a point here. I think it makes sense as a guideline to kind of "centralize" robustness to tpm.ko and leave as little responsibility as possible to device drivers.

Quoted 9 lines
Quoted 4 lines

I could understand in the context of a misc device but don't really when TPM 2.0 devices have their own device class. Using a 'tpm' class would in all cases break non-udev systems because major number is no longer 10 (misc).

I'm just saying it would be nice to force the major/minor to misc.tpm for tmp0.

No idea if that is OK or not.

I think that would be a mess. The way things are done in this v5 patch set is actually quite coherent and it does not break backwards compatibility because the "proper" device hierarchy is only used for TPM 2.0 devices.

I think the improvement for v6 would be to add a sysctl attribute to disable legacy device hierarchy and sysfs attributes. If that attribute is unset, the old misc hierarchy would be used for any TPM version and TPM 1.0 devices would use existing sysfs attributes.

If the flag is set, then the new proper device hierarchy would be used for any TPM device and we would have also chance to redefine sysfs attributes.

This would add some legacy clutter to the stack but would be a piss-off-free and non-ABI-breaking solution.

Quoted 1 line

Jason

PS. I feel that drivers/char/tpm is a like a desolated town. How many of the people currently marked as maintainers are actually participating to the subsystem development let alone driving it?

This subsystem is increasingly important to us given that major software platforms like Chrome OS make extensive use of it and I've heard that even bug fixes have taken some times over a year to get through. Does not look good at all.

/Jarkko

#12 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 72 lines · Jarkko Sakkinen
Quoted 11 lines · Jason Gunthorpe
Quoted 4 lines · Jarkko Sakkinen

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

I have to admit that I'm not quite following here but I assume that you restated this below in more verbose way and this is basically the same argument :)

Quoted 4 lines
Quoted 4 lines
Quoted 3 lines

And considering the volume of changes it might be better to leave 'dev' as a pointer to the tpm class rather than try and tackle that in this giant patch..

Quoted 8 lines
Quoted 1 line

Maybe, or maybe I could make the rename a separate patch?

Pointer then rename?

Quoted 2 lines

It's fairly mechanical, just a matter of replacing string "chip->dev" with "chip->pdev".

Not everyone should be replaced :|

I think the current variable name "dev" is miss-leading. The use of "pdev" would document better the appropriate use for that field (i.e. for the most cases DON'T use it).

Quoted 12 lines
Quoted 8 lines
Quoted 4 lines

drivers/char/tpm/tpm-dev.c void tpm_dev_del_device(struct tpm_chip *chip) · line 234

Quoted 1 line
drivers/char/tpm/tpm-dev.c +1 -0
+	chip->cdev.owner = chip->pdev->driver->owner;

Is that right? the cdev fops is in this module, not the driver's module..

tpm.ko defines the interface but TPM device driver module owns the character device. I think this is right and similar logic is also for example rtc_device_register().

Hmm, yes, I see that in rtc_dev_prepare - but I don't have time to figure out why that might be :)

Quoted 6 lines

On the surface, it doesn't seem to make sense: The cdev layer never calls into a function that goes to the chip module - all functions go to the fops in tpm.ko, and tmp.ko is (eventually) responsible for ensuring that ops never points to an unloaded module.

So why should it care what the driver module is??

Fully agreed, I think you got a point here. I think it makes sense as a guideline to kind of "centralize" robustness to tpm.ko and leave as little responsibility as possible to device drivers.

Quoted 9 lines
Quoted 4 lines

I could understand in the context of a misc device but don't really when TPM 2.0 devices have their own device class. Using a 'tpm' class would in all cases break non-udev systems because major number is no longer 10 (misc).

I'm just saying it would be nice to force the major/minor to misc.tpm for tmp0.

No idea if that is OK or not.

I think that would be a mess. The way things are done in this v5 patch set is actually quite coherent and it does not break backwards compatibility because the "proper" device hierarchy is only used for TPM 2.0 devices.

Quoted 4 lines

I think the improvement for v6 would be to add a sysctl attribute to disable legacy device hierarchy and sysfs attributes. If that attribute is unset, the old misc hierarchy would be used for any TPM version and TPM 1.0 devices would use existing sysfs attributes.

Mistake here. Should be a module parameter to be not racy, not sysctl attribute :)

Quoted 9 lines

If the flag is set, then the new proper device hierarchy would be used for any TPM device and we would have also chance to redefine sysfs attributes.

This would add some legacy clutter to the stack but would be a piss-off-free and non-ABI-breaking solution.

Quoted 1 line

Jason

Quoted 8 lines

PS. I feel that drivers/char/tpm is a like a desolated town. How many of the people currently marked as maintainers are actually participating to the subsystem development let alone driving it?

This subsystem is increasingly important to us given that major software platforms like Chrome OS make extensive use of it and I've heard that even bug fixes have taken some times over a year to get through. Does not look good at all.

/Jarkko

#13 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

In reply to Jarkko Sakkinen
Quoted 5 lines · Jarkko Sakkinen
Quoted 5 lines
Quoted 4 lines

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

Quoted 8 lines
Quoted 4 lines

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

I have to admit that I'm not quite following here but I assume that you restated this below in more verbose way and this is basically the same argument :)

I mean, if we have a patch that does:

struct tpm_chip {
struct device cdev; // the class device
struct device *pdev; // the 'platform' device chip is bound too

struct device *dev = pdev; // Temporary Compatability
[+ device_register/etc/etc]

Then both cdev and pdev should always be valid. We should not have cdev be valid for TPM2 and invalid for TPM1, that is just a big mess.

Just this change is perfectly safe, it creates the /sys/class/tpm/tpm0 directory, but doesn't change anything already existing

Then, a patch: go through and replace all uses of chip->dev with &chip->cdev in 90% of cases

Another patch: use chip->pdev for the handfull of the rest, and drop dev entirely

Then a patch: Drop misc_register entirely, no compat stuff. Explain clearly the resulting sysfs changes, CC the various people who monitor the sysfs API, act on any feedback. I'm hoping it is an OK change. [ If it is not OK then we can talk about using it only for TPM2 or
whatever ]

Quoted 3 lines

I think the current variable name "dev" is miss-leading. The use of "pdev" would document better the appropriate use for that field (i.e. for the most cases DON'T use it).

Yes, see above :)

Quoted 4 lines

I think that would be a mess. The way things are done in this v5 patch set is actually quite coherent and it does not break backwards compatibility because the "proper" device hierarchy is only used for TPM 2.0 devices.

I mean, just do something like this:

if (chip->id == 0)
chip->cdev.devt = MKDEV(MISC_MAJOR, TPM_MINOR)
else
chip->cdev.devt = [.. dynamic alloc_chrddev_region ..]

Very simple, keeps the major/minor for TPM0, moves the 'dev' file to the new location in sysfs.

I can't find another example of this in the kernel, so I don't know what the thinking is..

Jason

#14 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 34 lines · Jason Gunthorpe
Quoted 5 lines · Jarkko Sakkinen
Quoted 5 lines
Quoted 4 lines

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

Quoted 8 lines
Quoted 4 lines

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

I have to admit that I'm not quite following here but I assume that you restated this below in more verbose way and this is basically the same argument :)

I mean, if we have a patch that does:

struct tpm_chip {
struct device cdev; // the class device
struct device *pdev; // the 'platform' device chip is bound too

struct device *dev = pdev; // Temporary Compatability
[+ device_register/etc/etc]

Then both cdev and pdev should always be valid. We should not have cdev be valid for TPM2 and invalid for TPM1, that is just a big mess.

Just this change is perfectly safe, it creates the /sys/class/tpm/tpm0 directory, but doesn't change anything already existing

Then, a patch: go through and replace all uses of chip->dev with &chip->cdev in 90% of cases

Quoted 8 lines

Another patch: use chip->pdev for the handfull of the rest, and drop dev entirely

Then a patch: Drop misc_register entirely, no compat stuff. Explain clearly the resulting sysfs changes, CC the various people who monitor the sysfs API, act on any feedback. I'm hoping it is an OK change. [ If it is not OK then we can talk about using it only for TPM2 or
whatever ]

Hold on. So you are proposing that for a TPM 1.0 device you would have simultaneously as an intermediate step:

- /sys/class/tpm/tpm0
- /sys/class/misc/tpm0

Maybe it would be a better idea to just create patch that would simply

- wipe /sys/class/misc/tpm0
- introduce /sys/class/tpm/tpm0
- for TPM 1 put existing sysfs attributes /sys/class/tpm/tpm0

I would put this into a single patch. I don't really like those intermediate steps. I think they cause more confusion but I think as a whole the change is reasonable.

I'll do this "aggressive" patch for v6 and "soften" it based on feedback if it is not liked (and CC to appropriate people).

Quoted 18 lines
Quoted 3 lines

I think the current variable name "dev" is miss-leading. The use of "pdev" would document better the appropriate use for that field (i.e. for the most cases DON'T use it).

Yes, see above :)

Quoted 4 lines

I think that would be a mess. The way things are done in this v5 patch set is actually quite coherent and it does not break backwards compatibility because the "proper" device hierarchy is only used for TPM 2.0 devices.

I mean, just do something like this:

if (chip->id == 0)
chip->cdev.devt = MKDEV(MISC_MAJOR, TPM_MINOR)
else
chip->cdev.devt = [.. dynamic alloc_chrddev_region ..]

Quoted 5 lines

Very simple, keeps the major/minor for TPM0, moves the 'dev' file to the new location in sysfs.

I can't find another example of this in the kernel, so I don't know what the thinking is..

Maybe it would be reasonable to break the path structure and do this change for the benefit of backward compatibility. Not doing the change your proposed might really cause unwanted breakage.

Moving the current TPM sysfs attributes is not really an issue because they are only for human consumption (not machine readable in any sany way) :) And AFAIK TrouSerS does not use sysfs PPI interface.

Quoted 1 line

Jason

/Jarkko

#15 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines

Then a patch: Drop misc_register entirely, no compat stuff. Explain clearly the resulting sysfs changes, CC the various people who monitor the sysfs API, act on any feedback. I'm hoping it is an OK change. [ If it is not OK then we can talk about using it only for TPM2 or
whatever ]

Hold on. So you are proposing that for a TPM 1.0 device you would have simultaneously as an intermediate step:

- /sys/class/tpm/tpm0
- /sys/class/misc/tpm0

Yes, well more specifically:

/sys/class/tpm/tpm0/
/sys/class/misc/tpm0/dev

The reason for this is simply that adding to sysfs is certainly OK, I don't think the tpm and misc device will collide in any way - udev will look for the 'dev' file and ignore the class/tpm directory.

It breaks up the patch too, this would be a monster:

Quoted 1 line

Maybe it would be a better idea to just create patch that would simply

Because of all the variable rename noise and so forth.

Even if the net result is we apply several patchs in a row that wipes /sys/class/misc/tpm0 the patches themselves will be smaller and more reviewable if split, especially those big variable rename ones..

Quoted 3 lines

Moving the current TPM sysfs attributes is not really an issue because they are only for human consumption (not machine readable in any sany way) :) And AFAIK TrouSerS does not use sysfs PPI interface.

Someone in user space must use that event log and PPI stuff??? Does anyone know who and how?

Jason

#16 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 25 lines · Jason Gunthorpe
Quoted 11 lines · Jarkko Sakkinen
Quoted 5 lines

Then a patch: Drop misc_register entirely, no compat stuff. Explain clearly the resulting sysfs changes, CC the various people who monitor the sysfs API, act on any feedback. I'm hoping it is an OK change. [ If it is not OK then we can talk about using it only for TPM2 or
whatever ]

Hold on. So you are proposing that for a TPM 1.0 device you would have simultaneously as an intermediate step:

- /sys/class/tpm/tpm0
- /sys/class/misc/tpm0

Yes, well more specifically:

/sys/class/tpm/tpm0/
/sys/class/misc/tpm0/dev

The reason for this is simply that adding to sysfs is certainly OK, I don't think the tpm and misc device will collide in any way - udev will look for the 'dev' file and ignore the class/tpm directory.

It breaks up the patch too, this would be a monster:

Quoted 7 lines
Quoted 1 line

Maybe it would be a better idea to just create patch that would simply

Because of all the variable rename noise and so forth.

Even if the net result is we apply several patchs in a row that wipes /sys/class/misc/tpm0 the patches themselves will be smaller and more reviewable if split, especially those big variable rename ones..

OK, I see your point. I'll break it up into more reasonable steps.

Quoted 8 lines
Quoted 3 lines

Moving the current TPM sysfs attributes is not really an issue because they are only for human consumption (not machine readable in any sany way) :) And AFAIK TrouSerS does not use sysfs PPI interface.

Someone in user space must use that event log and PPI stuff??? Does anyone know who and how?

Jason

/Jarkko

#17 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

In reply to Jason Gunthorpe
Quoted 22 lines · Jason Gunthorpe
Quoted 5 lines · Jarkko Sakkinen
Quoted 5 lines
Quoted 4 lines

I used the class 'tpm' only for TPM 2.x because I didn't want to break the binary compatibility for TPM 1.x anyway. In ideal situtation both would be character devices inside the class 'tpm' and there would be sysfs attribute such as 'family' to mark the protocol to be used.

Quoted 8 lines
Quoted 4 lines

You can create the class without moving away from miscdev...

Not having the device creates way to much difference that has to be supported, way too messy.

I have to admit that I'm not quite following here but I assume that you restated this below in more verbose way and this is basically the same argument :)

I mean, if we have a patch that does:

struct tpm_chip {
struct device cdev; // the class device
struct device *pdev; // the 'platform' device chip is bound too

Quoted 5 lines

struct device *dev = pdev; // Temporary Compatability
[+ device_register/etc/etc]

Then both cdev and pdev should always be valid. We should not have cdev be valid for TPM2 and invalid for TPM1, that is just a big mess.

As a first patch I'll do a patch that does dev -> pdev rename and nothing else. IMHO it's clean and easy to review if no other changes are contained. One reason for this is obviously that I want to use cdev for struct cdev not for the class device.

Quoted 40 lines

Just this change is perfectly safe, it creates the /sys/class/tpm/tpm0 directory, but doesn't change anything already existing

Then, a patch: go through and replace all uses of chip->dev with &chip->cdev in 90% of cases

Another patch: use chip->pdev for the handfull of the rest, and drop dev entirely

Then a patch: Drop misc_register entirely, no compat stuff. Explain clearly the resulting sysfs changes, CC the various people who monitor the sysfs API, act on any feedback. I'm hoping it is an OK change. [ If it is not OK then we can talk about using it only for TPM2 or
whatever ]

Quoted 3 lines

I think the current variable name "dev" is miss-leading. The use of "pdev" would document better the appropriate use for that field (i.e. for the most cases DON'T use it).

Yes, see above :)

Quoted 4 lines

I think that would be a mess. The way things are done in this v5 patch set is actually quite coherent and it does not break backwards compatibility because the "proper" device hierarchy is only used for TPM 2.0 devices.

I mean, just do something like this:

if (chip->id == 0)
chip->cdev.devt = MKDEV(MISC_MAJOR, TPM_MINOR)
else
chip->cdev.devt = [.. dynamic alloc_chrddev_region ..]

Very simple, keeps the major/minor for TPM0, moves the 'dev' file to the new location in sysfs.

I can't find another example of this in the kernel, so I don't know what the thinking is..

Jason

#18 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 9 lines · Jarkko Sakkinen
Quoted 9 lines

I mean, if we have a patch that does:

struct tpm_chip {
struct device cdev; // the class device
struct device *pdev; // the 'platform' device chip is bound too

struct device *dev = pdev; // Temporary Compatability
[+ device_register/etc/etc]

Quoted 7 lines
Quoted 2 lines

Then both cdev and pdev should always be valid. We should not have cdev be valid for TPM2 and invalid for TPM1, that is just a big mess.

As a first patch I'll do a patch that does dev -> pdev rename and nothing else. IMHO it's clean and easy to review if no other changes are contained. One reason for this is obviously that I want to use cdev for struct cdev not for the class device.

Well, once you add cdev, pdev and dev, you want most uses of dev to become cdev and some uses to become pdev.

Just bulk renaming dev -> pdev and then bulk renaming pdev -> cdev seems like lots of churn...

Jason

#19 lore raw

Re: [PATCH v5 7/7] tpm: create TPM 2.0 devices using own device class

Quoted 14 lines · Jason Gunthorpe
Quoted 11 lines · Jarkko Sakkinen
Quoted 11 lines

I mean, if we have a patch that does:

struct tpm_chip {
struct device cdev; // the class device
struct device *pdev; // the 'platform' device chip is bound too

struct device *dev = pdev; // Temporary Compatability
[+ device_register/etc/etc]

Then both cdev and pdev should always be valid. We should not have cdev be valid for TPM2 and invalid for TPM1, that is just a big mess.

Quoted 7 lines
Quoted 4 lines

As a first patch I'll do a patch that does dev -> pdev rename and nothing else. IMHO it's clean and easy to review if no other changes are contained. One reason for this is obviously that I want to use cdev for struct cdev not for the class device.

Well, once you add cdev, pdev and dev, you want most uses of dev to become cdev and some uses to become pdev.

struct cdev uses variable name 'cdev' in my previous patch set so this naming scheme doesn't work.

I do not understand why dev -> pdev rename as the very first commit would be such a bad thing. It's anyway better variable name for it. After that variable name 'dev' is free to be used for class device.

Quoted 2 lines

Just bulk renaming dev -> pdev and then bulk renaming pdev -> cdev seems like lots of churn...

I'm not planning to do such thing. In the end there is:

struct device dev;
struct device *pdev;
struct cdev cdev;

This will require only one "rename commit".

What I'm going to take from your feedback is to make /dev/tpm0 special case when considering major:minor just like you proposed. It's very good idea.

Other thing I'm going to do is to leave PPI sysfs interface to tpmX/device/ppi at least for TPM1 devices.

I'll bake the next patch set hopefully before the end of this week. Lets see after that if it stil need refinement or breaking up to smaller patches.

Quoted 1 line

Jason

/Jarkko

#20 lore raw
In reply to Jarkko Sakkinen

I pushed couples of fixed in addition to these changes to:

https://github.com/jsakkine/linux-tpm2/tree/tpm2-v5

There was problem running self-test because the FIFO module that I have seems to give me TPM2_RC_TESTING when I try to start the self-test.

Additionally. I was able to test force parameter for tpm_tis. Resources are cleaned up properly at least for TPM2 devices.

/Jarkko

Quoted 69 lines · Jarkko Sakkinen

This patch set enables TPM2 protocol and provides drivers for FIFO and CRB interfaces.

Major changes since v1:

- Improved struct tpm_chip life-cycle by taking advantage of devres API.
- Refined sysfs attributes as simple key-values thereby not repeating mistakes in TPM1 sysfs attributes.
- Documented functions in tpm-chip.c and tpm2-cmd.c.
- Documented sysfs attributes.

Major changes since v2:

- Lots of fixes in calling order in device drivers (thanks to Jason Gunthorpe for pointing these out!).
- Attach sysfs attributes to the misc device because it represents TPM device to the user space.

Major changes since v3:

- Disable sysfs attibutes for TPM 2.0 for until we can sort out the best approach for them.
- Fixed all the style issues found with checkpatch.pl.

Major changes since v4:

- missing EXPORT_SYMBOL_GPL()
- own class for TPM devices used for TPM 2.0 devices and onwards.

Jarkko Sakkinen (6):
tpm: merge duplicate transmit_cmd() functions
tpm: two-phase chip management functions
tpm: fix multiple race conditions in tpm_ppi.c
tpm: TPM 2.0 baseline support
tpm: TPM 2.0 CRB Interface
tpm: create TPM 2.0 devices using own device class

Will Arthur (1):
tpm: TPM 2.0 FIFO Interface

 drivers/char/tpm/Kconfig            |   9 +
 drivers/char/tpm/Makefile           |   3 +-
 drivers/char/tpm/tpm-chip.c         | 209 +++++++++++++
 drivers/char/tpm/tpm-dev.c          |  77 ++++-
 drivers/char/tpm/tpm-interface.c    | 256 +++++-----------
 drivers/char/tpm/tpm-sysfs.c        |  29 +-
 drivers/char/tpm/tpm.h              | 113 ++++++-
 drivers/char/tpm/tpm2-cmd.c         | 566 ++++++++++++++++++++++++++++++++++++
 drivers/char/tpm/tpm_atmel.c        |  26 +-
 drivers/char/tpm/tpm_crb.c          | 334 +++++++++++++++++++++
 drivers/char/tpm/tpm_i2c_atmel.c    |  49 ++--
 drivers/char/tpm/tpm_i2c_infineon.c |  43 +--
 drivers/char/tpm/tpm_i2c_nuvoton.c  |  66 ++---
 drivers/char/tpm/tpm_i2c_stm_st33.c |  44 ++-
 drivers/char/tpm/tpm_ibmvtpm.c      |  17 +-
 drivers/char/tpm/tpm_infineon.c     |  51 ++--
 drivers/char/tpm/tpm_nsc.c          |  34 ++-
 drivers/char/tpm/tpm_ppi.c          | 136 +++++----
 drivers/char/tpm/tpm_tis.c          | 177 ++++++-----
 drivers/char/tpm/xen-tpmfront.c     |  14 +-
 20 files changed, 1711 insertions(+), 542 deletions(-)
 create mode 100644 drivers/char/tpm/tpm-chip.c
 create mode 100644 drivers/char/tpm/tpm2-cmd.c
 create mode 100644 drivers/char/tpm/tpm_crb.c
Signature · 1 line
2.1.0