]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Don't use 16bit BIOS return codes in tpmhw_* functions
authorKevin O'Connor <kevin@koconnor.net>
Wed, 30 Dec 2015 17:51:27 +0000 (12:51 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Tue, 5 Jan 2016 20:05:14 +0000 (15:05 -0500)
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
src/hw/tpm_drivers.h
src/tcgbios.c

index be0a4eb9b55ba9d92a8cd1a102d18d4dd1cca4ab..08fd1010df26ef1f025874e6a8cbf6a24c1492a7 100644 (file)
@@ -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;
 }
@@ -344,37 +344,37 @@ tpmhw_is_present(void)
     return TPMHW_driver_to_use != TPM_INVALID_DRIVER;
 }
 
-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();
 
index 7a87beb2d7d0bc345f5530c09b9c3e15042bfa20..15a60af27dc9cb3c50d1d7df1f1199f278960eb5 100644 (file)
@@ -13,7 +13,7 @@ enum tpmDurationType {
 int tpmhw_probe(void);
 int tpmhw_is_present(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]);
index 5e8fa63a0ae5a8cba563a07d8f2b337855d15689..641b2d64c1d47d40e48cedac0faa98401b87ca7a 100644 (file)
@@ -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,
-                            TPM_DURATION_TYPE_SHORT);
-    if (rc || resp_length != sizeof(rsp) || rsp.hdr.errcode)
+    int ret = tpmhw_transmit(0, &tre.hdr, &rsp, &resp_length,
+                             TPM_DURATION_TYPE_SHORT);
+    if (ret || resp_length != sizeof(rsp) || rsp.hdr.errcode)
         return -1;
 
     return tpm_log_event(pcpes, event);
@@ -684,10 +684,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;