* [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device
@ 2025-03-27 2:19 Qunqin Zhao
2025-03-27 2:19 ` [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry Qunqin Zhao
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Qunqin Zhao @ 2025-03-27 2:19 UTC (permalink / raw)
To: lee, herbert, davem, peterhuewe, jarkko
Cc: linux-kernel, loongarch, linux-crypto, jgg, linux-integrity,
pmenzel, Qunqin Zhao, Yinggang Gu
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>
---
v6: Replace all "ls6000se" with "loongson"
Prefix all with tpm_loongson instead of tpm_lsse.
Removed Jarkko's tag cause there are some changes in v6
v5: None
v4: Prefix all with tpm_lsse instead of tpm.
Removed MODULE_AUTHOR fields.
v3: Added reminder about Loongson security engine to git log.
drivers/char/tpm/Kconfig | 9 +++
drivers/char/tpm/Makefile | 1 +
drivers/char/tpm/tpm_loongson.c | 103 ++++++++++++++++++++++++++++++++
3 files changed, 113 insertions(+)
create mode 100644 drivers/char/tpm/tpm_loongson.c
diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
index 0fc9a510e..5d0e7a1f8 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_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.
+
source "drivers/char/tpm/st33zp24/Kconfig"
endif # TCG_TPM
diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
index 9bb142c75..e84a2f7a9 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_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..91e0390c8
--- /dev/null
+++ b/drivers/char/tpm/tpm_loongson.c
@@ -0,0 +1,103 @@
+// 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_msg {
+ u32 cmd;
+ u32 data_off;
+ u32 data_len;
+ u32 info[5];
+};
+
+struct tpm_loongson_dev {
+ struct lsse_ch *se_ch;
+ struct completion tpm_loongson_completion;
+};
+
+static void tpm_loongson_complete(struct lsse_ch *ch)
+{
+ struct tpm_loongson_dev *td = ch->priv;
+
+ complete(&td->tpm_loongson_completion);
+}
+
+static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
+{
+ struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
+ struct tpm_loongson_msg *rmsg;
+ int sig;
+
+ sig = wait_for_completion_interruptible(&td->tpm_loongson_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_loongson_send(struct tpm_chip *chip, u8 *buf, size_t count)
+{
+ struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
+ struct tpm_loongson_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 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 device *dev = &pdev->dev;
+ struct tpm_loongson_msg *smsg;
+ struct tpm_loongson_dev *td;
+ struct tpm_chip *chip;
+
+ td = devm_kzalloc(dev, sizeof(struct tpm_loongson_dev), GFP_KERNEL);
+ if (!td)
+ return -ENOMEM;
+
+ init_completion(&td->tpm_loongson_completion);
+ td->se_ch = se_init_ch(dev->parent, SE_CH_TPM, PAGE_SIZE,
+ 2 * sizeof(struct tpm_loongson_msg), td,
+ tpm_loongson_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, &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, td);
+
+ return tpm_chip_register(chip);
+}
+
+static struct platform_driver tpm_loongson_driver = {
+ .probe = tpm_loongson_probe,
+ .driver = {
+ .name = "loongson-tpm",
+ },
+};
+module_platform_driver(tpm_loongson_driver);
+
+MODULE_ALIAS("platform:loongson-tpm");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("Loongson TPM driver");
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry
2025-03-27 2:19 [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Qunqin Zhao
@ 2025-03-27 2:19 ` Qunqin Zhao
2025-03-27 13:31 ` Jarkko Sakkinen
2025-03-27 13:30 ` [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Jarkko Sakkinen
2025-03-31 10:15 ` Huacai Chen
2 siblings, 1 reply; 5+ messages in thread
From: Qunqin Zhao @ 2025-03-27 2:19 UTC (permalink / raw)
To: lee, herbert, davem, peterhuewe, jarkko
Cc: linux-kernel, loongarch, linux-crypto, jgg, linux-integrity,
pmenzel, Qunqin Zhao
Changes to Loongson TPM driver would be best reviewed by the Loongson
crypto driver maintainers.
Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
---
v6: "tpm_lsse.c" -> "tpm_loongson"
v4-v5: None
MAINTAINERS | 1 +
1 file changed, 1 insertion(+)
diff --git a/MAINTAINERS b/MAINTAINERS
index 814205642..16fcd35ff 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13606,6 +13606,7 @@ LOONGSON CRYPTO DRIVER
M: Qunqin Zhao <zhaoqunqin@loongson.com>
L: linux-crypto@vger.kernel.org
S: Maintained
+F: drivers/char/tpm/tpm_loongson.c
F: drivers/crypto/loongson/
LOONGSON-2 APB DMA DRIVER
--
2.45.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device
2025-03-27 2:19 [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Qunqin Zhao
2025-03-27 2:19 ` [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry Qunqin Zhao
@ 2025-03-27 13:30 ` Jarkko Sakkinen
2025-03-31 10:15 ` Huacai Chen
2 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2025-03-27 13:30 UTC (permalink / raw)
To: Qunqin Zhao
Cc: lee, herbert, davem, peterhuewe, linux-kernel, loongarch,
linux-crypto, jgg, linux-integrity, pmenzel, Yinggang Gu
On Thu, Mar 27, 2025 at 10:19:39AM +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>
> ---
> v6: Replace all "ls6000se" with "loongson"
> Prefix all with tpm_loongson instead of tpm_lsse.
> Removed Jarkko's tag cause there are some changes in v6
>
> v5: None
> v4: Prefix all with tpm_lsse instead of tpm.
> Removed MODULE_AUTHOR fields.
>
> v3: Added reminder about Loongson security engine to git log.
>
> drivers/char/tpm/Kconfig | 9 +++
> drivers/char/tpm/Makefile | 1 +
> drivers/char/tpm/tpm_loongson.c | 103 ++++++++++++++++++++++++++++++++
> 3 files changed, 113 insertions(+)
> create mode 100644 drivers/char/tpm/tpm_loongson.c
>
> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> index 0fc9a510e..5d0e7a1f8 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_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.
> +
> source "drivers/char/tpm/st33zp24/Kconfig"
> endif # TCG_TPM
> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
> index 9bb142c75..e84a2f7a9 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_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..91e0390c8
> --- /dev/null
> +++ b/drivers/char/tpm/tpm_loongson.c
> @@ -0,0 +1,103 @@
> +// 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_msg {
> + u32 cmd;
> + u32 data_off;
> + u32 data_len;
> + u32 info[5];
> +};
> +
> +struct tpm_loongson_dev {
> + struct lsse_ch *se_ch;
> + struct completion tpm_loongson_completion;
> +};
> +
> +static void tpm_loongson_complete(struct lsse_ch *ch)
> +{
> + struct tpm_loongson_dev *td = ch->priv;
> +
> + complete(&td->tpm_loongson_completion);
> +}
> +
> +static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_msg *rmsg;
> + int sig;
> +
> + sig = wait_for_completion_interruptible(&td->tpm_loongson_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_loongson_send(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_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 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 device *dev = &pdev->dev;
> + struct tpm_loongson_msg *smsg;
> + struct tpm_loongson_dev *td;
> + struct tpm_chip *chip;
> +
> + td = devm_kzalloc(dev, sizeof(struct tpm_loongson_dev), GFP_KERNEL);
> + if (!td)
> + return -ENOMEM;
> +
> + init_completion(&td->tpm_loongson_completion);
> + td->se_ch = se_init_ch(dev->parent, SE_CH_TPM, PAGE_SIZE,
> + 2 * sizeof(struct tpm_loongson_msg), td,
> + tpm_loongson_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, &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, td);
> +
> + return tpm_chip_register(chip);
> +}
> +
> +static struct platform_driver tpm_loongson_driver = {
> + .probe = tpm_loongson_probe,
> + .driver = {
> + .name = "loongson-tpm",
> + },
> +};
> +module_platform_driver(tpm_loongson_driver);
> +
> +MODULE_ALIAS("platform:loongson-tpm");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Loongson TPM driver");
> --
> 2.45.2
>
Looks good to me.
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry
2025-03-27 2:19 ` [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry Qunqin Zhao
@ 2025-03-27 13:31 ` Jarkko Sakkinen
0 siblings, 0 replies; 5+ messages in thread
From: Jarkko Sakkinen @ 2025-03-27 13:31 UTC (permalink / raw)
To: Qunqin Zhao
Cc: lee, herbert, davem, peterhuewe, linux-kernel, loongarch,
linux-crypto, jgg, linux-integrity, pmenzel
On Thu, Mar 27, 2025 at 10:19:40AM +0800, Qunqin Zhao wrote:
> Changes to Loongson TPM driver would be best reviewed by the Loongson
> crypto driver maintainers.
>
> Signed-off-by: Qunqin Zhao <zhaoqunqin@loongson.cn>
> ---
> v6: "tpm_lsse.c" -> "tpm_loongson"
> v4-v5: None
>
> MAINTAINERS | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 814205642..16fcd35ff 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -13606,6 +13606,7 @@ LOONGSON CRYPTO DRIVER
> M: Qunqin Zhao <zhaoqunqin@loongson.com>
> L: linux-crypto@vger.kernel.org
> S: Maintained
> +F: drivers/char/tpm/tpm_loongson.c
> F: drivers/crypto/loongson/
>
> LOONGSON-2 APB DMA DRIVER
> --
> 2.45.2
>
Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org>
BR, Jarkko
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device
2025-03-27 2:19 [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Qunqin Zhao
2025-03-27 2:19 ` [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry Qunqin Zhao
2025-03-27 13:30 ` [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Jarkko Sakkinen
@ 2025-03-31 10:15 ` Huacai Chen
2 siblings, 0 replies; 5+ messages in thread
From: Huacai Chen @ 2025-03-31 10:15 UTC (permalink / raw)
To: Qunqin Zhao
Cc: lee, herbert, davem, peterhuewe, jarkko, linux-kernel, loongarch,
linux-crypto, jgg, linux-integrity, pmenzel, Yinggang Gu
Hi, Qunqin,
On Thu, Mar 27, 2025 at 10:18 AM Qunqin Zhao <zhaoqunqin@loongson.cn> 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>
> ---
> v6: Replace all "ls6000se" with "loongson"
> Prefix all with tpm_loongson instead of tpm_lsse.
> Removed Jarkko's tag cause there are some changes in v6
>
> v5: None
> v4: Prefix all with tpm_lsse instead of tpm.
> Removed MODULE_AUTHOR fields.
>
> v3: Added reminder about Loongson security engine to git log.
>
> drivers/char/tpm/Kconfig | 9 +++
> drivers/char/tpm/Makefile | 1 +
> drivers/char/tpm/tpm_loongson.c | 103 ++++++++++++++++++++++++++++++++
> 3 files changed, 113 insertions(+)
> create mode 100644 drivers/char/tpm/tpm_loongson.c
>
> diff --git a/drivers/char/tpm/Kconfig b/drivers/char/tpm/Kconfig
> index 0fc9a510e..5d0e7a1f8 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_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.
Moving this entry between TCG_IBMVTPM and TCG_XEN is better
(alpha-betical order), others look good to me.
Huacai
> +
> source "drivers/char/tpm/st33zp24/Kconfig"
> endif # TCG_TPM
> diff --git a/drivers/char/tpm/Makefile b/drivers/char/tpm/Makefile
> index 9bb142c75..e84a2f7a9 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_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..91e0390c8
> --- /dev/null
> +++ b/drivers/char/tpm/tpm_loongson.c
> @@ -0,0 +1,103 @@
> +// 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_msg {
> + u32 cmd;
> + u32 data_off;
> + u32 data_len;
> + u32 info[5];
> +};
> +
> +struct tpm_loongson_dev {
> + struct lsse_ch *se_ch;
> + struct completion tpm_loongson_completion;
> +};
> +
> +static void tpm_loongson_complete(struct lsse_ch *ch)
> +{
> + struct tpm_loongson_dev *td = ch->priv;
> +
> + complete(&td->tpm_loongson_completion);
> +}
> +
> +static int tpm_loongson_recv(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_msg *rmsg;
> + int sig;
> +
> + sig = wait_for_completion_interruptible(&td->tpm_loongson_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_loongson_send(struct tpm_chip *chip, u8 *buf, size_t count)
> +{
> + struct tpm_loongson_dev *td = dev_get_drvdata(&chip->dev);
> + struct tpm_loongson_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 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 device *dev = &pdev->dev;
> + struct tpm_loongson_msg *smsg;
> + struct tpm_loongson_dev *td;
> + struct tpm_chip *chip;
> +
> + td = devm_kzalloc(dev, sizeof(struct tpm_loongson_dev), GFP_KERNEL);
> + if (!td)
> + return -ENOMEM;
> +
> + init_completion(&td->tpm_loongson_completion);
> + td->se_ch = se_init_ch(dev->parent, SE_CH_TPM, PAGE_SIZE,
> + 2 * sizeof(struct tpm_loongson_msg), td,
> + tpm_loongson_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, &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, td);
> +
> + return tpm_chip_register(chip);
> +}
> +
> +static struct platform_driver tpm_loongson_driver = {
> + .probe = tpm_loongson_probe,
> + .driver = {
> + .name = "loongson-tpm",
> + },
> +};
> +module_platform_driver(tpm_loongson_driver);
> +
> +MODULE_ALIAS("platform:loongson-tpm");
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Loongson TPM driver");
> --
> 2.45.2
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-03-31 10:15 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-27 2:19 [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Qunqin Zhao
2025-03-27 2:19 ` [PATCH v6 6/6] MAINTAINERS: Add tpm_loongson.c to LOONGSON CRYPTO DRIVER entry Qunqin Zhao
2025-03-27 13:31 ` Jarkko Sakkinen
2025-03-27 13:30 ` [PATCH v6 5/6] tpm: Add a driver for Loongson TPM device Jarkko Sakkinen
2025-03-31 10:15 ` Huacai Chen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).