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 <dsl...@verizon.com>
---
 hw/i386/pc.c          |   6 +++
 hw/misc/Makefile.objs |   1 +
 hw/misc/vmport_rpc.c  | 126 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 133 insertions(+)
 create mode 100644 hw/misc/vmport_rpc.c

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index c7af6aa..efae4d5 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1435,8 +1435,14 @@ void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi,
     i8042 = isa_create_simple(isa_bus, "i8042");
     i8042_setup_a20_line(i8042, &a20_line[0]);
     if (!no_vmport) {
+        ISADevice *vmport_rpc;
+
         vmport_init(isa_bus);
         vmmouse = isa_try_create(isa_bus, "vmmouse");
+        vmport_rpc = isa_try_create(isa_bus, "vmport_rpc");
+        if (vmport_rpc) {
+            qdev_init_nofail(DEVICE(vmport_rpc));
+        }
     } else {
         vmmouse = NULL;
     }
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 029a56f..5496992 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_rpc.c b/hw/misc/vmport_rpc.c
new file mode 100644
index 0000000..da724a4
--- /dev/null
+++ b/hw/misc/vmport_rpc.c
@@ -0,0 +1,126 @@
+/*
+ * 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_realizefn(DeviceState *dev, Error **errp)
+{
+    VMPortRpcState *s = VMPORT_RPC(dev);
+
+    vmport_register(VMPORT_RPC_COMMAND, vmport_rpc_ioport_read, s);
+}
+
+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_initfn(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = vmport_rpc_realizefn;
+    dc->reset = vmport_rpc_reset;
+    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_initfn,
+};
+
+static void vmport_rpc_register_types(void)
+{
+    type_register_static(&vmport_rpc_info);
+}
+
+type_init(vmport_rpc_register_types)
-- 
1.8.4


Reply via email to