From: Don Slutz <dslutz@verizon.com>
To: qemu-devel@nongnu.org
Cc: xen-devel@lists.xensource.com,
"Marcel Apfelbaum" <marcel.a@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Alexander Graf" <agraf@suse.de>,
"Don Slutz" <dslutz@verizon.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Anthony Liguori" <aliguori@amazon.com>,
"Andreas Färber" <afaerber@suse.de>,
"Stefano Stabellini" <stefano.stabellini@eu.citrix.com>
Subject: [Qemu-devel] [PATCH 1/1] xen-hvm.c: Add support for Xen access to vmport
Date: Fri, 26 Sep 2014 14:47:15 -0400 [thread overview]
Message-ID: <1411757235-29128-2-git-send-email-dslutz@verizon.com> (raw)
In-Reply-To: <1411757235-29128-1-git-send-email-dslutz@verizon.com>
This adds synchronisation of the vcpu registers
between Xen and QEMU.
Signed-off-by: Don Slutz <dslutz@verizon.com>
---
hw/misc/vmport.c | 32 ++++++++++++++++++++------------
include/hw/xen/xen.h | 6 ++++++
vl.c | 1 +
xen-hvm.c | 38 ++++++++++++++++++++++++++++++++++++--
4 files changed, 63 insertions(+), 14 deletions(-)
diff --git a/hw/misc/vmport.c b/hw/misc/vmport.c
index cd5716a..f984b51 100644
--- a/hw/misc/vmport.c
+++ b/hw/misc/vmport.c
@@ -26,6 +26,7 @@
#include "hw/i386/pc.h"
#include "sysemu/kvm.h"
#include "hw/qdev.h"
+#include "hw/xen/xen.h"
//#define VMPORT_DEBUG
@@ -49,6 +50,16 @@ typedef struct VMPortState
static VMPortState *port_state;
+static CPUX86State *vmport_get_env(CPUState *cs)
+{
+ X86CPU *cpu = X86_CPU(cs);
+
+ if (xen_enabled()) {
+ return xen_vmport_env();
+ }
+ return &cpu->env;
+}
+
void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque)
{
if (command >= VMPORT_ENTRIES)
@@ -63,8 +74,7 @@ static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
{
VMPortState *s = opaque;
CPUState *cs = current_cpu;
- X86CPU *cpu = X86_CPU(cs);
- CPUX86State *env = &cpu->env;
+ CPUX86State *env = vmport_get_env(cs);
unsigned char command;
uint32_t eax;
@@ -91,32 +101,31 @@ static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
static void vmport_ioport_write(void *opaque, hwaddr addr,
uint64_t val, unsigned size)
{
- X86CPU *cpu = X86_CPU(current_cpu);
+ CPUX86State *env = vmport_get_env(current_cpu);
- cpu->env.regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
+ env->regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
}
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
{
- X86CPU *cpu = X86_CPU(current_cpu);
+ CPUX86State *env = vmport_get_env(current_cpu);
- cpu->env.regs[R_EBX] = VMPORT_MAGIC;
+ env->regs[R_EBX] = VMPORT_MAGIC;
return 6;
}
static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
{
- X86CPU *cpu = X86_CPU(current_cpu);
+ CPUX86State *env = vmport_get_env(current_cpu);
- cpu->env.regs[R_EBX] = 0x1177;
+ env->regs[R_EBX] = 0x1177;
return ram_size;
}
/* vmmouse helpers */
void vmmouse_get_data(uint32_t *data)
{
- X86CPU *cpu = X86_CPU(current_cpu);
- CPUX86State *env = &cpu->env;
+ CPUX86State *env = vmport_get_env(current_cpu);
data[0] = env->regs[R_EAX]; data[1] = env->regs[R_EBX];
data[2] = env->regs[R_ECX]; data[3] = env->regs[R_EDX];
@@ -125,8 +134,7 @@ void vmmouse_get_data(uint32_t *data)
void vmmouse_set_data(const uint32_t *data)
{
- X86CPU *cpu = X86_CPU(current_cpu);
- CPUX86State *env = &cpu->env;
+ CPUX86State *env = vmport_get_env(current_cpu);
env->regs[R_EAX] = data[0]; env->regs[R_EBX] = data[1];
env->regs[R_ECX] = data[2]; env->regs[R_EDX] = data[3];
diff --git a/include/hw/xen/xen.h b/include/hw/xen/xen.h
index f71f2d8..8ea328c 100644
--- a/include/hw/xen/xen.h
+++ b/include/hw/xen/xen.h
@@ -22,12 +22,18 @@ extern uint32_t xen_domid;
extern enum xen_mode xen_mode;
extern bool xen_allowed;
+extern void *xen_opaque_env;
static inline bool xen_enabled(void)
{
return xen_allowed;
}
+static inline void *xen_vmport_env(void)
+{
+ return xen_opaque_env;
+}
+
int xen_pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num);
void xen_piix3_set_irq(void *opaque, int irq_num, int level);
void xen_piix_pci_write_config_client(uint32_t address, uint32_t val, int len);
diff --git a/vl.c b/vl.c
index dbdca59..443a9f5 100644
--- a/vl.c
+++ b/vl.c
@@ -215,6 +215,7 @@ static NotifierList machine_init_done_notifiers =
static bool tcg_allowed = true;
bool xen_allowed;
uint32_t xen_domid;
+void *xen_opaque_env;
enum xen_mode xen_mode = XEN_EMULATE;
static int tcg_tb_size;
diff --git a/xen-hvm.c b/xen-hvm.c
index 05e522c..e1274bb 100644
--- a/xen-hvm.c
+++ b/xen-hvm.c
@@ -857,14 +857,48 @@ static void cpu_handle_ioreq(void *opaque)
handle_buffered_iopage(state);
if (req) {
+#ifdef IOREQ_TYPE_VMWARE_PORT
+ if (req->type == IOREQ_TYPE_VMWARE_PORT) {
+ CPUX86State *env;
+ ioreq_t fake_req = {
+ .type = IOREQ_TYPE_PIO,
+ .addr = (uint16_t)req->size,
+ .size = 4,
+ .dir = IOREQ_READ,
+ .df = 0,
+ .data_is_ptr = 0,
+ };
+ if (!xen_opaque_env) {
+ xen_opaque_env = g_malloc(sizeof(CPUX86State));
+ }
+ env = xen_opaque_env;
+ env->regs[R_EAX] = (uint32_t)(req->addr >> 32);
+ env->regs[R_EBX] = (uint32_t)(req->addr);
+ env->regs[R_ECX] = req->count;
+ env->regs[R_EDX] = req->size;
+ env->regs[R_ESI] = (uint32_t)(req->data >> 32);
+ env->regs[R_EDI] = (uint32_t)(req->data);
+ handle_ioreq(&fake_req);
+ req->addr = ((uint64_t)fake_req.data << 32) |
+ (uint32_t)env->regs[R_EBX];
+ req->count = env->regs[R_ECX];
+ req->size = env->regs[R_EDX];
+ req->data = ((uint64_t)env->regs[R_ESI] << 32) |
+ (uint32_t)env->regs[R_EDI];
+ } else {
+ handle_ioreq(req);
+ }
+#else
handle_ioreq(req);
+#endif
if (req->state != STATE_IOREQ_INPROCESS) {
fprintf(stderr, "Badness in I/O request ... not in service?!: "
"%x, ptr: %x, port: %"PRIx64", "
- "data: %"PRIx64", count: %" FMT_ioreq_size ", size: %" FMT_ioreq_size "\n",
+ "data: %"PRIx64", count: %" FMT_ioreq_size
+ ", size: %" FMT_ioreq_size ", type: %"FMT_ioreq_size"\n",
req->state, req->data_is_ptr, req->addr,
- req->data, req->count, req->size);
+ req->data, req->count, req->size, req->type);
destroy_hvm_domain(false);
return;
}
--
1.8.4
next prev parent reply other threads:[~2014-09-26 18:47 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-26 18:47 [Qemu-devel] [PATCH 0/1] Add support for Xen access to vmport Don Slutz
2014-09-26 18:47 ` Don Slutz [this message]
2014-09-29 8:12 ` [Qemu-devel] [PATCH 1/1] xen-hvm.c: " Alexander Graf
2014-09-29 11:10 ` Paolo Bonzini
2014-09-29 11:53 ` Alexander Graf
2014-09-29 12:21 ` Paolo Bonzini
2014-09-29 12:57 ` Alexander Graf
2014-09-29 13:14 ` Paolo Bonzini
2014-09-30 1:05 ` Don Slutz
2014-09-30 8:14 ` Paolo Bonzini
2014-09-30 1:00 ` Don Slutz
2014-09-29 10:15 ` Stefano Stabellini
2014-09-29 10:25 ` Stefano Stabellini
2014-09-30 0:32 ` Don Slutz
2014-09-30 10:35 ` Stefano Stabellini
2014-10-01 5:21 ` Slutz, Donald Christopher
2014-10-01 9:20 ` Stefano Stabellini
2014-10-01 12:33 ` Don Slutz
2014-10-01 14:44 ` [Qemu-devel] [Xen-devel] " Ian Campbell
2014-10-01 16:01 ` Anthony Liguori
2014-10-01 15:08 ` [Qemu-devel] " Paul Durrant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411757235-29128-2-git-send-email-dslutz@verizon.com \
--to=dslutz@verizon.com \
--cc=afaerber@suse.de \
--cc=agraf@suse.de \
--cc=aliguori@amazon.com \
--cc=armbru@redhat.com \
--cc=marcel.a@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).