hid.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. /*
  2. * QEMU HID devices
  3. *
  4. * Copyright (c) 2005 Fabrice Bellard
  5. * Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com)
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #include "qemu/osdep.h"
  26. #include "ui/console.h"
  27. #include "qemu/timer.h"
  28. #include "hw/input/hid.h"
  29. #include "migration/vmstate.h"
  30. #include "trace.h"
  31. #define HID_USAGE_ERROR_ROLLOVER 0x01
  32. #define HID_USAGE_POSTFAIL 0x02
  33. #define HID_USAGE_ERROR_UNDEFINED 0x03
  34. /* Indices are QEMU keycodes, values are from HID Usage Table. Indices
  35. * above 0x80 are for keys that come after 0xe0 or 0xe1+0x1d or 0xe1+0x9d. */
  36. static const uint8_t hid_usage_keys[0x100] = {
  37. 0x00, 0x29, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
  38. 0x24, 0x25, 0x26, 0x27, 0x2d, 0x2e, 0x2a, 0x2b,
  39. 0x14, 0x1a, 0x08, 0x15, 0x17, 0x1c, 0x18, 0x0c,
  40. 0x12, 0x13, 0x2f, 0x30, 0x28, 0xe0, 0x04, 0x16,
  41. 0x07, 0x09, 0x0a, 0x0b, 0x0d, 0x0e, 0x0f, 0x33,
  42. 0x34, 0x35, 0xe1, 0x31, 0x1d, 0x1b, 0x06, 0x19,
  43. 0x05, 0x11, 0x10, 0x36, 0x37, 0x38, 0xe5, 0x55,
  44. 0xe2, 0x2c, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
  45. 0x3f, 0x40, 0x41, 0x42, 0x43, 0x53, 0x47, 0x5f,
  46. 0x60, 0x61, 0x56, 0x5c, 0x5d, 0x5e, 0x57, 0x59,
  47. 0x5a, 0x5b, 0x62, 0x63, 0x46, 0x00, 0x64, 0x44,
  48. 0x45, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e,
  49. 0xe8, 0xe9, 0x71, 0x72, 0x73, 0x00, 0x00, 0x00,
  50. 0x00, 0x00, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00,
  51. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  52. 0x00, 0x00, 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65,
  53. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  54. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  55. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56. 0x00, 0x00, 0x00, 0x00, 0x58, 0xe4, 0x00, 0x00,
  57. 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x00,
  59. 0x80, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x46,
  60. 0xe6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  61. 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x48, 0x4a,
  62. 0x52, 0x4b, 0x00, 0x50, 0x00, 0x4f, 0x00, 0x4d,
  63. 0x51, 0x4e, 0x49, 0x4c, 0x00, 0x00, 0x00, 0x00,
  64. 0x00, 0x00, 0x00, 0xe3, 0xe7, 0x65, 0x66, 0x00,
  65. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  69. };
  70. bool hid_has_events(HIDState *hs)
  71. {
  72. return hs->n > 0 || hs->idle_pending;
  73. }
  74. static void hid_idle_timer(void *opaque)
  75. {
  76. HIDState *hs = opaque;
  77. hs->idle_pending = true;
  78. hs->event(hs);
  79. }
  80. static void hid_del_idle_timer(HIDState *hs)
  81. {
  82. if (hs->idle_timer) {
  83. timer_del(hs->idle_timer);
  84. timer_free(hs->idle_timer);
  85. hs->idle_timer = NULL;
  86. }
  87. }
  88. void hid_set_next_idle(HIDState *hs)
  89. {
  90. if (hs->idle) {
  91. uint64_t expire_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) +
  92. NANOSECONDS_PER_SECOND * hs->idle * 4 / 1000;
  93. if (!hs->idle_timer) {
  94. hs->idle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, hid_idle_timer, hs);
  95. }
  96. timer_mod_ns(hs->idle_timer, expire_time);
  97. } else {
  98. hid_del_idle_timer(hs);
  99. }
  100. }
  101. static void hid_pointer_event(DeviceState *dev, QemuConsole *src,
  102. InputEvent *evt)
  103. {
  104. static const int bmap[INPUT_BUTTON__MAX] = {
  105. [INPUT_BUTTON_LEFT] = 0x01,
  106. [INPUT_BUTTON_RIGHT] = 0x02,
  107. [INPUT_BUTTON_MIDDLE] = 0x04,
  108. };
  109. HIDState *hs = (HIDState *)dev;
  110. HIDPointerEvent *e;
  111. InputMoveEvent *move;
  112. InputBtnEvent *btn;
  113. assert(hs->n < QUEUE_LENGTH);
  114. e = &hs->ptr.queue[(hs->head + hs->n) & QUEUE_MASK];
  115. switch (evt->type) {
  116. case INPUT_EVENT_KIND_REL:
  117. move = evt->u.rel.data;
  118. if (move->axis == INPUT_AXIS_X) {
  119. e->xdx += move->value;
  120. } else if (move->axis == INPUT_AXIS_Y) {
  121. e->ydy += move->value;
  122. }
  123. break;
  124. case INPUT_EVENT_KIND_ABS:
  125. move = evt->u.abs.data;
  126. if (move->axis == INPUT_AXIS_X) {
  127. e->xdx = move->value;
  128. } else if (move->axis == INPUT_AXIS_Y) {
  129. e->ydy = move->value;
  130. }
  131. break;
  132. case INPUT_EVENT_KIND_BTN:
  133. btn = evt->u.btn.data;
  134. if (btn->down) {
  135. e->buttons_state |= bmap[btn->button];
  136. if (btn->button == INPUT_BUTTON_WHEEL_UP) {
  137. e->dz--;
  138. } else if (btn->button == INPUT_BUTTON_WHEEL_DOWN) {
  139. e->dz++;
  140. }
  141. } else {
  142. e->buttons_state &= ~bmap[btn->button];
  143. }
  144. break;
  145. default:
  146. /* keep gcc happy */
  147. break;
  148. }
  149. }
  150. static void hid_pointer_sync(DeviceState *dev)
  151. {
  152. HIDState *hs = (HIDState *)dev;
  153. HIDPointerEvent *prev, *curr, *next;
  154. bool event_compression = false;
  155. if (hs->n == QUEUE_LENGTH-1) {
  156. /*
  157. * Queue full. We are losing information, but we at least
  158. * keep track of most recent button state.
  159. */
  160. return;
  161. }
  162. prev = &hs->ptr.queue[(hs->head + hs->n - 1) & QUEUE_MASK];
  163. curr = &hs->ptr.queue[(hs->head + hs->n) & QUEUE_MASK];
  164. next = &hs->ptr.queue[(hs->head + hs->n + 1) & QUEUE_MASK];
  165. if (hs->n > 0) {
  166. /*
  167. * No button state change between previous and current event
  168. * (and previous wasn't seen by the guest yet), so there is
  169. * motion information only and we can combine the two event
  170. * into one.
  171. */
  172. if (curr->buttons_state == prev->buttons_state) {
  173. event_compression = true;
  174. }
  175. }
  176. if (event_compression) {
  177. /* add current motion to previous, clear current */
  178. if (hs->kind == HID_MOUSE) {
  179. prev->xdx += curr->xdx;
  180. curr->xdx = 0;
  181. prev->ydy += curr->ydy;
  182. curr->ydy = 0;
  183. } else {
  184. prev->xdx = curr->xdx;
  185. prev->ydy = curr->ydy;
  186. }
  187. prev->dz += curr->dz;
  188. curr->dz = 0;
  189. } else {
  190. /* prepate next (clear rel, copy abs + btns) */
  191. if (hs->kind == HID_MOUSE) {
  192. next->xdx = 0;
  193. next->ydy = 0;
  194. } else {
  195. next->xdx = curr->xdx;
  196. next->ydy = curr->ydy;
  197. }
  198. next->dz = 0;
  199. next->buttons_state = curr->buttons_state;
  200. /* make current guest visible, notify guest */
  201. hs->n++;
  202. hs->event(hs);
  203. }
  204. }
  205. static void hid_keyboard_event(DeviceState *dev, QemuConsole *src,
  206. InputEvent *evt)
  207. {
  208. HIDState *hs = (HIDState *)dev;
  209. int scancodes[3], i, count;
  210. int slot;
  211. InputKeyEvent *key = evt->u.key.data;
  212. count = qemu_input_key_value_to_scancode(key->key,
  213. key->down,
  214. scancodes);
  215. if (hs->n + count > QUEUE_LENGTH) {
  216. trace_hid_kbd_queue_full();
  217. return;
  218. }
  219. for (i = 0; i < count; i++) {
  220. slot = (hs->head + hs->n) & QUEUE_MASK; hs->n++;
  221. hs->kbd.keycodes[slot] = scancodes[i];
  222. }
  223. hs->event(hs);
  224. }
  225. static void hid_keyboard_process_keycode(HIDState *hs)
  226. {
  227. uint8_t hid_code, index, key;
  228. int i, keycode, slot;
  229. if (hs->n == 0) {
  230. return;
  231. }
  232. slot = hs->head & QUEUE_MASK; QUEUE_INCR(hs->head); hs->n--;
  233. keycode = hs->kbd.keycodes[slot];
  234. if (!hs->n) {
  235. trace_hid_kbd_queue_empty();
  236. }
  237. key = keycode & 0x7f;
  238. index = key | ((hs->kbd.modifiers & (1 << 8)) >> 1);
  239. hid_code = hid_usage_keys[index];
  240. hs->kbd.modifiers &= ~(1 << 8);
  241. switch (hid_code) {
  242. case 0x00:
  243. return;
  244. case 0xe0:
  245. assert(key == 0x1d);
  246. if (hs->kbd.modifiers & (1 << 9)) {
  247. /* The hid_codes for the 0xe1/0x1d scancode sequence are 0xe9/0xe0.
  248. * Here we're processing the second hid_code. By dropping bit 9
  249. * and setting bit 8, the scancode after 0x1d will access the
  250. * second half of the table.
  251. */
  252. hs->kbd.modifiers ^= (1 << 8) | (1 << 9);
  253. return;
  254. }
  255. /* fall through to process Ctrl_L */
  256. case 0xe1 ... 0xe7:
  257. /* Ctrl_L/Ctrl_R, Shift_L/Shift_R, Alt_L/Alt_R, Win_L/Win_R.
  258. * Handle releases here, or fall through to process presses.
  259. */
  260. if (keycode & (1 << 7)) {
  261. hs->kbd.modifiers &= ~(1 << (hid_code & 0x0f));
  262. return;
  263. }
  264. /* fall through */
  265. case 0xe8 ... 0xe9:
  266. /* USB modifiers are just 1 byte long. Bits 8 and 9 of
  267. * hs->kbd.modifiers implement a state machine that detects the
  268. * 0xe0 and 0xe1/0x1d sequences. These bits do not follow the
  269. * usual rules where bit 7 marks released keys; they are cleared
  270. * elsewhere in the function as the state machine dictates.
  271. */
  272. hs->kbd.modifiers |= 1 << (hid_code & 0x0f);
  273. return;
  274. case 0xea ... 0xef:
  275. abort();
  276. default:
  277. break;
  278. }
  279. if (keycode & (1 << 7)) {
  280. for (i = hs->kbd.keys - 1; i >= 0; i--) {
  281. if (hs->kbd.key[i] == hid_code) {
  282. hs->kbd.key[i] = hs->kbd.key[-- hs->kbd.keys];
  283. hs->kbd.key[hs->kbd.keys] = 0x00;
  284. break;
  285. }
  286. }
  287. if (i < 0) {
  288. return;
  289. }
  290. } else {
  291. for (i = hs->kbd.keys - 1; i >= 0; i--) {
  292. if (hs->kbd.key[i] == hid_code) {
  293. break;
  294. }
  295. }
  296. if (i < 0) {
  297. if (hs->kbd.keys < sizeof(hs->kbd.key)) {
  298. hs->kbd.key[hs->kbd.keys++] = hid_code;
  299. }
  300. } else {
  301. return;
  302. }
  303. }
  304. }
  305. static inline int int_clamp(int val, int vmin, int vmax)
  306. {
  307. if (val < vmin) {
  308. return vmin;
  309. } else if (val > vmax) {
  310. return vmax;
  311. } else {
  312. return val;
  313. }
  314. }
  315. void hid_pointer_activate(HIDState *hs)
  316. {
  317. if (!hs->ptr.mouse_grabbed) {
  318. qemu_input_handler_activate(hs->s);
  319. hs->ptr.mouse_grabbed = 1;
  320. }
  321. }
  322. int hid_pointer_poll(HIDState *hs, uint8_t *buf, int len)
  323. {
  324. int dx, dy, dz, l;
  325. int index;
  326. HIDPointerEvent *e;
  327. hs->idle_pending = false;
  328. hid_pointer_activate(hs);
  329. /* When the buffer is empty, return the last event. Relative
  330. movements will all be zero. */
  331. index = (hs->n ? hs->head : hs->head - 1);
  332. e = &hs->ptr.queue[index & QUEUE_MASK];
  333. if (hs->kind == HID_MOUSE) {
  334. dx = int_clamp(e->xdx, -127, 127);
  335. dy = int_clamp(e->ydy, -127, 127);
  336. e->xdx -= dx;
  337. e->ydy -= dy;
  338. } else {
  339. dx = e->xdx;
  340. dy = e->ydy;
  341. }
  342. dz = int_clamp(e->dz, -127, 127);
  343. e->dz -= dz;
  344. if (hs->n &&
  345. !e->dz &&
  346. (hs->kind == HID_TABLET || (!e->xdx && !e->ydy))) {
  347. /* that deals with this event */
  348. QUEUE_INCR(hs->head);
  349. hs->n--;
  350. }
  351. /* Appears we have to invert the wheel direction */
  352. dz = 0 - dz;
  353. l = 0;
  354. switch (hs->kind) {
  355. case HID_MOUSE:
  356. if (len > l) {
  357. buf[l++] = e->buttons_state;
  358. }
  359. if (len > l) {
  360. buf[l++] = dx;
  361. }
  362. if (len > l) {
  363. buf[l++] = dy;
  364. }
  365. if (len > l) {
  366. buf[l++] = dz;
  367. }
  368. break;
  369. case HID_TABLET:
  370. if (len > l) {
  371. buf[l++] = e->buttons_state;
  372. }
  373. if (len > l) {
  374. buf[l++] = dx & 0xff;
  375. }
  376. if (len > l) {
  377. buf[l++] = dx >> 8;
  378. }
  379. if (len > l) {
  380. buf[l++] = dy & 0xff;
  381. }
  382. if (len > l) {
  383. buf[l++] = dy >> 8;
  384. }
  385. if (len > l) {
  386. buf[l++] = dz;
  387. }
  388. break;
  389. default:
  390. abort();
  391. }
  392. return l;
  393. }
  394. int hid_keyboard_poll(HIDState *hs, uint8_t *buf, int len)
  395. {
  396. hs->idle_pending = false;
  397. if (len < 2) {
  398. return 0;
  399. }
  400. hid_keyboard_process_keycode(hs);
  401. buf[0] = hs->kbd.modifiers & 0xff;
  402. buf[1] = 0;
  403. if (hs->kbd.keys > 6) {
  404. memset(buf + 2, HID_USAGE_ERROR_ROLLOVER, MIN(8, len) - 2);
  405. } else {
  406. memcpy(buf + 2, hs->kbd.key, MIN(8, len) - 2);
  407. }
  408. return MIN(8, len);
  409. }
  410. int hid_keyboard_write(HIDState *hs, uint8_t *buf, int len)
  411. {
  412. if (len > 0) {
  413. int ledstate = 0;
  414. /* 0x01: Num Lock LED
  415. * 0x02: Caps Lock LED
  416. * 0x04: Scroll Lock LED
  417. * 0x08: Compose LED
  418. * 0x10: Kana LED */
  419. hs->kbd.leds = buf[0];
  420. if (hs->kbd.leds & 0x04) {
  421. ledstate |= QEMU_SCROLL_LOCK_LED;
  422. }
  423. if (hs->kbd.leds & 0x01) {
  424. ledstate |= QEMU_NUM_LOCK_LED;
  425. }
  426. if (hs->kbd.leds & 0x02) {
  427. ledstate |= QEMU_CAPS_LOCK_LED;
  428. }
  429. kbd_put_ledstate(ledstate);
  430. }
  431. return 0;
  432. }
  433. void hid_reset(HIDState *hs)
  434. {
  435. switch (hs->kind) {
  436. case HID_KEYBOARD:
  437. memset(hs->kbd.keycodes, 0, sizeof(hs->kbd.keycodes));
  438. memset(hs->kbd.key, 0, sizeof(hs->kbd.key));
  439. hs->kbd.keys = 0;
  440. hs->kbd.modifiers = 0;
  441. break;
  442. case HID_MOUSE:
  443. case HID_TABLET:
  444. memset(hs->ptr.queue, 0, sizeof(hs->ptr.queue));
  445. break;
  446. }
  447. hs->head = 0;
  448. hs->n = 0;
  449. hs->protocol = 1;
  450. hs->idle = 0;
  451. hs->idle_pending = false;
  452. hid_del_idle_timer(hs);
  453. }
  454. void hid_free(HIDState *hs)
  455. {
  456. qemu_input_handler_unregister(hs->s);
  457. hid_del_idle_timer(hs);
  458. }
  459. static QemuInputHandler hid_keyboard_handler = {
  460. .name = "QEMU HID Keyboard",
  461. .mask = INPUT_EVENT_MASK_KEY,
  462. .event = hid_keyboard_event,
  463. };
  464. static QemuInputHandler hid_mouse_handler = {
  465. .name = "QEMU HID Mouse",
  466. .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_REL,
  467. .event = hid_pointer_event,
  468. .sync = hid_pointer_sync,
  469. };
  470. static QemuInputHandler hid_tablet_handler = {
  471. .name = "QEMU HID Tablet",
  472. .mask = INPUT_EVENT_MASK_BTN | INPUT_EVENT_MASK_ABS,
  473. .event = hid_pointer_event,
  474. .sync = hid_pointer_sync,
  475. };
  476. void hid_init(HIDState *hs, int kind, HIDEventFunc event)
  477. {
  478. hs->kind = kind;
  479. hs->event = event;
  480. if (hs->kind == HID_KEYBOARD) {
  481. hs->s = qemu_input_handler_register((DeviceState *)hs,
  482. &hid_keyboard_handler);
  483. qemu_input_handler_activate(hs->s);
  484. } else if (hs->kind == HID_MOUSE) {
  485. hs->s = qemu_input_handler_register((DeviceState *)hs,
  486. &hid_mouse_handler);
  487. } else if (hs->kind == HID_TABLET) {
  488. hs->s = qemu_input_handler_register((DeviceState *)hs,
  489. &hid_tablet_handler);
  490. }
  491. }
  492. static int hid_post_load(void *opaque, int version_id)
  493. {
  494. HIDState *s = opaque;
  495. hid_set_next_idle(s);
  496. if (s->n == QUEUE_LENGTH && (s->kind == HID_TABLET ||
  497. s->kind == HID_MOUSE)) {
  498. /*
  499. * Handle ptr device migration from old qemu with full queue.
  500. *
  501. * Throw away everything but the last event, so we propagate
  502. * at least the current button state to the guest. Also keep
  503. * current position for the tablet, signal "no motion" for the
  504. * mouse.
  505. */
  506. HIDPointerEvent evt;
  507. evt = s->ptr.queue[(s->head+s->n) & QUEUE_MASK];
  508. if (s->kind == HID_MOUSE) {
  509. evt.xdx = 0;
  510. evt.ydy = 0;
  511. }
  512. s->ptr.queue[0] = evt;
  513. s->head = 0;
  514. s->n = 1;
  515. }
  516. return 0;
  517. }
  518. static const VMStateDescription vmstate_hid_ptr_queue = {
  519. .name = "HIDPointerEventQueue",
  520. .version_id = 1,
  521. .minimum_version_id = 1,
  522. .fields = (VMStateField[]) {
  523. VMSTATE_INT32(xdx, HIDPointerEvent),
  524. VMSTATE_INT32(ydy, HIDPointerEvent),
  525. VMSTATE_INT32(dz, HIDPointerEvent),
  526. VMSTATE_INT32(buttons_state, HIDPointerEvent),
  527. VMSTATE_END_OF_LIST()
  528. }
  529. };
  530. const VMStateDescription vmstate_hid_ptr_device = {
  531. .name = "HIDPointerDevice",
  532. .version_id = 1,
  533. .minimum_version_id = 1,
  534. .post_load = hid_post_load,
  535. .fields = (VMStateField[]) {
  536. VMSTATE_STRUCT_ARRAY(ptr.queue, HIDState, QUEUE_LENGTH, 0,
  537. vmstate_hid_ptr_queue, HIDPointerEvent),
  538. VMSTATE_UINT32(head, HIDState),
  539. VMSTATE_UINT32(n, HIDState),
  540. VMSTATE_INT32(protocol, HIDState),
  541. VMSTATE_UINT8(idle, HIDState),
  542. VMSTATE_END_OF_LIST(),
  543. }
  544. };
  545. const VMStateDescription vmstate_hid_keyboard_device = {
  546. .name = "HIDKeyboardDevice",
  547. .version_id = 1,
  548. .minimum_version_id = 1,
  549. .post_load = hid_post_load,
  550. .fields = (VMStateField[]) {
  551. VMSTATE_UINT32_ARRAY(kbd.keycodes, HIDState, QUEUE_LENGTH),
  552. VMSTATE_UINT32(head, HIDState),
  553. VMSTATE_UINT32(n, HIDState),
  554. VMSTATE_UINT16(kbd.modifiers, HIDState),
  555. VMSTATE_UINT8(kbd.leds, HIDState),
  556. VMSTATE_UINT8_ARRAY(kbd.key, HIDState, 16),
  557. VMSTATE_INT32(kbd.keys, HIDState),
  558. VMSTATE_INT32(protocol, HIDState),
  559. VMSTATE_UINT8(idle, HIDState),
  560. VMSTATE_END_OF_LIST(),
  561. }
  562. };