From patchwork Wed Nov 6 14:38:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Bryant X-Patchwork-Id: 288937 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 84F9F2C008E for ; Thu, 7 Nov 2013 01:39:58 +1100 (EST) Received: from localhost ([::1]:34307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4Gy-0005jb-Lt for incoming@patchwork.ozlabs.org; Wed, 06 Nov 2013 09:39:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47567) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4GK-0005SV-GS for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:39:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ve4G8-0000BP-Hl for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:39:16 -0500 Received: from e35.co.us.ibm.com ([32.97.110.153]:55515) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ve4G8-0000BK-BB for qemu-devel@nongnu.org; Wed, 06 Nov 2013 09:39:04 -0500 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 6 Nov 2013 07:39:03 -0700 Received: from d03dlp02.boulder.ibm.com (9.17.202.178) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 6 Nov 2013 07:39:01 -0700 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by d03dlp02.boulder.ibm.com (Postfix) with ESMTP id 9E1063E40026 for ; Wed, 6 Nov 2013 07:39:00 -0700 (MST) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rA6Ed0T7320718 for ; Wed, 6 Nov 2013 07:39:00 -0700 Received: from d03av02.boulder.ibm.com (localhost [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rA6EcxIh007467 for ; Wed, 6 Nov 2013 07:39:00 -0700 Received: from localhost ([9.80.103.90]) by d03av02.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rA6EcwvA007424; Wed, 6 Nov 2013 07:38:59 -0700 From: Corey Bryant To: qemu-devel@nongnu.org Date: Wed, 6 Nov 2013 09:38:56 -0500 Message-Id: <1383748736-8821-1-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.1.4 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13110614-6688-0000-0000-000003379339 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 32.97.110.153 Cc: Corey Bryant , aliguori@amazon.com Subject: [Qemu-devel] [PATCH 2/4] tpm: Share tpm_write_fatal_error_response X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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(-) 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;