From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqkw5-0003Db-2C for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yqkw1-0002Ta-MD for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:36 -0400 Received: from e34.co.us.ibm.com ([32.97.110.152]:57149) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yqkw0-0002TO-NP for qemu-devel@nongnu.org; Fri, 08 May 2015 12:15:32 -0400 Received: from /spool/local by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 8 May 2015 10:15:32 -0600 Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 6B1E719D8042 for ; Fri, 8 May 2015 10:06:34 -0600 (MDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t48GFUBt26542198 for ; Fri, 8 May 2015 09:15:30 -0700 Received: from d03av03.boulder.ibm.com (localhost [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t48GFTjR010656 for ; Fri, 8 May 2015 10:15:30 -0600 From: Stefan Berger Date: Fri, 8 May 2015 12:15:18 -0400 Message-Id: <1431101720-701152-5-git-send-email-stefanb@linux.vnet.ibm.com> In-Reply-To: <1431101720-701152-1-git-send-email-stefanb@linux.vnet.ibm.com> References: <1431101720-701152-1-git-send-email-stefanb@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v2 4/6] Introduce condition to notifiy waiters of completed command List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org, mst@redhat.com Cc: imammedo@redhat.com, kevin@koconnor.net, stefanb@us.ibm.com, quan.xu@intel.com, Stefan Berger Introduce a lock and a condition to notify anyone waiting for the completion of the execution of a TPM command by the backend (thread). The backend uses the condition to signal anyone waiting for command completion. We need to place the condition in two locations: one is invoked by the backend thread, the other by the bottom half thread. We will use the signalling to wait for command completion before VM suspend. Signed-off-by: Stefan Berger --- hw/tpm/tpm_int.h | 3 +++ hw/tpm/tpm_tis.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/hw/tpm/tpm_int.h b/hw/tpm/tpm_int.h index 6b2c9c9..70be1ad 100644 --- a/hw/tpm/tpm_int.h +++ b/hw/tpm/tpm_int.h @@ -30,6 +30,9 @@ struct TPMState { char *backend; TPMBackend *be_driver; TPMVersion be_tpm_version; + + QemuMutex state_lock; + QemuCond cmd_complete; }; #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS) diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c index 1fb4e17..f278e1e 100644 --- a/hw/tpm/tpm_tis.c +++ b/hw/tpm/tpm_tis.c @@ -367,6 +367,8 @@ static void tpm_tis_receive_bh(void *opaque) TPMTISEmuState *tis = &s->s.tis; uint8_t locty = s->locty_number; + qemu_mutex_lock(&s->state_lock); + tpm_tis_sts_set(&tis->loc[locty], TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE); tis->loc[locty].state = TPM_TIS_STATE_COMPLETION; @@ -383,6 +385,10 @@ static void tpm_tis_receive_bh(void *opaque) tpm_tis_raise_irq(s, locty, TPM_TIS_INT_DATA_AVAILABLE | TPM_TIS_INT_STS_VALID); #endif + + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); } /* @@ -402,6 +408,11 @@ static void tpm_tis_receive_cb(TPMState *s, uint8_t locty, } } + qemu_mutex_lock(&s->state_lock); + /* notify of completed command */ + qemu_cond_signal(&s->cmd_complete); + qemu_mutex_unlock(&s->state_lock); + qemu_bh_schedule(tis->bh); } @@ -1097,6 +1108,9 @@ static void tpm_tis_initfn(Object *obj) memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops, s, "tpm-tis-mmio", TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT); + + qemu_mutex_init(&s->state_lock); + qemu_cond_init(&s->cmd_complete); } static void tpm_tis_class_init(ObjectClass *klass, void *data) -- 1.9.3