From patchwork Fri Jul 22 16:02:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 592471 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:b811:0:0:0:0 with SMTP id fc17csp635468mab; Fri, 22 Jul 2022 09:03:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLg7Yp2JdALgK7QNdf2iahMEZjfIoWsR93Ww6iywZQEHJaoJ4JbriQceG9Xf951HMKATZN X-Received: by 2002:a05:6638:4883:b0:33f:7948:e685 with SMTP id ct3-20020a056638488300b0033f7948e685mr351063jab.138.1658505811032; Fri, 22 Jul 2022 09:03:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658505811; cv=none; d=google.com; s=arc-20160816; b=pYp/QAEJ6pNn0iizovklF6w17Ycl8RgUAuiLdTvg8oawxJNRpxd1Ejj7CIZsu5GxxI o0ybbJgH0YqgYYFBuI4agp6d3Ww2oSoKCtUyOAodRO1R48rXeigEMwGLxOFTHzV0I4du gMnfD9F0H4Fp+l0FpDZfB36hj09qqvAIt7oTJGILATzR4LXp7LdU1ZlXB4X6mRB8m4xM ZAdh4xm6CWPU1x/CH5XOYLDRbLKWI+MpzXJk9w78BfRvU6CYWf6LMlQ83xgWPxY2NuJK /TqrzOHcFNzc0GbJFoj6h8POBdrcp4SvRnXlQ3RGAsmgcHOG3iaCpuCYRQ7hS7CDckJK PRfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from; bh=hhIEDv824oFbwoUzUhAli043EaCj59KWEUNXVzvKBTA=; b=CyqBb/zpZ5SCqkxZqMrB+ILX9Cl5znbDcWg/K7otZ9M2Eugdga1gaax845OODg8eLQ OiPhQHutq/Qynf99l39h1ayLRgYYrbYCN+eWvbX8osA2GFFAcIkDU9dtYLHaFgSFF6fL 1D8fYKBWZJKFf5HVGkuV5ep4esSB1f3Kgo/emqDvh+GH3PtgQAQEDm1uoBEx7oaPdL8U n3voNd4QZ4IgmcPatCinHz8pEHgARuSCGuY8ez2NfW7NzSV4HP9qg4L6OHE6k0ceKfvx DFxItP0H0coiQZ6b5HyBXEx3ITOOfm0wx57CmxN8EvapF0xRGISZ0ddvlsjR3SBoQYPC 5Y4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id s12-20020a056e0218cc00b002ca96391aa1si4498298ilu.142.2022.07.22.09.03.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 09:03:31 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 9753C83FB5; Fri, 22 Jul 2022 18:02:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id B72EE83FB2; Fri, 22 Jul 2022 18:02:41 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by phobos.denx.de (Postfix) with ESMTP id 8E9E083F9B for ; Fri, 22 Jul 2022 18:02:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sughosh.ganu@linaro.org Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 7557E106F; Fri, 22 Jul 2022 09:02:37 -0700 (PDT) Received: from a076522.blr.arm.com (a076522.blr.arm.com [10.162.16.44]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id F21033F73D; Fri, 22 Jul 2022 09:02:34 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v8 4/8] tpm: Add the RNG child device Date: Fri, 22 Jul 2022 21:32:05 +0530 Message-Id: <20220722160209.863840-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220722160209.863840-1-sughosh.ganu@linaro.org> References: <20220722160209.863840-1-sughosh.ganu@linaro.org> MIME-Version: 1.0 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 The TPM device comes with the random number generator(RNG) functionality which is built into the TPM device. Add logic to add the RNG child device in the TPM uclass post probe callback. The RNG device can then be used to pass a set of random bytes to the linux kernel, need for address space randomisation through the EFI_RNG_PROTOCOL interface. No compatible string is provided because this is not available in the binding defined by Linux. If multiple rand devices are in the system, then some method of selecting them (other than device tree) will need to be used, or a binding will need to be added. Signed-off-by: Sughosh Ganu Reviewed-by: Ilias Apalodimas --- Changes since V7: * Added a paragraph in the commit message highlighting the absence of the compatible string in the RNG driver, as suggested by Simon. * Rearranged the inclusion of headers as per the coding style guidelines, as suggested by Simon. * Use TPM_RNG_DRV_NAME for the RNG child name as suggested by Simon. drivers/tpm/tpm-uclass.c | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..0eb35f50c4 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -9,12 +9,16 @@ #include #include #include -#include -#include +#include #include #include +#include +#include +#include #include "tpm_internal.h" +#define TPM_RNG_DRV_NAME "tpm-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +140,36 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = TPM_RNG_DRV_NAME; + struct udevice *child; + + if (CONFIG_IS_ENABLED(TPM_RNG)) { + ret = device_find_first_child_by_uclass(dev, UCLASS_RNG, + &child); + + if (ret != -ENODEV) { + log_debug("RNG child already added to the TPM device\n"); + return ret; + } + + ret = device_bind_driver(dev, drv, TPM_RNG_DRV_NAME, &child); + if (ret) + return log_msg_ret("bind", ret); + } + + return 0; +} + UCLASS_DRIVER(tpm) = { - .id = UCLASS_TPM, - .name = "tpm", - .flags = DM_UC_FLAG_SEQ_ALIAS, + .id = UCLASS_TPM, + .name = "tpm", + .flags = DM_UC_FLAG_SEQ_ALIAS, #if CONFIG_IS_ENABLED(OF_REAL) - .post_bind = dm_scan_fdt_dev, + .post_bind = dm_scan_fdt_dev, #endif + .post_probe = tpm_uclass_post_probe, .per_device_auto = sizeof(struct tpm_chip_priv), };