From patchwork Wed Jul 20 12:29:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 591863 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5817:0:0:0:0 with SMTP id j23csp4893259max; Wed, 20 Jul 2022 05:30:51 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sF74QiKnDWpwHYxxu2rgzHmrC4xTv7XO3Mdo2SXopjk2r3+S28pPhsMN6CxrDaUZ2y+UHn X-Received: by 2002:a05:6638:1654:b0:341:6650:df93 with SMTP id a20-20020a056638165400b003416650df93mr8517915jat.287.1658320251462; Wed, 20 Jul 2022 05:30:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658320251; cv=none; d=google.com; s=arc-20160816; b=JP7WMhwswPMcA0gxj1YP2/DDaqASZku3kIG9JJCIqInlqsNRRbPJazHrmOoFpgz+4u Y3mL0I3llB9tavQPXdXB8l465x7ixPMysy1UEWVbZlSUcrF9R1NUT6mu0JZkTa+/XTZQ z6G+SAS5dQLqDAczCxK6S0y0zDoYZrN6La/IBEs9eKuxS2IVQnJiO3qq67SJKmDwyJwW Wep6Vaqnm5DB5fF5NaFbgC3aeEN0veWxoUnvwVp7QyaQzh4LsnWtq9GdVSGme51RQFCK wMNr6iUD3vjGtEJo1UTuSjS0R6Z2r7GEHN3ye29+ZEs4iDRslFz7w0D8xGYteh0UheDE 2bMA== 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=T1A2ldxjKhcFJ5bLm4n4nXZ2S1mwzYZRlR10/0Lb2RM=; b=uyvxEQdammgOpyAy5KlNjaTMvWxPg3SuPKuQDkrUSe7gPRIe2LZHIx3iRDXRRCkXqn YxJ9RaVATZaUeWjQFHk0beGY8VfDFGBgTMsrUjBORaFVSubKoWdueR5yKo1NVnpLzzG9 ObhK06H5LV8IR7fzP3B61CN/+R5/lX/NLIXJ95wBuSd7oftJLEVpY/zBnGO8ZAnj4NaH kc7nYXepq/WXASfN1w8lCUAUn3UTosE+AxcmkdvlIMbVVXuUP+Bsk1ZK1D/R6cakhguV ihCqEAsZCMsgqfy4i1Pm2WCkG3aX3QvKhv5T6KxqQTu8y20gYhjddk4CdwhGMtm+8ntg 09xw== 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 188-20020a6b14c5000000b0067b898f1230si15717536iou.43.2022.07.20.05.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 05:30:51 -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 EB2AE84079; Wed, 20 Jul 2022 14:30:28 +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 92D1E84094; Wed, 20 Jul 2022 14:30:14 +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 6E16584068 for ; Wed, 20 Jul 2022 14:30:10 +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 4A14C1576; Wed, 20 Jul 2022 05:30:10 -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 CCDE43F73D; Wed, 20 Jul 2022 05:30:07 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Heinrich Schuchardt , Ilias Apalodimas , Simon Glass , Tom Rini , Sughosh Ganu Subject: [PATCH v7 3/7] tpm: Add the RNG child device Date: Wed, 20 Jul 2022 17:59:22 +0530 Message-Id: <20220720122926.415659-4-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220720122926.415659-1-sughosh.ganu@linaro.org> References: <20220720122926.415659-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 Reviewed-by: Ilias Apalodimas --- Changes since V6: None 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), };