Re: [tpmdd-devel] [PATCH] TPM: Issue TPM_STARTUP at driver load ifthe TPM has not been started

From: Jason Gunthorpe
Date: Mon Oct 01 2012 - 13:39:08 EST


On Mon, Oct 01, 2012 at 12:10:03PM -0500, Kent Yoder wrote:

> > I'm not familiar enough with how the power management flow works with
> > the TPM to do this. I don't think that can be the general case
> > because:
> >
> > 3. If stType = TPM_ST_STATE
> > a. If the TPM has no state to restore, the TPM MUST set the internal
> > state such that it returns TPM_FAILEDSELFTEST to all subsequent
> > commands.
> >
> > So you need to know a save state exists in the TPM before attempting
> > the command?
>
> Presumably we'd have called TPM_SaveState on suspend. It might be
> possible to set a flag based on whether we needed to call startup at
> init time that tells the driver to call save/restore state during
> suspend/resume.

Curiously the current code does call TPM_SaveState on suspend, but
relies on the BIOS to do TPM_Startup(ST_STATE) on resume, why the
asymmetry?

Anyhow, I think the thing would be something like this. I have no
means to test TPM suspend, so I'll just post this as a note here. It
will apply over v2 of my patch.

diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index b13ad77..7a8136a 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -1336,10 +1336,23 @@ EXPORT_SYMBOL_GPL(tpm_pm_suspend);
int tpm_pm_resume(struct device *dev)
{
struct tpm_chip *chip = dev_get_drvdata(dev);
+ struct tpm_cmd_t tpm_cmd;

if (chip == NULL)
return -ENODEV;

+ tpm_cmd.header.in = tpm_getcap_header;
+ 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, 0);
+ if (rc == TPM_ERR_INVALID_POSTINIT) {
+ /* The BIOS did not restart the TPM, execute a startup
+ command. */
+ dev_info(chip->dev, "Issuing TPM_STARTUP");
+ tpm_startup(chip, TPM_ST_STATE);
+ }
+
return 0;
}
EXPORT_SYMBOL_GPL(tpm_pm_resume);

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/