2007-08-26 19:48:12 +02:00
|
|
|
/*
|
|
|
|
* QEMU VMPort emulation
|
|
|
|
*
|
2011-12-02 10:30:41 +01:00
|
|
|
* Copyright (C) 2007 Hervé Poussineau
|
2007-08-26 19:48:12 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2020-03-12 17:54:16 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Guest code that interacts with this virtual device can be found
|
|
|
|
* in VMware open-vm-tools open-source project:
|
|
|
|
* https://github.com/vmware/open-vm-tools
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:17:17 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/isa/isa.h"
|
2017-01-10 11:59:55 +01:00
|
|
|
#include "sysemu/hw_accel.h"
|
2017-12-21 22:11:03 +01:00
|
|
|
#include "qemu/log.h"
|
2020-05-04 10:33:41 +02:00
|
|
|
#include "vmport.h"
|
2020-05-04 10:33:42 +02:00
|
|
|
#include "cpu.h"
|
2017-12-15 04:43:55 +01:00
|
|
|
#include "trace.h"
|
2008-08-19 21:13:06 +02:00
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
#define VMPORT_CMD_GETVERSION 0x0a
|
|
|
|
#define VMPORT_CMD_GETRAMSIZE 0x14
|
|
|
|
|
|
|
|
#define VMPORT_ENTRIES 0x2c
|
|
|
|
#define VMPORT_MAGIC 0x564D5868
|
|
|
|
|
2013-04-27 22:18:54 +02:00
|
|
|
#define VMPORT(obj) OBJECT_CHECK(VMPortState, (obj), TYPE_VMPORT)
|
|
|
|
|
2017-10-17 18:44:24 +02:00
|
|
|
typedef struct VMPortState {
|
2013-04-27 22:18:54 +02:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2011-08-16 17:38:14 +02:00
|
|
|
MemoryRegion io;
|
2013-06-22 08:07:06 +02:00
|
|
|
VMPortReadFunc *func[VMPORT_ENTRIES];
|
2007-08-26 19:48:12 +02:00
|
|
|
void *opaque[VMPORT_ENTRIES];
|
|
|
|
} VMPortState;
|
|
|
|
|
2011-02-17 04:27:19 +01:00
|
|
|
static VMPortState *port_state;
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2013-06-22 08:07:06 +02:00
|
|
|
void vmport_register(unsigned char command, VMPortReadFunc *func, void *opaque)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
2017-10-17 18:44:24 +02:00
|
|
|
if (command >= VMPORT_ENTRIES) {
|
2007-08-26 19:48:12 +02:00
|
|
|
return;
|
2017-10-17 18:44:24 +02:00
|
|
|
}
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2017-12-15 04:43:55 +01:00
|
|
|
trace_vmport_register(command, func, opaque);
|
2011-02-17 04:27:19 +01:00
|
|
|
port_state->func[command] = func;
|
|
|
|
port_state->opaque[command] = opaque;
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
|
|
|
|
2012-10-08 13:44:24 +02:00
|
|
|
static uint64_t vmport_ioport_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
|
|
|
VMPortState *s = opaque;
|
2013-05-27 05:17:50 +02:00
|
|
|
CPUState *cs = current_cpu;
|
|
|
|
X86CPU *cpu = X86_CPU(cs);
|
|
|
|
CPUX86State *env = &cpu->env;
|
2007-08-26 19:48:12 +02:00
|
|
|
unsigned char command;
|
2007-10-09 05:19:01 +02:00
|
|
|
uint32_t eax;
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu_synchronize_state(cs);
|
2010-02-03 21:16:41 +01:00
|
|
|
|
2008-04-07 21:47:25 +02:00
|
|
|
eax = env->regs[R_EAX];
|
2017-10-17 18:44:24 +02:00
|
|
|
if (eax != VMPORT_MAGIC) {
|
2007-08-26 19:48:12 +02:00
|
|
|
return eax;
|
2017-10-17 18:44:24 +02:00
|
|
|
}
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2008-04-07 21:47:25 +02:00
|
|
|
command = env->regs[R_ECX];
|
2017-12-15 04:43:55 +01:00
|
|
|
trace_vmport_command(command);
|
|
|
|
if (command >= VMPORT_ENTRIES || !s->func[command]) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "vmport: unknown command %x\n", command);
|
2007-08-26 19:48:12 +02:00
|
|
|
return eax;
|
|
|
|
}
|
|
|
|
|
|
|
|
return s->func[command](s->opaque[command], addr);
|
|
|
|
}
|
|
|
|
|
2012-10-08 13:44:24 +02:00
|
|
|
static void vmport_ioport_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2008-07-28 20:58:02 +02:00
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
2008-07-28 20:58:02 +02:00
|
|
|
|
2013-05-27 05:17:50 +02:00
|
|
|
cpu->env.regs[R_EAX] = vmport_ioport_read(opaque, addr, 4);
|
2008-07-28 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
2007-08-26 19:48:12 +02:00
|
|
|
static uint32_t vmport_cmd_get_version(void *opaque, uint32_t addr)
|
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
|
|
|
|
cpu->env.regs[R_EBX] = VMPORT_MAGIC;
|
2007-08-26 19:48:12 +02:00
|
|
|
return 6;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t vmport_cmd_ram_size(void *opaque, uint32_t addr)
|
|
|
|
{
|
2013-05-27 05:17:50 +02:00
|
|
|
X86CPU *cpu = X86_CPU(current_cpu);
|
|
|
|
|
|
|
|
cpu->env.regs[R_EBX] = 0x1177;
|
2007-08-26 19:48:12 +02:00
|
|
|
return ram_size;
|
|
|
|
}
|
|
|
|
|
2011-08-16 17:38:14 +02:00
|
|
|
static const MemoryRegionOps vmport_ops = {
|
2012-10-08 13:44:24 +02:00
|
|
|
.read = vmport_ioport_read,
|
|
|
|
.write = vmport_ioport_write,
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 4,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-16 17:38:14 +02:00
|
|
|
};
|
|
|
|
|
2012-11-25 02:37:14 +01:00
|
|
|
static void vmport_realizefn(DeviceState *dev, Error **errp)
|
2007-08-26 19:48:12 +02:00
|
|
|
{
|
2012-11-25 02:37:14 +01:00
|
|
|
ISADevice *isadev = ISA_DEVICE(dev);
|
2013-04-27 22:18:54 +02:00
|
|
|
VMPortState *s = VMPORT(dev);
|
2007-08-26 19:48:12 +02:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->io, OBJECT(s), &vmport_ops, s, "vmport", 1);
|
2012-11-25 02:37:14 +01:00
|
|
|
isa_register_ioport(isadev, &s->io, 0x5658);
|
2011-08-16 17:38:14 +02:00
|
|
|
|
2011-02-17 04:27:19 +01:00
|
|
|
port_state = s;
|
2007-08-26 19:48:12 +02:00
|
|
|
/* Register some generic port commands */
|
2008-04-07 21:47:25 +02:00
|
|
|
vmport_register(VMPORT_CMD_GETVERSION, vmport_cmd_get_version, NULL);
|
|
|
|
vmport_register(VMPORT_CMD_GETRAMSIZE, vmport_cmd_ram_size, NULL);
|
2007-08-26 19:48:12 +02:00
|
|
|
}
|
2011-02-05 15:34:41 +01:00
|
|
|
|
2011-12-04 18:52:49 +01:00
|
|
|
static void vmport_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-11-25 02:37:14 +01:00
|
|
|
|
|
|
|
dc->realize = vmport_realizefn;
|
2013-11-28 17:27:02 +01:00
|
|
|
/* Reason: realize sets global port_state */
|
2017-05-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2011-12-04 18:52:49 +01:00
|
|
|
}
|
|
|
|
|
2013-01-10 16:19:07 +01:00
|
|
|
static const TypeInfo vmport_info = {
|
2013-04-27 22:18:54 +02:00
|
|
|
.name = TYPE_VMPORT,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(VMPortState),
|
|
|
|
.class_init = vmport_class_initfn,
|
2011-02-05 15:34:41 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void vmport_register_types(void)
|
2011-02-05 15:34:41 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&vmport_info);
|
2011-02-05 15:34:41 +01:00
|
|
|
}
|
2012-02-09 15:20:55 +01:00
|
|
|
|
|
|
|
type_init(vmport_register_types)
|