dm: tpm: Convert the TPM command and library to driver model
authorSimon Glass <sjg@chromium.org>
Sun, 23 Aug 2015 00:31:32 +0000 (18:31 -0600)
committerSimon Glass <sjg@chromium.org>
Mon, 31 Aug 2015 13:57:28 +0000 (07:57 -0600)
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@chromium.org>
Acked-by: Christophe Ricard<christophe-h.ricard@st.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
common/cmd_tpm.c
include/tpm.h
lib/tpm.c

index 0294952e69a73849293d43a9974d1d2a1bbdecfc..bad20066ef8f31c5655409aa9d509ccf525bfec2 100644 (file)
@@ -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 = tpm_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");
index e4472d3ed4e3e3d24e5bb5049be5a832e70be98a..445952b055df71f1f2050ff2b5a6c456f0afc66c 100644 (file)
@@ -349,7 +349,7 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
  *
  * @return 0 on success, non-0 on error.
  */
-uint32_t tpm_init(void);
+int tpm_init(void);
 
 /**
  * Issue a TPM_Startup command.
index d9789b022ab3e9c507f4d2983da1bb6c746c90a9..19bf0b59905cf374d2a2b1e2a3bacb80efdab44b 100644 (file)
--- 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,9 +241,20 @@ 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 = tpm_xfer(dev, command, tpm_command_size(command),
+                      response, &response_length);
+#else
        err = tis_sendrecv(command, tpm_command_size(command),
                        response, &response_length);
-       if (err)
+#endif
+       if (err < 0)
                return TPM_LIB_ERROR;
        if (size_ptr)
                *size_ptr = response_length;
@@ -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 tpm_open(dev);
+#else
        err = tis_init();
        if (err)
                return err;
 
        return tis_open();
+#endif
 }
 
 uint32_t tpm_startup(enum tpm_startup_type mode)