diff options
author | Juan Quintela <quintela@redhat.com> | 2009-08-20 19:42:36 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-08-27 20:30:22 -0500 |
commit | b31442c31e0b7aaeebce5128700752997c8e495f (patch) | |
tree | f33e2f6baa990d7d8159bd9e6bf9b10195fd7e9b | |
parent | 6f67c50ff42943a2ae51202dad0ef996dc40bb51 (diff) |
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>
-rw-r--r-- | hw/ps2.c | 119 |
1 files changed, 52 insertions, 67 deletions
@@ -526,59 +526,29 @@ static void ps2_mouse_reset(void *opaque) s->mouse_buttons = 0; } -static void ps2_common_save (QEMUFile *f, PS2State *s) -{ - qemu_put_be32 (f, s->write_cmd); - qemu_put_be32 (f, s->queue.rptr); - qemu_put_be32 (f, s->queue.wptr); - qemu_put_be32 (f, s->queue.count); - qemu_put_buffer (f, s->queue.data, sizeof (s->queue.data)); -} - -static void ps2_common_load (QEMUFile *f, PS2State *s) -{ - 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 const VMStateDescription vmstate_ps2_common = { + .name = "PS2 Common State", + .version_id = 3, + .minimum_version_id = 2, + .minimum_version_id_old = 2, + .fields = (VMStateField []) { + 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 int ps2_kbd_load(QEMUFile* f, void* opaque, int version_id) +static int ps2_kbd_load_old(QEMUFile* f, void* opaque, int version_id) { PS2KbdState *s = (PS2KbdState*)opaque; if (version_id != 2 && version_id != 3) 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->translate=qemu_get_be32(f); if (version_id == 3) @@ -588,26 +558,41 @@ static int ps2_kbd_load(QEMUFile* f, void* opaque, int version_id) return 0; } -static int ps2_mouse_load(QEMUFile* f, void* opaque, int version_id) -{ - PS2MouseState *s = (PS2MouseState*)opaque; - - if (version_id != 2) - return -EINVAL; +static const VMStateDescription vmstate_ps2_keyboard = { + .name = "ps2kbd", + .version_id = 3, + .minimum_version_id = 3, + .minimum_version_id_old = 2, + .load_state_old = ps2_kbd_load_old, + .fields = (VMStateField []) { + VMSTATE_STRUCT(common, PS2KbdState, 0, vmstate_ps2_common, PS2State), + VMSTATE_INT32(scan_enabled, PS2KbdState), + VMSTATE_INT32(translate, PS2KbdState), + VMSTATE_INT32_V(scancode_set, PS2KbdState,3), + VMSTATE_END_OF_LIST() + } +}; - ps2_common_load (f, &s->common); - qemu_get_8s(f, &s->mouse_status); - qemu_get_8s(f, &s->mouse_resolution); - qemu_get_8s(f, &s->mouse_sample_rate); - qemu_get_8s(f, &s->mouse_wrap); - 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) { @@ -617,7 +602,7 @@ void *ps2_kbd_init(void (*update_irq)(void *, int), void *update_arg) s->common.update_arg = update_arg; s->scancode_set = 2; 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_register_reset(ps2_kbd_reset, 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_arg = update_arg; 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_register_reset(ps2_mouse_reset, s); return s; |