[U-Boot] [PATCH 16/25] dm: tpm: Convert the TPM command and library to driver model
Simon Glass
sjg at chromium.org
Tue Aug 11 16:48:08 CEST 2015
Add driver model support to the TPM command and the TPM library. Both
support only a single TPM at present.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
common/cmd_tpm.c | 26 ++++++++++++++++++++++++++
include/tpm.h | 2 +-
lib/tpm.c | 29 +++++++++++++++++++++++++----
3 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/common/cmd_tpm.c b/common/cmd_tpm.c
index 0294952..274e3cd 100644
--- a/common/cmd_tpm.c
+++ b/common/cmd_tpm.c
@@ -6,6 +6,7 @@
#include <common.h>
#include <command.h>
+#include <dm.h>
#include <malloc.h>
#include <tpm.h>
#include <asm/unaligned.h>
@@ -438,6 +439,21 @@ TPM_COMMAND_NO_ARG(tpm_force_clear)
TPM_COMMAND_NO_ARG(tpm_physical_enable)
TPM_COMMAND_NO_ARG(tpm_physical_disable)
+#ifdef CONFIG_DM_TPM
+static int get_tpm(struct udevice **devp)
+{
+ int rc;
+
+ rc = uclass_first_device(UCLASS_TPM, devp);
+ if (rc) {
+ printf("Could not find TPM (ret=%d)\n", rc);
+ return CMD_RET_FAILURE;
+ }
+
+ return 0;
+}
+#endif
+
static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
int argc, char * const argv[])
{
@@ -452,7 +468,17 @@ static int do_tpm_raw_transfer(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}
+#ifdef CONFIG_DM_TPM
+ struct udevice *dev;
+
+ rc = get_tpm(&dev);
+ if (rc)
+ return rc;
+
+ rc = tis_xfer(dev, command, count, response, &response_length);
+#else
rc = tis_sendrecv(command, count, response, &response_length);
+#endif
free(command);
if (!rc) {
puts("tpm response:\n");
diff --git a/include/tpm.h b/include/tpm.h
index 88aeba2..9a0f87c 100644
--- a/include/tpm.h
+++ b/include/tpm.h
@@ -157,7 +157,7 @@ enum tpm_return_code {
*
* @return 0 on success, non-0 on error.
*/
-uint32_t tpm_init(void);
+int tpm_init(void);
/**
* Issue a TPM_Startup command.
diff --git a/lib/tpm.c b/lib/tpm.c
index d9789b0..9e2cc77 100644
--- a/lib/tpm.c
+++ b/lib/tpm.c
@@ -6,10 +6,11 @@
*/
#include <common.h>
-#include <stdarg.h>
-#include <u-boot/sha1.h>
+#include <dm.h>
+#include <tis.h>
#include <tpm.h>
#include <asm/unaligned.h>
+#include <u-boot/sha1.h>
/* Internal error of TPM command library */
#define TPM_LIB_ERROR ((uint32_t)~0u)
@@ -240,8 +241,19 @@ static uint32_t tpm_sendrecv_command(const void *command,
response = response_buffer;
response_length = sizeof(response_buffer);
}
+#ifdef CONFIG_DM_TPM
+ struct udevice *dev;
+ int ret;
+
+ ret = uclass_first_device(UCLASS_TPM, &dev);
+ if (ret)
+ return ret;
+ err = tis_xfer(dev, command, tpm_command_size(command),
+ response, &response_length);
+#else
err = tis_sendrecv(command, tpm_command_size(command),
response, &response_length);
+#endif
if (err)
return TPM_LIB_ERROR;
if (size_ptr)
@@ -250,15 +262,24 @@ static uint32_t tpm_sendrecv_command(const void *command,
return tpm_return_code(response);
}
-uint32_t tpm_init(void)
+int tpm_init(void)
{
- uint32_t err;
+ int err;
+#ifdef CONFIG_DM_TPM
+ struct udevice *dev;
+
+ err = uclass_first_device(UCLASS_TPM, &dev);
+ if (err)
+ return err;
+ return tis_open(dev);
+#else
err = tis_init();
if (err)
return err;
return tis_open();
+#endif
}
uint32_t tpm_startup(enum tpm_startup_type mode)
--
2.5.0.rc2.392.g76e840b
More information about the U-Boot
mailing list