From 963f7b9e5ec4713eb45dfb656659d2c9cf5d9f83 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 only need send-receive function which is now returned by tis_probe() on success, thus further reducing number of functions to export from drivers. This also removes check for opening TIS twice that seems to have no value. Change-Id: I52ad8d69d50d449f031c36b15bf70ef07986946c Ticket: https://ticket.coreboot.org/issues/433 Signed-off-by: Sergii Dmytruk Reviewed-on: https://review.coreboot.org/c/coreboot/+/76954 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/drivers/i2c/tpm/cr50.c | 1 - src/drivers/i2c/tpm/tis.c | 38 +++++++++++++------------------------- src/drivers/i2c/tpm/tis_atmel.c | 19 +++++++------------ src/drivers/i2c/tpm/tpm.c | 2 -- src/drivers/i2c/tpm/tpm.h | 1 - 5 files changed, 20 insertions(+), 41 deletions(-) (limited to 'src/drivers/i2c') diff --git a/src/drivers/i2c/tpm/cr50.c b/src/drivers/i2c/tpm/cr50.c index 3351ca2700..8462198410 100644 --- a/src/drivers/i2c/tpm/cr50.c +++ b/src/drivers/i2c/tpm/cr50.c @@ -505,7 +505,6 @@ tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t d cr50_set_board_cfg(); } - chip->is_open = 1; return TPM_SUCCESS; } diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c index a5c3b8fdf3..6cb05f0dd7 100644 --- a/src/drivers/i2c/tpm/tis.c +++ b/src/drivers/i2c/tpm/tis.c @@ -19,29 +19,6 @@ static struct tpm_chip chip; #define TPM_CMD_COUNT_BYTE 2 #define TPM_CMD_ORDINAL_BYTE 6 -tpm_result_t tis_open(void) -{ - tpm_result_t rc; - - if (chip.is_open) { - printk(BIOS_DEBUG, "%s() called twice.\n", __func__); - return TPM_CB_FAIL; - } - - rc = tpm_vendor_init(&chip, CONFIG_DRIVER_TPM_I2C_BUS, - CONFIG_DRIVER_TPM_I2C_ADDR); - if (rc != TPM_SUCCESS) - chip.is_open = 0; - - return rc; -} - -tpm_result_t tis_init(void) -{ - return tpm_vendor_probe(CONFIG_DRIVER_TPM_I2C_BUS, - CONFIG_DRIVER_TPM_I2C_ADDR); -} - static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf, size_t rbufsiz) { @@ -103,8 +80,8 @@ out: return rc; } -tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, - uint8_t *recvbuf, size_t *rbuf_len) +static tpm_result_t i2c_tpm_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, + uint8_t *recvbuf, size_t *rbuf_len) { ASSERT(sbuf_size >= 10); @@ -140,3 +117,14 @@ tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, return TPM_SUCCESS; } + +tis_sendrecv_fn tis_probe(void) +{ + if (tpm_vendor_probe(CONFIG_DRIVER_TPM_I2C_BUS, CONFIG_DRIVER_TPM_I2C_ADDR)) + return NULL; + + if (tpm_vendor_init(&chip, CONFIG_DRIVER_TPM_I2C_BUS, CONFIG_DRIVER_TPM_I2C_ADDR)) + return NULL; + + return &i2c_tpm_sendrecv; +} diff --git a/src/drivers/i2c/tpm/tis_atmel.c b/src/drivers/i2c/tpm/tis_atmel.c index 91ed6a99e3..0a29049d95 100644 --- a/src/drivers/i2c/tpm/tis_atmel.c +++ b/src/drivers/i2c/tpm/tis_atmel.c @@ -22,18 +22,8 @@ struct tpm_output_header { uint32_t return_code; } __packed; -tpm_result_t tis_open(void) -{ - return TPM_SUCCESS; -} - -tpm_result_t tis_init(void) -{ - return TPM_SUCCESS; -} - -tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, - uint8_t *recvbuf, size_t *rbuf_len) +static tpm_result_t i2c_tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, + uint8_t *recvbuf, size_t *rbuf_len) { size_t hdr_bytes; struct tpm_output_header *header; @@ -116,3 +106,8 @@ tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size, /* Successful transfer */ return TPM_SUCCESS; } + +tis_sendrecv_fn tis_probe(void) +{ + return &i2c_tis_sendrecv; +} diff --git a/src/drivers/i2c/tpm/tpm.c b/src/drivers/i2c/tpm/tpm.c index 91c310b8f3..541eb3aaa0 100644 --- a/src/drivers/i2c/tpm/tpm.c +++ b/src/drivers/i2c/tpm/tpm.c @@ -507,8 +507,6 @@ tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t d tpm_dev.sleep_short = SLEEP_DURATION; tpm_dev.sleep_long = SLEEP_DURATION_LONG; - chip->is_open = 1; - chip->req_complete_mask = TPM_STS_DATA_AVAIL | TPM_STS_VALID; chip->req_complete_val = TPM_STS_DATA_AVAIL | TPM_STS_VALID; chip->req_canceled = TPM_STS_COMMAND_READY; diff --git a/src/drivers/i2c/tpm/tpm.h b/src/drivers/i2c/tpm/tpm.h index fb9837789d..628ad4dc69 100644 --- a/src/drivers/i2c/tpm/tpm.h +++ b/src/drivers/i2c/tpm/tpm.h @@ -39,7 +39,6 @@ enum tpm_timeout { #define TPM_DID_VID(l) (0x0006 | ((l) << 4)) struct tpm_chip { - int is_open; uint8_t req_complete_mask; uint8_t req_complete_val; uint8_t req_canceled; -- cgit v1.2.3