aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/i2c
diff options
context:
space:
mode:
authorJon Murphy <jpmurphy@google.com>2023-09-05 11:36:43 -0600
committerRaul Rangel <rrangel@chromium.org>2023-09-28 16:54:37 +0000
commitd7b8dc9cf5978809912dcffefce2eda5937c9653 (patch)
tree56befbc9563ce2baca6f31ccbfb041e99fb858d6 /src/drivers/i2c
parent53fc667943052bd592b8406bdf4bf652c6c9cd3a (diff)
treewide: convert to tpm_result_t
Convert TPM functions to return TPM error codes(referred to as tpm_result_t) values to match the TCG standard. BUG=b:296439237 TEST=build and boot to Skyrim BRANCH=None Change-Id: Ifdf9ff6c2a1f9b938dbb04d245799391115eb6b1 Signed-off-by: Jon Murphy <jpmurphy@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/77666 Reviewed-by: Raul Rangel <rrangel@chromium.org> Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/drivers/i2c')
-rw-r--r--src/drivers/i2c/tpm/cr50.c182
-rw-r--r--src/drivers/i2c/tpm/tis.c34
-rw-r--r--src/drivers/i2c/tpm/tis_atmel.c26
-rw-r--r--src/drivers/i2c/tpm/tpm.c16
-rw-r--r--src/drivers/i2c/tpm/tpm.h5
5 files changed, 150 insertions, 113 deletions
diff --git a/src/drivers/i2c/tpm/cr50.c b/src/drivers/i2c/tpm/cr50.c
index 929628407d..d207f2b20b 100644
--- a/src/drivers/i2c/tpm/cr50.c
+++ b/src/drivers/i2c/tpm/cr50.c
@@ -56,12 +56,12 @@ static struct tpm_inf_dev tpm_dev;
* 2) wait for TPM to indicate it is ready
* 3) read 'len' bytes of TPM response into the provided 'buffer'
*
- * Return -1 on error, 0 on success.
+ * Returns TSS Return Code from TCG TPM Structures. See tss_errors.h
*/
-static int cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
+static tpm_result_t cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
{
if (tpm_dev.addr == 0)
- return -1;
+ return TPM_CB_FAIL;
/* Clear interrupt before starting transaction */
cr50_plat_irq_status();
@@ -69,20 +69,20 @@ static int cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
/* Send the register address byte to the TPM */
if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, &addr, 1)) {
printk(BIOS_ERR, "%s: Address write failed\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
/* Wait for TPM to be ready with response data */
if (cr50_wait_tpm_ready() != CB_SUCCESS)
- return -1;
+ return TPM_CB_FAIL;
/* Read response data from the TPM */
if (i2c_read_raw(tpm_dev.bus, tpm_dev.addr, buffer, len)) {
printk(BIOS_ERR, "%s: Read response failed\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
- return 0;
+ return TPM_SUCCESS;
}
/*
@@ -96,14 +96,14 @@ static int cr50_i2c_read(uint8_t addr, uint8_t *buffer, size_t len)
* 2) send the address+data to the TPM
* 3) wait for TPM to indicate it is done writing
*
- * Returns -1 on error, 0 on success.
+ * Returns TSS Return Code from TCG TPM Structures. See tss_errors.h
*/
-static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
+static tpm_result_t cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
{
if (tpm_dev.addr == 0)
- return -1;
+ return TPM_CB_INVALID_ARG;
if (len > CR50_MAX_BUFSIZE)
- return -1;
+ return TPM_CB_INVALID_ARG;
/* Prepend the 'register address' to the buffer */
tpm_dev.buf[0] = addr;
@@ -115,11 +115,11 @@ static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
/* Send write request buffer with address */
if (i2c_write_raw(tpm_dev.bus, tpm_dev.addr, tpm_dev.buf, len + 1)) {
printk(BIOS_ERR, "%s: Error writing to TPM\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
/* Wait for TPM to be ready */
- return cr50_wait_tpm_ready() == CB_SUCCESS ? 0 : -1;
+ return cr50_wait_tpm_ready() == CB_SUCCESS ? TPM_SUCCESS : TPM_CB_FAIL;
}
/*
@@ -128,11 +128,13 @@ static int cr50_i2c_write(uint8_t addr, const uint8_t *buffer, size_t len)
*
* This function will make sure that the AP does not proceed with boot until
* TPM finished reset processing.
+ *
+ * Returns TSS Return Code from TCG TPM Structures. See tss_errors.h
*/
-static int process_reset(void)
+static tpm_result_t process_reset(void)
{
struct stopwatch sw;
- int rc = 0;
+ tpm_result_t rc = TPM_SUCCESS;
uint8_t access;
/*
@@ -162,59 +164,72 @@ static int process_reset(void)
printk(BIOS_INFO, "TPM ready after %lld ms\n",
stopwatch_duration_msecs(&sw));
- return 0;
+ return TPM_SUCCESS;
} while (!stopwatch_expired(&sw));
- if (rc)
- printk(BIOS_ERR, "Failed to read TPM\n");
- else
+ if (rc) {
+ printk(BIOS_ERR, "Failed to read TPM with error %d\n", rc);
+ return rc;
+ } else
printk(BIOS_ERR,
"TPM failed to reset after %lld ms, status: %#x\n",
stopwatch_duration_msecs(&sw), access);
-
- return -1;
+ return TPM_CB_FAIL;
}
/*
* Locality could be already claimed (if this is a later coreboot stage and
* the RO did not release it), or not yet claimed, if this is verstage or the
* older RO did release it.
+ *
+ * Returns TSS Return Code from TCG TPM Structures. See tss_errors.h
*/
-static int claim_locality(void)
+static tpm_result_t claim_locality(void)
{
uint8_t access;
const uint8_t mask = TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY;
+ tpm_result_t rc = TPM_SUCCESS;
- if (cr50_i2c_read(TPM_ACCESS(0), &access, sizeof(access)))
- return -1;
+ rc = cr50_i2c_read(TPM_ACCESS(0), &access, sizeof(access));
+ if (rc)
+ return rc;
if ((access & mask) == mask) {
printk(BIOS_INFO, "Locality already claimed\n");
- return 0;
+ return TPM_SUCCESS;
}
access = TPM_ACCESS_REQUEST_USE;
- if (cr50_i2c_write(TPM_ACCESS(0),
- &access, sizeof(access)))
- return -1;
+ rc = cr50_i2c_write(TPM_ACCESS(0),
+ &access, sizeof(access));
+ if (rc)
+ return rc;
- if (cr50_i2c_read(TPM_ACCESS(0), &access, sizeof(access)))
- return -1;
+ rc = cr50_i2c_read(TPM_ACCESS(0), &access, sizeof(access));
+ if (rc)
+ return rc;
if ((access & mask) != mask) {
printk(BIOS_INFO, "Failed to claim locality.\n");
- return -1;
+ return TPM_CB_FAIL;
}
- return 0;
+ return TPM_SUCCESS;
}
-/* cr50 requires all 4 bytes of status register to be read */
+/*
+ * cr50 requires all 4 bytes of status register to be read
+ *
+ * Returns lowest 8-bits of the TIS Status register value
+ * see tis_status bit mask enumerated type in tis.h.
+ * Return 0 on error.
+ */
static uint8_t cr50_i2c_tis_status(void)
{
uint8_t buf[4];
- if (cr50_i2c_read(TPM_STS(tpm_dev.locality), buf, sizeof(buf)) < 0) {
- printk(BIOS_ERR, "%s: Failed to read status\n", __func__);
+ tpm_result_t rc = cr50_i2c_read(TPM_STS(tpm_dev.locality), buf, sizeof(buf));
+ if (rc) {
+ printk(BIOS_ERR, "%s: Failed to read status with error %#x\n", __func__, rc);
return 0;
}
return buf[0];
@@ -229,16 +244,21 @@ static void cr50_i2c_tis_ready(void)
}
/* cr50 uses bytes 3:2 of status register for burst count and
- * all 4 bytes must be read */
-static int cr50_i2c_wait_burststs(uint8_t mask, size_t *burst, int *status)
+ * all 4 bytes must be read
+ *
+ * Returns TSS Return Code from TCG TPM Structures. See tss_errors.h
+ */
+static tpm_result_t cr50_i2c_wait_burststs(uint8_t mask, size_t *burst, int *status)
{
uint8_t buf[4];
struct stopwatch sw;
+ tpm_result_t rc = TPM_SUCCESS;
stopwatch_init_msecs_expire(&sw, CR50_TIMEOUT_LONG_MS);
while (!stopwatch_expired(&sw)) {
- if (cr50_i2c_read(TPM_STS(tpm_dev.locality), buf, sizeof(buf)) != 0) {
+ rc = cr50_i2c_read(TPM_STS(tpm_dev.locality), buf, sizeof(buf));
+ if (rc) {
mdelay(CR50_TIMEOUT_SHORT_MS);
continue;
}
@@ -249,13 +269,14 @@ static int cr50_i2c_wait_burststs(uint8_t mask, size_t *burst, int *status)
/* Check if mask matches and burst is valid */
if ((*status & mask) == mask &&
*burst > 0 && *burst <= CR50_MAX_BUFSIZE)
- return 0;
+ return TPM_SUCCESS;
mdelay(CR50_TIMEOUT_SHORT_MS);
}
-
- printk(BIOS_ERR, "%s: Timeout reading burst and status\n", __func__);
- return -1;
+ printk(BIOS_ERR, "%s: Timeout reading burst and status with error %#x\n", __func__, rc);
+ if (rc)
+ return rc;
+ return TPM_CB_TIMEOUT;
}
static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len)
@@ -264,18 +285,21 @@ static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len)
uint8_t addr = TPM_DATA_FIFO(tpm_dev.locality);
uint8_t mask = TPM_STS_VALID | TPM_STS_DATA_AVAIL;
int status;
+ tpm_result_t rc = TPM_SUCCESS;
if (buf_len < TPM_HEADER_SIZE)
goto out_err;
- if (cr50_i2c_wait_burststs(mask, &burstcnt, &status) < 0) {
- printk(BIOS_ERR, "%s: First chunk not available\n", __func__);
+ rc = cr50_i2c_wait_burststs(mask, &burstcnt, &status);
+ if (rc) {
+ printk(BIOS_ERR, "%s: First chunk not available with error %#x\n", __func__, rc);
goto out_err;
}
/* Read first chunk of burstcnt bytes */
- if (cr50_i2c_read(addr, buf, burstcnt) != 0) {
- printk(BIOS_ERR, "%s: Read failed\n", __func__);
+ rc = cr50_i2c_read(addr, buf, burstcnt);
+ if (rc) {
+ printk(BIOS_ERR, "%s: Read failed with error %#x\n", __func__, rc);
goto out_err;
}
@@ -291,12 +315,13 @@ static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len)
current = burstcnt;
while (current < expected) {
/* Read updated burst count and check status */
- if (cr50_i2c_wait_burststs(mask, &burstcnt, &status) < 0)
+ if (cr50_i2c_wait_burststs(mask, &burstcnt, &status))
goto out_err;
len = MIN(burstcnt, expected - current);
- if (cr50_i2c_read(addr, buf + current, len) != 0) {
- printk(BIOS_ERR, "%s: Read failed\n", __func__);
+ rc = cr50_i2c_read(addr, buf + current, len);
+ if (rc) {
+ printk(BIOS_ERR, "%s: Read failed with error %#x\n", __func__, rc);
goto out_err;
}
@@ -304,7 +329,7 @@ static int cr50_i2c_tis_recv(uint8_t *buf, size_t buf_len)
}
/* Ensure TPM is done reading data */
- if (cr50_i2c_wait_burststs(TPM_STS_VALID, &burstcnt, &status) < 0)
+ if (cr50_i2c_wait_burststs(TPM_STS_VALID, &burstcnt, &status))
goto out_err;
if (status & TPM_STS_DATA_AVAIL) {
printk(BIOS_ERR, "%s: Data still available\n", __func__);
@@ -326,6 +351,7 @@ static int cr50_i2c_tis_send(uint8_t *buf, size_t len)
size_t burstcnt, limit, sent = 0;
uint8_t tpm_go[4] = { TPM_STS_GO };
struct stopwatch sw;
+ tpm_result_t rc = TPM_SUCCESS;
stopwatch_init_msecs_expire(&sw, CR50_TIMEOUT_LONG_MS);
@@ -348,14 +374,15 @@ static int cr50_i2c_tis_send(uint8_t *buf, size_t len)
mask |= TPM_STS_DATA_EXPECT;
/* Read burst count and check status */
- if (cr50_i2c_wait_burststs(mask, &burstcnt, &status) < 0)
+ if (cr50_i2c_wait_burststs(mask, &burstcnt, &status))
goto out_err;
/* Use burstcnt - 1 to account for the address byte
* that is inserted by cr50_i2c_write() */
limit = MIN(burstcnt - 1, len);
- if (cr50_i2c_write(TPM_DATA_FIFO(tpm_dev.locality), &buf[sent], limit) != 0) {
- printk(BIOS_ERR, "%s: Write failed\n", __func__);
+ rc = cr50_i2c_write(TPM_DATA_FIFO(tpm_dev.locality), &buf[sent], limit);
+ if (rc) {
+ printk(BIOS_ERR, "%s: Write failed with error %#x\n", __func__, rc);
goto out_err;
}
@@ -364,7 +391,7 @@ static int cr50_i2c_tis_send(uint8_t *buf, size_t len)
}
/* Ensure TPM is not expecting more data */
- if (cr50_i2c_wait_burststs(TPM_STS_VALID, &burstcnt, &status) < 0)
+ if (cr50_i2c_wait_burststs(TPM_STS_VALID, &burstcnt, &status))
goto out_err;
if (status & TPM_STS_DATA_EXPECT) {
printk(BIOS_ERR, "%s: Data still expected\n", __func__);
@@ -372,8 +399,9 @@ static int cr50_i2c_tis_send(uint8_t *buf, size_t len)
}
/* Start the TPM command */
- if (cr50_i2c_write(TPM_STS(tpm_dev.locality), tpm_go, sizeof(tpm_go)) < 0) {
- printk(BIOS_ERR, "%s: Start command failed\n", __func__);
+ rc = cr50_i2c_write(TPM_STS(tpm_dev.locality), tpm_go, sizeof(tpm_go));
+ if (rc) {
+ printk(BIOS_ERR, "%s: Start command failed with error %#x\n", __func__, rc);
goto out_err;
}
return sent;
@@ -396,14 +424,15 @@ static void cr50_vendor_init(struct tpm_chip *chip)
chip->cancel = &cr50_i2c_tis_ready;
}
-int tpm_vendor_probe(unsigned int bus, uint32_t addr)
+tpm_result_t tpm_vendor_probe(unsigned int bus, uint32_t addr)
{
- return 0;
+ return TPM_SUCCESS;
}
-static int cr50_i2c_probe(uint32_t *did_vid)
+static tpm_result_t cr50_i2c_probe(uint32_t *did_vid)
{
int retries;
+ tpm_result_t rc = TPM_SUCCESS;
/*
* 1s should be enough to synchronize with the TPM even under the
@@ -414,14 +443,13 @@ static int cr50_i2c_probe(uint32_t *did_vid)
printk(BIOS_INFO, "Probing TPM I2C: ");
for (retries = 100; retries > 0; retries--) {
- int rc;
rc = cr50_i2c_read(TPM_DID_VID(0), (uint8_t *)did_vid, 4);
/* Exit once DID and VID verified */
if (!rc && (*did_vid == CR50_DID_VID || *did_vid == TI50_DID_VID)) {
printk(BIOS_INFO, "done! DID_VID 0x%08x\n", *did_vid);
- return 0;
+ return TPM_SUCCESS;
}
/* TPM might be resetting, let's retry in a bit. */
@@ -432,17 +460,21 @@ static int cr50_i2c_probe(uint32_t *did_vid)
/*
* I2C reads failed, or the DID and VID didn't match
*/
- printk(BIOS_ERR, "DID_VID 0x%08x not recognized\n", *did_vid);
- return -1;
+ if (!rc) {
+ printk(BIOS_ERR, "DID_VID 0x%08x not recognized\n", *did_vid);
+ return TPM_CB_FAIL;
+ }
+ return rc;
}
-int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
+tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
{
uint32_t did_vid = 0;
+ tpm_result_t rc = TPM_SUCCESS;
if (dev_addr == 0) {
printk(BIOS_ERR, "%s: missing device address\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
tpm_dev.bus = bus;
@@ -450,15 +482,19 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
cr50_vendor_init(chip);
- if (cr50_i2c_probe(&did_vid))
- return -1;
+ rc = cr50_i2c_probe(&did_vid);
+ if (rc)
+ return rc;
- if (ENV_SEPARATE_VERSTAGE || ENV_BOOTBLOCK)
- if (process_reset())
- return -1;
+ if (ENV_SEPARATE_VERSTAGE || ENV_BOOTBLOCK) {
+ rc = process_reset();
+ if (rc)
+ return rc;
+ }
- if (claim_locality())
- return -1;
+ rc = claim_locality();
+ if (rc)
+ return rc;
printk(BIOS_DEBUG, "cr50 TPM 2.0 (i2c %u:0x%02x id %#x)\n",
bus, dev_addr, did_vid >> 16);
@@ -470,7 +506,7 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
}
chip->is_open = 1;
- return 0;
+ return TPM_SUCCESS;
}
enum cb_err tis_vendor_write(unsigned int addr, const void *buffer, size_t bytes)
diff --git a/src/drivers/i2c/tpm/tis.c b/src/drivers/i2c/tpm/tis.c
index 25b7f40801..a5c3b8fdf3 100644
--- a/src/drivers/i2c/tpm/tis.c
+++ b/src/drivers/i2c/tpm/tis.c
@@ -19,27 +19,24 @@ static struct tpm_chip chip;
#define TPM_CMD_COUNT_BYTE 2
#define TPM_CMD_ORDINAL_BYTE 6
-int tis_open(void)
+tpm_result_t tis_open(void)
{
- int rc;
+ tpm_result_t rc;
if (chip.is_open) {
printk(BIOS_DEBUG, "%s() called twice.\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
rc = tpm_vendor_init(&chip, CONFIG_DRIVER_TPM_I2C_BUS,
CONFIG_DRIVER_TPM_I2C_ADDR);
- if (rc < 0)
+ if (rc != TPM_SUCCESS)
chip.is_open = 0;
- if (rc)
- return -1;
-
- return 0;
+ return rc;
}
-int tis_init(void)
+tpm_result_t tis_init(void)
{
return tpm_vendor_probe(CONFIG_DRIVER_TPM_I2C_BUS,
CONFIG_DRIVER_TPM_I2C_ADDR);
@@ -48,23 +45,23 @@ int tis_init(void)
static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
size_t rbufsiz)
{
- int rc;
+ int rc = -1;
uint32_t count;
memcpy(&count, sbuf + TPM_CMD_COUNT_BYTE, sizeof(count));
count = be32_to_cpu(count);
if (!chip.send || !chip.status || !chip.cancel)
- return -1;
+ goto out;
if (count == 0) {
printk(BIOS_DEBUG, "%s: no data\n", __func__);
- return -1;
+ goto out;
}
if (count > sbufsiz) {
printk(BIOS_DEBUG, "%s: invalid count value %#x %zx\n", __func__,
count, sbufsiz);
- return -1;
+ goto out;
}
ASSERT(chip.send);
@@ -95,11 +92,10 @@ static ssize_t tpm_transmit(const uint8_t *sbuf, size_t sbufsiz, void *rbuf,
ASSERT(chip.cancel);
chip.cancel();
printk(BIOS_DEBUG, "%s: Operation Timed out\n", __func__);
- rc = -1; //ETIME;
+ rc = -1;
goto out;
out_recv:
-
rc = chip.recv((uint8_t *)rbuf, rbufsiz);
if (rc < 0)
printk(BIOS_DEBUG, "%s: tpm_recv: error %d\n", __func__, rc);
@@ -107,7 +103,7 @@ out:
return rc;
}
-int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
+tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
uint8_t *recvbuf, size_t *rbuf_len)
{
ASSERT(sbuf_size >= 10);
@@ -124,12 +120,12 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
if (len < 10) {
*rbuf_len = 0;
- return -1;
+ return TPM_CB_FAIL;
}
if (len > *rbuf_len) {
*rbuf_len = len;
- return -1;
+ return TPM_CB_FAIL;
}
*rbuf_len = len;
@@ -142,5 +138,5 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
hexdump(recvbuf, *rbuf_len);
}
- return 0;
+ return TPM_SUCCESS;
}
diff --git a/src/drivers/i2c/tpm/tis_atmel.c b/src/drivers/i2c/tpm/tis_atmel.c
index 669ac68f6c..91ed6a99e3 100644
--- a/src/drivers/i2c/tpm/tis_atmel.c
+++ b/src/drivers/i2c/tpm/tis_atmel.c
@@ -22,17 +22,17 @@ struct tpm_output_header {
uint32_t return_code;
} __packed;
-int tis_open(void)
+tpm_result_t tis_open(void)
{
- return 0;
+ return TPM_SUCCESS;
}
-int tis_init(void)
+tpm_result_t tis_init(void)
{
- return 0;
+ return TPM_SUCCESS;
}
-int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
+tpm_result_t tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
uint8_t *recvbuf, size_t *rbuf_len)
{
size_t hdr_bytes;
@@ -60,8 +60,10 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
sbuf_size);
if ((status < 0) && (!stopwatch_expired(&sw)))
continue;
- if (status < 0)
- return status;
+ if (status < 0) {
+ printk(BIOS_ERR, "I2C write error: %d\n", status);
+ return TPM_CB_COMMUNICATION_ERROR;
+ }
break;
}
@@ -79,7 +81,7 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
udelay(SLEEP_DURATION);
} while (!stopwatch_expired(&sw));
if (status != sizeof(*header))
- return -1;
+ return TPM_CB_COMMUNICATION_ERROR;
/* Determine the number of bytes remaining */
recv_bytes = MIN(be32_to_cpu(*(uint32_t *)&header->length),
@@ -94,8 +96,10 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
/* Read the full TPM response */
status = i2c_read_raw(CONFIG_DRIVER_TPM_I2C_BUS,
CONFIG_DRIVER_TPM_I2C_ADDR, recvbuf, recv_bytes);
- if (status < 0)
- return status;
+ if (status < 0) {
+ printk(BIOS_ERR, "I2C read error: %d\n", status);
+ return TPM_CB_COMMUNICATION_ERROR;
+ }
}
/* Return the number of bytes received */
@@ -110,5 +114,5 @@ int tis_sendrecv(const uint8_t *sendbuf, size_t sbuf_size,
}
/* Successful transfer */
- return 0;
+ return TPM_SUCCESS;
}
diff --git a/src/drivers/i2c/tpm/tpm.c b/src/drivers/i2c/tpm/tpm.c
index c88dcdd4b9..4dbefb44f3 100644
--- a/src/drivers/i2c/tpm/tpm.c
+++ b/src/drivers/i2c/tpm/tpm.c
@@ -451,7 +451,7 @@ out_err:
/* Initialization of I2C TPM */
-int tpm_vendor_probe(unsigned int bus, uint32_t addr)
+tpm_result_t tpm_vendor_probe(unsigned int bus, uint32_t addr)
{
struct stopwatch sw;
uint8_t buf = 0;
@@ -487,18 +487,18 @@ int tpm_vendor_probe(unsigned int bus, uint32_t addr)
* Claim failure if the ValidSts (bit 7) is clear.
*/
if (!(buf & TPM_STS_VALID))
- return -1;
+ return TPM_CB_FAIL;
- return 0;
+ return TPM_SUCCESS;
}
-int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
+tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
{
uint32_t vendor;
if (dev_addr == 0) {
printk(BIOS_ERR, "%s: missing device address\n", __func__);
- return -1;
+ return TPM_CB_FAIL;
}
tpm_dev.chip_type = UNKNOWN;
@@ -518,7 +518,7 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
chip->cancel = &tpm_tis_i2c_ready;
if (request_locality(0) != 0)
- return -1;
+ return TPM_CB_FAIL;
/* Read four bytes from DID_VID register */
if (iic_tpm_read(TPM_DID_VID(0), (uint8_t *)&vendor, 4) < 0)
@@ -543,9 +543,9 @@ int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr)
* Standard timeout values are used so far
*/
- return 0;
+ return TPM_SUCCESS;
out_err:
release_locality(0, 1);
- return -1;
+ return TPM_CB_FAIL;
}
diff --git a/src/drivers/i2c/tpm/tpm.h b/src/drivers/i2c/tpm/tpm.h
index d4176cc511..fb9837789d 100644
--- a/src/drivers/i2c/tpm/tpm.h
+++ b/src/drivers/i2c/tpm/tpm.h
@@ -12,6 +12,7 @@
#ifndef __DRIVERS_TPM_SLB9635_I2C_TPM_H__
#define __DRIVERS_TPM_SLB9635_I2C_TPM_H__
+#include <security/tpm/tss_errors.h>
#include <stdint.h>
enum tpm_timeout {
@@ -51,8 +52,8 @@ struct tpm_chip {
/* ---------- Interface for TPM vendor ------------ */
-int tpm_vendor_probe(unsigned int bus, uint32_t addr);
+tpm_result_t tpm_vendor_probe(unsigned int bus, uint32_t addr);
-int tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr);
+tpm_result_t tpm_vendor_init(struct tpm_chip *chip, unsigned int bus, uint32_t dev_addr);
#endif /* __DRIVERS_TPM_SLB9635_I2C_TPM_H__ */