Port PS2 devices to VMState design
This uses STRUCT and BUFFER Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
6f67c50ff4
commit
b31442c31e
117
hw/ps2.c
117
hw/ps2.c
|
@ -526,59 +526,29 @@ static void ps2_mouse_reset(void *opaque)
|
||||||
s->mouse_buttons = 0;
|
s->mouse_buttons = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ps2_common_save (QEMUFile *f, PS2State *s)
|
static const VMStateDescription vmstate_ps2_common = {
|
||||||
{
|
.name = "PS2 Common State",
|
||||||
qemu_put_be32 (f, s->write_cmd);
|
.version_id = 3,
|
||||||
qemu_put_be32 (f, s->queue.rptr);
|
.minimum_version_id = 2,
|
||||||
qemu_put_be32 (f, s->queue.wptr);
|
.minimum_version_id_old = 2,
|
||||||
qemu_put_be32 (f, s->queue.count);
|
.fields = (VMStateField []) {
|
||||||
qemu_put_buffer (f, s->queue.data, sizeof (s->queue.data));
|
VMSTATE_INT32(write_cmd, PS2State),
|
||||||
|
VMSTATE_INT32(queue.rptr, PS2State),
|
||||||
|
VMSTATE_INT32(queue.wptr, PS2State),
|
||||||
|
VMSTATE_INT32(queue.count, PS2State),
|
||||||
|
VMSTATE_BUFFER(queue.data, PS2State),
|
||||||
|
VMSTATE_END_OF_LIST()
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
static void ps2_common_load (QEMUFile *f, PS2State *s)
|
static int ps2_kbd_load_old(QEMUFile* f, void* opaque, int version_id)
|
||||||
{
|
|
||||||
s->write_cmd=qemu_get_be32 (f);
|
|
||||||
s->queue.rptr=qemu_get_be32 (f);
|
|
||||||
s->queue.wptr=qemu_get_be32 (f);
|
|
||||||
s->queue.count=qemu_get_be32 (f);
|
|
||||||
qemu_get_buffer (f, s->queue.data, sizeof (s->queue.data));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ps2_kbd_save(QEMUFile* f, void* opaque)
|
|
||||||
{
|
|
||||||
PS2KbdState *s = (PS2KbdState*)opaque;
|
|
||||||
|
|
||||||
ps2_common_save (f, &s->common);
|
|
||||||
qemu_put_be32(f, s->scan_enabled);
|
|
||||||
qemu_put_be32(f, s->translate);
|
|
||||||
qemu_put_be32(f, s->scancode_set);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ps2_mouse_save(QEMUFile* f, void* opaque)
|
|
||||||
{
|
|
||||||
PS2MouseState *s = (PS2MouseState*)opaque;
|
|
||||||
|
|
||||||
ps2_common_save (f, &s->common);
|
|
||||||
qemu_put_8s(f, &s->mouse_status);
|
|
||||||
qemu_put_8s(f, &s->mouse_resolution);
|
|
||||||
qemu_put_8s(f, &s->mouse_sample_rate);
|
|
||||||
qemu_put_8s(f, &s->mouse_wrap);
|
|
||||||
qemu_put_8s(f, &s->mouse_type);
|
|
||||||
qemu_put_8s(f, &s->mouse_detect_state);
|
|
||||||
qemu_put_be32(f, s->mouse_dx);
|
|
||||||
qemu_put_be32(f, s->mouse_dy);
|
|
||||||
qemu_put_be32(f, s->mouse_dz);
|
|
||||||
qemu_put_8s(f, &s->mouse_buttons);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ps2_kbd_load(QEMUFile* f, void* opaque, int version_id)
|
|
||||||
{
|
{
|
||||||
PS2KbdState *s = (PS2KbdState*)opaque;
|
PS2KbdState *s = (PS2KbdState*)opaque;
|
||||||
|
|
||||||
if (version_id != 2 && version_id != 3)
|
if (version_id != 2 && version_id != 3)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
ps2_common_load (f, &s->common);
|
vmstate_load_state(f, &vmstate_ps2_common, &s->common, version_id);
|
||||||
s->scan_enabled=qemu_get_be32(f);
|
s->scan_enabled=qemu_get_be32(f);
|
||||||
s->translate=qemu_get_be32(f);
|
s->translate=qemu_get_be32(f);
|
||||||
if (version_id == 3)
|
if (version_id == 3)
|
||||||
|
@ -588,26 +558,41 @@ static int ps2_kbd_load(QEMUFile* f, void* opaque, int version_id)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ps2_mouse_load(QEMUFile* f, void* opaque, int version_id)
|
static const VMStateDescription vmstate_ps2_keyboard = {
|
||||||
{
|
.name = "ps2kbd",
|
||||||
PS2MouseState *s = (PS2MouseState*)opaque;
|
.version_id = 3,
|
||||||
|
.minimum_version_id = 3,
|
||||||
if (version_id != 2)
|
.minimum_version_id_old = 2,
|
||||||
return -EINVAL;
|
.load_state_old = ps2_kbd_load_old,
|
||||||
|
.fields = (VMStateField []) {
|
||||||
ps2_common_load (f, &s->common);
|
VMSTATE_STRUCT(common, PS2KbdState, 0, vmstate_ps2_common, PS2State),
|
||||||
qemu_get_8s(f, &s->mouse_status);
|
VMSTATE_INT32(scan_enabled, PS2KbdState),
|
||||||
qemu_get_8s(f, &s->mouse_resolution);
|
VMSTATE_INT32(translate, PS2KbdState),
|
||||||
qemu_get_8s(f, &s->mouse_sample_rate);
|
VMSTATE_INT32_V(scancode_set, PS2KbdState,3),
|
||||||
qemu_get_8s(f, &s->mouse_wrap);
|
VMSTATE_END_OF_LIST()
|
||||||
qemu_get_8s(f, &s->mouse_type);
|
|
||||||
qemu_get_8s(f, &s->mouse_detect_state);
|
|
||||||
s->mouse_dx=qemu_get_be32(f);
|
|
||||||
s->mouse_dy=qemu_get_be32(f);
|
|
||||||
s->mouse_dz=qemu_get_be32(f);
|
|
||||||
qemu_get_8s(f, &s->mouse_buttons);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static const VMStateDescription vmstate_ps2_mouse = {
|
||||||
|
.name = "ps2mouse",
|
||||||
|
.version_id = 2,
|
||||||
|
.minimum_version_id = 2,
|
||||||
|
.minimum_version_id_old = 2,
|
||||||
|
.fields = (VMStateField []) {
|
||||||
|
VMSTATE_STRUCT(common, PS2MouseState, 0, vmstate_ps2_common, PS2State),
|
||||||
|
VMSTATE_UINT8(mouse_status, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_resolution, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_sample_rate, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_wrap, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_type, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_detect_state, PS2MouseState),
|
||||||
|
VMSTATE_INT32(mouse_dx, PS2MouseState),
|
||||||
|
VMSTATE_INT32(mouse_dy, PS2MouseState),
|
||||||
|
VMSTATE_INT32(mouse_dz, PS2MouseState),
|
||||||
|
VMSTATE_UINT8(mouse_buttons, PS2MouseState),
|
||||||
|
VMSTATE_END_OF_LIST()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg)
|
void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg)
|
||||||
{
|
{
|
||||||
|
@ -617,7 +602,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg)
|
||||||
s->common.update_arg = update_arg;
|
s->common.update_arg = update_arg;
|
||||||
s->scancode_set = 2;
|
s->scancode_set = 2;
|
||||||
ps2_kbd_reset(s);
|
ps2_kbd_reset(s);
|
||||||
register_savevm("ps2kbd", 0, 3, ps2_kbd_save, ps2_kbd_load, s);
|
vmstate_register(0, &vmstate_ps2_keyboard, s);
|
||||||
qemu_add_kbd_event_handler(ps2_put_keycode, s);
|
qemu_add_kbd_event_handler(ps2_put_keycode, s);
|
||||||
qemu_register_reset(ps2_kbd_reset, s);
|
qemu_register_reset(ps2_kbd_reset, s);
|
||||||
return s;
|
return s;
|
||||||
|
@ -630,7 +615,7 @@ void *ps2_mouse_init(void (*update_irq)(void *, int), void *update_arg)
|
||||||
s->common.update_irq = update_irq;
|
s->common.update_irq = update_irq;
|
||||||
s->common.update_arg = update_arg;
|
s->common.update_arg = update_arg;
|
||||||
ps2_mouse_reset(s);
|
ps2_mouse_reset(s);
|
||||||
register_savevm("ps2mouse", 0, 2, ps2_mouse_save, ps2_mouse_load, s);
|
vmstate_register(0, &vmstate_ps2_mouse, s);
|
||||||
qemu_add_mouse_event_handler(ps2_mouse_event, s, 0, "QEMU PS/2 Mouse");
|
qemu_add_mouse_event_handler(ps2_mouse_event, s, 0, "QEMU PS/2 Mouse");
|
||||||
qemu_register_reset(ps2_mouse_reset, s);
|
qemu_register_reset(ps2_mouse_reset, s);
|
||||||
return s;
|
return s;
|
||||||
|
|
Loading…
Reference in a new issue