@@ -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
@@ -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,
new file mode 100644
@@ -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)
@@ -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);