From: Jarkko Sakkinen <jarkko@kernel.org>
To: Qunqin Zhao <zhaoqunqin@loongson.cn>
Cc: lee@kernel.org, herbert@gondor.apana.org.au,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
davem@davemloft.net, linux-crypto@vger.kernel.org,
peterhuewe@gmx.de, jgg@ziepe.ca, linux-integrity@vger.kernel.org,
Yinggang Gu <guyinggang@loongson.cn>,
Huacai Chen <chenhuacai@loongson.cn>
Subject: Re: [PATCH v12 3/4] tpm: Add a driver for Loongson TPM device
Date: Sat, 19 Jul 2025 15:09:34 +0300 [thread overview]
Message-ID: <aHuK_pY2Ap4B7JWZ@kernel.org> (raw)
In-Reply-To: <20250705072045.1067-4-zhaoqunqin@loongson.cn>
On Sat, Jul 05, 2025 at 03:20:44PM +0800, Qunqin Zhao wrote:
> Loongson Security Engine supports random number generation, hash,
> symmetric encryption and asymmetric encryption. Based on these
> encryption functions, TPM2 have been implemented in the Loongson
> Security Engine firmware. This driver is responsible for copying data
> into the memory visible to the firmware and receiving data from the
> firmware.
>
> Co-developed-by: Yinggang Gu <guyinggang@loongson.cn>
> Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> Reviewed-by: Huacai Chen <chenhuacai@loongson.cn>
> ---
> drivers/char/tpm/Kconfig | 9 ++++
> drivers/char/tpm/Makefile | 1 +
> drivers/char/tpm/tpm_loongson.c | 84 +++++++++++++++++++++++++++++++++
> 3 files changed, 94 insertions(+)
> create mode 100644 drivers/char/tpm/tpm_loongson.c
>
> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> index dddd702b2..ba3924eb1 100644
> --- a/drivers/char/tpm/Kconfig
> +++ b/drivers/char/tpm/Kconfig
> @@ -189,6 +189,15 @@ config TCG_IBMVTPM
> will be accessible from within Linux. To compile this driver
> as a module, choose M here; the module will be called tpm_ibmvtpm.
>
> +config TCG_LOONGSON
> + tristate "Loongson TPM Interface"
> + depends on MFD_LOONGSON_SE
> + help
> + If you want to make Loongson TPM support available, say Yes and
> + it will be accessible from within Linux. To compile this
> + driver as a module, choose M here; the module will be called
> + tpm_loongson.
> +
> config TCG_XEN
> tristate "XEN TPM Interface"
> depends on TCG_TPM && XEN
> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
> index 9de1b3ea3..5b5cdc0d3 100644
> --- a/drivers/char/tpm/Makefile
> +++ b/drivers/char/tpm/Makefile
> @@ -46,3 +46,4 @@ obj-$(CONFIG_TCG_ARM_CRB_FFA) += tpm_crb_ffa.o
> obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
> obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
> obj-$(CONFIG_TCG_SVSM) += tpm_svsm.o
> +obj-$(CONFIG_TCG_LOONGSON) += tpm_loongson.o
> diff --git a/drivers/char/tpm/tpm_loongson.c b/drivers/char/tpm/tpm_loongson.c
> new file mode 100644
> index 000000000..a4ec23639
> --- /dev/null
> +++ b/drivers/char/tpm/tpm_loongson.c
> @@ -0,0 +1,84 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/* Copyright (c) 2025 Loongson Technology Corporation Limited. */
> +
> +#include <linux/device.h>
> +#include <linux/mfd/loongson-se.h>
> +#include <linux/platform_device.h>
> +#include <linux/wait.h>
> +
> +#include "tpm.h"
> +
> +struct tpm_loongson_cmd {
> + u32 cmd_id;
> + u32 data_off;
> + u32 data_len;
> + u32 pad[5];
> +};
> +
> +static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct loongson_se_engine *tpm_engine = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_cmd *cmd_ret = tpm_engine->command_ret;
> +
> + if (cmd_ret->data_len > count)
> + return -EIO;
> +
> + memcpy(buf, tpm_engine->data_buffer, cmd_ret->data_len);
> +
> + return cmd_ret->data_len;
> +}
> +
> +static int tpm_loongson_send(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct loongson_se_engine *tpm_engine = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_cmd *cmd = tpm_engine->command;
> +
> + if (count > tpm_engine->buffer_size)
> + return -E2BIG;
> +
> + cmd->data_len = count;
> + memcpy(tpm_engine->data_buffer, buf, count);
> +
> + return loongson_se_send_engine_cmd(tpm_engine);
> +}
> +
> +static const struct tpm_class_ops tpm_loongson_ops = {
> + .flags = TPM_OPS_AUTO_STARTUP,
> + .recv = tpm_loongson_recv,
> + .send = tpm_loongson_send,
> +};
> +
> +static int tpm_loongson_probe(struct platform_device *pdev)
> +{
> + struct loongson_se_engine *tpm_engine;
> + struct device *dev = &pdev->dev;
> + struct tpm_loongson_cmd *cmd;
> + struct tpm_chip *chip;
> +
> + tpm_engine = loongson_se_init_engine(dev->parent, SE_ENGINE_TPM);
> + if (!tpm_engine)
> + return -ENODEV;
> + cmd = tpm_engine->command;
> + cmd->cmd_id = SE_CMD_TPM;
> + cmd->data_off = tpm_engine->buffer_off;
> +
> + chip = tpmm_chip_alloc(dev, &tpm_loongson_ops);
> + if (IS_ERR(chip))
> + return PTR_ERR(chip);
> + chip->flags = TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_IRQ;
> + dev_set_drvdata(&chip->dev, tpm_engine);
> +
> + return tpm_chip_register(chip);
> +}
> +
> +static struct platform_driver tpm_loongson = {
> + .probe = tpm_loongson_probe,
> + .driver = {
> + .name = "tpm_loongson",
> + },
> +};
> +module_platform_driver(tpm_loongson);
> +
> +MODULE_ALIAS("platform:tpm_loongson");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Loongson TPM driver");
> --
> 2.45.2
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
Can you take this through loongson tree? It's highly unlikely to
conflict with anything.
BR, Jarkko
next prev parent reply other threads:[~2025-07-19 12:09 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-05 7:20 [PATCH v12 0/4] Add Loongson Security Engine chip driver Qunqin Zhao
2025-07-05 7:20 ` [PATCH v12 1/4] mfd: Add support for Loongson Security Engine chip controller Qunqin Zhao
2025-07-05 7:20 ` [PATCH v12 2/4] crypto: loongson - add Loongson RNG driver support Qunqin Zhao
2025-08-19 12:55 ` Lee Jones
2025-08-20 2:33 ` Herbert Xu
2025-07-05 7:20 ` [PATCH v12 3/4] tpm: Add a driver for Loongson TPM device Qunqin Zhao
2025-07-07 9:48 ` Stefano Garzarella
2025-07-26 7:05 ` Qunqin Zhao
2025-07-19 12:09 ` Jarkko Sakkinen [this message]
2025-07-20 1:05 ` Huacai Chen
2025-07-05 7:20 ` [PATCH v12 4/4] MAINTAINERS: Add entry for Loongson Security Engine drivers Qunqin Zhao
2025-09-02 11:32 ` [PATCH v12 0/4] Add Loongson Security Engine chip driver Lee Jones
2025-09-02 11:33 ` Lee Jones
2025-09-02 12:42 ` [GIT PULL] Immutable branch between MFD, Char and Crypto due for the v6.18 merge window Lee Jones
2025-09-12 21:32 ` Nathan Chancellor
2025-09-16 7:58 ` Lee Jones
2025-09-16 8:00 ` Lee Jones
2025-09-16 19:16 ` Nathan Chancellor
2025-09-17 9:38 ` Lee Jones
2025-09-17 17:12 ` Nathan Chancellor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aHuK_pY2Ap4B7JWZ@kernel.org \
--to=jarkko@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=davem@davemloft.net \
--cc=guyinggang@loongson.cn \
--cc=herbert@gondor.apana.org.au \
--cc=jgg@ziepe.ca \
--cc=lee@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=peterhuewe@gmx.de \
--cc=zhaoqunqin@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.