From 40ae1706a447ca81fed31287ec30f28823504c01 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Wed, 31 Aug 2016 13:51:14 -0700 Subject: drivers/i2c/tpm: Make driver safe for use in x86 pre-ram Use CAR accessors where needed for accessing static data. In some cases this required some minor restructuring to pass in a variable instead of use a global one. For the tpm_vendor_init the structure no longer has useful defaults, which nobody was depending on anyway. This now requires the caller to provide a non-zero address. Tested by enabling I2C TPM on reef and compiling successfully. Change-Id: I8e02fbcebf5fe10c4122632eda1c48b247478289 Signed-off-by: Duncan Laurie Reviewed-on: https://review.coreboot.org/16394 Tested-by: build bot (Jenkins) Reviewed-by: Furquan Shaikh Reviewed-by: Paul Menzel --- src/drivers/i2c/tpm/tis.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/drivers/i2c/tpm/tis.c') diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c index 0404109510..c6173b47ed 100644 --- a/src/drivers/i2c/tpm/tis.c +++ b/src/drivers/i2c/tpm/tis.c @@ -13,6 +13,7 @@ * GNU General Public License for more details. */ +#include #include #include #include @@ -26,7 +27,7 @@ #include /* global structure for tpm chip data */ -struct tpm_chip g_chip; +static struct tpm_chip g_chip CAR_GLOBAL; #define TPM_CMD_COUNT_BYTE 2 #define TPM_CMD_ORDINAL_BYTE 6 @@ -34,18 +35,18 @@ struct tpm_chip g_chip; int tis_open(void) { + struct tpm_chip *chip = car_get_var_ptr(&g_chip); int rc; - if (g_chip.is_open) { + if (chip->is_open) { printk(BIOS_DEBUG, "tis_open() called twice.\n"); return -1; } - rc = tpm_vendor_init(CONFIG_DRIVER_TPM_I2C_BUS, - CONFIG_DRIVER_TPM_I2C_ADDR); - + rc = tpm_vendor_init(chip, CONFIG_DRIVER_TPM_I2C_BUS, + CONFIG_DRIVER_TPM_I2C_ADDR); if (rc < 0) - g_chip.is_open = 0; + chip->is_open = 0; if (rc) { return -1; @@ -56,9 +57,11 @@ int tis_open(void) int tis_close(void) { - if (g_chip.is_open) { - tpm_vendor_cleanup(&g_chip); - g_chip.is_open = 0; + struct tpm_chip *chip = car_get_var_ptr(&g_chip); + + if (chip->is_open) { + tpm_vendor_cleanup(chip); + chip->is_open = 0; } return 0; @@ -104,8 +107,7 @@ static ssize_t tpm_transmit(const uint8_t *buf, size_t bufsiz) { int rc; uint32_t count, ordinal; - - struct tpm_chip *chip = &g_chip; + struct tpm_chip *chip = car_get_var_ptr(&g_chip); memcpy(&count, buf + TPM_CMD_COUNT_BYTE, sizeof(count)); count = be32_to_cpu(count); -- cgit v1.2.3