]> git.sur5r.net Git - u-boot/blobdiff - drivers/tpm/tpm_tis_sandbox.c
sf: add Gigadevice gd25q16c entry
[u-boot] / drivers / tpm / tpm_tis_sandbox.c
index ed4b0391278307c77ffefcd6f7464b30527149d6..8816d55759fdf7bba66537bbf9efe2434afe6a49 100644 (file)
@@ -1,10 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (c) 2013 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
+#include <dm.h>
+#include <tpm-v1.h>
 #include <asm/state.h>
 #include <asm/unaligned.h>
 #include <linux/crc8.h>
@@ -56,7 +57,7 @@ enum {
  */
 static struct tpm_state {
        uint8_t nvdata[NV_SEQ_COUNT][NV_DATA_SIZE];
-} state;
+} g_state;
 
 /**
  * sandbox_tpm_read_state() - read the sandbox EC state from the state file
@@ -82,7 +83,7 @@ static int sandbox_tpm_read_state(const void *blob, int node)
                sprintf(prop_name, "nvdata%d", i);
                prop = fdt_getprop(blob, node, prop_name, &len);
                if (prop && len == NV_DATA_SIZE)
-                       memcpy(state.nvdata[i], prop, NV_DATA_SIZE);
+                       memcpy(g_state.nvdata[i], prop, NV_DATA_SIZE);
        }
 
        return 0;
@@ -110,7 +111,7 @@ static int sandbox_tpm_write_state(void *blob, int node)
                char prop_name[20];
 
                sprintf(prop_name, "nvdata%d", i);
-               fdt_setprop(blob, node, prop_name, state.nvdata[i],
+               fdt_setprop(blob, node, prop_name, g_state.nvdata[i],
                            NV_DATA_SIZE);
        }
 
@@ -135,10 +136,11 @@ static int index_to_seq(uint32_t index)
        return -1;
 }
 
-int tis_sendrecv(const u8 *sendbuf, size_t send_size,
-                u8 *recvbuf, size_t *recv_len)
+static int sandbox_tpm_xfer(struct udevice *dev, const uint8_t *sendbuf,
+                           size_t send_size, uint8_t *recvbuf,
+                           size_t *recv_len)
 {
-       struct tpm_state *tpm = &state;
+       struct tpm_state *tpm = dev_get_priv(dev);
        uint32_t code, index, length, type;
        uint8_t *data;
        int seq;
@@ -211,10 +213,10 @@ int tis_sendrecv(const u8 *sendbuf, size_t send_size,
 
                        data = recvbuf + TPM_RESPONSE_HEADER_LENGTH +
                                        sizeof(uint32_t);
+                       memset(&rsk, 0, sizeof(struct rollback_space_kernel));
                        rsk.struct_version = 2;
                        rsk.uid = ROLLBACK_SPACE_KERNEL_UID;
-                       rsk.kernel_versions = 0;
-                       rsk.crc8 = crc8((unsigned char *)&rsk,
+                       rsk.crc8 = crc8(0, (unsigned char *)&rsk,
                                        offsetof(struct rollback_space_kernel,
                                                 crc8));
                        memcpy(data, &rsk, sizeof(rsk));
@@ -241,20 +243,50 @@ int tis_sendrecv(const u8 *sendbuf, size_t send_size,
        return 0;
 }
 
-int tis_open(void)
+static int sandbox_tpm_get_desc(struct udevice *dev, char *buf, int size)
 {
-       printf("%s\n", __func__);
+       if (size < 15)
+               return -ENOSPC;
+
+       return snprintf(buf, size, "sandbox TPM");
+}
+
+static int sandbox_tpm_probe(struct udevice *dev)
+{
+       struct tpm_state *tpm = dev_get_priv(dev);
+
+       memcpy(tpm, &g_state, sizeof(*tpm));
+
        return 0;
 }
 
-int tis_close(void)
+static int sandbox_tpm_open(struct udevice *dev)
 {
-       printf("%s\n", __func__);
        return 0;
 }
 
-int tis_init(void)
+static int sandbox_tpm_close(struct udevice *dev)
 {
-       printf("%s\n", __func__);
        return 0;
 }
+
+static const struct tpm_ops sandbox_tpm_ops = {
+       .open           = sandbox_tpm_open,
+       .close          = sandbox_tpm_close,
+       .get_desc       = sandbox_tpm_get_desc,
+       .xfer           = sandbox_tpm_xfer,
+};
+
+static const struct udevice_id sandbox_tpm_ids[] = {
+       { .compatible = "google,sandbox-tpm" },
+       { }
+};
+
+U_BOOT_DRIVER(sandbox_tpm) = {
+       .name   = "sandbox_tpm",
+       .id     = UCLASS_TPM,
+       .of_match = sandbox_tpm_ids,
+       .ops    = &sandbox_tpm_ops,
+       .probe  = sandbox_tpm_probe,
+       .priv_auto_alloc_size = sizeof(struct tpm_state),
+};