1#ifndef QEMU_HID_H
2#define QEMU_HID_H
3
4#include "migration/vmstate.h"
5
6#define HID_MOUSE 1
7#define HID_TABLET 2
8#define HID_KEYBOARD 3
9
10typedef struct HIDPointerEvent {
11 int32_t xdx, ydy;
12 int32_t dz, buttons_state;
13} HIDPointerEvent;
14
15#define QUEUE_LENGTH 16
16#define QUEUE_MASK (QUEUE_LENGTH-1u)
17#define QUEUE_INCR(v) ((v)++, (v) &= QUEUE_MASK)
18
19typedef struct HIDState HIDState;
20typedef void (*HIDEventFunc)(HIDState *s);
21
22typedef struct HIDMouseState {
23 HIDPointerEvent queue[QUEUE_LENGTH];
24 int mouse_grabbed;
25 QEMUPutMouseEntry *eh_entry;
26} HIDMouseState;
27
28typedef struct HIDKeyboardState {
29 uint32_t keycodes[QUEUE_LENGTH];
30 uint16_t modifiers;
31 uint8_t leds;
32 uint8_t key[16];
33 int32_t keys;
34 QEMUPutKbdEntry *eh_entry;
35} HIDKeyboardState;
36
37struct HIDState {
38 union {
39 HIDMouseState ptr;
40 HIDKeyboardState kbd;
41 };
42 uint32_t head;
43 uint32_t n;
44 int kind;
45 int32_t protocol;
46 uint8_t idle;
47 bool idle_pending;
48 QEMUTimer *idle_timer;
49 HIDEventFunc event;
50};
51
52void hid_init(HIDState *hs, int kind, HIDEventFunc event);
53void hid_reset(HIDState *hs);
54void hid_free(HIDState *hs);
55
56bool hid_has_events(HIDState *hs);
57void hid_set_next_idle(HIDState *hs);
58void hid_pointer_activate(HIDState *hs);
59int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len);
60int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len);
61int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len);
62
63extern const VMStateDescription vmstate_hid_keyboard_device;
64
65#define VMSTATE_HID_KEYBOARD_DEVICE(_field, _state) { \
66 .name = (stringify(_field)), \
67 .size = sizeof(HIDState), \
68 .vmsd = &vmstate_hid_keyboard_device, \
69 .flags = VMS_STRUCT, \
70 .offset = vmstate_offset_value(_state, _field, HIDState), \
71}
72
73extern const VMStateDescription vmstate_hid_ptr_device;
74
75#define VMSTATE_HID_POINTER_DEVICE(_field, _state) { \
76 .name = (stringify(_field)), \
77 .size = sizeof(HIDState), \
78 .vmsd = &vmstate_hid_ptr_device, \
79 .flags = VMS_STRUCT, \
80 .offset = vmstate_offset_value(_state, _field, HIDState), \
81}
82
83
84#endif
85