Skip to content

Commit 08eff49

Browse files
Jiandi AnJarkko Sakkinen
authored andcommitted
tpm/tpm_crb: Enable TPM CRB interface for ARM64
This enables TPM Command Response Buffer interface driver for ARM64 and implements an ARM specific TPM CRB start method that invokes a Secure Monitor Call (SMC) to request the TrustZone Firmware to execute or cancel a TPM 2.0 command. In ARM, TrustZone security extensions enable a secure software environment with Secure Monitor mode. A Secure Monitor Call (SMC) is used to enter the Secure Monitor mode and perform a Secure Monitor service to communicate with TrustZone firmware which has control over the TPM hardware. Signed-off-by: Jiandi An <anjiandi@codeaurora.org> Tested-by: Shanker Donthineni <shankerd@codeaurora.org> Reviewed-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> Tested-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com> (on x86/PTT) Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
1 parent cf8252c commit 08eff49

2 files changed

Lines changed: 66 additions & 3 deletions

File tree

‎drivers/char/tpm/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ config TCG_XEN
136136

137137
config TCG_CRB
138138
tristate "TPM 2.0 CRB Interface"
139-
depends on X86 && ACPI
139+
depends on ACPI
140140
---help---
141141
If you have a TPM security chip that is compliant with the
142142
TCG CRB 2.0 TPM specification say Yes and it will be accessible

‎drivers/char/tpm/tpm_crb.c‎

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <linux/rculist.h>
2121
#include <linux/module.h>
2222
#include <linux/pm_runtime.h>
23+
#ifdef CONFIG_ARM64
24+
#include <linux/arm-smccc.h>
25+
#endif
2326
#include "tpm.h"
2427

2528
#define ACPI_SIG_TPM2 "TPM2"
@@ -93,6 +96,7 @@ enum crb_status {
9396
enum crb_flags {
9497
CRB_FL_ACPI_START = BIT(0),
9598
CRB_FL_CRB_START = BIT(1),
99+
CRB_FL_CRB_SMC_START = BIT(2),
96100
};
97101

98102
struct crb_priv {
@@ -103,6 +107,15 @@ struct crb_priv {
103107
u8 __iomem *cmd;
104108
u8 __iomem *rsp;
105109
u32 cmd_size;
110+
u32 smc_func_id;
111+
};
112+
113+
struct tpm2_crb_smc {
114+
u32 interrupt;
115+
u8 interrupt_flags;
116+
u8 op_flags;
117+
u16 reserved2;
118+
u32 smc_func_id;
106119
};
107120

108121
/**
@@ -122,7 +135,8 @@ struct crb_priv {
122135
*/
123136
static int __maybe_unused crb_go_idle(struct device *dev, struct crb_priv *priv)
124137
{
125-
if (priv->flags & CRB_FL_ACPI_START)
138+
if ((priv->flags & CRB_FL_ACPI_START) ||
139+
(priv->flags & CRB_FL_CRB_SMC_START))
126140
return 0;
127141

128142
iowrite32(CRB_CTRL_REQ_GO_IDLE, &priv->regs_t->ctrl_req);
@@ -167,7 +181,8 @@ static bool crb_wait_for_reg_32(u32 __iomem *reg, u32 mask, u32 value,
167181
static int __maybe_unused crb_cmd_ready(struct device *dev,
168182
struct crb_priv *priv)
169183
{
170-
if (priv->flags & CRB_FL_ACPI_START)
184+
if ((priv->flags & CRB_FL_ACPI_START) ||
185+
(priv->flags & CRB_FL_CRB_SMC_START))
171186
return 0;
172187

173188
iowrite32(CRB_CTRL_REQ_CMD_READY, &priv->regs_t->ctrl_req);
@@ -262,6 +277,34 @@ static int crb_do_acpi_start(struct tpm_chip *chip)
262277
return rc;
263278
}
264279

280+
#ifdef CONFIG_ARM64
281+
/*
282+
* This is a TPM Command Response Buffer start method that invokes a
283+
* Secure Monitor Call to requrest the firmware to execute or cancel
284+
* a TPM 2.0 command.
285+
*/
286+
static int tpm_crb_smc_start(struct device *dev, unsigned long func_id)
287+
{
288+
struct arm_smccc_res res;
289+
290+
arm_smccc_smc(func_id, 0, 0, 0, 0, 0, 0, 0, &res);
291+
if (res.a0 != 0) {
292+
dev_err(dev,
293+
FW_BUG "tpm_crb_smc_start() returns res.a0 = 0x%lx\n",
294+
res.a0);
295+
return -EIO;
296+
}
297+
298+
return 0;
299+
}
300+
#else
301+
static int tpm_crb_smc_start(struct device *dev, unsigned long func_id)
302+
{
303+
dev_err(dev, FW_BUG "tpm_crb: incorrect start method\n");
304+
return -EINVAL;
305+
}
306+
#endif
307+
265308
static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
266309
{
267310
struct crb_priv *priv = dev_get_drvdata(&chip->dev);
@@ -289,6 +332,11 @@ static int crb_send(struct tpm_chip *chip, u8 *buf, size_t len)
289332
if (priv->flags & CRB_FL_ACPI_START)
290333
rc = crb_do_acpi_start(chip);
291334

335+
if (priv->flags & CRB_FL_CRB_SMC_START) {
336+
iowrite32(CRB_START_INVOKE, &priv->regs_t->ctrl_start);
337+
rc = tpm_crb_smc_start(&chip->dev, priv->smc_func_id);
338+
}
339+
292340
return rc;
293341
}
294342

@@ -483,6 +531,7 @@ static int crb_acpi_add(struct acpi_device *device)
483531
struct crb_priv *priv;
484532
struct tpm_chip *chip;
485533
struct device *dev = &device->dev;
534+
struct tpm2_crb_smc *crb_smc;
486535
acpi_status status;
487536
u32 sm;
488537
int rc;
@@ -515,6 +564,20 @@ static int crb_acpi_add(struct acpi_device *device)
515564
sm == ACPI_TPM2_COMMAND_BUFFER_WITH_START_METHOD)
516565
priv->flags |= CRB_FL_ACPI_START;
517566

567+
if (sm == ACPI_TPM2_COMMAND_BUFFER_WITH_SMC) {
568+
if (buf->header.length < (sizeof(*buf) + sizeof(*crb_smc))) {
569+
dev_err(dev,
570+
FW_BUG "TPM2 ACPI table has wrong size %u for start method type %d\n",
571+
buf->header.length,
572+
ACPI_TPM2_COMMAND_BUFFER_WITH_SMC);
573+
return -EINVAL;
574+
}
575+
crb_smc = ACPI_ADD_PTR(struct tpm2_crb_smc, buf,
576+
ACPI_TPM2_START_METHOD_PARAMETER_OFFSET);
577+
priv->smc_func_id = crb_smc->smc_func_id;
578+
priv->flags |= CRB_FL_CRB_SMC_START;
579+
}
580+
518581
rc = crb_map_io(device, priv, buf);
519582
if (rc)
520583
return rc;

0 commit comments

Comments
 (0)