From: christophe.ricard <christophe.ricard@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 19/25] dm: tpm: sandbox: Convert TPM driver to driver model
Date: Tue, 11 Aug 2015 23:42:55 +0200 [thread overview]
Message-ID: <55CA6C5F.2000608@gmail.com> (raw)
In-Reply-To: <1439304497-10081-20-git-send-email-sjg@chromium.org>
Acked-by: Christophe Ricard <christophe-h.ricard@st.com>
On 11/08/2015 16:48, Simon Glass wrote:
> Convert the sandbox TPM driver to use driver model. Add it to the device
> tree so that it can be found on start-up.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> arch/sandbox/dts/sandbox.dts | 4 ++++
> configs/sandbox_defconfig | 1 +
> drivers/tpm/tpm_tis_sandbox.c | 48 ++++++++++++++++++++++++++++++++-----------
> 3 files changed, 41 insertions(+), 12 deletions(-)
>
> diff --git a/arch/sandbox/dts/sandbox.dts b/arch/sandbox/dts/sandbox.dts
> index 8927527..758c4a5 100644
> --- a/arch/sandbox/dts/sandbox.dts
> +++ b/arch/sandbox/dts/sandbox.dts
> @@ -156,6 +156,10 @@
> sides = <4>;
> };
>
> + tpm {
> + compatible = "google,sandbox-tpm";
> + };
> +
> triangle {
> compatible = "demo-shape";
> colour = "cyan";
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index b68d688..2600bf7 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -31,6 +31,7 @@ CONFIG_CROS_EC_KEYB=y
> CONFIG_LED=y
> CONFIG_LED_GPIO=y
> CONFIG_SANDBOX_SERIAL=y
> +CONFIG_DM_TPM=y
> CONFIG_TPM_TIS_SANDBOX=y
> CONFIG_SYS_I2C_SANDBOX=y
> CONFIG_SANDBOX_SPI=y
> diff --git a/drivers/tpm/tpm_tis_sandbox.c b/drivers/tpm/tpm_tis_sandbox.c
> index ed4b039..7a481dd 100644
> --- a/drivers/tpm/tpm_tis_sandbox.c
> +++ b/drivers/tpm/tpm_tis_sandbox.c
> @@ -5,6 +5,8 @@
> */
>
> #include <common.h>
> +#include <dm.h>
> +#include <tis.h>
> #include <asm/state.h>
> #include <asm/unaligned.h>
> #include <linux/crc8.h>
> @@ -56,7 +58,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 +84,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 +112,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 +137,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;
> @@ -241,20 +244,41 @@ int tis_sendrecv(const u8 *sendbuf, size_t send_size,
> return 0;
> }
>
> -int tis_open(void)
> +static int sandbox_tpm_probe(struct udevice *dev)
> {
> - printf("%s\n", __func__);
> + 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,
> + .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),
> +};
next prev parent reply other threads:[~2015-08-11 21:42 UTC|newest]
Thread overview: 64+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-11 14:47 [U-Boot] [PATCH 00/25] dm: Convert TPM drivers to driver model Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 01/25] tpm: Remove old pre-driver-model I2C code Simon Glass
2015-08-11 21:41 ` christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 02/25] tpm: Drop two unused options Simon Glass
2015-08-11 21:44 ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 03/25] tpm: Add Kconfig options for TPMs Simon Glass
2015-08-11 21:45 ` christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-11 14:47 ` [U-Boot] [PATCH 04/25] tpm: Convert board config TPM options to Kconfig Simon Glass
2015-08-11 21:45 ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 05/25] tpm: Convert drivers to use SPDX Simon Glass
2015-08-11 21:41 ` christophe.ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 06/25] tpm: Move the I2C TPM code into one file Simon Glass
2015-08-11 21:42 ` christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-13 20:26 ` Christophe Ricard
2015-08-11 14:47 ` [U-Boot] [PATCH 07/25] tpm: tpm_tis_i2c: Drop unnecessary methods Simon Glass
2015-08-11 21:47 ` christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-13 20:28 ` Christophe Ricard
2015-08-13 22:53 ` Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 08/25] tpm: tpm_tis_i2c: Drop struct tpm_vendor_specific Simon Glass
2015-08-11 21:47 ` christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-13 20:32 ` Christophe Ricard
2015-08-13 22:53 ` Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 09/25] tpm: tpm_tis_i2c: Merge struct tpm_dev into tpm_chip Simon Glass
2015-08-11 21:46 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 10/25] tpm: tpm_tis_i2c: Merge struct tpm " Simon Glass
2015-08-11 21:46 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 11/25] tpm: tpm_tis_i2c: Move definitions into the header file Simon Glass
2015-08-11 21:45 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 12/25] tpm: tpm_tis_i2c: Simplify init code Simon Glass
2015-08-11 21:45 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 13/25] tpm: tpm_tis_i2c: Use a consistent tpm_tis_i2c_ prefix Simon Glass
2015-08-11 21:44 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 14/25] tpm: tpm_tis_i2c: Tidy up delays Simon Glass
2015-08-11 21:44 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 15/25] dm: tpm: Add a uclass for Trusted Platform Modules Simon Glass
2015-08-11 21:44 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 16/25] dm: tpm: Convert the TPM command and library to driver model Simon Glass
2015-08-11 21:43 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 17/25] dm: i2c: Add a command to adjust the offset length Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 18/25] tpm: Report tpm errors on the command line Simon Glass
2015-08-11 21:43 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 19/25] dm: tpm: sandbox: Convert TPM driver to driver model Simon Glass
2015-08-11 21:42 ` christophe.ricard [this message]
2015-08-11 14:48 ` [U-Boot] [PATCH 20/25] tpm: Check that parse_byte_string() has data to parse Simon Glass
2015-08-11 21:42 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 21/25] exynos: x86: dts: Add tpm nodes to the device tree for Chrome OS devices Simon Glass
2015-08-11 14:48 ` [U-Boot] [PATCH 22/25] dm: tpm: Convert I2C driver to driver model Simon Glass
2015-08-11 21:41 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 23/25] dm: tpm: Convert LPC " Simon Glass
2015-08-11 21:41 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 24/25] tpm: Add a 'tpm info' command Simon Glass
2015-08-11 21:40 ` christophe.ricard
2015-08-11 14:48 ` [U-Boot] [PATCH 25/25] tegra: nyan: Enable TPM command and driver Simon Glass
2015-08-11 21:40 ` christophe.ricard
2015-08-11 21:50 ` [U-Boot] [PATCH 00/25] dm: Convert TPM drivers to driver model christophe.ricard
2015-08-13 1:30 ` Simon Glass
2015-08-13 20:22 ` Christophe Ricard
2015-08-13 22:52 ` Simon Glass
2015-08-20 21:39 ` Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55CA6C5F.2000608@gmail.com \
--to=christophe.ricard@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox