Skip to content

Commit

Permalink
security/tpm: remove tis_close()
Browse files Browse the repository at this point in the history
This function was never called from outside of drivers and
src/drivers/pc80/tpm/tis.c was the only one doing it in a questionable
way.

tpm_vendor_cleanup() also isn't needed as one of tis_close() functions
was its only caller.

Change-Id: I9df76adfc21fca9fa1d1af7c40635ec0684ceb0f
Ticket: https://ticket.coreboot.org/issues/433
Signed-off-by: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68989
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
  • Loading branch information
SergiiDmytruk authored and felixheld committed Dec 5, 2022
1 parent 2393ad0 commit 0a89d52
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 115 deletions.
13 changes: 0 additions & 13 deletions src/drivers/crb/tis.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ int tis_open(void)
return 0;
}

int tis_close(void)
{
if (tpm_is_open) {
/*
* Do we need to do something here, like waiting for a
* transaction to stop?
*/
tpm_is_open = 0;
}

return 0;
}

int tis_init(void)
{
struct tpm2_info info;
Expand Down
4 changes: 0 additions & 4 deletions src/drivers/i2c/tpm/cr50.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,10 +494,6 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
return 0;
}

void tpm_vendor_cleanup(struct tpm_chip *chip)
{
}

enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
{
return cr50_i2c_write(addr & 0xff, buffer, bytes) ? CB_ERR : CB_SUCCESS;
Expand Down
10 changes: 0 additions & 10 deletions src/drivers/i2c/tpm/tis.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,6 @@ int tis_open(void)
return 0;
}

int tis_close(void)
{
if (chip.is_open) {
tpm_vendor_cleanup(&chip);
chip.is_open = 0;
}

return 0;
}

int tis_init(void)
{
return tpm_vendor_probe(CONFIG_DRIVER_TPM_I2C_BUS,
Expand Down
5 changes: 0 additions & 5 deletions src/drivers/i2c/tpm/tis_atmel.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ int tis_open(void)
return 0;
}

int tis_close(void)
{
return 0;
}

int tis_init(void)
{
return 0;
Expand Down
5 changes: 0 additions & 5 deletions src/drivers/i2c/tpm/tpm.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,3 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
release_locality(chip, 0, 1);
return -1;
}

void tpm_vendor_cleanup(struct tpm_chip *chip)
{
release_locality(chip, chip->vendor.locality, 1);
}
2 changes: 0 additions & 2 deletions src/drivers/i2c/tpm/tpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,4 @@ int tpm_vendor_probe(unsigned int bus, uint32_t addr);

int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr);

void tpm_vendor_cleanup(struct tpm_chip *chip);

#endif /* __DRIVERS_TPM_SLB9635_I2C_TPM_H__ */
66 changes: 14 additions & 52 deletions src/drivers/pc80/tpm/tis.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <device/device.h>
#include <console/console.h>
#include <security/tpm/tis.h>
#include <security/tpm/tss.h>
#include <device/pnp.h>
#include <drivers/tpm/tpm_ppi.h>
#include <timer.h>
Expand Down Expand Up @@ -316,11 +317,6 @@ static int tis_wait_access(int locality, u8 mask, u8 expected)
return TPM_TIMEOUT_ERR;
}

static inline int tis_wait_dropped_access(int locality)
{
return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY, 0);
}

static inline int tis_wait_received_access(int locality)
{
return tis_wait_access(locality, TIS_ACCESS_ACTIVE_LOCALITY,
Expand All @@ -337,11 +333,6 @@ static inline void tis_request_access(int locality)
tpm_write_access(TIS_ACCESS_REQUEST_USE, locality);
}

static inline void tis_drop_access(int locality)
{
tpm_write_access(TIS_ACCESS_ACTIVE_LOCALITY, locality);
}

/*
* PC Client Specific TPM Interface Specification section 11.2.12:
*
Expand Down Expand Up @@ -632,58 +623,35 @@ int tis_init(void)
/*
* tis_open()
*
* Requests access to locality 0 for the caller. After all commands have been
* completed the caller is supposed to call tis_close().
* Requests access to locality 0 for the caller.
*
* Returns 0 on success, TPM_DRIVER_ERR on failure.
*/
int tis_open(void)
{
u8 locality = 0; /* we use locality zero for everything */

if (tis_close())
return TPM_DRIVER_ERR;
if (!tis_has_access(locality)) {
/* request access to locality */
tis_request_access(locality);

/* now request access to locality */
tis_request_access(locality);
/* did we get a lock? */
if (tis_wait_received_access(locality)) {
printf("%s:%d - failed to lock locality %u\n",
__FILE__, __LINE__, locality);
return TPM_DRIVER_ERR;
}

/* did we get a lock? */
if (tis_wait_received_access(locality)) {
printf("%s:%d - failed to lock locality %u\n",
__FILE__, __LINE__, locality);
return TPM_DRIVER_ERR;
/* Certain TPMs seem to need some delay here or they hang... */
udelay(10);
}

/* Certain TPMs seem to need some delay here or they hang... */
udelay(10);

if (tis_command_ready(locality) == TPM_TIMEOUT_ERR)
return TPM_DRIVER_ERR;

return 0;
}

/*
* tis_close()
*
* terminate the current session with the TPM by releasing the locked
* locality. Returns 0 on success of TPM_DRIVER_ERR on failure (in case lock
* removal did not succeed).
*/
int tis_close(void)
{
u8 locality = 0;
if (tis_has_access(locality)) {
tis_drop_access(locality);
if (tis_wait_dropped_access(locality)) {
printf("%s:%d - failed to release locality %u\n",
__FILE__, __LINE__, locality);
return TPM_DRIVER_ERR;
}
}
return 0;
}

/*
* tis_sendrecv()
*
Expand Down Expand Up @@ -727,10 +695,8 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t send_size,
static int tis_setup_interrupt(int vector, int polarity)
{
u8 locality = 0;
int has_access = tis_has_access(locality);

/* Open connection and request access if not already granted */
if (!has_access && tis_open() < 0)
if (tlcl_lib_init())
return TPM_DRIVER_ERR;

/* Set TPM interrupt vector */
Expand All @@ -739,10 +705,6 @@ static int tis_setup_interrupt(int vector, int polarity)
/* Set TPM interrupt polarity and disable interrupts */
tpm_write_int_polarity(polarity, locality);

/* Close connection if it was opened */
if (!has_access && tis_close() < 0)
return TPM_DRIVER_ERR;

return 0;
}

Expand Down
13 changes: 0 additions & 13 deletions src/drivers/spi/tpm/tis.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,6 @@ int tis_open(void)
return 0;
}

int tis_close(void)
{
if (tpm_is_open) {
/*
* Do we need to do something here, like waiting for a
* transaction to stop?
*/
tpm_is_open = 0;
}

return 0;
}

int tis_init(void)
{
struct spi_slave spi;
Expand Down
12 changes: 1 addition & 11 deletions src/security/tpm/tis.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,12 @@ int tis_init(void);
/*
* tis_open()
*
* Requests access to locality 0 for the caller. After all commands have been
* completed the caller is supposed to call tis_close().
* Requests access to locality 0 for the caller.
*
* Returns 0 on success, -1 on failure.
*/
int tis_open(void);

/*
* tis_close()
*
* terminate the current session with the TPM by releasing the locked
* locality. Returns 0 on success of -1 on failure (in case lock
* removal did not succeed).
*/
int tis_close(void);

/*
* tis_sendrecv()
*
Expand Down

0 comments on commit 0a89d52

Please sign in to comment.