qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v8 4/8] vmport_rpc: Add the object vmport_rpc


From: Don Slutz
Subject: [Qemu-devel] [PATCH v8 4/8] vmport_rpc: Add the object vmport_rpc
Date: Tue, 23 Jun 2015 19:39:29 -0400

From: Don Slutz <address@hidden>

This is the 1st part of "Add limited support of VMware's hyper-call
rpc".

This patch uses existing infrastructure used by vmmouse.c (provided
by vmport.c) to handle the VMware backdoor command 30.

One of the better on-line references is:

https://sites.google.com/site/chitchatvmback/backdoor

More in next patch.

Signed-off-by: Don Slutz <address@hidden>
CC: Don Slutz <address@hidden>
---
v8:
      Dropped code to always add the new device.
      Add code to check for vmport enabled.


 hw/misc/Makefile.objs |   1 +
 hw/misc/vmport.c      |   8 ++--
 hw/misc/vmport_rpc.c  | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/hw/i386/pc.h  |   2 +-
 4 files changed, 137 insertions(+), 4 deletions(-)
 create mode 100644 hw/misc/vmport_rpc.c

diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 4aa76ff..e04c8ac 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -7,6 +7,7 @@ common-obj-$(CONFIG_ISA_TESTDEV) += pc-testdev.o
 common-obj-$(CONFIG_PCI_TESTDEV) += pci-testdev.o
 
 obj-$(CONFIG_VMPORT) += vmport.o
+obj-$(CONFIG_VMPORT) += vmport_rpc.o
 
 # ARM devices
 common-obj-$(CONFIG_PL310) += arm_l2x0.o
diff --git a/hw/misc/vmport.c b/hw/misc/vmport.c
index 783827d..6794ecf 100644
--- a/hw/misc/vmport.c
+++ b/hw/misc/vmport.c
@@ -50,13 +50,15 @@ typedef struct VMPortState
 
 static VMPortState *port_state;
 
-void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque)
+bool vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque)
 {
-    if (command >= VMPORT_ENTRIES)
-        return;
+    if (command >= VMPORT_ENTRIES || !port_state) {
+        return false;
+    }
 
     port_state->func[command] = func;
     port_state->opaque[command] = opaque;
+    return true;
 }
 
 static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
diff --git a/hw/misc/vmport_rpc.c b/hw/misc/vmport_rpc.c
new file mode 100644
index 0000000..3b1baea
--- /dev/null
+++ b/hw/misc/vmport_rpc.c
@@ -0,0 +1,130 @@
+/*
+ * QEMU VMPORT RPC emulation
+ *
+ * Copyright (C) 2015 Verizon Corporation
+ *
+ * This file is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License Version 2 (GPLv2)
+ * as published by the Free Software Foundation.
+ *
+ * This file 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
+ * General Public License for more details. <http://www.gnu.org/licenses/>.
+ */
+
+/*
+ * One of the better on-line references is:
+ *
+ * https://sites.google.com/site/chitchatvmback/backdoor
+ *
+ * Which points you to:
+ *
+ * http://open-vm-tools.sourceforge.net/
+ *
+ * as a place to get more accurate information by studying.
+ */
+
+#include "hw/hw.h"
+#include "hw/i386/pc.h"
+#include "hw/qdev.h"
+#include "trace.h"
+#include "qmp-commands.h"
+#include "qapi/qmp/qerror.h"
+
+/* #define VMPORT_RPC_DEBUG */
+
+#define TYPE_VMPORT_RPC "vmport_rpc"
+#define VMPORT_RPC(obj) OBJECT_CHECK(VMPortRpcState, (obj), TYPE_VMPORT_RPC)
+
+/* VMPORT RPC Command */
+#define VMPORT_RPC_COMMAND  30
+
+/* The vmport_rpc object. */
+typedef struct VMPortRpcState {
+    ISADevice parent_obj;
+
+    /* Properties */
+    uint64_t reset_time;
+    uint64_t build_number_value;
+    uint64_t build_number_time;
+
+    /* Private data */
+} VMPortRpcState;
+
+typedef struct {
+    uint32_t eax;
+    uint32_t ebx;
+    uint32_t ecx;
+    uint32_t edx;
+    uint32_t esi;
+    uint32_t edi;
+} vregs;
+
+static uint32_t vmport_rpc_ioport_read(void *opaque, uint32_t addr)
+{
+    VMPortRpcState *s = opaque;
+    union {
+        uint32_t data[6];
+        vregs regs;
+    } ur;
+
+    vmmouse_get_data(ur.data);
+
+    s->build_number_time++;
+
+    vmmouse_set_data(ur.data);
+    return ur.data[0];
+}
+
+static void vmport_rpc_reset(DeviceState *d)
+{
+    VMPortRpcState *s = VMPORT_RPC(d);
+
+    s->reset_time = 14;
+    s->build_number_value = 0;
+    s->build_number_time = 0;
+}
+
+static void vmport_rpc_realize(DeviceState *dev, Error **errp)
+{
+    VMPortRpcState *s = VMPORT_RPC(dev);
+
+    if (!vmport_register(VMPORT_RPC_COMMAND, vmport_rpc_ioport_read, s)) {
+        error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+                  "vmport_rpc needs vmport enabled");
+    }
+}
+
+static Property vmport_rpc_properties[] = {
+    DEFINE_PROP_UINT64("reset-time", VMPortRpcState, reset_time, 14),
+    DEFINE_PROP_UINT64("build-number-value", VMPortRpcState,
+                       build_number_value, 0),
+    DEFINE_PROP_UINT64("build-number-time", VMPortRpcState,
+                       build_number_time, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void vmport_rpc_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = vmport_rpc_realize;
+    dc->reset = vmport_rpc_reset;
+    dc->desc = "Enable VMware's hyper-call rpc";
+    dc->props = vmport_rpc_properties;
+}
+
+static const TypeInfo vmport_rpc_info = {
+    .name          = TYPE_VMPORT_RPC,
+    .parent        = TYPE_ISA_DEVICE,
+    .instance_size = sizeof(VMPortRpcState),
+    .class_init    = vmport_rpc_class_init,
+};
+
+static void vmport_rpc_register_types(void)
+{
+    type_register_static(&vmport_rpc_info);
+}
+
+type_init(vmport_rpc_register_types)
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index 86c5651..3270a97 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -142,7 +142,7 @@ static inline void vmport_init(ISABus *bus)
     isa_create_simple(bus, "vmport");
 }
 
-void vmport_register(unsigned char command, VMPortReadFunc *func, void 
*opaque);
+bool vmport_register(unsigned char command, VMPortReadFunc *func, void 
*opaque);
 void vmmouse_get_data(uint32_t *data);
 void vmmouse_set_data(const uint32_t *data);
 
-- 
1.8.3.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]