From a11be4c303eabb142e074c7ca14b6ae0d293f0cb Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 21 Feb 2023 06:24:52 -0700 Subject: tpm: Implement tpm_auto_start() for TPMv1.2 Add an implementation of this, moving the common call to tpm_init() up into the common API implementation. Add a test. Reviewed-by: Ilias Apalodimas Signed-off-by: Simon Glass Signed-off-by: Ilias Apalodimas --- lib/tpm_api.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'lib/tpm_api.c') diff --git a/lib/tpm_api.c b/lib/tpm_api.c index 5b2c11a277c..3ef5e811794 100644 --- a/lib/tpm_api.c +++ b/lib/tpm_api.c @@ -37,10 +37,23 @@ u32 tpm_startup(struct udevice *dev, enum tpm_startup_type mode) u32 tpm_auto_start(struct udevice *dev) { - if (tpm_is_v2(dev)) - return tpm2_auto_start(dev); + u32 rc; - return -ENOSYS; + /* + * the tpm_init() will return -EBUSY if the init has already happened + * The selftest and startup code can run multiple times with no side + * effects + */ + rc = tpm_init(dev); + if (rc && rc != -EBUSY) + return rc; + + if (tpm_is_v1(dev)) + return tpm1_auto_start(dev); + else if (tpm_is_v2(dev)) + return tpm2_auto_start(dev); + else + return -ENOSYS; } u32 tpm_resume(struct udevice *dev) -- cgit v1.2.3