Patchwork [2/4] tpm: Share tpm_write_fatal_error_response

login
register
mail settings
Submitter Corey Bryant
Date Nov. 6, 2013, 2:38 p.m.
Message ID <1383748736-8821-1-git-send-email-coreyb@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/288937/
State New
Headers show

Comments

Corey Bryant - Nov. 6, 2013, 2:38 p.m.
Move tpm_write_fatal_error_response to tpm.c where it can be shared
by multiple backends, and change the return code from void to the
size of the message.

Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
---
 hw/tpm/tpm_passthrough.c     |   14 --------------
 hw/tpm/tpm_tis.h             |    1 +
 include/sysemu/tpm_backend.h |    2 ++
 tpm.c                        |   19 +++++++++++++++++++
 4 files changed, 22 insertions(+), 14 deletions(-)

Patch

diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c
index 56e9e0f..602307a 100644
--- a/hw/tpm/tpm_passthrough.c
+++ b/hw/tpm/tpm_passthrough.c
@@ -98,20 +98,6 @@  static uint32_t tpm_passthrough_get_size_from_buffer(const uint8_t *buf)
     return be32_to_cpu(resp->len);
 }
 
-/*
- * Write an error message in the given output buffer.
- */
-static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
-{
-    if (out_len >= sizeof(struct tpm_resp_hdr)) {
-        struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;
-
-        resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
-        resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));
-        resp->errcode = cpu_to_be32(TPM_FAIL);
-    }
-}
-
 static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt,
                                         const uint8_t *in, uint32_t in_len,
                                         uint8_t *out, uint32_t out_len)
diff --git a/hw/tpm/tpm_tis.h b/hw/tpm/tpm_tis.h
index 916152a..6dec43b 100644
--- a/hw/tpm/tpm_tis.h
+++ b/hw/tpm/tpm_tis.h
@@ -19,6 +19,7 @@ 
 
 #include "hw/isa/isa.h"
 #include "qemu-common.h"
+#include "sysemu/tpm_backend.h"
 
 #define TPM_TIS_ADDR_BASE           0xFED40000
 
diff --git a/include/sysemu/tpm_backend.h b/include/sysemu/tpm_backend.h
index 825f33b..c7a7281 100644
--- a/include/sysemu/tpm_backend.h
+++ b/include/sysemu/tpm_backend.h
@@ -207,4 +207,6 @@  const TPMDriverOps *tpm_get_backend_driver(const char *type);
 int tpm_register_model(enum TpmModel model);
 int tpm_register_driver(const TPMDriverOps *tdo);
 
+uint32_t tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len);
+
 #endif
diff --git a/tpm.c b/tpm.c
index d68d69f..1dd516b 100644
--- a/tpm.c
+++ b/tpm.c
@@ -19,6 +19,7 @@ 
 #include "sysemu/tpm.h"
 #include "qemu/config-file.h"
 #include "qmp-commands.h"
+#include "hw/tpm/tpm_int.h"
 
 static QLIST_HEAD(, TPMBackend) tpm_backends =
     QLIST_HEAD_INITIALIZER(tpm_backends);
@@ -61,6 +62,24 @@  static bool tpm_model_is_registered(enum TpmModel model)
     return false;
 }
 
+/*
+ * Write an error message in the given output buffer.
+ */
+uint32_t tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len)
+{
+    if (out_len >= sizeof(struct tpm_resp_hdr)) {
+        struct tpm_resp_hdr *resp = (struct tpm_resp_hdr *)out;
+
+        resp->tag = cpu_to_be16(TPM_TAG_RSP_COMMAND);
+        resp->len = cpu_to_be32(sizeof(struct tpm_resp_hdr));
+        resp->errcode = cpu_to_be32(TPM_FAIL);
+
+        return sizeof(struct tpm_resp_hdr);
+    }
+
+    return 0;
+}
+
 const TPMDriverOps *tpm_get_backend_driver(const char *type)
 {
     int i;