4 * Copyright (c) 2005 Fabrice Bellard
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
26 #include "qemu/osdep.h"
27 #include "ui/console.h"
29 #include "migration/vmstate.h"
31 #include "qapi/error.h"
32 #include "qemu/module.h"
33 #include "qemu/timer.h"
34 #include "hw/input/hid.h"
35 #include "hw/usb/hid.h"
36 #include "hw/qdev-properties.h"
38 typedef struct USBHIDState {
47 #define TYPE_USB_HID "usb-hid"
48 #define USB_HID(obj) OBJECT_CHECK(USBHIDState, (obj), TYPE_USB_HID)
64 static const USBDescStrings desc_strings = {
65 [STR_MANUFACTURER] = "QEMU",
66 [STR_PRODUCT_MOUSE] = "QEMU USB Mouse",
67 [STR_PRODUCT_TABLET] = "QEMU USB Tablet",
68 [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard",
69 [STR_SERIAL_COMPAT] = "42",
70 [STR_CONFIG_MOUSE] = "HID Mouse",
71 [STR_CONFIG_TABLET] = "HID Tablet",
72 [STR_CONFIG_KEYBOARD] = "HID Keyboard",
73 [STR_SERIAL_MOUSE] = "89126",
74 [STR_SERIAL_TABLET] = "28754",
75 [STR_SERIAL_KEYBOARD] = "68284",
78 static const USBDescIface desc_iface_mouse = {
79 .bInterfaceNumber = 0,
81 .bInterfaceClass = USB_CLASS_HID,
82 .bInterfaceSubClass = 0x01, /* boot */
83 .bInterfaceProtocol = 0x02,
85 .descs = (USBDescOther[]) {
89 0x09, /* u8 bLength */
90 USB_DT_HID, /* u8 bDescriptorType */
91 0x01, 0x00, /* u16 HID_class */
92 0x00, /* u8 country_code */
93 0x01, /* u8 num_descriptors */
94 USB_DT_REPORT, /* u8 type: Report */
99 .eps = (USBDescEndpoint[]) {
101 .bEndpointAddress = USB_DIR_IN | 0x01,
102 .bmAttributes = USB_ENDPOINT_XFER_INT,
109 static const USBDescIface desc_iface_mouse2 = {
110 .bInterfaceNumber = 0,
112 .bInterfaceClass = USB_CLASS_HID,
113 .bInterfaceSubClass = 0x01, /* boot */
114 .bInterfaceProtocol = 0x02,
116 .descs = (USBDescOther[]) {
119 .data = (uint8_t[]) {
120 0x09, /* u8 bLength */
121 USB_DT_HID, /* u8 bDescriptorType */
122 0x01, 0x00, /* u16 HID_class */
123 0x00, /* u8 country_code */
124 0x01, /* u8 num_descriptors */
125 USB_DT_REPORT, /* u8 type: Report */
130 .eps = (USBDescEndpoint[]) {
132 .bEndpointAddress = USB_DIR_IN | 0x01,
133 .bmAttributes = USB_ENDPOINT_XFER_INT,
135 .bInterval = 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */
140 static const USBDescIface desc_iface_tablet = {
141 .bInterfaceNumber = 0,
143 .bInterfaceClass = USB_CLASS_HID,
144 .bInterfaceProtocol = 0x00,
146 .descs = (USBDescOther[]) {
149 .data = (uint8_t[]) {
150 0x09, /* u8 bLength */
151 USB_DT_HID, /* u8 bDescriptorType */
152 0x01, 0x00, /* u16 HID_class */
153 0x00, /* u8 country_code */
154 0x01, /* u8 num_descriptors */
155 USB_DT_REPORT, /* u8 type: Report */
160 .eps = (USBDescEndpoint[]) {
162 .bEndpointAddress = USB_DIR_IN | 0x01,
163 .bmAttributes = USB_ENDPOINT_XFER_INT,
170 static const USBDescIface desc_iface_tablet2 = {
171 .bInterfaceNumber = 0,
173 .bInterfaceClass = USB_CLASS_HID,
174 .bInterfaceProtocol = 0x00,
176 .descs = (USBDescOther[]) {
179 .data = (uint8_t[]) {
180 0x09, /* u8 bLength */
181 USB_DT_HID, /* u8 bDescriptorType */
182 0x01, 0x00, /* u16 HID_class */
183 0x00, /* u8 country_code */
184 0x01, /* u8 num_descriptors */
185 USB_DT_REPORT, /* u8 type: Report */
190 .eps = (USBDescEndpoint[]) {
192 .bEndpointAddress = USB_DIR_IN | 0x01,
193 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .bInterval = 4, /* 2 ^ (4-1) * 125 usecs = 1 ms */
200 static const USBDescIface desc_iface_keyboard = {
201 .bInterfaceNumber = 0,
203 .bInterfaceClass = USB_CLASS_HID,
204 .bInterfaceSubClass = 0x01, /* boot */
205 .bInterfaceProtocol = 0x01, /* keyboard */
207 .descs = (USBDescOther[]) {
210 .data = (uint8_t[]) {
211 0x09, /* u8 bLength */
212 USB_DT_HID, /* u8 bDescriptorType */
213 0x11, 0x01, /* u16 HID_class */
214 0x00, /* u8 country_code */
215 0x01, /* u8 num_descriptors */
216 USB_DT_REPORT, /* u8 type: Report */
217 0x3f, 0, /* u16 len */
221 .eps = (USBDescEndpoint[]) {
223 .bEndpointAddress = USB_DIR_IN | 0x01,
224 .bmAttributes = USB_ENDPOINT_XFER_INT,
231 static const USBDescIface desc_iface_keyboard2 = {
232 .bInterfaceNumber = 0,
234 .bInterfaceClass = USB_CLASS_HID,
235 .bInterfaceSubClass = 0x01, /* boot */
236 .bInterfaceProtocol = 0x01, /* keyboard */
238 .descs = (USBDescOther[]) {
241 .data = (uint8_t[]) {
242 0x09, /* u8 bLength */
243 USB_DT_HID, /* u8 bDescriptorType */
244 0x11, 0x01, /* u16 HID_class */
245 0x00, /* u8 country_code */
246 0x01, /* u8 num_descriptors */
247 USB_DT_REPORT, /* u8 type: Report */
248 0x3f, 0, /* u16 len */
252 .eps = (USBDescEndpoint[]) {
254 .bEndpointAddress = USB_DIR_IN | 0x01,
255 .bmAttributes = USB_ENDPOINT_XFER_INT,
257 .bInterval = 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */
262 static const USBDescDevice desc_device_mouse = {
264 .bMaxPacketSize0 = 8,
265 .bNumConfigurations = 1,
266 .confs = (USBDescConfig[]) {
269 .bConfigurationValue = 1,
270 .iConfiguration = STR_CONFIG_MOUSE,
271 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
274 .ifs = &desc_iface_mouse,
279 static const USBDescDevice desc_device_mouse2 = {
281 .bMaxPacketSize0 = 64,
282 .bNumConfigurations = 1,
283 .confs = (USBDescConfig[]) {
286 .bConfigurationValue = 1,
287 .iConfiguration = STR_CONFIG_MOUSE,
288 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
291 .ifs = &desc_iface_mouse2,
296 static const USBDescDevice desc_device_tablet = {
298 .bMaxPacketSize0 = 8,
299 .bNumConfigurations = 1,
300 .confs = (USBDescConfig[]) {
303 .bConfigurationValue = 1,
304 .iConfiguration = STR_CONFIG_TABLET,
305 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
308 .ifs = &desc_iface_tablet,
313 static const USBDescDevice desc_device_tablet2 = {
315 .bMaxPacketSize0 = 64,
316 .bNumConfigurations = 1,
317 .confs = (USBDescConfig[]) {
320 .bConfigurationValue = 1,
321 .iConfiguration = STR_CONFIG_TABLET,
322 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
325 .ifs = &desc_iface_tablet2,
330 static const USBDescDevice desc_device_keyboard = {
332 .bMaxPacketSize0 = 8,
333 .bNumConfigurations = 1,
334 .confs = (USBDescConfig[]) {
337 .bConfigurationValue = 1,
338 .iConfiguration = STR_CONFIG_KEYBOARD,
339 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
342 .ifs = &desc_iface_keyboard,
347 static const USBDescDevice desc_device_keyboard2 = {
349 .bMaxPacketSize0 = 64,
350 .bNumConfigurations = 1,
351 .confs = (USBDescConfig[]) {
354 .bConfigurationValue = 1,
355 .iConfiguration = STR_CONFIG_KEYBOARD,
356 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_WAKEUP,
359 .ifs = &desc_iface_keyboard2,
364 static const USBDescMSOS desc_msos_suspend = {
365 .SelectiveSuspendEnabled = true,
368 static const USBDesc desc_mouse = {
373 .iManufacturer = STR_MANUFACTURER,
374 .iProduct = STR_PRODUCT_MOUSE,
375 .iSerialNumber = STR_SERIAL_MOUSE,
377 .full = &desc_device_mouse,
379 .msos = &desc_msos_suspend,
382 static const USBDesc desc_mouse2 = {
387 .iManufacturer = STR_MANUFACTURER,
388 .iProduct = STR_PRODUCT_MOUSE,
389 .iSerialNumber = STR_SERIAL_MOUSE,
391 .full = &desc_device_mouse,
392 .high = &desc_device_mouse2,
394 .msos = &desc_msos_suspend,
397 static const USBDesc desc_tablet = {
402 .iManufacturer = STR_MANUFACTURER,
403 .iProduct = STR_PRODUCT_TABLET,
404 .iSerialNumber = STR_SERIAL_TABLET,
406 .full = &desc_device_tablet,
408 .msos = &desc_msos_suspend,
411 static const USBDesc desc_tablet2 = {
416 .iManufacturer = STR_MANUFACTURER,
417 .iProduct = STR_PRODUCT_TABLET,
418 .iSerialNumber = STR_SERIAL_TABLET,
420 .full = &desc_device_tablet,
421 .high = &desc_device_tablet2,
423 .msos = &desc_msos_suspend,
426 static const USBDesc desc_keyboard = {
431 .iManufacturer = STR_MANUFACTURER,
432 .iProduct = STR_PRODUCT_KEYBOARD,
433 .iSerialNumber = STR_SERIAL_KEYBOARD,
435 .full = &desc_device_keyboard,
437 .msos = &desc_msos_suspend,
440 static const USBDesc desc_keyboard2 = {
445 .iManufacturer = STR_MANUFACTURER,
446 .iProduct = STR_PRODUCT_KEYBOARD,
447 .iSerialNumber = STR_SERIAL_KEYBOARD,
449 .full = &desc_device_keyboard,
450 .high = &desc_device_keyboard2,
452 .msos = &desc_msos_suspend,
455 static const uint8_t qemu_mouse_hid_report_descriptor[] = {
456 0x05, 0x01, /* Usage Page (Generic Desktop) */
457 0x09, 0x02, /* Usage (Mouse) */
458 0xa1, 0x01, /* Collection (Application) */
459 0x09, 0x01, /* Usage (Pointer) */
460 0xa1, 0x00, /* Collection (Physical) */
461 0x05, 0x09, /* Usage Page (Button) */
462 0x19, 0x01, /* Usage Minimum (1) */
463 0x29, 0x03, /* Usage Maximum (3) */
464 0x15, 0x00, /* Logical Minimum (0) */
465 0x25, 0x01, /* Logical Maximum (1) */
466 0x95, 0x03, /* Report Count (3) */
467 0x75, 0x01, /* Report Size (1) */
468 0x81, 0x02, /* Input (Data, Variable, Absolute) */
469 0x95, 0x01, /* Report Count (1) */
470 0x75, 0x05, /* Report Size (5) */
471 0x81, 0x01, /* Input (Constant) */
472 0x05, 0x01, /* Usage Page (Generic Desktop) */
473 0x09, 0x30, /* Usage (X) */
474 0x09, 0x31, /* Usage (Y) */
475 0x09, 0x38, /* Usage (Wheel) */
476 0x15, 0x81, /* Logical Minimum (-0x7f) */
477 0x25, 0x7f, /* Logical Maximum (0x7f) */
478 0x75, 0x08, /* Report Size (8) */
479 0x95, 0x03, /* Report Count (3) */
480 0x81, 0x06, /* Input (Data, Variable, Relative) */
481 0xc0, /* End Collection */
482 0xc0, /* End Collection */
485 static const uint8_t qemu_tablet_hid_report_descriptor[] = {
486 0x05, 0x01, /* Usage Page (Generic Desktop) */
487 0x09, 0x02, /* Usage (Mouse) */
488 0xa1, 0x01, /* Collection (Application) */
489 0x09, 0x01, /* Usage (Pointer) */
490 0xa1, 0x00, /* Collection (Physical) */
491 0x05, 0x09, /* Usage Page (Button) */
492 0x19, 0x01, /* Usage Minimum (1) */
493 0x29, 0x03, /* Usage Maximum (3) */
494 0x15, 0x00, /* Logical Minimum (0) */
495 0x25, 0x01, /* Logical Maximum (1) */
496 0x95, 0x03, /* Report Count (3) */
497 0x75, 0x01, /* Report Size (1) */
498 0x81, 0x02, /* Input (Data, Variable, Absolute) */
499 0x95, 0x01, /* Report Count (1) */
500 0x75, 0x05, /* Report Size (5) */
501 0x81, 0x01, /* Input (Constant) */
502 0x05, 0x01, /* Usage Page (Generic Desktop) */
503 0x09, 0x30, /* Usage (X) */
504 0x09, 0x31, /* Usage (Y) */
505 0x15, 0x00, /* Logical Minimum (0) */
506 0x26, 0xff, 0x7f, /* Logical Maximum (0x7fff) */
507 0x35, 0x00, /* Physical Minimum (0) */
508 0x46, 0xff, 0x7f, /* Physical Maximum (0x7fff) */
509 0x75, 0x10, /* Report Size (16) */
510 0x95, 0x02, /* Report Count (2) */
511 0x81, 0x02, /* Input (Data, Variable, Absolute) */
512 0x05, 0x01, /* Usage Page (Generic Desktop) */
513 0x09, 0x38, /* Usage (Wheel) */
514 0x15, 0x81, /* Logical Minimum (-0x7f) */
515 0x25, 0x7f, /* Logical Maximum (0x7f) */
516 0x35, 0x00, /* Physical Minimum (same as logical) */
517 0x45, 0x00, /* Physical Maximum (same as logical) */
518 0x75, 0x08, /* Report Size (8) */
519 0x95, 0x01, /* Report Count (1) */
520 0x81, 0x06, /* Input (Data, Variable, Relative) */
521 0xc0, /* End Collection */
522 0xc0, /* End Collection */
525 static const uint8_t qemu_keyboard_hid_report_descriptor[] = {
526 0x05, 0x01, /* Usage Page (Generic Desktop) */
527 0x09, 0x06, /* Usage (Keyboard) */
528 0xa1, 0x01, /* Collection (Application) */
529 0x75, 0x01, /* Report Size (1) */
530 0x95, 0x08, /* Report Count (8) */
531 0x05, 0x07, /* Usage Page (Key Codes) */
532 0x19, 0xe0, /* Usage Minimum (224) */
533 0x29, 0xe7, /* Usage Maximum (231) */
534 0x15, 0x00, /* Logical Minimum (0) */
535 0x25, 0x01, /* Logical Maximum (1) */
536 0x81, 0x02, /* Input (Data, Variable, Absolute) */
537 0x95, 0x01, /* Report Count (1) */
538 0x75, 0x08, /* Report Size (8) */
539 0x81, 0x01, /* Input (Constant) */
540 0x95, 0x05, /* Report Count (5) */
541 0x75, 0x01, /* Report Size (1) */
542 0x05, 0x08, /* Usage Page (LEDs) */
543 0x19, 0x01, /* Usage Minimum (1) */
544 0x29, 0x05, /* Usage Maximum (5) */
545 0x91, 0x02, /* Output (Data, Variable, Absolute) */
546 0x95, 0x01, /* Report Count (1) */
547 0x75, 0x03, /* Report Size (3) */
548 0x91, 0x01, /* Output (Constant) */
549 0x95, 0x06, /* Report Count (6) */
550 0x75, 0x08, /* Report Size (8) */
551 0x15, 0x00, /* Logical Minimum (0) */
552 0x25, 0xff, /* Logical Maximum (255) */
553 0x05, 0x07, /* Usage Page (Key Codes) */
554 0x19, 0x00, /* Usage Minimum (0) */
555 0x29, 0xff, /* Usage Maximum (255) */
556 0x81, 0x00, /* Input (Data, Array) */
557 0xc0, /* End Collection */
560 static void usb_hid_changed(HIDState *hs)
562 USBHIDState *us = container_of(hs, USBHIDState, hid);
564 usb_wakeup(us->intr, 0);
567 static void usb_hid_handle_reset(USBDevice *dev)
569 USBHIDState *us = USB_HID(dev);
574 static void usb_hid_handle_control(USBDevice *dev, USBPacket *p,
575 int request, int value, int index, int length, uint8_t *data)
577 USBHIDState *us = USB_HID(dev);
578 HIDState *hs = &us->hid;
581 ret = usb_desc_handle_control(dev, p, request, value, index, length, data);
587 /* hid specific requests */
588 case InterfaceRequest | USB_REQ_GET_DESCRIPTOR:
589 switch (value >> 8) {
591 if (hs->kind == HID_MOUSE) {
592 memcpy(data, qemu_mouse_hid_report_descriptor,
593 sizeof(qemu_mouse_hid_report_descriptor));
594 p->actual_length = sizeof(qemu_mouse_hid_report_descriptor);
595 } else if (hs->kind == HID_TABLET) {
596 memcpy(data, qemu_tablet_hid_report_descriptor,
597 sizeof(qemu_tablet_hid_report_descriptor));
598 p->actual_length = sizeof(qemu_tablet_hid_report_descriptor);
599 } else if (hs->kind == HID_KEYBOARD) {
600 memcpy(data, qemu_keyboard_hid_report_descriptor,
601 sizeof(qemu_keyboard_hid_report_descriptor));
602 p->actual_length = sizeof(qemu_keyboard_hid_report_descriptor);
610 if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
611 p->actual_length = hid_pointer_poll(hs, data, length);
612 } else if (hs->kind == HID_KEYBOARD) {
613 p->actual_length = hid_keyboard_poll(hs, data, length);
617 if (hs->kind == HID_KEYBOARD) {
618 p->actual_length = hid_keyboard_write(hs, data, length);
623 case HID_GET_PROTOCOL:
624 if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) {
627 data[0] = hs->protocol;
628 p->actual_length = 1;
630 case HID_SET_PROTOCOL:
631 if (hs->kind != HID_KEYBOARD && hs->kind != HID_MOUSE) {
634 hs->protocol = value;
638 p->actual_length = 1;
641 hs->idle = (uint8_t) (value >> 8);
642 hid_set_next_idle(hs);
643 if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
644 hid_pointer_activate(hs);
649 p->status = USB_RET_STALL;
654 static void usb_hid_handle_data(USBDevice *dev, USBPacket *p)
656 USBHIDState *us = USB_HID(dev);
657 HIDState *hs = &us->hid;
658 uint8_t buf[p->iov.size];
663 if (p->ep->nr == 1) {
664 if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
665 hid_pointer_activate(hs);
667 if (!hid_has_events(hs)) {
668 p->status = USB_RET_NAK;
671 hid_set_next_idle(hs);
672 if (hs->kind == HID_MOUSE || hs->kind == HID_TABLET) {
673 len = hid_pointer_poll(hs, buf, p->iov.size);
674 } else if (hs->kind == HID_KEYBOARD) {
675 len = hid_keyboard_poll(hs, buf, p->iov.size);
677 usb_packet_copy(p, buf, len);
685 p->status = USB_RET_STALL;
690 static void usb_hid_unrealize(USBDevice *dev)
692 USBHIDState *us = USB_HID(dev);
697 static void usb_hid_initfn(USBDevice *dev, int kind,
698 const USBDesc *usb1, const USBDesc *usb2,
701 USBHIDState *us = USB_HID(dev);
702 switch (us->usb_version) {
704 dev->usb_desc = usb1;
707 dev->usb_desc = usb2;
710 dev->usb_desc = NULL;
712 if (!dev->usb_desc) {
713 error_setg(errp, "Invalid usb version %d for usb hid device",
718 usb_desc_create_serial(dev);
720 us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
721 hid_init(&us->hid, kind, usb_hid_changed);
722 if (us->display && us->hid.s) {
723 qemu_input_handler_bind(us->hid.s, us->display, us->head, NULL);
727 static void usb_tablet_realize(USBDevice *dev, Error **errp)
730 usb_hid_initfn(dev, HID_TABLET, &desc_tablet, &desc_tablet2, errp);
733 static void usb_mouse_realize(USBDevice *dev, Error **errp)
735 usb_hid_initfn(dev, HID_MOUSE, &desc_mouse, &desc_mouse2, errp);
738 static void usb_keyboard_realize(USBDevice *dev, Error **errp)
740 usb_hid_initfn(dev, HID_KEYBOARD, &desc_keyboard, &desc_keyboard2, errp);
743 static int usb_ptr_post_load(void *opaque, int version_id)
745 USBHIDState *s = opaque;
747 if (s->dev.remote_wakeup) {
748 hid_pointer_activate(&s->hid);
753 static const VMStateDescription vmstate_usb_ptr = {
756 .minimum_version_id = 1,
757 .post_load = usb_ptr_post_load,
758 .fields = (VMStateField[]) {
759 VMSTATE_USB_DEVICE(dev, USBHIDState),
760 VMSTATE_HID_POINTER_DEVICE(hid, USBHIDState),
761 VMSTATE_END_OF_LIST()
765 static const VMStateDescription vmstate_usb_kbd = {
768 .minimum_version_id = 1,
769 .fields = (VMStateField[]) {
770 VMSTATE_USB_DEVICE(dev, USBHIDState),
771 VMSTATE_HID_KEYBOARD_DEVICE(hid, USBHIDState),
772 VMSTATE_END_OF_LIST()
776 static void usb_hid_class_initfn(ObjectClass *klass, void *data)
778 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
780 uc->handle_reset = usb_hid_handle_reset;
781 uc->handle_control = usb_hid_handle_control;
782 uc->handle_data = usb_hid_handle_data;
783 uc->unrealize = usb_hid_unrealize;
784 uc->handle_attach = usb_desc_attach;
787 static const TypeInfo usb_hid_type_info = {
788 .name = TYPE_USB_HID,
789 .parent = TYPE_USB_DEVICE,
790 .instance_size = sizeof(USBHIDState),
792 .class_init = usb_hid_class_initfn,
795 static Property usb_tablet_properties[] = {
796 DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2),
797 DEFINE_PROP_STRING("display", USBHIDState, display),
798 DEFINE_PROP_UINT32("head", USBHIDState, head, 0),
799 DEFINE_PROP_END_OF_LIST(),
802 static void usb_tablet_class_initfn(ObjectClass *klass, void *data)
804 DeviceClass *dc = DEVICE_CLASS(klass);
805 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
807 uc->realize = usb_tablet_realize;
808 uc->product_desc = "QEMU USB Tablet";
809 dc->vmsd = &vmstate_usb_ptr;
810 device_class_set_props(dc, usb_tablet_properties);
811 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
814 static const TypeInfo usb_tablet_info = {
815 .name = "usb-tablet",
816 .parent = TYPE_USB_HID,
817 .class_init = usb_tablet_class_initfn,
820 static Property usb_mouse_properties[] = {
821 DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2),
822 DEFINE_PROP_END_OF_LIST(),
825 static void usb_mouse_class_initfn(ObjectClass *klass, void *data)
827 DeviceClass *dc = DEVICE_CLASS(klass);
828 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
830 uc->realize = usb_mouse_realize;
831 uc->product_desc = "QEMU USB Mouse";
832 dc->vmsd = &vmstate_usb_ptr;
833 device_class_set_props(dc, usb_mouse_properties);
834 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
837 static const TypeInfo usb_mouse_info = {
839 .parent = TYPE_USB_HID,
840 .class_init = usb_mouse_class_initfn,
843 static Property usb_keyboard_properties[] = {
844 DEFINE_PROP_UINT32("usb_version", USBHIDState, usb_version, 2),
845 DEFINE_PROP_STRING("display", USBHIDState, display),
846 DEFINE_PROP_END_OF_LIST(),
849 static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)
851 DeviceClass *dc = DEVICE_CLASS(klass);
852 USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
854 uc->realize = usb_keyboard_realize;
855 uc->product_desc = "QEMU USB Keyboard";
856 dc->vmsd = &vmstate_usb_kbd;
857 device_class_set_props(dc, usb_keyboard_properties);
858 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
861 static const TypeInfo usb_keyboard_info = {
863 .parent = TYPE_USB_HID,
864 .class_init = usb_keyboard_class_initfn,
867 static void usb_hid_register_types(void)
869 type_register_static(&usb_hid_type_info);
870 type_register_static(&usb_tablet_info);
871 usb_legacy_register("usb-tablet", "tablet", NULL);
872 type_register_static(&usb_mouse_info);
873 usb_legacy_register("usb-mouse", "mouse", NULL);
874 type_register_static(&usb_keyboard_info);
875 usb_legacy_register("usb-kbd", "keyboard", NULL);
878 type_init(usb_hid_register_types)