From patchwork Mon May 11 08:43:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xu, Quan" X-Patchwork-Id: 470824 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id BDE0314010F for ; Mon, 11 May 2015 23:51:46 +1000 (AEST) Received: from localhost ([::1]:37535 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro7U-0005Dh-GY for incoming@patchwork.ozlabs.org; Mon, 11 May 2015 09:51:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43583) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro0o-0001KJ-Js for qemu-devel@nongnu.org; Mon, 11 May 2015 09:44:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yro0n-0002uT-Eq for qemu-devel@nongnu.org; Mon, 11 May 2015 09:44:50 -0400 Received: from mga02.intel.com ([134.134.136.20]:57594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yro0n-0002nK-51 for qemu-devel@nongnu.org; Mon, 11 May 2015 09:44:49 -0400 Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP; 11 May 2015 06:44:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,407,1427785200"; d="scan'208";a="693050680" Received: from xen-commits.sh.intel.com ([10.239.131.210]) by orsmga001.jf.intel.com with ESMTP; 11 May 2015 06:44:46 -0700 From: Quan Xu To: stefano.stabellini@eu.citrix.com, stefanb@linux.vnet.ibm.com, qemu-devel@nongnu.org Date: Mon, 11 May 2015 04:43:12 -0400 Message-Id: <1431333794-28761-5-git-send-email-quan.xu@intel.com> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1431333794-28761-1-git-send-email-quan.xu@intel.com> References: <1431333794-28761-1-git-send-email-quan.xu@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 134.134.136.20 Cc: wei.liu2@citrix.com, dgdegra@tycho.nsa.gov, Quan Xu , xen-devel@lists.xen.org Subject: [Qemu-devel] [PATCH v7 4/6] Qemu-Xen-vTPM: Move tpm_passthrough_is_selftest() into tpm_util.c 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 and rename it to tpm_util_is_selftest(). Signed-off-by: Quan Xu Reviewed-by: Stefan Berger --- hw/tpm/Makefile.objs | 2 +- hw/tpm/tpm_passthrough.c | 13 +------------ hw/tpm/tpm_util.c | 39 +++++++++++++++++++++++++++++++++++++++ include/sysemu/tpm_backend_int.h | 1 + 4 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 hw/tpm/tpm_util.c diff --git a/hw/tpm/Makefile.objs b/hw/tpm/Makefile.objs index 57919fa..e8fca65 100644 --- a/hw/tpm/Makefile.objs +++ b/hw/tpm/Makefile.objs @@ -1,3 +1,3 @@ -common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o +common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o tpm_util.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o common-obj-$(CONFIG_TPM_XENSTUBDOMS) += xen_vtpm_frontend.o diff --git a/hw/tpm/tpm_passthrough.c b/hw/tpm/tpm_passthrough.c index 2a45071..ff08e15 100644 --- a/hw/tpm/tpm_passthrough.c +++ b/hw/tpm/tpm_passthrough.c @@ -112,17 +112,6 @@ static void tpm_write_fatal_error_response(uint8_t *out, uint32_t out_len) } } -static bool tpm_passthrough_is_selftest(const uint8_t *in, uint32_t in_len) -{ - struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; - - if (in_len >= sizeof(*hdr)) { - return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); - } - - return false; -} - 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, @@ -136,7 +125,7 @@ static int tpm_passthrough_unix_tx_bufs(TPMPassthruState *tpm_pt, tpm_pt->tpm_executing = true; *selftest_done = false; - is_selftest = tpm_passthrough_is_selftest(in, in_len); + is_selftest = tpm_util_is_selftest(in, in_len); ret = tpm_passthrough_unix_write(tpm_pt->tpm_fd, in, in_len); if (ret != in_len) { diff --git a/hw/tpm/tpm_util.c b/hw/tpm/tpm_util.c new file mode 100644 index 0000000..73be8c5 --- /dev/null +++ b/hw/tpm/tpm_util.c @@ -0,0 +1,39 @@ +/* + * TPM util functions + * + * * Copyright (c) 2015 Intel Corporation + * Authors: + * Quan Xu + * + * Copyright (c) 2010 - 2013 IBM Corporation + * Authors: + * Stefan Berger + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see + */ + +#include "sysemu/tpm_backend.h" +#include "tpm_int.h" +#include "sysemu/tpm_backend_int.h" + +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len) +{ + struct tpm_req_hdr *hdr = (struct tpm_req_hdr *)in; + + if (in_len >= sizeof(*hdr)) { + return (be32_to_cpu(hdr->ordinal) == TPM_ORD_ContinueSelfTest); + } + + return false; +} diff --git a/include/sysemu/tpm_backend_int.h b/include/sysemu/tpm_backend_int.h index 05d94d0..e18acab 100644 --- a/include/sysemu/tpm_backend_int.h +++ b/include/sysemu/tpm_backend_int.h @@ -34,6 +34,7 @@ void tpm_backend_thread_create(TPMBackendThread *tbt, void tpm_backend_thread_end(TPMBackendThread *tbt); void tpm_backend_thread_tpm_reset(TPMBackendThread *tbt, GFunc func, gpointer user_data); +bool tpm_util_is_selftest(const uint8_t *in, uint32_t in_len); typedef enum TPMBackendCmd { TPM_BACKEND_CMD_INIT = 1,