From patchwork Sun Mar 13 14:47:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 550924 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp1826255mag; Sun, 13 Mar 2022 07:49:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNbF8tB+ufb2bhcXJMZ5ixgM9GHXew3QOpCKLwrneasbaQgAGubHv1+BgzfdmrwHz/Gsve X-Received: by 2002:a17:907:72d0:b0:6db:4788:66a9 with SMTP id du16-20020a17090772d000b006db478866a9mr16131167ejc.516.1647182988253; Sun, 13 Mar 2022 07:49:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647182988; cv=none; d=google.com; s=arc-20160816; b=vWU+43FoBLmOEnrr7B0N0ipaHzuPyCHn6XsuEovHKq31YUdkcZPrEbw9bbD89rZuFy BLG7G69TvkC+WTuOIpFB1IioId7jaLGyJ6kewDl+H+xOvUqghEFz8dho6uJAHPHKijr2 LdBHjBWNYdWKoznwPPgFxczcZQ2mvAI6aYm8DV5IbqLzvSnle1Wei2yUZeYQ8ANPqIJ2 +B/8BCGyNxmpHeF0aQXS2PtmLRr1Fw/cDkddGYkzTwIqrgwfg8DLtssKD3VveXc/7VUx rWvivgZGczmS1NFU+4BHcC5MlUbn5TGK810hUnGrJ32K+KN4yl8PjmKG9ZkYdxOL4lYf hI0w== 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=FYSgouCwzP/nEhAitZcJ/PtxxI5CGXoUTn91ZMZcsAM=; b=EWn9VYs0YAkx2WGoRgYk+PWB987baeHcOMJiO4QNL7WMPPj/04+8bTS3nNjvm1GNK5 zB4CxLCMq9y9pO1U4CkyPjgHDwJ64ZZcv70MMgMdOzHf/QjLTs4SM4X4KNjPFERfTB2I bwjxClWPL08Khn1xevkl6X7iWGCwLUDUwRdTmhGJwPeEvEj20q4OE8TN2z9WyZuI55vl hiI8HA+72EIauu5jqFoLTjK9ncOPh3xs1Z2Yz+PgcPx0hOsYL2QzJNqBllVT6fRToYD1 TymlG2a8SnZGXfeCA/9MUov3GCykFJvkANKhsCMAhNwzQAbmpMaX5sDGpeFFO8sbCP0O MO/Q== 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 k23-20020aa7c057000000b00412d12ce714si8139275edo.225.2022.03.13.07.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Mar 2022 07:49:48 -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 39B2A83B11; Sun, 13 Mar 2022 15:49:42 +0100 (CET) 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 25908830F6; Sun, 13 Mar 2022 15:49:07 +0100 (CET) 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 EABC2831B5 for ; Sun, 13 Mar 2022 15:48:56 +0100 (CET) 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 5B8741042; Sun, 13 Mar 2022 07:48:56 -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 8FBA33F7D7; Sun, 13 Mar 2022 07:48:54 -0700 (PDT) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v5 4/9] tpm: Add the RNG child device Date: Sun, 13 Mar 2022 20:17:57 +0530 Message-Id: <20220313144802.65687-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220313144802.65687-1-sughosh.ganu@linaro.org> References: <20220313144802.65687-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.5 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 V4: * Put a check for CONFIG_TPM_RNG for binding the RNG device with it's driver in the post_probe callback instead of putting CONFIG_{SPL,TPL}_BUILD guards drivers/tpm/tpm-uclass.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..e1c61d26f0 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,28 @@ 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_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), };