From patchwork Mon Jul 4 13:34:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 587141 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1ec:0:0:0:0 with SMTP id 12csp839641map; Mon, 4 Jul 2022 06:35:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1urxF5k4ug2Bwz9mXLrnnOk7OUmDkU8R5Xd0ZDe/bJMg7aN64HyOtp/bgirRkXGmLUcft6n X-Received: by 2002:a05:6512:3d08:b0:47f:79a9:66f0 with SMTP id d8-20020a0565123d0800b0047f79a966f0mr18974660lfv.576.1656941752634; Mon, 04 Jul 2022 06:35:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656941752; cv=none; d=google.com; s=arc-20160816; b=UU6nipOZYzTla+ofvafEGwWsSjBSV13s71i2rnclLbnpxvZ+r7P9iZNIpqihjkgHzI h6gbyzl00Mg0Se2FrqzzmLzqBRGkF6jZpZm6PSIa4NpPYLIxkaqmaMkxDE0xDz8lNkpe lc4IuBx4z02b9eCTvxfE9pWbnmghw/otuHb1h1+Q1StXOAsZmNO4cpIFSGSpAcY3vRya vPEK2sgMUed6YqNgx5Jt9GqxdKUJikPY8gtTRWgOnlHa5Px6lKae7IJrrcclkjXWb3dT pjs/5uT49xTmnIgCMFH18zcu6eHbY1RyXrFeE8scTt9iDqxOCcTlFPVH1ZxUDHApLW7k +KJw== 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=jgxZ6Ri+4NcnnZzvnsgS3LS4abHkFReRMi9QV4jZTG8=; b=W2qzbhLtviXc+BaQiHwQEOrgVup7GIwHV0DZcrUMPap+xabDY9+SFsF+NhU7uvwJDS a8Sj795uy4K1L8ok98ENe25ejxziSB6o6DWK+tVvxYBC8HTLgzY1dFw8cY9wItu0Up96 IZ0F1djD9twxco56zopBGR4onEex+q/ijkYnAiJOXfBQVLCw3+xBKXK9RBfZWakMQfYx cqKWpJniyyiEGHIiyFdfj6PCM4TFzbFsx3/9FBZ/jp+zbZrk68BAxbWolJGOuYnK/aVV FUA88CfL1mum3CxFnmn/Bkj8HbJ28y1KRi0ZgkXad9NVCeQEhQUKCc09qf6eNCswaDNY FmWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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. [85.214.62.61]) by mx.google.com with ESMTPS id w2-20020a05651234c200b004796750377fsi24937055lfr.220.2022.07.04.06.35.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 06:35:52 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 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 2D8B9844C0; Mon, 4 Jul 2022 15:35:24 +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 52C2E844B9; Mon, 4 Jul 2022 15:35:22 +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,T_SCC_BODY_TEXT_LINE 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 C3B5684499 for ; Mon, 4 Jul 2022 15:35:19 +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 5DA2023A; Mon, 4 Jul 2022 06:35:19 -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 2FF293F66F; Mon, 4 Jul 2022 06:35:16 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v6 3/7] tpm: Add the RNG child device Date: Mon, 4 Jul 2022 19:04:40 +0530 Message-Id: <20220704133444.1110715-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220704133444.1110715-1-sughosh.ganu@linaro.org> References: <20220704133444.1110715-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. Signed-off-by: Sughosh Ganu --- Changes since V5: * Check if the TPM RNG device has already been added, through a call to device_find_first_child_by_uclass() drivers/tpm/tpm-uclass.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..e1f1ef01e1 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,15 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +#include + +#define TPM_RNG_DRV_NAME "tpm-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +141,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-rng0", &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), };