Skip to content

Commit

Permalink
tpm, tpm_tis: startup chip before testing for interrupts
Browse files Browse the repository at this point in the history
[ Upstream commit 548eb51 ]

In tpm_tis_gen_interrupt() a request for a property value is sent to the
TPM to test if interrupts are generated. However after a power cycle the
TPM responds with TPM_RC_INITIALIZE which indicates that the TPM is not
yet properly initialized.
Fix this by first starting the TPM up before the request is sent. For this
the startup implementation is removed from tpm_chip_register() and put
into the new function tpm_chip_startup() which is called before the
interrupts are tested.

Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
Tested-by: Jarkko Sakkinen <jarkko@kernel.org>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
Stable-dep-of: 99d4645 ("tpm: Prevent hwrng from activating during resume")
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
linosanfilippo-kunbus authored and gregkh committed May 30, 2023
1 parent e09bf4b commit fde5ff4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
38 changes: 24 additions & 14 deletions drivers/char/tpm/tpm-chip.c
Expand Up @@ -605,6 +605,30 @@ static int tpm_get_pcr_allocation(struct tpm_chip *chip)
return rc;
}

/*
* tpm_chip_startup() - performs auto startup and allocates the PCRs
* @chip: TPM chip to use.
*/
int tpm_chip_startup(struct tpm_chip *chip)
{
int rc;

rc = tpm_chip_start(chip);
if (rc)
return rc;

rc = tpm_auto_startup(chip);
if (rc)
goto stop;

rc = tpm_get_pcr_allocation(chip);
stop:
tpm_chip_stop(chip);

return rc;
}
EXPORT_SYMBOL_GPL(tpm_chip_startup);

/*
* tpm_chip_register() - create a character device for the TPM chip
* @chip: TPM chip to use.
Expand All @@ -620,20 +644,6 @@ int tpm_chip_register(struct tpm_chip *chip)
{
int rc;

rc = tpm_chip_start(chip);
if (rc)
return rc;
rc = tpm_auto_startup(chip);
if (rc) {
tpm_chip_stop(chip);
return rc;
}

rc = tpm_get_pcr_allocation(chip);
tpm_chip_stop(chip);
if (rc)
return rc;

tpm_sysfs_add_device(chip);

tpm_bios_log_setup(chip);
Expand Down
1 change: 1 addition & 0 deletions drivers/char/tpm/tpm.h
Expand Up @@ -263,6 +263,7 @@ static inline void tpm_msleep(unsigned int delay_msec)
delay_msec * 1000);
};

int tpm_chip_startup(struct tpm_chip *chip);
int tpm_chip_start(struct tpm_chip *chip);
void tpm_chip_stop(struct tpm_chip *chip);
struct tpm_chip *tpm_find_get_ops(struct tpm_chip *chip);
Expand Down
5 changes: 5 additions & 0 deletions drivers/char/tpm/tpm_tis_core.c
Expand Up @@ -1124,6 +1124,11 @@ int tpm_tis_core_init(struct device *dev, struct tpm_tis_data *priv, int irq,
/* INTERRUPT Setup */
init_waitqueue_head(&priv->read_queue);
init_waitqueue_head(&priv->int_queue);

rc = tpm_chip_startup(chip);
if (rc)
goto out_err;

if (irq != -1) {
/*
* Before doing irq testing issue a command to the TPM in polling mode
Expand Down

0 comments on commit fde5ff4

Please sign in to comment.