Skip to content

Commit faddec8

Browse files
stefano-garzarellajarkkojs
authored andcommitted
tpm/tpm_svsm: support TPM_CHIP_FLAG_SYNC
This driver does not support interrupts, and receiving the response is synchronous with sending the command. Enable synchronous send() with TPM_CHIP_FLAG_SYNC, which implies that ->send() already fills the provided buffer with a response, and ->recv() is not implemented. Keep using the same pre-allocated buffer to avoid having to allocate it for each command. We need the buffer to have the header required by the SVSM protocol and the command contiguous in memory. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Jarkko Sakkinen <jarkko@kernel.org> Signed-off-by: Jarkko Sakkinen <jarkko@kernel.org>
1 parent 0637c10 commit faddec8

1 file changed

Lines changed: 11 additions & 16 deletions

File tree

drivers/char/tpm/tpm_svsm.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,37 +26,31 @@ struct tpm_svsm_priv {
2626
};
2727

2828
static int tpm_svsm_send(struct tpm_chip *chip, u8 *buf, size_t bufsiz,
29-
size_t len)
29+
size_t cmd_len)
3030
{
3131
struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev);
3232
int ret;
3333

34-
ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, len);
34+
ret = svsm_vtpm_cmd_request_fill(priv->buffer, 0, buf, cmd_len);
3535
if (ret)
3636
return ret;
3737

3838
/*
3939
* The SVSM call uses the same buffer for the command and for the
40-
* response, so after this call, the buffer will contain the response
41-
* that can be used by .recv() op.
40+
* response, so after this call, the buffer will contain the response.
41+
*
42+
* Note: we have to use an internal buffer because the device in SVSM
43+
* expects the svsm_vtpm header + data to be physically contiguous.
4244
*/
43-
return snp_svsm_vtpm_send_command(priv->buffer);
44-
}
45-
46-
static int tpm_svsm_recv(struct tpm_chip *chip, u8 *buf, size_t len)
47-
{
48-
struct tpm_svsm_priv *priv = dev_get_drvdata(&chip->dev);
45+
ret = snp_svsm_vtpm_send_command(priv->buffer);
46+
if (ret)
47+
return ret;
4948

50-
/*
51-
* The internal buffer contains the response after we send the command
52-
* to SVSM.
53-
*/
54-
return svsm_vtpm_cmd_response_parse(priv->buffer, buf, len);
49+
return svsm_vtpm_cmd_response_parse(priv->buffer, buf, bufsiz);
5550
}
5651

5752
static struct tpm_class_ops tpm_chip_ops = {
5853
.flags = TPM_OPS_AUTO_STARTUP,
59-
.recv = tpm_svsm_recv,
6054
.send = tpm_svsm_send,
6155
};
6256

@@ -85,6 +79,7 @@ static int __init tpm_svsm_probe(struct platform_device *pdev)
8579

8680
dev_set_drvdata(&chip->dev, priv);
8781

82+
chip->flags |= TPM_CHIP_FLAG_SYNC;
8883
err = tpm2_probe(chip);
8984
if (err)
9085
return err;

0 commit comments

Comments
 (0)