From patchwork Wed Feb 15 13:27:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 57545 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp192381wrn; Wed, 15 Feb 2023 05:33:41 -0800 (PST) X-Google-Smtp-Source: AK7set9zPSpYaiXOGV4tBxD4a7P+o7UhrFdDv/A5dkMeU136nnntaWmyzNeWfo6WXS8JVCxjKMGd X-Received: by 2002:a17:902:f38d:b0:19a:b092:b31a with SMTP id f13-20020a170902f38d00b0019ab092b31amr2121329ple.8.1676468021258; Wed, 15 Feb 2023 05:33:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468021; cv=none; d=google.com; s=arc-20160816; b=wmc7QF7CIputG7D9Z0TZ14gd8Ar73nV6saRy5lU1oSWJaSlxv5ReYVq8dizLI3+VIS Gd2oTJks80uT7+3gSK0XECBz3UJ7Ql1MoLgqfIg/3qyShCmAvodzj/vN7EYw8PMQQOLr NKWwsByobjm6wFk4DzLOhzX9wD3K+XXOFaUlGb6mz05eB4Wsi6rIv/PdXrq3ZVGvpXnN AJu3nsdrepgrAs4g6IPV9oYmDX0PTYnzKe5CEo5vmYzZu9aPbaD3VCbpCNuC7i3C9I+W k4jyMn+yn0KTHD9XiG5V+nxwQho8ng1nzroLT2Y4BPG3Q3pEIKuqjbLTzwzIG1oCLeRX tGZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=jBsjj8yAoR05wSmP0AQYji7nDGth0V9UXrMPpO8JlTw=; b=QRRd4uMUgPkD3zuFOh5xrU0zl1zqt+vHDhEKihfYHz9kmhhtikJwyD4CZvuPiV7Q1C y/pdIAp/UbPs9aKSXORAGS+RLBt1kRs/SA6zpVSJ9uOYVGhFFDJv4DEuBaFhU5tejWgB SvHH6mCw5xkyIXTWiEDlonyPoPVuHcnW4AgU4j1sr7JeNjZaM406/D0kbEE2j3vIIMe4 fmvVt+78cEWpvZidxLXxS2sln2JYOUNNdb9PjbWQsDa2qf6ecgDEwhI7ICfe9XAz2wOK aLAWBybzElSw5j8f8dTg6b4nL4N0xpk+Ei5gal60+vbh32KadbX2YWjPcokcRHRjlA5B 79Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q10-20020a656a8a000000b004fabdc5c7c3si16979940pgu.495.2023.02.15.05.33.23; Wed, 15 Feb 2023 05:33:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbjBON3l (ORCPT + 99 others); Wed, 15 Feb 2023 08:29:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232333AbjBON31 (ORCPT ); Wed, 15 Feb 2023 08:29:27 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6004939B9F; Wed, 15 Feb 2023 05:29:10 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pSHq4-0005qU-1f; Wed, 15 Feb 2023 14:28:48 +0100 Date: Wed, 15 Feb 2023 13:27:11 +0000 From: Daniel Golle To: Sean Wang , Olivia Mackall , Herbert Xu , Matthias Brugger , AngeloGioacchino Del Regno , Conor Dooley , Mingming Su , linux-crypto@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] hwrng: add driver for MediaTek TRNG SMC Message-ID: <89865515728cb937b6591160ad9c30b4bcc8dd41.1676467500.git.daniel@makrotopia.org> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904131514788852?= X-GMAIL-MSGID: =?utf-8?q?1757904131514788852?= Add driver providing kernel-side support for the Random Number Generator hardware found on Mediatek SoCs which have a driver in ARM TrustedFirmware-A allowing Linux to read random numbers using a non-standard vendor-defined Secure Monitor Call. Signed-off-by: Daniel Golle --- MAINTAINERS | 1 + drivers/char/hw_random/Kconfig | 16 +++++++ drivers/char/hw_random/Makefile | 1 + drivers/char/hw_random/mtk-rng-v2.c | 74 +++++++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 drivers/char/hw_random/mtk-rng-v2.c base-commit: 9d9019bcea1aac7eed64a1a4966282b6b7b141c8 diff --git a/MAINTAINERS b/MAINTAINERS index be167c695c64..90d82aba6d73 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13148,6 +13148,7 @@ F: drivers/leds/leds-mt6323.c MEDIATEK RANDOM NUMBER GENERATOR SUPPORT M: Sean Wang S: Maintained +F: drivers/char/hw_random/mtk-rng-v2.c F: drivers/char/hw_random/mtk-rng.c MEDIATEK SMI DRIVER diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig index 4fdf07ae3c54..7c900185486d 100644 --- a/drivers/char/hw_random/Kconfig +++ b/drivers/char/hw_random/Kconfig @@ -439,6 +439,22 @@ config HW_RANDOM_MTK If unsure, say Y. +config HW_RANDOM_MTK_V2 + tristate "Mediatek Random Number Generator support (v2/SMC)" + depends on HW_RANDOM + depends on (ARM64 && ARCH_MEDIATEK) || COMPILE_TEST + default y + help + This driver provides kernel-side support for the Random Number + Generator hardware found on Mediatek SoCs which have a driver + in ARM TrustedFirmware-A allowing Linux to read using a non- + standard vendor-defined Secure Monitor Call. + + To compile this driver as a module, choose M here. the + module will be called mtk-rng-v2. + + If unsure, say Y. + config HW_RANDOM_S390 tristate "S390 True Random Number Generator support" depends on S390 diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile index 09bde4a0f971..ba319c509e86 100644 --- a/drivers/char/hw_random/Makefile +++ b/drivers/char/hw_random/Makefile @@ -38,6 +38,7 @@ obj-$(CONFIG_HW_RANDOM_PIC32) += pic32-rng.o obj-$(CONFIG_HW_RANDOM_MESON) += meson-rng.o obj-$(CONFIG_HW_RANDOM_CAVIUM) += cavium-rng.o cavium-rng-vf.o obj-$(CONFIG_HW_RANDOM_MTK) += mtk-rng.o +obj-$(CONFIG_HW_RANDOM_MTK_V2) += mtk-rng-v2.o obj-$(CONFIG_HW_RANDOM_S390) += s390-trng.o obj-$(CONFIG_HW_RANDOM_KEYSTONE) += ks-sa-rng.o obj-$(CONFIG_HW_RANDOM_OPTEE) += optee-rng.o diff --git a/drivers/char/hw_random/mtk-rng-v2.c b/drivers/char/hw_random/mtk-rng-v2.c new file mode 100644 index 000000000000..6e61f4361d9e --- /dev/null +++ b/drivers/char/hw_random/mtk-rng-v2.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Driver for Mediatek Hardware Random Number Generator (v2/SMCC) + * + * Copyright (C) 2023 Daniel Golle + * based on patch from Mingming Su + */ +#define MTK_RNG_DEV KBUILD_MODNAME + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MTK_SIP_KERNEL_GET_RND MTK_SIP_SMC_CMD(0x550) + +static int mtk_rng_v2_read(struct hwrng *rng, void *buf, size_t max, bool wait) +{ + struct arm_smccc_res res; + int retval = 0; + + while (max >= sizeof(u32)) { + arm_smccc_smc(MTK_SIP_KERNEL_GET_RND, 0, 0, 0, 0, 0, 0, 0, + &res); + if (res.a0) + break; + + *(u32 *)buf = res.a1; + retval += sizeof(u32); + buf += sizeof(u32); + max -= sizeof(u32); + } + + return retval || !wait ? retval : -EIO; +} + +static int mtk_rng_v2_probe(struct platform_device *pdev) +{ + struct hwrng *trng; + + trng = devm_kzalloc(&pdev->dev, sizeof(*trng), GFP_KERNEL); + if (!trng) + return -ENOMEM; + + trng->name = pdev->name; + trng->read = mtk_rng_v2_read; + trng->quality = 900; + + return devm_hwrng_register(&pdev->dev, trng); +} + +static const struct of_device_id mtk_rng_v2_match[] = { + { .compatible = "mediatek,mt7981-rng" }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtk_rng_v2_match); + +static struct platform_driver mtk_rng_v2_driver = { + .probe = mtk_rng_v2_probe, + .driver = { + .name = KBUILD_MODNAME, + .of_match_table = mtk_rng_v2_match, + }, +}; +module_platform_driver(mtk_rng_v2_driver); + +MODULE_DESCRIPTION("Mediatek Random Number Generator Driver (v2/SMC)"); +MODULE_AUTHOR("Daniel Golle "); +MODULE_LICENSE("GPL"); From patchwork Wed Feb 15 13:27:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 57544 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp192358wrn; Wed, 15 Feb 2023 05:33:38 -0800 (PST) X-Google-Smtp-Source: AK7set/HVTMp1XfMOqgV7qVEVWYhynoKxnfmcr+Q5Ai7vG63E01fNn4CbP4xfw8/i1GWfp93HZJL X-Received: by 2002:a05:6a21:9988:b0:c3:19ef:1a83 with SMTP id ve8-20020a056a21998800b000c319ef1a83mr2355810pzb.32.1676468018468; Wed, 15 Feb 2023 05:33:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468018; cv=none; d=google.com; s=arc-20160816; b=kDeHPGw25CV/5pas7Kw5El2FalUuHjCEwvZViZxdbiLdie4SKz/QISKPBNfzLrjvKL GAm03Oiale4Gi6jKx8QiPOiUoOBYPOK1nSI5mYC+Pp8LNcMj3n3RVaRf56LGhqEJhwbY X5TGfNCjN+OjfnYpusd0lQ42hrel7AeaDskh6/sGYoNlK7eAMYwV+oPtIF7rYDceDgUA UoBgKHZCMVDFt4YdDmz9Jb8mkTzevjuih2uu39e5Ao7fEvHhWl8lwoIoOtr++QjwZgyT H2d00e7qzzdOhnfB+4axTiFSBihCUi5f64B871Ok/TczCK+yNGNERrcSB+Z/gTjwjDEj 7eGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:to:from:date; bh=MSMPkWyjIoGOy2ttBCZV00bjpKccjsu3EX/wfKuDA/g=; b=DwJe7y2fFIMcqlbBeAW1JMzOg87oMxf7kCX2cbM4qNkWHYGQwoNa9qneuaZYMH0OPD r+ulKds+L9T1S2ycdVAK+If89cglHqJ767RueKS0K9rzhyPW0eKtj/quTaNj8oYt1pKl /vMHOhTEwc8O+FhleAoya4LCoPXT1+DoD1gkALZ8rivmi6luRehZ+p9B5uC4dt4HX+/D bNvu3Ee4crBNXw3hBgc6tWLCa68NWPcMk56Kd17if2hg3JeFfyi5lLVSWmjXkEXkAaz2 LxhPq3U7T/jo63kAiAczoBBeiT1bSa7OaBVJscoiCJVFnAe4t2H4spRveJy5pKbfqXp9 oGVQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y5-20020aa79e05000000b005a8d85904e1si5217053pfq.361.2023.02.15.05.33.21; Wed, 15 Feb 2023 05:33:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231969AbjBON3i (ORCPT + 99 others); Wed, 15 Feb 2023 08:29:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232106AbjBON30 (ORCPT ); Wed, 15 Feb 2023 08:29:26 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B45D95580; Wed, 15 Feb 2023 05:29:09 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96) (envelope-from ) id 1pSHqN-0005qp-0A; Wed, 15 Feb 2023 14:29:07 +0100 Date: Wed, 15 Feb 2023 13:27:30 +0000 From: Daniel Golle To: devicetree@vger.kernel.org, Sean Wang , Olivia Mackall , Herbert Xu , Rob Herring , Krzysztof Kozlowski , Matthias Brugger , AngeloGioacchino Del Regno , Conor Dooley , Mingming Su , linux-crypto@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] dt-bindings: rng: Add MediaTek MT7981 TRNG Message-ID: References: <89865515728cb937b6591160ad9c30b4bcc8dd41.1676467500.git.daniel@makrotopia.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <89865515728cb937b6591160ad9c30b4bcc8dd41.1676467500.git.daniel@makrotopia.org> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904129088191918?= X-GMAIL-MSGID: =?utf-8?q?1757904129088191918?= Add documentation to describe the MediaTek true random number generator which is provided by ARM TrustedFirmware-A of the MT7981. Signed-off-by: Daniel Golle --- .../bindings/rng/mediatek,mt7981-rng.yaml | 39 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/rng/mediatek,mt7981-rng.yaml diff --git a/Documentation/devicetree/bindings/rng/mediatek,mt7981-rng.yaml b/Documentation/devicetree/bindings/rng/mediatek,mt7981-rng.yaml new file mode 100644 index 000000000000..d577d60538d8 --- /dev/null +++ b/Documentation/devicetree/bindings/rng/mediatek,mt7981-rng.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/rng/mediatek,mt7981-rng.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek Random number generator (v2/SMC) + +maintainers: + - Daniel Golle + +properties: + $nodename: + pattern: "^rng$" + + compatible: + enum: + - mediatek,mt7981-rng + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: rng + +required: + - compatible + +additionalProperties: false + +examples: + - | + rng { + compatible = "mediatek,mt7981-rng"; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 90d82aba6d73..523f1abf00d5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -13148,6 +13148,7 @@ F: drivers/leds/leds-mt6323.c MEDIATEK RANDOM NUMBER GENERATOR SUPPORT M: Sean Wang S: Maintained +F: Documentation/devicetree/bindings/rng/mediatek,* F: drivers/char/hw_random/mtk-rng-v2.c F: drivers/char/hw_random/mtk-rng.c