2007-03-20 16:45:27 +00:00
|
|
|
/*
|
|
|
|
* QEMU VMMouse emulation
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
2007-03-20 16:45:27 +00:00
|
|
|
* Copyright (C) 2007 Anthony Liguori <anthony@codemonkey.ws>
|
2007-09-16 21:08:06 +00:00
|
|
|
*
|
2007-03-20 16:45:27 +00: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.
|
|
|
|
*/
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/hw.h"
|
2012-11-28 11:06:30 +00:00
|
|
|
#include "ui/console.h"
|
2013-02-05 16:06:20 +00:00
|
|
|
#include "hw/input/ps2.h"
|
|
|
|
#include "hw/i386/pc.h"
|
2013-02-04 14:40:22 +00:00
|
|
|
#include "hw/qdev.h"
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
/* debug only vmmouse */
|
|
|
|
//#define DEBUG_VMMOUSE
|
|
|
|
|
|
|
|
/* VMMouse Commands */
|
|
|
|
#define VMMOUSE_GETVERSION 10
|
|
|
|
#define VMMOUSE_DATA 39
|
|
|
|
#define VMMOUSE_STATUS 40
|
|
|
|
#define VMMOUSE_COMMAND 41
|
|
|
|
|
|
|
|
#define VMMOUSE_READ_ID 0x45414552
|
|
|
|
#define VMMOUSE_DISABLE 0x000000f5
|
|
|
|
#define VMMOUSE_REQUEST_RELATIVE 0x4c455252
|
|
|
|
#define VMMOUSE_REQUEST_ABSOLUTE 0x53424152
|
|
|
|
|
|
|
|
#define VMMOUSE_QUEUE_SIZE 1024
|
|
|
|
|
|
|
|
#define VMMOUSE_VERSION 0x3442554a
|
|
|
|
|
|
|
|
#ifdef DEBUG_VMMOUSE
|
|
|
|
#define DPRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
2013-04-27 20:18:53 +00:00
|
|
|
#define TYPE_VMMOUSE "vmmouse"
|
|
|
|
#define VMMOUSE(obj) OBJECT_CHECK(VMMouseState, (obj), TYPE_VMMOUSE)
|
|
|
|
|
|
|
|
typedef struct VMMouseState
|
2007-03-20 16:45:27 +00:00
|
|
|
{
|
2013-04-27 20:18:53 +00:00
|
|
|
ISADevice parent_obj;
|
|
|
|
|
2007-03-20 16:45:27 +00:00
|
|
|
uint32_t queue[VMMOUSE_QUEUE_SIZE];
|
2009-09-10 01:04:40 +00:00
|
|
|
int32_t queue_size;
|
2007-03-20 16:45:27 +00:00
|
|
|
uint16_t nb_queue;
|
|
|
|
uint16_t status;
|
|
|
|
uint8_t absolute;
|
|
|
|
QEMUPutMouseEntry *entry;
|
|
|
|
void *ps2_mouse;
|
|
|
|
} VMMouseState;
|
|
|
|
|
|
|
|
static uint32_t vmmouse_get_status(VMMouseState *s)
|
|
|
|
{
|
|
|
|
DPRINTF("vmmouse_get_status()\n");
|
|
|
|
return (s->status << 16) | s->nb_queue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_mouse_event(void *opaque, int x, int y, int dz, int buttons_state)
|
|
|
|
{
|
|
|
|
VMMouseState *s = opaque;
|
|
|
|
int buttons = 0;
|
|
|
|
|
|
|
|
if (s->nb_queue > (VMMOUSE_QUEUE_SIZE - 4))
|
2007-08-26 17:45:23 +00:00
|
|
|
return;
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
DPRINTF("vmmouse_mouse_event(%d, %d, %d, %d)\n",
|
2007-08-26 17:45:23 +00:00
|
|
|
x, y, dz, buttons_state);
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
if ((buttons_state & MOUSE_EVENT_LBUTTON))
|
2007-08-26 17:45:23 +00:00
|
|
|
buttons |= 0x20;
|
2007-03-20 16:45:27 +00:00
|
|
|
if ((buttons_state & MOUSE_EVENT_RBUTTON))
|
2007-08-26 17:45:23 +00:00
|
|
|
buttons |= 0x10;
|
2007-03-20 16:45:27 +00:00
|
|
|
if ((buttons_state & MOUSE_EVENT_MBUTTON))
|
2007-08-26 17:45:23 +00:00
|
|
|
buttons |= 0x08;
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
if (s->absolute) {
|
2007-08-26 17:45:23 +00:00
|
|
|
x <<= 1;
|
|
|
|
y <<= 1;
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s->queue[s->nb_queue++] = buttons;
|
|
|
|
s->queue[s->nb_queue++] = x;
|
|
|
|
s->queue[s->nb_queue++] = y;
|
|
|
|
s->queue[s->nb_queue++] = dz;
|
|
|
|
|
|
|
|
/* need to still generate PS2 events to notify driver to
|
|
|
|
read from queue */
|
2010-05-22 07:59:01 +00:00
|
|
|
i8042_isa_mouse_fake_event(s->ps2_mouse);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
2010-10-08 10:30:13 +00:00
|
|
|
static void vmmouse_remove_handler(VMMouseState *s)
|
2007-03-20 16:45:27 +00:00
|
|
|
{
|
|
|
|
if (s->entry) {
|
2007-08-26 17:45:23 +00:00
|
|
|
qemu_remove_mouse_event_handler(s->entry);
|
|
|
|
s->entry = NULL;
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
2010-10-08 10:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_update_handler(VMMouseState *s, int absolute)
|
|
|
|
{
|
|
|
|
if (s->status != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (s->absolute != absolute) {
|
|
|
|
s->absolute = absolute;
|
|
|
|
vmmouse_remove_handler(s);
|
|
|
|
}
|
|
|
|
if (s->entry == NULL) {
|
2007-08-26 17:45:23 +00:00
|
|
|
s->entry = qemu_add_mouse_event_handler(vmmouse_mouse_event,
|
|
|
|
s, s->absolute,
|
|
|
|
"vmmouse");
|
2010-10-08 10:30:13 +00:00
|
|
|
qemu_activate_mouse_event_handler(s->entry);
|
|
|
|
}
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_read_id(VMMouseState *s)
|
|
|
|
{
|
|
|
|
DPRINTF("vmmouse_read_id()\n");
|
|
|
|
|
|
|
|
if (s->nb_queue == VMMOUSE_QUEUE_SIZE)
|
2007-08-26 17:45:23 +00:00
|
|
|
return;
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
s->queue[s->nb_queue++] = VMMOUSE_VERSION;
|
|
|
|
s->status = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_request_relative(VMMouseState *s)
|
|
|
|
{
|
|
|
|
DPRINTF("vmmouse_request_relative()\n");
|
2010-10-08 10:30:13 +00:00
|
|
|
vmmouse_update_handler(s, 0);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_request_absolute(VMMouseState *s)
|
|
|
|
{
|
|
|
|
DPRINTF("vmmouse_request_absolute()\n");
|
2010-10-08 10:30:13 +00:00
|
|
|
vmmouse_update_handler(s, 1);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_disable(VMMouseState *s)
|
|
|
|
{
|
|
|
|
DPRINTF("vmmouse_disable()\n");
|
|
|
|
s->status = 0xffff;
|
2010-10-08 10:30:13 +00:00
|
|
|
vmmouse_remove_handler(s);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void vmmouse_data(VMMouseState *s, uint32_t *data, uint32_t size)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
DPRINTF("vmmouse_data(%d)\n", size);
|
|
|
|
|
|
|
|
if (size == 0 || size > 6 || size > s->nb_queue) {
|
2007-08-26 17:45:23 +00:00
|
|
|
printf("vmmouse: driver requested too much data %d\n", size);
|
|
|
|
s->status = 0xffff;
|
2010-10-08 10:30:13 +00:00
|
|
|
vmmouse_remove_handler(s);
|
2007-08-26 17:45:23 +00:00
|
|
|
return;
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
2007-08-26 17:45:23 +00:00
|
|
|
data[i] = s->queue[i];
|
2007-03-20 16:45:27 +00:00
|
|
|
|
|
|
|
s->nb_queue -= size;
|
|
|
|
if (s->nb_queue)
|
2007-08-26 17:45:23 +00:00
|
|
|
memmove(s->queue, &s->queue[size], sizeof(s->queue[0]) * s->nb_queue);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t vmmouse_ioport_read(void *opaque, uint32_t addr)
|
|
|
|
{
|
|
|
|
VMMouseState *s = opaque;
|
|
|
|
uint32_t data[6];
|
|
|
|
uint16_t command;
|
|
|
|
|
|
|
|
vmmouse_get_data(data);
|
|
|
|
|
|
|
|
command = data[2] & 0xFFFF;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case VMMOUSE_STATUS:
|
2007-08-26 17:45:23 +00:00
|
|
|
data[0] = vmmouse_get_status(s);
|
|
|
|
break;
|
2007-03-20 16:45:27 +00:00
|
|
|
case VMMOUSE_COMMAND:
|
2007-08-26 17:45:23 +00:00
|
|
|
switch (data[1]) {
|
|
|
|
case VMMOUSE_DISABLE:
|
|
|
|
vmmouse_disable(s);
|
|
|
|
break;
|
|
|
|
case VMMOUSE_READ_ID:
|
|
|
|
vmmouse_read_id(s);
|
|
|
|
break;
|
|
|
|
case VMMOUSE_REQUEST_RELATIVE:
|
|
|
|
vmmouse_request_relative(s);
|
|
|
|
break;
|
|
|
|
case VMMOUSE_REQUEST_ABSOLUTE:
|
|
|
|
vmmouse_request_absolute(s);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("vmmouse: unknown command %x\n", data[1]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-20 16:45:27 +00:00
|
|
|
case VMMOUSE_DATA:
|
2007-08-26 17:45:23 +00:00
|
|
|
vmmouse_data(s, data, data[1]);
|
|
|
|
break;
|
2007-03-20 16:45:27 +00:00
|
|
|
default:
|
2007-08-26 17:45:23 +00:00
|
|
|
printf("vmmouse: unknown command %x\n", command);
|
|
|
|
break;
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vmmouse_set_data(data);
|
|
|
|
return data[0];
|
|
|
|
}
|
|
|
|
|
2009-09-29 20:48:21 +00:00
|
|
|
static int vmmouse_post_load(void *opaque, int version_id)
|
2007-03-20 16:45:27 +00:00
|
|
|
{
|
|
|
|
VMMouseState *s = opaque;
|
|
|
|
|
2010-10-08 10:30:13 +00:00
|
|
|
vmmouse_remove_handler(s);
|
|
|
|
vmmouse_update_handler(s, s->absolute);
|
2007-03-20 16:45:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-10 01:04:40 +00:00
|
|
|
static const VMStateDescription vmstate_vmmouse = {
|
|
|
|
.name = "vmmouse",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.minimum_version_id_old = 0,
|
|
|
|
.post_load = vmmouse_post_load,
|
|
|
|
.fields = (VMStateField []) {
|
|
|
|
VMSTATE_INT32_EQUAL(queue_size, VMMouseState),
|
|
|
|
VMSTATE_UINT32_ARRAY(queue, VMMouseState, VMMOUSE_QUEUE_SIZE),
|
|
|
|
VMSTATE_UINT16(nb_queue, VMMouseState),
|
|
|
|
VMSTATE_UINT16(status, VMMouseState),
|
|
|
|
VMSTATE_UINT8(absolute, VMMouseState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-02-05 14:34:45 +00:00
|
|
|
static void vmmouse_reset(DeviceState *d)
|
2007-03-20 16:45:27 +00:00
|
|
|
{
|
2013-04-27 20:18:53 +00:00
|
|
|
VMMouseState *s = VMMOUSE(d);
|
2007-03-20 16:45:27 +00:00
|
|
|
|
2011-02-12 17:44:11 +00:00
|
|
|
s->queue_size = VMMOUSE_QUEUE_SIZE;
|
2012-01-25 20:04:14 +00:00
|
|
|
|
|
|
|
vmmouse_disable(s);
|
2011-02-05 14:34:45 +00:00
|
|
|
}
|
2007-03-20 16:45:27 +00:00
|
|
|
|
2012-11-25 01:37:14 +00:00
|
|
|
static void vmmouse_realizefn(DeviceState *dev, Error **errp)
|
2011-02-05 14:34:45 +00:00
|
|
|
{
|
2013-04-27 20:18:53 +00:00
|
|
|
VMMouseState *s = VMMOUSE(dev);
|
2007-03-20 16:45:27 +00:00
|
|
|
|
2011-02-05 14:34:45 +00:00
|
|
|
DPRINTF("vmmouse_init\n");
|
2007-03-20 16:45:27 +00:00
|
|
|
|
2007-08-26 17:46:38 +00:00
|
|
|
vmport_register(VMMOUSE_STATUS, vmmouse_ioport_read, s);
|
|
|
|
vmport_register(VMMOUSE_COMMAND, vmmouse_ioport_read, s);
|
|
|
|
vmport_register(VMMOUSE_DATA, vmmouse_ioport_read, s);
|
2011-02-05 14:34:45 +00:00
|
|
|
}
|
|
|
|
|
2011-12-08 03:34:16 +00:00
|
|
|
static Property vmmouse_properties[] = {
|
|
|
|
DEFINE_PROP_PTR("ps2_mouse", VMMouseState, ps2_mouse),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2011-12-04 17:52:49 +00:00
|
|
|
static void vmmouse_class_initfn(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-11-25 01:37:14 +00:00
|
|
|
|
|
|
|
dc->realize = vmmouse_realizefn;
|
qdev: Replace no_user by cannot_instantiate_with_device_add_yet
In an ideal world, machines can be built by wiring devices together
with configuration, not code. Unfortunately, that's not the world we
live in right now. We still have quite a few devices that need to be
wired up by code. If you try to device_add such a device, it'll fail
in sometimes mysterious ways. If you're lucky, you get an
unmysterious immediate crash.
To protect users from such badness, DeviceClass member no_user used to
make device models unavailable with -device / device_add, but that
regressed in commit 18b6dad. The device model is still omitted from
help, but is available anyway.
Attempts to fix the regression have been rejected with the argument
that the purpose of no_user isn't clear, and it's prone to misuse.
This commit clarifies no_user's purpose. Anthony suggested to rename
it cannot_instantiate_with_device_add_yet_due_to_internal_bugs, which
I shorten somewhat to keep checkpatch happy. While there, make it
bool.
Every use of cannot_instantiate_with_device_add_yet gets a FIXME
comment asking for rationale. The next few commits will clean them
all up, either by providing a rationale, or by getting rid of the use.
With that done, the regression fix is hopefully acceptable.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
2013-11-28 16:26:54 +00:00
|
|
|
dc->cannot_instantiate_with_device_add_yet = true; /* FIXME explain why */
|
2011-12-08 03:34:16 +00:00
|
|
|
dc->reset = vmmouse_reset;
|
|
|
|
dc->vmsd = &vmstate_vmmouse;
|
|
|
|
dc->props = vmmouse_properties;
|
2011-12-04 17:52:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 15:19:07 +00:00
|
|
|
static const TypeInfo vmmouse_info = {
|
2013-04-27 20:18:53 +00:00
|
|
|
.name = TYPE_VMMOUSE,
|
2011-12-08 03:34:16 +00:00
|
|
|
.parent = TYPE_ISA_DEVICE,
|
|
|
|
.instance_size = sizeof(VMMouseState),
|
|
|
|
.class_init = vmmouse_class_initfn,
|
2011-02-05 14:34:45 +00:00
|
|
|
};
|
|
|
|
|
2012-02-09 14:20:55 +00:00
|
|
|
static void vmmouse_register_types(void)
|
2011-02-05 14:34:45 +00:00
|
|
|
{
|
2011-12-08 03:34:16 +00:00
|
|
|
type_register_static(&vmmouse_info);
|
2007-03-20 16:45:27 +00:00
|
|
|
}
|
2012-02-09 14:20:55 +00:00
|
|
|
|
|
|
|
type_init(vmmouse_register_types)
|