From patchwork Fri Mar 4 13:34:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sughosh Ganu X-Patchwork-Id: 548117 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6713:0:0:0:0 with SMTP id u19csp22369mag; Fri, 4 Mar 2022 05:36:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhwYNm3Ce6Gjfk07vi/kTdzKW4Fvs8X0V++o9uQyppgjCVVjgrqNdJWa8ZHkn4eN5CKyTs X-Received: by 2002:a17:907:d92:b0:6da:7ac4:533c with SMTP id go18-20020a1709070d9200b006da7ac4533cmr9233899ejc.234.1646400989538; Fri, 04 Mar 2022 05:36:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646400989; cv=none; d=google.com; s=arc-20160816; b=TkzjAaOYRjgeiDinQDbcapglcEziWv4Pnd7Z+Yrf3USMpkdhamQQmEzDuCTaME+VSj vLtVANP3Fq2/21w65TbrjXA4n6QuPqat0YKGPasNtWjh7otR0I8eyYNLoMtYvWytVRjT I6vU8MCvwv7Dn8qDZjtvu2+PePFiHp4eD/yOXhNP4F2+pHIb7ufhmERnzfy1fLAfOPrB c9GuFw+Og6xLOaaU4oT3MfmxqkAr1NdSlBukEXuzquugtGMK/CFJWCZF2h75z71emlA9 8AtXmiLfK0XvV9qf6wzDSXJUc26ZVkMtcCCRhuU33UIFhoMc3UBojTt6bOLvlB68yiZo gdSw== 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=+beEPOWulrMaXXwAVGHA5PyJ6uOPk70fvF9TUuqbYek=; b=rr2WNNlEBZZq2vSdwDFZyKphF1uDK//OZa0r5XAPLkbqO6wM3OK+yWfKzTmka3CNaq r7c1Ijv0wpxkhIxf5W8pRkShIEo6J9gySQLz3AV1cMK3K1PUTsnLBH3NlilNjGBULGfO Et+uS7NalHNXti224O3thJ3loVcWxQuFvxNCwK6XGOQO99CZ6TMD77vBz2xObkjXmRof CpxCspec0bFnMTXb6Pa+UFSgVZiF5SFjrXN0ENwtd6GJGYB1eO0iSj5uSGR3WhZSwF8Z MSpN7yL68sRcmSytp57ZotKxRE3JWaj0S3k1y+WEVzR5qKSs0fsNlm8f91sQ9p1NA5i+ ytbQ== 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 w16-20020a1709061f1000b006d1240c3431si3050607ejj.896.2022.03.04.05.36.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 05:36:29 -0800 (PST) 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 BB31183D3E; Fri, 4 Mar 2022 14:35:47 +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 D732F83D48; Fri, 4 Mar 2022 14:35:24 +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 938DC83CB4 for ; Fri, 4 Mar 2022 14:35:09 +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 B7ED41396; Fri, 4 Mar 2022 05:35:08 -0800 (PST) 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 1804B3F70D; Fri, 4 Mar 2022 05:35:06 -0800 (PST) From: Sughosh Ganu To: u-boot@lists.denx.de Cc: Ilias Apalodimas , Simon Glass , Heinrich Schuchardt , Sughosh Ganu Subject: [PATCH v3 4/8] tpm: Add the RNG child device Date: Fri, 4 Mar 2022 19:04:25 +0530 Message-Id: <20220304133429.1047752-5-sughosh.ganu@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220304133429.1047752-1-sughosh.ganu@linaro.org> References: <20220304133429.1047752-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 V2: * Enable DM_RNG when CONFIG_TPM is enabled to build the RNG uclass code drivers/tpm/tpm-uclass.c | 60 +++++++++++++++++++++++++++++++++++++--- lib/Kconfig | 1 + 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/drivers/tpm/tpm-uclass.c b/drivers/tpm/tpm-uclass.c index f67fe1019b..d1b9e0a757 100644 --- a/drivers/tpm/tpm-uclass.c +++ b/drivers/tpm/tpm-uclass.c @@ -11,10 +11,16 @@ #include #include #include +#include #include #include #include "tpm_internal.h" +#include + +#define TPM_RNG1_DRV_NAME "tpm1-rng" +#define TPM_RNG2_DRV_NAME "tpm2-rng" + int tpm_open(struct udevice *dev) { struct tpm_ops *ops = tpm_get_ops(dev); @@ -136,12 +142,58 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, return 0; } +#if IS_ENABLED(CONFIG_TPM) +static int tpm_uclass_post_probe(struct udevice *dev) +{ + int ret; + const char *drv = tpm_is_v1(dev) ? + TPM_RNG1_DRV_NAME : TPM_RNG2_DRV_NAME; + struct udevice *child; + + ret = device_bind_driver(dev, drv, "tpm-rng0", &child); + if (ret == -ENOENT) { + log_err("No driver configured for tpm-rng device\n"); + return 0; + } + + if (ret) { + log_err("Unable to bind rng driver with the tpm-rng device\n"); + return ret; + } + + return 0; +} + +static int tpm_uclass_child_pre_probe(struct udevice *dev) +{ + int ret; + + ret = tpm_open(dev->parent); + if (ret == -EBUSY) { + log_info("TPM device already opened\n"); + } else if (ret) { + log_err("Unable to open TPM device\n"); + return ret; + } + + ret = tpm_startup(dev->parent, TPM_ST_CLEAR); + if (ret) + log_err("Unable to start TPM device\n"); + + return ret; +} +#endif /* CONFIG_TPM */ + 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 +#if IS_ENABLED(CONFIG_TPM) + .post_probe = tpm_uclass_post_probe, + .child_pre_probe = tpm_uclass_child_pre_probe, #endif .per_device_auto = sizeof(struct tpm_chip_priv), }; diff --git a/lib/Kconfig b/lib/Kconfig index 3c6fa99b1a..0f05c97afc 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -341,6 +341,7 @@ source lib/crypt/Kconfig config TPM bool "Trusted Platform Module (TPM) Support" depends on DM + select 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