From: christophe.ricard <christophe.ricard@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 15/25] dm: tpm: Add a uclass for Trusted Platform Modules
Date: Tue, 11 Aug 2015 23:44:01 +0200 [thread overview]
Message-ID: <55CA6CA1.8040405@gmail.com> (raw)
In-Reply-To: <1439304497-10081-16-git-send-email-sjg@chromium.org>
Hi Simon,
I think we are pretty inline for the uclass.
Please find below some few remarks.
On 11/08/2015 16:48, Simon Glass wrote:
> Add a new uclass for TPMs which uses almost the same TIS (TPM Interface
> Specification) as is currently implemented. Since init() is handled by the
> normal driver model probe() method, we don't need to implement that. Also
> rename the transfer method to xfer() which is a less clumbsy name.
>
> Once all drivers and users are converted to driver model we can remove the
> old code.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> drivers/tpm/Kconfig | 9 +++++
> drivers/tpm/Makefile | 2 +
> drivers/tpm/tpm-uclass.c | 57 ++++++++++++++++++++++++++++
> include/dm/uclass-id.h | 1 +
> include/tis.h | 97 ++++++++++++++++++++++++++++++++++++++++++++++++
> 5 files changed, 166 insertions(+)
> create mode 100644 drivers/tpm/tpm-uclass.c
>
> diff --git a/drivers/tpm/Kconfig b/drivers/tpm/Kconfig
> index 993d2d7..800239e 100644
> --- a/drivers/tpm/Kconfig
> +++ b/drivers/tpm/Kconfig
> @@ -1,3 +1,12 @@
> +config DM_TPM
> + bool "Enable driver model for Trusted Platform Module drivers"
> + depends on DM && TPM
> + help
> + Enable driver model for TPMs. The TIS interface (tis_open(),
> + tis_sendrecv(), etc.) is then implemented by the TPM uclass. Note
> + that even with driver model only a single TPM is currently
> + supported, since the tpm library assumes this.
> +
> config TPM_TIS_SANDBOX
> bool "Enable sandbox TPM driver"
> depends on SANDBOX
> diff --git a/drivers/tpm/Makefile b/drivers/tpm/Makefile
> index 597966c..0d328f8 100644
> --- a/drivers/tpm/Makefile
> +++ b/drivers/tpm/Makefile
> @@ -3,6 +3,8 @@
> # SPDX-License-Identifier: GPL-2.0+
> #
>
> +obj-$(CONFIG_DM_TPM) += tpm-uclass.o
> +
> obj-$(CONFIG_TPM_ATMEL_TWI) += tpm_atmel_twi.o
> obj-$(CONFIG_TPM_TIS_I2C) += tpm_tis_i2c.o
> obj-$(CONFIG_TPM_TIS_LPC) += tpm_tis_lpc.o
> diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c
> new file mode 100644
> index 0000000..ccade5b
> --- /dev/null
> +++ b/drivers/tpm/tpm-uclass.c
> @@ -0,0 +1,57 @@
> +/*
> + * Copyright (c) 2015 Google, Inc
> + * Written by Simon Glass <sjg@chromium.org>
> + *
> + * SPDX-License-Identifier: GPL-2.0+
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <tis.h>
> +
> +int tis_open(struct udevice *dev)
> +{
> + struct tpm_ops *ops = tpm_get_ops(dev);
> +
> + if (!ops->open)
> + return -ENOSYS;
> +
> + return ops->open(dev);
> +}
> +
> +int tis_close(struct udevice *dev)
> +{
> + struct tpm_ops *ops = tpm_get_ops(dev);
> +
> + if (!ops->close)
> + return -ENOSYS;
> +
> + return ops->close(dev);
> +}
> +
> +int tis_get_desc(struct udevice *dev, char *buf, int size)
> +{
> + struct tpm_ops *ops = tpm_get_ops(dev);
> +
> + if (!ops->get_desc)
> + return -ENOSYS;
> +
> + return ops->get_desc(dev, buf, size);
> +}
> +
> +int tis_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
> + uint8_t *recvbuf, size_t *recv_size)
> +{
> + struct tpm_ops *ops = tpm_get_ops(dev);
> +
> + if (!ops->xfer)
> + return -ENOSYS;
> +
> + return ops->xfer(dev, sendbuf, send_size, recvbuf, recv_size);
> +}
tis_xfer could be more generic and rely on tpm_transmit from original tpm.c.
The command duration could be calculated at probe time during driver
initialisation running one single getcapability command.
> +
> +UCLASS_DRIVER(tpm) = {
> + .id = UCLASS_TPM,
> + .name = "tpm",
> + .flags = DM_UC_FLAG_SEQ_ALIAS,
> +};
> diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
> index c744044..3eff895 100644
> --- a/include/dm/uclass-id.h
> +++ b/include/dm/uclass-id.h
> @@ -54,6 +54,7 @@ enum uclass_id {
> UCLASS_SPI_GENERIC, /* Generic SPI flash target */
> UCLASS_SYSCON, /* System configuration device */
> UCLASS_THERMAL, /* Thermal sensor */
> + UCLASS_TPM, /* Trusted Platform Module TIS interface */
> UCLASS_USB, /* USB bus */
> UCLASS_USB_DEV_GENERIC, /* USB generic device */
> UCLASS_USB_HUB, /* USB hub */
> diff --git a/include/tis.h b/include/tis.h
> index 40a1f86..6620554 100644
> --- a/include/tis.h
> +++ b/include/tis.h
> @@ -7,6 +7,102 @@
> #ifndef __TIS_H
> #define __TIS_H
>
> +#ifdef CONFIG_DM_TPM
> +struct tpm_ops {
As per a previous comment, an init handler could be usefull.
> + /**
> + * open() - Request access to locality 0 for the caller
> + *
> + * After all commands have been completed the caller should call
> + * tis_close().
> + *
> + * @dev: Device to close
> + * @return 0 ok OK, -ve on error
> + */
> + int (*open)(struct udevice *dev);
> +
> + /**
> + * tis_close() - Close the current session
> + *
> + * Releasing the locked locality. Returns 0 on success, -ve 1 on
> + * failure (in case lock removal did not succeed).
> + *
> + * @dev: Device to close
> + * @return 0 ok OK, -ve on error
> + */
> + int (*close)(struct udevice *dev);
> +
> + /**
> + * get_desc() - Get a text description of the TPM
> + *
> + * @dev: Device to check
> + * @buf: Buffer to put the string
> + * @size: Maximum size of buffer
> + * @return length of string, or -ENOSPC it no space
> + */
> + int (*get_desc)(struct udevice *dev, char *buf, int size);
> +
> + /**
> + * xfer() - send data to the TPM and get response
> + *
> + * @dev: Device to talk to
> + * @sendbuf: Buffer of the data to send
> + * @send_size: Size of the data to send
> + * @recvbuf: Buffer to save the response to
> + * @recv_size: Pointer to the size of the response buffer
> + *
> + * Returns 0 on success (and places the number of response bytes at
> + * recv_size) or -ve on failure.
> + */
> + int (*xfer)(struct udevice *dev, const uint8_t *sendbuf,
> + size_t send_size, uint8_t *recvbuf, size_t *recv_size);
> +};
> +
> +#define tpm_get_ops(dev) ((struct tpm_ops *)(dev)->driver->ops)
why not device_get_ops(dev) ?
> +
> +/*
> + * open() - Request access to locality 0 for the caller
> + *
> + * After all commands have been completed the caller is supposed to
> + * call tis_close().
> + *
> + * Returns 0 on success, -ve on failure.
> + */
> +int tis_open(struct udevice *dev);
> +
> +/*
> + * tis_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 tis_close(struct udevice *dev);
> +
> +/**
> + * tis_get_desc() - Get a text description of the TPM
> + *
> + * @dev: Device to check
> + * @buf: Buffer to put the string
> + * @size: Maximum size of buffer
> + * @return length of string, or -ENOSPC it no space
> + */
> +int tis_get_desc(struct udevice *dev, char *buf, int size);
> +
> +/*
> + * tis_sendrecv() - send data to the TPM and get response
> + *
> + * @sendbuf - buffer of the data to send
> + * @send_size size of the data to send
> + * @recvbuf - memory to save the response to
> + * @recv_len - pointer to the size of the response buffer
> + *
> + * Returns 0 on success (and places the number of response bytes at
> + * recv_len) or -ve on failure.
> + */
> +int tis_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,
> + uint8_t *recvbuf, size_t *recv_size);
> +
As at the moment there is a 1 - 1 link with TPM and a platform, are you
sure udevice should be a parameter ?
> +#else
> +
> #include <common.h>
>
> /* Low-level interface to access TPM */
> @@ -53,5 +149,6 @@ int tis_close(void);
> */
> int tis_sendrecv(const uint8_t *sendbuf, size_t send_size, uint8_t *recvbuf,
> size_t *recv_len);
> +#endif
>
> #endif /* __TIS_H */
Best Regards
Christophe
next prev parent reply other threads:[~2015-08-11 21:44 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 [this message]
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
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=55CA6CA1.8040405@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.