Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Introduce condition to notify waiters of completed command
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 <stefanb@linux.vnet.ibm.com>
  • Loading branch information
stefanberger committed Dec 31, 2016
1 parent 27d6cd8 commit 9d8c9c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions hw/tpm/tpm_int.h
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions hw/tpm/tpm_tis.c
Expand Up @@ -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;
Expand All @@ -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);
}

/*
Expand All @@ -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);
}

Expand Down Expand Up @@ -1071,6 +1082,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)
Expand Down

0 comments on commit 9d8c9c3

Please sign in to comment.