mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qunqin Zhao <zhaoqunqin@loongson.cn>
To: Jarkko Sakkinen <jarkko@kernel.org>
Cc: lee@kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net,
	peterhuewe@gmx.de, linux-kernel@vger.kernel.org,
	loongarch@lists.linux.dev, linux-crypto@vger.kernel.org,
	jgg@ziepe.ca, linux-integrity@vger.kernel.org,
	Yinggang Gu <guyinggang@loongson.cn>
Subject: Re: [PATCH v2 3/3] tpm: Add a driver for Loongson TPM device
Date: Thu, 13 Feb 2025 11:56:25 +0800	[thread overview]
Message-ID: <c825cd7b-a255-d296-baa0-c1a746cb1bce@loongson.cn> (raw)
In-Reply-To: <Z60SfDaWnbgddUnA@kernel.org>


在 2025/2/13 上午5:28, Jarkko Sakkinen 写道:
> On Wed, Feb 12, 2025 at 11:31:13AM +0800, Qunqin Zhao wrote:
>> TPM2.0 is implemented in Loongson security engine. This is the driver
> TPM 2.0 or just TPM2 (either is fine with me). Quick reminder what
> Loongson security engine (I could not know that and it would be nice
> to have that in git log).

Looks like just TPM2 is better.

Some explanations about Loongson security engine will be added to git log.

>
>> for it.
>>
>> Co-developed-by: Yinggang Gu <guyinggang@loongson.cn>
>> Signed-off-by: Yinggang Gu <guyinggang@loongson.cn>
>> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
>> ---
>>   MAINTAINERS                 |   1 +
>>   drivers/char/tpm/Kconfig    |   9 ++++
>>   drivers/char/tpm/Makefile   |   1 +
>>   drivers/char/tpm/tpm_lsse.c | 104 ++++++++++++++++++++++++++++++++++++
>>   4 files changed, 115 insertions(+)
>>   create mode 100644 drivers/char/tpm/tpm_lsse.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 6493d58436..6aad0f08ad 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -13484,6 +13484,7 @@ LOONGSON CRYPTO DRIVER
>>   M:	Qunqin Zhao <zhaoqunqin@loongson.com>
>>   L:	linux-crypto@vger.kernel.org
>>   S:	Maintained
>> +F:	drivers/char/tpm/tpm_lsse.c
>>   F:	drivers/crypto/loongson/
>>   
>>   LOONGSON-2 APB DMA DRIVER
> Probably MAINTAINERS update should be a separate patch.

Some  MAINTAINERS updates are not  separated form the driver patch.  
Like the submit of "drivers/mfd/max7714*".

So it seems whether the updates to MAINTAINERS  are separated or not is OK.

BR, Qunqin.

>> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
>> index 0fc9a510e0..56d0417065 100644
>> --- a/drivers/char/tpm/Kconfig
>> +++ b/drivers/char/tpm/Kconfig
>> @@ -225,5 +225,14 @@ config TCG_FTPM_TEE
>>   	help
>>   	  This driver proxies for firmware TPM running in TEE.
>>   
>> +config TCG_LSSE
>> +	tristate "Loongson TPM Interface"
>> +	depends on MFD_LS6000SE
>> +	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_lsse.
>> +
>>   source "drivers/char/tpm/st33zp24/Kconfig"
>>   endif # TCG_TPM
>> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
>> index 9bb142c752..bf2280352d 100644
>> --- a/drivers/char/tpm/Makefile
>> +++ b/drivers/char/tpm/Makefile
>> @@ -44,3 +44,4 @@ obj-$(CONFIG_TCG_XEN) += xen-tpmfront.o
>>   obj-$(CONFIG_TCG_CRB) += tpm_crb.o
>>   obj-$(CONFIG_TCG_VTPM_PROXY) += tpm_vtpm_proxy.o
>>   obj-$(CONFIG_TCG_FTPM_TEE) += tpm_ftpm_tee.o
>> +obj-$(CONFIG_TCG_LSSE) += tpm_lsse.o
>> diff --git a/drivers/char/tpm/tpm_lsse.c b/drivers/char/tpm/tpm_lsse.c
>> new file mode 100644
>> index 0000000000..3fd2d9bac8
>> --- /dev/null
>> +++ b/drivers/char/tpm/tpm_lsse.c
>> @@ -0,0 +1,104 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/* Copyright (c) 2025 Loongson Technology Corporation Limited. */
>> +
>> +#include <linux/device.h>
>> +#include <linux/mfd/ls6000se.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/wait.h>
>> +
>> +#include "tpm.h"
>> +
>> +struct tpm_msg {
>> +	u32 cmd;
>> +	u32 data_off;
>> +	u32 data_len;
>> +	u32 info[5];
>> +};
>> +
>> +struct tpm_dev {
>> +	struct lsse_ch *se_ch;
>> +	struct completion tpm_completion;
>> +};
>> +
>> +static void tpm_complete(struct lsse_ch *ch)
>> +{
>> +	struct tpm_dev *td = ch->priv;
>> +
>> +	complete(&td->tpm_completion);
>> +}
>> +
>> +static int tpm_ls_recv(struct tpm_chip *chip, u8 *buf, size_t count)
>> +{
>> +	struct tpm_dev *td = dev_get_drvdata(&chip->dev);
>> +	struct tpm_msg *rmsg;
>> +	int sig;
>> +
>> +	sig = wait_for_completion_interruptible(&td->tpm_completion);
>> +	if (sig)
>> +		return sig;
>> +
>> +	rmsg = td->se_ch->rmsg;
>> +	memcpy(buf, td->se_ch->data_buffer, rmsg->data_len);
>> +
>> +	return rmsg->data_len;
>> +}
>> +
>> +static int tpm_ls_send(struct tpm_chip *chip, u8 *buf, size_t count)
>> +{
>> +	struct tpm_dev *td = dev_get_drvdata(&chip->dev);
>> +	struct tpm_msg *smsg = td->se_ch->smsg;
>> +
>> +	memcpy(td->se_ch->data_buffer, buf, count);
>> +	smsg->data_len = count;
>> +
>> +	return se_send_ch_requeset(td->se_ch);
>> +}
>> +
>> +static const struct tpm_class_ops lsse_tpm_ops = {
>> +	.flags = TPM_OPS_AUTO_STARTUP,
>> +	.recv = tpm_ls_recv,
>> +	.send = tpm_ls_send,
>> +};
>> +
>> +static int lsse_tpm_probe(struct platform_device *pdev)
>> +{
>> +	struct device *dev = &pdev->dev;
>> +	struct tpm_chip *chip;
>> +	struct tpm_msg *smsg;
>> +	struct tpm_dev *td;
>> +
>> +	td = devm_kzalloc(dev, sizeof(struct tpm_dev), GFP_KERNEL);
>> +	if (!td)
>> +		return -ENOMEM;
>> +
>> +	init_completion(&td->tpm_completion);
>> +	td->se_ch = se_init_ch(dev->parent, SE_CH_TPM, PAGE_SIZE,
>> +			       2 * sizeof(struct tpm_msg), td, tpm_complete);
>> +	if (!td->se_ch)
>> +		return -ENODEV;
>> +	smsg = td->se_ch->smsg;
>> +	smsg->cmd = SE_CMD_TPM;
>> +	smsg->data_off = td->se_ch->off;
>> +
>> +	chip = tpmm_chip_alloc(dev, &lsse_tpm_ops);
>> +	if (IS_ERR(chip))
>> +		return PTR_ERR(chip);
>> +	chip->flags = TPM_CHIP_FLAG_TPM2 | TPM_CHIP_FLAG_IRQ;
>> +	dev_set_drvdata(&chip->dev, td);
>> +
>> +	return tpm_chip_register(chip);
>> +}
>> +
>> +static struct platform_driver lsse_tpm_driver = {
>> +	.probe   = lsse_tpm_probe,
>> +	.driver  = {
>> +		.name  = "ls6000se-tpm",
>> +	},
>> +};
>> +module_platform_driver(lsse_tpm_driver);
>> +
>> +MODULE_ALIAS("platform:ls6000se-tpm");
>> +MODULE_LICENSE("GPL");
>> +MODULE_AUTHOR("Yinggang Gu <guyinggang@loongson.cn>");
>> +MODULE_AUTHOR("Qunqin Zhao <zhaoqunqin@loongson.cn>");
>> +MODULE_DESCRIPTION("Loongson TPM driver");
>> -- 
>> 2.43.0
>>
> BR, Jarkko


  reply	other threads:[~2025-02-13  3:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  3:31 [PATCH v2 0/3] Drivers for Loongson security engine Qunqin Zhao
2025-02-12  3:31 ` [PATCH v2 1/3] mfd: Add support for Loongson Security Module Qunqin Zhao
2025-02-12  3:31 ` [PATCH v2 2/3] crypto: loongson - add Loongson RNG driver support Qunqin Zhao
2025-02-12  3:31 ` [PATCH v2 3/3] tpm: Add a driver for Loongson TPM device Qunqin Zhao
2025-02-12 21:28   ` Jarkko Sakkinen
2025-02-13  3:56     ` Qunqin Zhao [this message]
2025-02-13 22:10       ` Jarkko Sakkinen
2025-02-14  1:12         ` Qunqin Zhao

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=c825cd7b-a255-d296-baa0-c1a746cb1bce@loongson.cn \
    --to=zhaoqunqin@loongson.cn \
    --cc=davem@davemloft.net \
    --cc=guyinggang@loongson.cn \
    --cc=herbert@gondor.apana.org.au \
    --cc=jarkko@kernel.org \
    --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 \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®