mirror of https://gitee.com/openkylin/qemu.git
hid: introduce hid vmstate macros
Add VMSTATE macros to describe a HIDState. Based on usb-hid.c descriptions. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
parent
bb0db5273f
commit
ccd4ed065b
58
hw/hid.c
58
hw/hid.c
|
@ -407,3 +407,61 @@ void hid_init(HIDState *hs, int kind, HIDEventFunc event)
|
||||||
1, "QEMU HID Tablet");
|
1, "QEMU HID Tablet");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int hid_post_load(void *opaque, int version_id)
|
||||||
|
{
|
||||||
|
HIDState *s = opaque;
|
||||||
|
|
||||||
|
if (s->idle) {
|
||||||
|
hid_set_next_idle(s, qemu_get_clock_ns(vm_clock));
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const VMStateDescription vmstate_hid_ptr_queue = {
|
||||||
|
.name = "HIDPointerEventQueue",
|
||||||
|
.version_id = 1,
|
||||||
|
.minimum_version_id = 1,
|
||||||
|
.fields = (VMStateField[]) {
|
||||||
|
VMSTATE_INT32(xdx, HIDPointerEvent),
|
||||||
|
VMSTATE_INT32(ydy, HIDPointerEvent),
|
||||||
|
VMSTATE_INT32(dz, HIDPointerEvent),
|
||||||
|
VMSTATE_INT32(buttons_state, HIDPointerEvent),
|
||||||
|
VMSTATE_END_OF_LIST()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const VMStateDescription vmstate_hid_ptr_device = {
|
||||||
|
.name = "HIDPointerDevice",
|
||||||
|
.version_id = 1,
|
||||||
|
.minimum_version_id = 1,
|
||||||
|
.post_load = hid_post_load,
|
||||||
|
.fields = (VMStateField[]) {
|
||||||
|
VMSTATE_STRUCT_ARRAY(ptr.queue, HIDState, QUEUE_LENGTH, 0,
|
||||||
|
vmstate_hid_ptr_queue, HIDPointerEvent),
|
||||||
|
VMSTATE_UINT32(head, HIDState),
|
||||||
|
VMSTATE_UINT32(n, HIDState),
|
||||||
|
VMSTATE_INT32(protocol, HIDState),
|
||||||
|
VMSTATE_UINT8(idle, HIDState),
|
||||||
|
VMSTATE_END_OF_LIST(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const VMStateDescription vmstate_hid_keyboard_device = {
|
||||||
|
.name = "HIDKeyboardDevice",
|
||||||
|
.version_id = 1,
|
||||||
|
.minimum_version_id = 1,
|
||||||
|
.post_load = hid_post_load,
|
||||||
|
.fields = (VMStateField[]) {
|
||||||
|
VMSTATE_UINT32_ARRAY(kbd.keycodes, HIDState, QUEUE_LENGTH),
|
||||||
|
VMSTATE_UINT32(head, HIDState),
|
||||||
|
VMSTATE_UINT32(n, HIDState),
|
||||||
|
VMSTATE_UINT16(kbd.modifiers, HIDState),
|
||||||
|
VMSTATE_UINT8(kbd.leds, HIDState),
|
||||||
|
VMSTATE_UINT8_ARRAY(kbd.key, HIDState, 16),
|
||||||
|
VMSTATE_INT32(kbd.keys, HIDState),
|
||||||
|
VMSTATE_INT32(protocol, HIDState),
|
||||||
|
VMSTATE_UINT8(idle, HIDState),
|
||||||
|
VMSTATE_END_OF_LIST(),
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
20
hw/hw.h
20
hw/hw.h
|
@ -701,6 +701,26 @@ extern const VMStateDescription vmstate_ptimer;
|
||||||
.offset = vmstate_offset_pointer(_state, _field, ptimer_state), \
|
.offset = vmstate_offset_pointer(_state, _field, ptimer_state), \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern const VMStateDescription vmstate_hid_keyboard_device;
|
||||||
|
|
||||||
|
#define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) { \
|
||||||
|
.name = (stringify(_field)), \
|
||||||
|
.size = sizeof(HIDState), \
|
||||||
|
.vmsd = &vmstate_hid_keyboard_device, \
|
||||||
|
.flags = VMS_STRUCT, \
|
||||||
|
.offset = vmstate_offset_value(_state, _field, HIDState), \
|
||||||
|
}
|
||||||
|
|
||||||
|
extern const VMStateDescription vmstate_hid_ptr_device;
|
||||||
|
|
||||||
|
#define VMSTATE_HID_POINTER_DEVICE(_field, _state) { \
|
||||||
|
.name = (stringify(_field)), \
|
||||||
|
.size = sizeof(HIDState), \
|
||||||
|
.vmsd = &vmstate_hid_ptr_device, \
|
||||||
|
.flags = VMS_STRUCT, \
|
||||||
|
.offset = vmstate_offset_value(_state, _field, HIDState), \
|
||||||
|
}
|
||||||
|
|
||||||
/* _f : field name
|
/* _f : field name
|
||||||
_f_n : num of elements field_name
|
_f_n : num of elements field_name
|
||||||
_n : num of elements
|
_n : num of elements
|
||||||
|
|
Loading…
Reference in New Issue