From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 972FFCCA473 for ; Wed, 6 Jul 2022 13:26:59 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 495048452D; Wed, 6 Jul 2022 15:26:57 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="irxfAXZR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 279F084531; Wed, 6 Jul 2022 15:26:56 +0200 (CEST) Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 89B8A8452D for ; Wed, 6 Jul 2022 15:26:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-wr1-x42a.google.com with SMTP id v16so10632655wrd.13 for ; Wed, 06 Jul 2022 06:26:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=nYlCE/sTncwLgUzWVq0MlFzqJbdS5yLFuN8ump1DxVU=; b=irxfAXZRdhmWAhlTR2I6RUVlY+NmUmTtGYZ3EWPhL2i5H0I76Uu5uJ7ShW9tQCA7KK Tz8ykNUmj98jGibmr7uZ33UxyvkD8hS4GjN1I+gmpLEvokqLiLqzdfTVowqYVa0Lfgx4 eMkBO6UceqOmoBQYpVYlSRM0MJ3i6m6hHEByqNCtcE1y8kaH0HFQaWm/Wk7+ZYkc/UJY ZiuECMGwfqx31rvy19sGxIs4VNvv1c67xnGizfUYFPhefywXjwCDqRQzeBV8UxoCEuTU oaAls2bIKSouRAIztC6HpH6G0kXSgxLgdwuWrKUIJw7HJ7467WZPJ01N/sDGyn3Eh321 jaTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=nYlCE/sTncwLgUzWVq0MlFzqJbdS5yLFuN8ump1DxVU=; b=DJmP9c8vQg5+W96p2m1cnff/1LfYcqoNJ7z4GPiedZqaY07KmJ/38fPtxjLJQIyZUO 4EyV1EFbRxBqDUy4HKKtVeGH0V+FkKL5xWykrXjjip03Eign8qNMBNN9gdKOKI4Zd56f Di/RFbxcKZcxKJxr/jOYkh2b5qTj7OJfGxdGYI83noOrP8a8FMBvecS+UqWqeL2WG8iU ldWrppTyAl+NGqeTqQBXdweunZIkSUV4CyoP3Rx31KB8XsZZaZ4J+NBl9Ddl9xbzQF6H i6qe97hPHRlTMwTxXu4/YLF0QIrBsXIxP+2IlfNfKvqoA4BCQ0oYeFpwnpDY2t75t2Ev srhg== X-Gm-Message-State: AJIora+wCbeJAcEwOyvv2GzkhBj/Vb39cql6ILRnyP1HJzPOQ47i3TLC w9TMcodViHIYA2M3a9OFdkDejA== X-Google-Smtp-Source: AGRyM1uP1ccR7wtKpotaBNMiEWLTdi+EzW1+92P/8GrKG8qlBkerx2neZfaMSFsAtp6Oq1BG4DZyfw== X-Received: by 2002:adf:f78d:0:b0:21d:6e79:88a2 with SMTP id q13-20020adff78d000000b0021d6e7988a2mr11571176wrp.493.1657114012999; Wed, 06 Jul 2022 06:26:52 -0700 (PDT) Received: from hera ([46.103.15.185]) by smtp.gmail.com with ESMTPSA id l1-20020a5d5601000000b0021d7799cf4csm3350388wrv.61.2022.07.06.06.26.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 06:26:52 -0700 (PDT) Date: Wed, 6 Jul 2022 16:26:49 +0300 From: Ilias Apalodimas To: Sughosh Ganu Cc: u-boot@lists.denx.de, Heinrich Schuchardt , Simon Glass , Tom Rini Subject: Re: [PATCH v6 2/7] tpm: rng: Add driver model interface for TPM RNG device Message-ID: References: <20220704133444.1110715-1-sughosh.ganu@linaro.org> <20220704133444.1110715-3-sughosh.ganu@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220704133444.1110715-3-sughosh.ganu@linaro.org> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On Mon, Jul 04, 2022 at 07:04:39PM +0530, Sughosh Ganu wrote: > The TPM device has a builtin random number generator(RNG) > functionality. Expose the RNG functions of the TPM device to the > driver model so that they can be used by the EFI_RNG_PROTOCOL if the > protocol is installed. > > Also change the function arguments and return type of the random > number functions to comply with the driver model api. > > Signed-off-by: Sughosh Ganu > --- > Changes since V5: > * Use the dev_get_parent() interface for getting the TPM device when > calling the tpm_get_random() function > > drivers/rng/Kconfig | 11 +++++++++++ > drivers/rng/Makefile | 1 + > drivers/rng/tpm_rng.c | 23 +++++++++++++++++++++++ > lib/Kconfig | 1 + > lib/tpm-v1.c | 13 +++++++------ > lib/tpm-v2.c | 6 +++--- > lib/tpm_api.c | 6 +++--- > 7 files changed, 49 insertions(+), 12 deletions(-) > create mode 100644 drivers/rng/tpm_rng.c > > diff --git a/drivers/rng/Kconfig b/drivers/rng/Kconfig > index c10f7d345b..67c65311c7 100644 > --- a/drivers/rng/Kconfig > +++ b/drivers/rng/Kconfig > @@ -58,4 +58,15 @@ config RNG_IPROC200 > depends on DM_RNG > help > Enable random number generator for RPI4. > + > +config TPM_RNG > + bool "Enable random number generator on TPM device" > + depends on TPM > + default y > + help > + The TPM device has an inbuilt random number generator > + functionality. Enable random number generator on TPM > + devices. Maybe we discussed this on a previous version, but why do we want to have this as a config option? Code size? A TPM will always be able to generate a random number. Couldn't we compile this based on an existing TPM Kconfig option? > + > + > endif > diff --git a/drivers/rng/Makefile b/drivers/rng/Makefile > index 435b3b965a..e4ca9c4149 100644 > --- a/drivers/rng/Makefile > +++ b/drivers/rng/Makefile > @@ -11,3 +11,4 @@ obj-$(CONFIG_RNG_OPTEE) += optee_rng.o > obj-$(CONFIG_RNG_STM32MP1) += stm32mp1_rng.o > obj-$(CONFIG_RNG_ROCKCHIP) += rockchip_rng.o > obj-$(CONFIG_RNG_IPROC200) += iproc_rng200.o > +obj-$(CONFIG_TPM_RNG) += tpm_rng.o > diff --git a/drivers/rng/tpm_rng.c b/drivers/rng/tpm_rng.c > new file mode 100644 > index 0000000000..1a5e9e2e4b > --- /dev/null > +++ b/drivers/rng/tpm_rng.c > @@ -0,0 +1,23 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2022, Linaro Limited > + */ > + > +#include > +#include > +#include > + > +static int rng_tpm_random_read(struct udevice *dev, void *data, size_t count) > +{ > + return tpm_get_random(dev_get_parent(dev), data, count); > +} > + > +static const struct dm_rng_ops tpm_rng_ops = { > + .read = rng_tpm_random_read, > +}; > + > +U_BOOT_DRIVER(tpm_rng) = { > + .name = "tpm-rng", > + .id = UCLASS_RNG, > + .ops = &tpm_rng_ops, > +}; > diff --git a/lib/Kconfig b/lib/Kconfig > index acc0ac081a..17efaa4c80 100644 > --- a/lib/Kconfig > +++ b/lib/Kconfig > @@ -358,6 +358,7 @@ source lib/crypt/Kconfig > config TPM > bool "Trusted Platform Module (TPM) Support" > depends on DM > + imply DM_RNG > help > This enables support for TPMs which can be used to provide security > features for your board. The TPM can be connected via LPC or I2C > diff --git a/lib/tpm-v1.c b/lib/tpm-v1.c > index 22a769c587..f7091e5bc7 100644 > --- a/lib/tpm-v1.c > +++ b/lib/tpm-v1.c > @@ -9,12 +9,13 @@ > #include > #include > #include > -#include > -#include > #include > #include > #include "tpm-utils.h" > > +#include > +#include > + > #ifdef CONFIG_TPM_AUTH_SESSIONS > > #ifndef CONFIG_SHA1 > @@ -892,19 +893,19 @@ u32 tpm1_get_random(struct udevice *dev, void *data, u32 count) > if (pack_byte_string(buf, sizeof(buf), "sd", > 0, command, sizeof(command), > length_offset, this_bytes)) > - return TPM_LIB_ERROR; > + return -EIO; > err = tpm_sendrecv_command(dev, buf, response, > &response_length); > if (err) > return err; > if (unpack_byte_string(response, response_length, "d", > data_size_offset, &data_size)) > - return TPM_LIB_ERROR; > + return -EIO; > if (data_size > count) > - return TPM_LIB_ERROR; > + return -EIO; > if (unpack_byte_string(response, response_length, "s", > data_offset, out, data_size)) > - return TPM_LIB_ERROR; > + return -EIO; > > count -= data_size; > out += data_size; > diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c > index 1bf627853a..abca9a14b0 100644 > --- a/lib/tpm-v2.c > +++ b/lib/tpm-v2.c > @@ -585,19 +585,19 @@ u32 tpm2_get_random(struct udevice *dev, void *data, u32 count) > if (pack_byte_string(buf, sizeof(buf), "sw", > 0, command_v2, sizeof(command_v2), > sizeof(command_v2), this_bytes)) > - return TPM_LIB_ERROR; > + return -EIO; > err = tpm_sendrecv_command(dev, buf, response, > &response_length); > if (err) > return err; > if (unpack_byte_string(response, response_length, "w", > data_size_offset, &data_size)) > - return TPM_LIB_ERROR; > + return -EIO; > if (data_size > this_bytes) > return TPM_LIB_ERROR; > if (unpack_byte_string(response, response_length, "s", > data_offset, out, data_size)) > - return TPM_LIB_ERROR; > + return -EIO; > > count -= data_size; > out += data_size; > diff --git a/lib/tpm_api.c b/lib/tpm_api.c > index 4ac4612c81..032f383ca0 100644 > --- a/lib/tpm_api.c > +++ b/lib/tpm_api.c > @@ -269,7 +269,7 @@ u32 tpm_get_random(struct udevice *dev, void *data, u32 count) > if (tpm_is_v1(dev)) > return tpm1_get_random(dev, data, count); > else if (tpm_is_v2(dev)) > - return -ENOSYS; /* not implemented yet */ > - else > - return -ENOSYS; > + return tpm2_get_random(dev, data, count); > + > + return -ENOSYS; > } > -- > 2.25.1 > Thanks /Ilias