Don't use the return codes from the 16bit BIOS spec in the internal tpmhw functions. Only the 16bit BIOS interface code should need to handle the details of that spec.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- src/hw/tpm_drivers.c | 20 ++++++++++---------- src/hw/tpm_drivers.h | 2 +- src/tcgbios.c | 22 ++++++++++++---------- 3 files changed, 23 insertions(+), 21 deletions(-)
diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c index dc09779..733c161 100644 --- a/src/hw/tpm_drivers.c +++ b/src/hw/tpm_drivers.c @@ -10,7 +10,7 @@ #include "byteorder.h" // be32_to_cpu #include "config.h" // CONFIG_TPM_TIS_SHA1THRESHOLD #include "hw/tpm_drivers.h" // struct tpm_driver -#include "std/tcg.h" // TCG_NO_RESPONSE +#include "std/tcg.h" // TCG_RESPONSE_TIMEOUT #include "output.h" // warn_timeout #include "stacks.h" // yield #include "string.h" // memcpy @@ -280,7 +280,7 @@ static u32 tis_waitdatavalid(void) u32 timeout_c = tpm_drivers[TIS_DRIVER_IDX].timeouts[TIS_TIMEOUT_TYPE_C];
if (tis_wait_sts(locty, timeout_c, TIS_STS_VALID, TIS_STS_VALID) != 0) - rc = TCG_NO_RESPONSE; + rc = 1;
return rc; } @@ -298,7 +298,7 @@ static u32 tis_waitrespready(enum tpmDurationType to_t)
if (tis_wait_sts(locty, timeout, TIS_STS_DATA_AVAILABLE, TIS_STS_DATA_AVAILABLE) != 0) - rc = TCG_NO_RESPONSE; + rc = 1;
return rc; } @@ -338,37 +338,37 @@ tpmhw_probe(void) return -1; }
-u32 +int tpmhw_transmit(u8 locty, struct tpm_req_header *req, void *respbuffer, u32 *respbufferlen, enum tpmDurationType to_t) { if (TPMHW_driver_to_use == TPM_INVALID_DRIVER) - return TCG_FATAL_COM_ERROR; + return -1;
struct tpm_driver *td = &tpm_drivers[TPMHW_driver_to_use];
u32 irc = td->activate(locty); if (irc != 0) { /* tpm could not be activated */ - return TCG_FATAL_COM_ERROR; + return -1; }
irc = td->senddata((void*)req, be32_to_cpu(req->totlen)); if (irc != 0) - return TCG_FATAL_COM_ERROR; + return -1;
irc = td->waitdatavalid(); if (irc != 0) - return TCG_FATAL_COM_ERROR; + return -1;
irc = td->waitrespready(to_t); if (irc != 0) - return TCG_FATAL_COM_ERROR; + return -1;
irc = td->readresp(respbuffer, respbufferlen); if (irc != 0) - return TCG_FATAL_COM_ERROR; + return -1;
td->ready();
diff --git a/src/hw/tpm_drivers.h b/src/hw/tpm_drivers.h index afa3027..47909e2 100644 --- a/src/hw/tpm_drivers.h +++ b/src/hw/tpm_drivers.h @@ -12,7 +12,7 @@ enum tpmDurationType {
int tpmhw_probe(void); struct tpm_req_header; -u32 tpmhw_transmit(u8 locty, struct tpm_req_header *req, +int tpmhw_transmit(u8 locty, struct tpm_req_header *req, void *respbuffer, u32 *respbufferlen, enum tpmDurationType to_t); void tpmhw_set_timeouts(u32 timeouts[4], u32 durations[3]); diff --git a/src/tcgbios.c b/src/tcgbios.c index da104e4..b31de39 100644 --- a/src/tcgbios.c +++ b/src/tcgbios.c @@ -193,8 +193,8 @@ build_and_send_cmd(u8 locty, u32 ordinal, const u8 *append, u32 append_size, if (append_size) memcpy(req.cmd, append, append_size);
- u32 rc = tpmhw_transmit(locty, &req.trqh, obuffer, &obuffer_len, to_t); - int ret = rc ? -1 : be32_to_cpu(trsh->errcode); + int ret = tpmhw_transmit(locty, &req.trqh, obuffer, &obuffer_len, to_t); + ret = ret ? -1 : be32_to_cpu(trsh->errcode); dprintf(DEBUG_tcg, "Return from build_and_send_cmd(%x, %x %x) = %x\n", ordinal, req.cmd[0], req.cmd[1], ret); return ret; @@ -232,9 +232,9 @@ tpm_get_capability(u32 cap, u32 subcap, struct tpm_rsp_header *rsp, u32 rsize) .subCap = cpu_to_be32(subcap) }; u32 resp_size = rsize; - u32 rc = tpmhw_transmit(0, &trgc.hdr, rsp, &resp_size, - TPM_DURATION_TYPE_SHORT); - int ret = (rc || resp_size != rsize) ? -1 : be32_to_cpu(rsp->errcode); + int ret = tpmhw_transmit(0, &trgc.hdr, rsp, &resp_size, + TPM_DURATION_TYPE_SHORT); + ret = (ret || resp_size != rsize) ? -1 : be32_to_cpu(rsp->errcode); dprintf(DEBUG_tcg, "TCGBIOS: Return code from TPM_GetCapability(%d, %d)" " = %x\n", cap, subcap, ret); if (ret) { @@ -298,9 +298,9 @@ tpm_log_extend_event(struct pcpes *pcpes, const void *event)
struct tpm_rsp_extend rsp; u32 resp_length = sizeof(rsp); - u32 rc = tpmhw_transmit(0, &tre.hdr, &rsp, &resp_length, + int ret = tpmhw_transmit(0, &tre.hdr, &rsp, &resp_length, TPM_DURATION_TYPE_SHORT); - if (rc || resp_length != sizeof(rsp) || rsp.hdr.errcode) + if (ret || resp_length != sizeof(rsp) || rsp.hdr.errcode) return -1;
return tpm_log_event(pcpes, event); @@ -686,10 +686,12 @@ pass_through_to_tpm_int(struct pttti *pttti, struct pttto *pttto) }
u32 resbuflen = pttti->opblength - offsetof(struct pttto, tpmopout); - rc = tpmhw_transmit(0, trh, pttto->tpmopout, &resbuflen, - TPM_DURATION_TYPE_LONG /* worst case */); - if (rc) + int ret = tpmhw_transmit(0, trh, pttto->tpmopout, &resbuflen, + TPM_DURATION_TYPE_LONG /* worst case */); + if (ret) { + rc = TCG_FATAL_COM_ERROR; goto err_exit; + }
pttto->opblength = offsetof(struct pttto, tpmopout) + resbuflen; pttto->reserved = 0;