[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 5/5] Adapt TPM host backend to use threadlets
From: |
Andreas Niederl |
Subject: |
[Qemu-devel] [PATCH 5/5] Adapt TPM host backend to use threadlets |
Date: |
Fri, 18 Feb 2011 16:33:35 +0100 |
Signed-off-by: Andreas Niederl <address@hidden>
---
Makefile.objs | 3 -
hw/tpm_host_backend.c | 111 ++++++++++++++-----------------------------------
2 files changed, 32 insertions(+), 82 deletions(-)
diff --git a/Makefile.objs b/Makefile.objs
index 55fd6b5..5209a9b 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -285,9 +285,6 @@ hw-obj-$(CONFIG_VIRTFS) += virtio-9p-xattr-user.o
virtio-9p-posix-acl.o
# TPM passthrough device
hw-obj-$(CONFIG_TPM) += tpm_tis.o tpm_backend.o tpm_host_backend.o
-ifndef CONFIG_THREAD
-common-obj-$(CONFIG_TPM) += qemu-thread.o
-endif
######################################################################
# libdis
diff --git a/hw/tpm_host_backend.c b/hw/tpm_host_backend.c
index 4ae9deb..9204ede 100644
--- a/hw/tpm_host_backend.c
+++ b/hw/tpm_host_backend.c
@@ -20,17 +20,11 @@
#include <signal.h>
#include "qemu-common.h"
-#include "qemu-thread.h"
+#include "qemu-threadlet.h"
#include "hw/tpm_int.h"
-typedef struct {
- QemuThread id;
- QemuMutex lock;
- QemuCond send_command;
-} TPMThread;
-
#define STATUS_DONE (1 << 1)
#define STATUS_IN_PROGRESS (1 << 0)
#define STATUS_IDLE 0
@@ -38,7 +32,7 @@ typedef struct {
typedef struct {
TPMDriver common;
- TPMThread thread;
+ ThreadletWork work;
uint8_t send_status;
uint8_t recv_status;
@@ -56,7 +50,6 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty,
uint32_t len)
drv->locty = locty;
- qemu_mutex_lock(&hdrv->thread.lock);
switch (hdrv->send_status) {
case STATUS_IN_PROGRESS:
break;
@@ -65,7 +58,7 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty,
uint32_t len)
hdrv->recv_len = TPM_MAX_PKT;
/* asynchronous send */
n = 1;
- qemu_cond_signal( &hdrv->thread.send_command);
+ submit_work(&hdrv->work);
break;
case STATUS_DONE:
n = hdrv->send_len;
@@ -78,7 +71,6 @@ static int tpm_host_send(TPMDriver *drv, uint8_t locty,
uint32_t len)
hdrv->send_status);
break;
}
- qemu_mutex_unlock(&hdrv->thread.lock);
return n;
}
@@ -90,7 +82,6 @@ static int tpm_host_recv(TPMDriver *drv, uint8_t locty,
uint32_t len)
drv->locty = locty;
- qemu_mutex_lock(&hdrv->thread.lock);
switch (hdrv->recv_status) {
case STATUS_IN_PROGRESS:
break;
@@ -107,7 +98,6 @@ static int tpm_host_recv(TPMDriver *drv, uint8_t locty,
uint32_t len)
hdrv->recv_status);
break;
}
- qemu_mutex_unlock(&hdrv->thread.lock);
return n;
}
@@ -153,82 +143,50 @@ static int unix_read(int fd, uint8_t *buf, uint32_t len)
return len - len1;
}
-static void die2(int err, const char *what)
-{
- fprintf(stderr, "%s failed: %s\n", what, strerror(err));
- abort();
-}
-
-static void die(const char *what)
+static void tpm_host_send_receive(ThreadletWork *work)
{
- die2(errno, what);
-}
-
-static void *tpm_host_thread(void *opaque)
-{
- TPMHostDriver *drv = opaque;
+ TPMHostDriver *drv = container_of(work, TPMHostDriver, work);
TPMDriver *s = &drv->common;
- sigset_t set;
uint32_t tpm_ret;
int ret;
- /* block all signals */
- if (sigfillset(&set)) {
- die("sigfillset");
- }
- if (sigprocmask(SIG_BLOCK, &set, NULL)) {
- die("sigprocmask");
- }
-
- qemu_mutex_lock(&drv->thread.lock);
- while (1) {
- qemu_cond_wait(&drv->thread.send_command, &drv->thread.lock);
- drv->send_status = STATUS_IN_PROGRESS;
- qemu_mutex_unlock(&drv->thread.lock);
+ drv->send_status = STATUS_IN_PROGRESS;
- DSHOW_BUFF(s->buf, "To TPM");
+ DSHOW_BUFF(s->buf, "To TPM");
- ret = unix_write(drv->fd, s->buf, drv->send_len);
+ ret = unix_write(drv->fd, s->buf, drv->send_len);
- qemu_mutex_lock(&drv->thread.lock);
- drv->send_len = ret;
- drv->send_status = STATUS_DONE;
+ drv->send_len = ret;
+ drv->send_status = STATUS_DONE;
- if (ret < 0) {
- fprintf(stderr, "Error: while transmitting data to host tpm"
- ": %s (%i)\n",
- strerror(errno), errno);
- continue;
- }
+ if (ret < 0) {
+ fprintf(stderr, "Error: while transmitting data to host tpm"
+ ": %s (%i)\n",
+ strerror(errno), errno);
+ }
- drv->recv_status = STATUS_IN_PROGRESS;
- qemu_mutex_unlock(&drv->thread.lock);
+ drv->recv_status = STATUS_IN_PROGRESS;
- ret = unix_read(drv->fd, s->buf, drv->recv_len);
+ ret = unix_read(drv->fd, s->buf, drv->recv_len);
- qemu_mutex_lock(&drv->thread.lock);
- drv->recv_len = ret;
- drv->recv_status = STATUS_DONE;
- drv->send_status = STATUS_IDLE;
+ drv->recv_len = ret;
+ drv->recv_status = STATUS_DONE;
+ drv->send_status = STATUS_IDLE;
- if (ret < 0) {
- fprintf(stderr, "Error: while reading data from host tpm"
- ": %s (%i)\n",
- strerror(errno), errno);
- continue;
- }
+ if (ret < 0) {
+ fprintf(stderr, "Error: while reading data from host tpm"
+ ": %s (%i)\n",
+ strerror(errno), errno);
+ }
- DSHOW_BUFF(s->buf, "From TPM");
+ DSHOW_BUFF(s->buf, "From TPM");
- tpm_ret = (s->buf[8])*256 + s->buf[9];
- if (tpm_ret) {
- DPRINTF("tpm command failed with error %d\n", tpm_ret);
- } else {
- DPRINTF("tpm command succeeded\n");
- }
+ tpm_ret = (s->buf[8])*256 + s->buf[9];
+ if (tpm_ret) {
+ DPRINTF("tpm command failed with error %d\n", tpm_ret);
+ } else {
+ DPRINTF("tpm command succeeded\n");
}
-
- return NULL;
}
@@ -236,7 +194,6 @@ TPMDriver *qemu_tpm_host_open(QemuOpts *opts)
{
TPMDriver *drv = NULL;
TPMHostDriver *hdrv = NULL;
- TPMThread *thread = NULL;
char *path = NULL;
int fd = -1;
@@ -263,11 +220,7 @@ TPMDriver *qemu_tpm_host_open(QemuOpts *opts)
}
hdrv->fd = fd;
- thread = &hdrv->thread;
- qemu_mutex_init(&thread->lock);
- qemu_cond_init( &thread->send_command);
-
- qemu_thread_create(&thread->id, &tpm_host_thread, hdrv);
+ hdrv->work.func = tpm_host_send_receive;
return drv;
--
1.7.4.1
Re: [Qemu-devel] [PATCH 1/5] Add TPM 1.2 device interface, Stefan Berger, 2011/02/18
[Qemu-devel] [PATCH 5/5] Adapt TPM host backend to use threadlets,
Andreas Niederl <=