From d43154486d27323f64334203e9bc8baf08af6845 Mon Sep 17 00:00:00 2001 From: Sergii Dmytruk Date: Sat, 29 Oct 2022 20:42:28 +0300 Subject: security/tpm/: turn tis_{init,open} into tis_probe Init was always followed by open and after successful initialization we need only send-receive function, which is now returned by tis_probe on success further reducing number of functions to export from drivers. Change-Id: Ib4ce35ada24e3959ea1a518c29d431b4ae123809 Ticket: https://ticket.coreboot.org/issues/433 Signed-off-by: Sergii Dmytruk Reviewed-on: https://review.coreboot.org/c/coreboot/+/68991 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/drivers/spi/tpm/tis.c | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'src/drivers/spi') diff --git a/src/drivers/spi/tpm/tis.c b/src/drivers/spi/tpm/tis.c index b9b2a4a5cb..310b1c09ea 100644 --- a/src/drivers/spi/tpm/tis.c +++ b/src/drivers/spi/tpm/tis.c @@ -5,8 +5,6 @@ #include "tpm.h" -static unsigned int tpm_is_open; - static const struct { uint16_t vid; uint16_t did; @@ -29,16 +27,20 @@ static const char *tis_get_dev_name(struct tpm2_info *info) return "Unknown"; } -int tis_open(void) +static int tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, + uint8_t *recvbuf, size_t *rbuf_len) { - if (tpm_is_open) { - printk(BIOS_ERR, "%s() called twice.\n", __func__); + int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len); + + if (len == 0) return -1; - } + + *rbuf_len = len; + return 0; } -int tis_init(void) +tis_sendrecv_fn tis_probe(void) { struct spi_slave spi; struct tpm2_info info; @@ -46,12 +48,12 @@ int tis_init(void) if (spi_setup_slave(CONFIG_DRIVER_TPM_SPI_BUS, CONFIG_DRIVER_TPM_SPI_CHIP, &spi)) { printk(BIOS_ERR, "Failed to setup TPM SPI slave\n"); - return -1; + return NULL; } if (tpm2_init(&spi)) { printk(BIOS_ERR, "Failed to initialize TPM SPI interface\n"); - return -1; + return NULL; } tpm2_get_info(&info); @@ -59,18 +61,5 @@ int tis_init(void) printk(BIOS_INFO, "Initialized TPM device %s revision %d\n", tis_get_dev_name(&info), info.revision); - return 0; -} - -int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, - uint8_t *recvbuf, size_t *rbuf_len) -{ - int len = tpm2_process_command(sendbuf, sbuf_size, recvbuf, *rbuf_len); - - if (len == 0) - return -1; - - *rbuf_len = len; - - return 0; + return &tpm_sendrecv; } -- cgit v1.2.3