]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
tpm: Export the open/close functions
authorSimon Glass <sjg@chromium.org>
Sun, 18 Nov 2018 21:22:26 +0000 (14:22 -0700)
committerSimon Glass <sjg@chromium.org>
Thu, 29 Nov 2018 16:30:06 +0000 (09:30 -0700)
At present these functions are not accessible outside the TPM library, but
in some cases we need to call them. Export them in the header file and add
a define for the SHA1 digest size.

Also adjust tpm_open() to call tpm_close() first so that the TPM is in a
known state before opening (e.g. by a previous phase of U-Boot).

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/tpm/tpm_tis_lpc.c
include/tpm-common.h
lib/tpm-utils.h

index e993fd9f833d98d053d23377bc4a7ec87331c312..30194bce07814a5867eca1ace5d42a8f13ca8c96 100644 (file)
@@ -388,6 +388,27 @@ static int tis_readresponse(struct udevice *dev, u8 *buffer, size_t len)
        return offset;
 }
 
+static int tpm_tis_lpc_close(struct udevice *dev)
+{
+       struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
+       struct tpm_locality *regs = priv->regs;
+       u8 locality = 0;
+
+       if (tpm_read_word(priv, &regs[locality].access) &
+           TIS_ACCESS_ACTIVE_LOCALITY) {
+               tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY,
+                              &regs[locality].access);
+
+               if (tis_wait_reg(priv, &regs[locality].access,
+                                TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) {
+                       printf("%s:%d - failed to release locality %d\n",
+                              __FILE__, __LINE__, locality);
+                       return -ETIMEDOUT;
+               }
+       }
+       return 0;
+}
+
 static int tpm_tis_lpc_open(struct udevice *dev)
 {
        struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
@@ -395,6 +416,12 @@ static int tpm_tis_lpc_open(struct udevice *dev)
        u8 locality = 0; /* we use locality zero for everything. */
        int ret;
 
+       ret = tpm_tis_lpc_close(dev);
+       if (ret) {
+               printf("%s: Failed to close TPM\n", __func__);
+               return ret;
+       }
+
        /* now request access to locality. */
        tpm_write_word(priv, TIS_ACCESS_REQUEST_USE, &regs[locality].access);
 
@@ -410,27 +437,7 @@ static int tpm_tis_lpc_open(struct udevice *dev)
 
        tpm_write_word(priv, TIS_STS_COMMAND_READY,
                       &regs[locality].tpm_status);
-       return 0;
-}
-
-static int tpm_tis_lpc_close(struct udevice *dev)
-{
-       struct tpm_tis_lpc_priv *priv = dev_get_priv(dev);
-       struct tpm_locality *regs = priv->regs;
-       u8 locality = 0;
-
-       if (tpm_read_word(priv, &regs[locality].access) &
-           TIS_ACCESS_ACTIVE_LOCALITY) {
-               tpm_write_word(priv, TIS_ACCESS_ACTIVE_LOCALITY,
-                              &regs[locality].access);
 
-               if (tis_wait_reg(priv, &regs[locality].access,
-                                TIS_ACCESS_ACTIVE_LOCALITY, 0) == -ETIMEDOUT) {
-                       printf("%s:%d - failed to release locality %d\n",
-                              __FILE__, __LINE__, locality);
-                       return -ETIMEDOUT;
-               }
-       }
        return 0;
 }
 
index 449ad4c96e1dbd8caf69110a1b89b0c8e13c0913..f8c5569003e8d8aac075232acbd1df838b1d7425 100644 (file)
@@ -181,6 +181,24 @@ int do_##cmd(cmd_tbl_t *cmdtp, int flag,           \
        return report_return_code(cmd());               \
 }
 
+/**
+ * tpm_open() - Request access to locality 0 for the caller
+ *
+ * After all commands have been completed the caller is supposed to
+ * call tpm_close().
+ *
+ * Returns 0 on success, -ve on failure.
+ */
+int tpm_open(struct udevice *dev);
+
+/**
+ * tpm_close() - Close the current session
+ *
+ * Releasing the locked locality. Returns 0 on success, -ve 1 on
+ * failure (in case lock removal did not succeed).
+ */
+int tpm_close(struct udevice *dev);
+
 /**
  * tpm_get_desc() - Get a text description of the TPM
  *
index a9cb7dc7ee5d8edad573e5698ace389f7179fc5e..ac95f262f56a9ebbf60dd0ff605b3a2d4baef0a2 100644 (file)
 #define tpm_u16(x) __MSB(x), __LSB(x)
 #define tpm_u32(x) tpm_u16((x) >> 16), tpm_u16((x) & 0xFFFF)
 
-/**
- * tpm_open() - Request access to locality 0 for the caller
- *
- * After all commands have been completed the caller is supposed to
- * call tpm_close().
- *
- * Returns 0 on success, -ve on failure.
- */
-int tpm_open(struct udevice *dev);
-
-/**
- * tpm_close() - Close the current session
- *
- * Releasing the locked locality. Returns 0 on success, -ve 1 on
- * failure (in case lock removal did not succeed).
- */
-int tpm_close(struct udevice *dev);
-
 /**
  * Pack data into a byte string.  The data types are specified in
  * the format string: 'b' means unsigned byte, 'w' unsigned word,