4 * Copyright (c) 2005 Fabrice Bellard
5 * Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com)
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 "ui/console.h"
28 #include "hw/usb/desc.h"
29 #include "qemu/timer.h"
30 #include "hw/input/hid.h"
32 /* HID interface requests */
33 #define GET_REPORT 0xa101
34 #define GET_IDLE 0xa102
35 #define GET_PROTOCOL 0xa103
36 #define SET_REPORT 0x2109
37 #define SET_IDLE 0x210a
38 #define SET_PROTOCOL 0x210b
40 /* HID descriptor types */
41 #define USB_DT_HID 0x21
42 #define USB_DT_REPORT 0x22
43 #define USB_DT_PHY 0x23
45 typedef struct USBHIDState
{
54 #define TYPE_USB_HID "usb-hid"
55 #define USB_HID(obj) OBJECT_CHECK(USBHIDState, (obj), TYPE_USB_HID)
68 static const USBDescStrings desc_strings
= {
69 [STR_MANUFACTURER
] = "QEMU",
70 [STR_PRODUCT_MOUSE
] = "QEMU USB Mouse",
71 [STR_PRODUCT_TABLET
] = "QEMU USB Tablet",
72 [STR_PRODUCT_KEYBOARD
] = "QEMU USB Keyboard",
73 [STR_SERIALNUMBER
] = "42", /* == remote wakeup works */
74 [STR_CONFIG_MOUSE
] = "HID Mouse",
75 [STR_CONFIG_TABLET
] = "HID Tablet",
76 [STR_CONFIG_KEYBOARD
] = "HID Keyboard",
79 static const USBDescIface desc_iface_mouse
= {
80 .bInterfaceNumber
= 0,
82 .bInterfaceClass
= USB_CLASS_HID
,
83 .bInterfaceSubClass
= 0x01, /* boot */
84 .bInterfaceProtocol
= 0x02,
86 .descs
= (USBDescOther
[]) {
90 0x09, /* u8 bLength */
91 USB_DT_HID
, /* u8 bDescriptorType */
92 0x01, 0x00, /* u16 HID_class */
93 0x00, /* u8 country_code */
94 0x01, /* u8 num_descriptors */
95 USB_DT_REPORT
, /* u8 type: Report */
100 .eps
= (USBDescEndpoint
[]) {
102 .bEndpointAddress
= USB_DIR_IN
| 0x01,
103 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
110 static const USBDescIface desc_iface_mouse2
= {
111 .bInterfaceNumber
= 0,
113 .bInterfaceClass
= USB_CLASS_HID
,
114 .bInterfaceSubClass
= 0x01, /* boot */
115 .bInterfaceProtocol
= 0x02,
117 .descs
= (USBDescOther
[]) {
120 .data
= (uint8_t[]) {
121 0x09, /* u8 bLength */
122 USB_DT_HID
, /* u8 bDescriptorType */
123 0x01, 0x00, /* u16 HID_class */
124 0x00, /* u8 country_code */
125 0x01, /* u8 num_descriptors */
126 USB_DT_REPORT
, /* u8 type: Report */
131 .eps
= (USBDescEndpoint
[]) {
133 .bEndpointAddress
= USB_DIR_IN
| 0x01,
134 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
136 .bInterval
= 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */
141 static const USBDescIface desc_iface_tablet
= {
142 .bInterfaceNumber
= 0,
144 .bInterfaceClass
= USB_CLASS_HID
,
145 .bInterfaceProtocol
= 0x02,
147 .descs
= (USBDescOther
[]) {
150 .data
= (uint8_t[]) {
151 0x09, /* u8 bLength */
152 USB_DT_HID
, /* u8 bDescriptorType */
153 0x01, 0x00, /* u16 HID_class */
154 0x00, /* u8 country_code */
155 0x01, /* u8 num_descriptors */
156 USB_DT_REPORT
, /* u8 type: Report */
161 .eps
= (USBDescEndpoint
[]) {
163 .bEndpointAddress
= USB_DIR_IN
| 0x01,
164 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
171 static const USBDescIface desc_iface_tablet2
= {
172 .bInterfaceNumber
= 0,
174 .bInterfaceClass
= USB_CLASS_HID
,
175 .bInterfaceProtocol
= 0x02,
177 .descs
= (USBDescOther
[]) {
180 .data
= (uint8_t[]) {
181 0x09, /* u8 bLength */
182 USB_DT_HID
, /* u8 bDescriptorType */
183 0x01, 0x00, /* u16 HID_class */
184 0x00, /* u8 country_code */
185 0x01, /* u8 num_descriptors */
186 USB_DT_REPORT
, /* u8 type: Report */
191 .eps
= (USBDescEndpoint
[]) {
193 .bEndpointAddress
= USB_DIR_IN
| 0x01,
194 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
196 .bInterval
= 4, /* 2 ^ (4-1) * 125 usecs = 1 ms */
201 static const USBDescIface desc_iface_keyboard
= {
202 .bInterfaceNumber
= 0,
204 .bInterfaceClass
= USB_CLASS_HID
,
205 .bInterfaceSubClass
= 0x01, /* boot */
206 .bInterfaceProtocol
= 0x01, /* keyboard */
208 .descs
= (USBDescOther
[]) {
211 .data
= (uint8_t[]) {
212 0x09, /* u8 bLength */
213 USB_DT_HID
, /* u8 bDescriptorType */
214 0x11, 0x01, /* u16 HID_class */
215 0x00, /* u8 country_code */
216 0x01, /* u8 num_descriptors */
217 USB_DT_REPORT
, /* u8 type: Report */
218 0x3f, 0, /* u16 len */
222 .eps
= (USBDescEndpoint
[]) {
224 .bEndpointAddress
= USB_DIR_IN
| 0x01,
225 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
232 static const USBDescIface desc_iface_keyboard2
= {
233 .bInterfaceNumber
= 0,
235 .bInterfaceClass
= USB_CLASS_HID
,
236 .bInterfaceSubClass
= 0x01, /* boot */
237 .bInterfaceProtocol
= 0x01, /* keyboard */
239 .descs
= (USBDescOther
[]) {
242 .data
= (uint8_t[]) {
243 0x09, /* u8 bLength */
244 USB_DT_HID
, /* u8 bDescriptorType */
245 0x11, 0x01, /* u16 HID_class */
246 0x00, /* u8 country_code */
247 0x01, /* u8 num_descriptors */
248 USB_DT_REPORT
, /* u8 type: Report */
249 0x3f, 0, /* u16 len */
253 .eps
= (USBDescEndpoint
[]) {
255 .bEndpointAddress
= USB_DIR_IN
| 0x01,
256 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
258 .bInterval
= 7, /* 2 ^ (8-1) * 125 usecs = 8 ms */
263 static const USBDescDevice desc_device_mouse
= {
265 .bMaxPacketSize0
= 8,
266 .bNumConfigurations
= 1,
267 .confs
= (USBDescConfig
[]) {
270 .bConfigurationValue
= 1,
271 .iConfiguration
= STR_CONFIG_MOUSE
,
272 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
275 .ifs
= &desc_iface_mouse
,
280 static const USBDescDevice desc_device_mouse2
= {
282 .bMaxPacketSize0
= 64,
283 .bNumConfigurations
= 1,
284 .confs
= (USBDescConfig
[]) {
287 .bConfigurationValue
= 1,
288 .iConfiguration
= STR_CONFIG_MOUSE
,
289 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
292 .ifs
= &desc_iface_mouse2
,
297 static const USBDescDevice desc_device_tablet
= {
299 .bMaxPacketSize0
= 8,
300 .bNumConfigurations
= 1,
301 .confs
= (USBDescConfig
[]) {
304 .bConfigurationValue
= 1,
305 .iConfiguration
= STR_CONFIG_TABLET
,
306 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
309 .ifs
= &desc_iface_tablet
,
314 static const USBDescDevice desc_device_tablet2
= {
316 .bMaxPacketSize0
= 64,
317 .bNumConfigurations
= 1,
318 .confs
= (USBDescConfig
[]) {
321 .bConfigurationValue
= 1,
322 .iConfiguration
= STR_CONFIG_TABLET
,
323 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
326 .ifs
= &desc_iface_tablet2
,
331 static const USBDescDevice desc_device_keyboard
= {
333 .bMaxPacketSize0
= 8,
334 .bNumConfigurations
= 1,
335 .confs
= (USBDescConfig
[]) {
338 .bConfigurationValue
= 1,
339 .iConfiguration
= STR_CONFIG_KEYBOARD
,
340 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
343 .ifs
= &desc_iface_keyboard
,
348 static const USBDescDevice desc_device_keyboard2
= {
350 .bMaxPacketSize0
= 64,
351 .bNumConfigurations
= 1,
352 .confs
= (USBDescConfig
[]) {
355 .bConfigurationValue
= 1,
356 .iConfiguration
= STR_CONFIG_KEYBOARD
,
357 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
360 .ifs
= &desc_iface_keyboard2
,
365 static const USBDescMSOS desc_msos_suspend
= {
366 .SelectiveSuspendEnabled
= true,
369 static const USBDesc desc_mouse
= {
374 .iManufacturer
= STR_MANUFACTURER
,
375 .iProduct
= STR_PRODUCT_MOUSE
,
376 .iSerialNumber
= STR_SERIALNUMBER
,
378 .full
= &desc_device_mouse
,
380 .msos
= &desc_msos_suspend
,
383 static const USBDesc desc_mouse2
= {
388 .iManufacturer
= STR_MANUFACTURER
,
389 .iProduct
= STR_PRODUCT_MOUSE
,
390 .iSerialNumber
= STR_SERIALNUMBER
,
392 .full
= &desc_device_mouse
,
393 .high
= &desc_device_mouse2
,
395 .msos
= &desc_msos_suspend
,
398 static const USBDesc desc_tablet
= {
403 .iManufacturer
= STR_MANUFACTURER
,
404 .iProduct
= STR_PRODUCT_TABLET
,
405 .iSerialNumber
= STR_SERIALNUMBER
,
407 .full
= &desc_device_tablet
,
409 .msos
= &desc_msos_suspend
,
412 static const USBDesc desc_tablet2
= {
417 .iManufacturer
= STR_MANUFACTURER
,
418 .iProduct
= STR_PRODUCT_TABLET
,
419 .iSerialNumber
= STR_SERIALNUMBER
,
421 .full
= &desc_device_tablet
,
422 .high
= &desc_device_tablet2
,
424 .msos
= &desc_msos_suspend
,
427 static const USBDesc desc_keyboard
= {
432 .iManufacturer
= STR_MANUFACTURER
,
433 .iProduct
= STR_PRODUCT_KEYBOARD
,
434 .iSerialNumber
= STR_SERIALNUMBER
,
436 .full
= &desc_device_keyboard
,
438 .msos
= &desc_msos_suspend
,
441 static const USBDesc desc_keyboard2
= {
446 .iManufacturer
= STR_MANUFACTURER
,
447 .iProduct
= STR_PRODUCT_KEYBOARD
,
448 .iSerialNumber
= STR_SERIALNUMBER
,
450 .full
= &desc_device_keyboard
,
451 .high
= &desc_device_keyboard2
,
453 .msos
= &desc_msos_suspend
,
456 static const uint8_t qemu_mouse_hid_report_descriptor
[] = {
457 0x05, 0x01, /* Usage Page (Generic Desktop) */
458 0x09, 0x02, /* Usage (Mouse) */
459 0xa1, 0x01, /* Collection (Application) */
460 0x09, 0x01, /* Usage (Pointer) */
461 0xa1, 0x00, /* Collection (Physical) */
462 0x05, 0x09, /* Usage Page (Button) */
463 0x19, 0x01, /* Usage Minimum (1) */
464 0x29, 0x03, /* Usage Maximum (3) */
465 0x15, 0x00, /* Logical Minimum (0) */
466 0x25, 0x01, /* Logical Maximum (1) */
467 0x95, 0x03, /* Report Count (3) */
468 0x75, 0x01, /* Report Size (1) */
469 0x81, 0x02, /* Input (Data, Variable, Absolute) */
470 0x95, 0x01, /* Report Count (1) */
471 0x75, 0x05, /* Report Size (5) */
472 0x81, 0x01, /* Input (Constant) */
473 0x05, 0x01, /* Usage Page (Generic Desktop) */
474 0x09, 0x30, /* Usage (X) */
475 0x09, 0x31, /* Usage (Y) */
476 0x09, 0x38, /* Usage (Wheel) */
477 0x15, 0x81, /* Logical Minimum (-0x7f) */
478 0x25, 0x7f, /* Logical Maximum (0x7f) */
479 0x75, 0x08, /* Report Size (8) */
480 0x95, 0x03, /* Report Count (3) */
481 0x81, 0x06, /* Input (Data, Variable, Relative) */
482 0xc0, /* End Collection */
483 0xc0, /* End Collection */
486 static const uint8_t qemu_tablet_hid_report_descriptor
[] = {
487 0x05, 0x01, /* Usage Page (Generic Desktop) */
488 0x09, 0x01, /* Usage (Pointer) */
489 0xa1, 0x01, /* Collection (Application) */
490 0x09, 0x01, /* Usage (Pointer) */
491 0xa1, 0x00, /* Collection (Physical) */
492 0x05, 0x09, /* Usage Page (Button) */
493 0x19, 0x01, /* Usage Minimum (1) */
494 0x29, 0x03, /* Usage Maximum (3) */
495 0x15, 0x00, /* Logical Minimum (0) */
496 0x25, 0x01, /* Logical Maximum (1) */
497 0x95, 0x03, /* Report Count (3) */
498 0x75, 0x01, /* Report Size (1) */
499 0x81, 0x02, /* Input (Data, Variable, Absolute) */
500 0x95, 0x01, /* Report Count (1) */
501 0x75, 0x05, /* Report Size (5) */
502 0x81, 0x01, /* Input (Constant) */
503 0x05, 0x01, /* Usage Page (Generic Desktop) */
504 0x09, 0x30, /* Usage (X) */
505 0x09, 0x31, /* Usage (Y) */
506 0x15, 0x00, /* Logical Minimum (0) */
507 0x26, 0xff, 0x7f, /* Logical Maximum (0x7fff) */
508 0x35, 0x00, /* Physical Minimum (0) */
509 0x46, 0xff, 0x7f, /* Physical Maximum (0x7fff) */
510 0x75, 0x10, /* Report Size (16) */
511 0x95, 0x02, /* Report Count (2) */
512 0x81, 0x02, /* Input (Data, Variable, Absolute) */
513 0x05, 0x01, /* Usage Page (Generic Desktop) */
514 0x09, 0x38, /* Usage (Wheel) */
515 0x15, 0x81, /* Logical Minimum (-0x7f) */
516 0x25, 0x7f, /* Logical Maximum (0x7f) */
517 0x35, 0x00, /* Physical Minimum (same as logical) */
518 0x45, 0x00, /* Physical Maximum (same as logical) */
519 0x75, 0x08, /* Report Size (8) */
520 0x95, 0x01, /* Report Count (1) */
521 0x81, 0x06, /* Input (Data, Variable, Relative) */
522 0xc0, /* End Collection */
523 0xc0, /* End Collection */
526 static const uint8_t qemu_keyboard_hid_report_descriptor
[] = {
527 0x05, 0x01, /* Usage Page (Generic Desktop) */
528 0x09, 0x06, /* Usage (Keyboard) */
529 0xa1, 0x01, /* Collection (Application) */
530 0x75, 0x01, /* Report Size (1) */
531 0x95, 0x08, /* Report Count (8) */
532 0x05, 0x07, /* Usage Page (Key Codes) */
533 0x19, 0xe0, /* Usage Minimum (224) */
534 0x29, 0xe7, /* Usage Maximum (231) */
535 0x15, 0x00, /* Logical Minimum (0) */
536 0x25, 0x01, /* Logical Maximum (1) */
537 0x81, 0x02, /* Input (Data, Variable, Absolute) */
538 0x95, 0x01, /* Report Count (1) */
539 0x75, 0x08, /* Report Size (8) */
540 0x81, 0x01, /* Input (Constant) */
541 0x95, 0x05, /* Report Count (5) */
542 0x75, 0x01, /* Report Size (1) */
543 0x05, 0x08, /* Usage Page (LEDs) */
544 0x19, 0x01, /* Usage Minimum (1) */
545 0x29, 0x05, /* Usage Maximum (5) */
546 0x91, 0x02, /* Output (Data, Variable, Absolute) */
547 0x95, 0x01, /* Report Count (1) */
548 0x75, 0x03, /* Report Size (3) */
549 0x91, 0x01, /* Output (Constant) */
550 0x95, 0x06, /* Report Count (6) */
551 0x75, 0x08, /* Report Size (8) */
552 0x15, 0x00, /* Logical Minimum (0) */
553 0x25, 0xff, /* Logical Maximum (255) */
554 0x05, 0x07, /* Usage Page (Key Codes) */
555 0x19, 0x00, /* Usage Minimum (0) */
556 0x29, 0xff, /* Usage Maximum (255) */
557 0x81, 0x00, /* Input (Data, Array) */
558 0xc0, /* End Collection */
561 static void usb_hid_changed(HIDState
*hs
)
563 USBHIDState
*us
= container_of(hs
, USBHIDState
, hid
);
565 usb_wakeup(us
->intr
, 0);
568 static void usb_hid_handle_reset(USBDevice
*dev
)
570 USBHIDState
*us
= USB_HID(dev
);
575 static void usb_hid_handle_control(USBDevice
*dev
, USBPacket
*p
,
576 int request
, int value
, int index
, int length
, uint8_t *data
)
578 USBHIDState
*us
= USB_HID(dev
);
579 HIDState
*hs
= &us
->hid
;
582 ret
= usb_desc_handle_control(dev
, p
, request
, value
, index
, length
, data
);
588 /* hid specific requests */
589 case InterfaceRequest
| USB_REQ_GET_DESCRIPTOR
:
590 switch (value
>> 8) {
592 if (hs
->kind
== HID_MOUSE
) {
593 memcpy(data
, qemu_mouse_hid_report_descriptor
,
594 sizeof(qemu_mouse_hid_report_descriptor
));
595 p
->actual_length
= sizeof(qemu_mouse_hid_report_descriptor
);
596 } else if (hs
->kind
== HID_TABLET
) {
597 memcpy(data
, qemu_tablet_hid_report_descriptor
,
598 sizeof(qemu_tablet_hid_report_descriptor
));
599 p
->actual_length
= sizeof(qemu_tablet_hid_report_descriptor
);
600 } else if (hs
->kind
== HID_KEYBOARD
) {
601 memcpy(data
, qemu_keyboard_hid_report_descriptor
,
602 sizeof(qemu_keyboard_hid_report_descriptor
));
603 p
->actual_length
= sizeof(qemu_keyboard_hid_report_descriptor
);
611 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
612 p
->actual_length
= hid_pointer_poll(hs
, data
, length
);
613 } else if (hs
->kind
== HID_KEYBOARD
) {
614 p
->actual_length
= hid_keyboard_poll(hs
, data
, length
);
618 if (hs
->kind
== HID_KEYBOARD
) {
619 p
->actual_length
= hid_keyboard_write(hs
, data
, length
);
625 if (hs
->kind
!= HID_KEYBOARD
&& hs
->kind
!= HID_MOUSE
) {
628 data
[0] = hs
->protocol
;
629 p
->actual_length
= 1;
632 if (hs
->kind
!= HID_KEYBOARD
&& hs
->kind
!= HID_MOUSE
) {
635 hs
->protocol
= value
;
639 p
->actual_length
= 1;
642 hs
->idle
= (uint8_t) (value
>> 8);
643 hid_set_next_idle(hs
);
644 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
645 hid_pointer_activate(hs
);
650 p
->status
= USB_RET_STALL
;
655 static void usb_hid_handle_data(USBDevice
*dev
, USBPacket
*p
)
657 USBHIDState
*us
= USB_HID(dev
);
658 HIDState
*hs
= &us
->hid
;
659 uint8_t buf
[p
->iov
.size
];
664 if (p
->ep
->nr
== 1) {
665 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
666 hid_pointer_activate(hs
);
668 if (!hid_has_events(hs
)) {
669 p
->status
= USB_RET_NAK
;
672 hid_set_next_idle(hs
);
673 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
674 len
= hid_pointer_poll(hs
, buf
, p
->iov
.size
);
675 } else if (hs
->kind
== HID_KEYBOARD
) {
676 len
= hid_keyboard_poll(hs
, buf
, p
->iov
.size
);
678 usb_packet_copy(p
, buf
, len
);
686 p
->status
= USB_RET_STALL
;
691 static void usb_hid_handle_destroy(USBDevice
*dev
)
693 USBHIDState
*us
= USB_HID(dev
);
698 static void usb_hid_initfn(USBDevice
*dev
, int kind
,
699 const USBDesc
*usb1
, const USBDesc
*usb2
,
702 USBHIDState
*us
= USB_HID(dev
);
703 switch (us
->usb_version
) {
705 dev
->usb_desc
= usb1
;
708 dev
->usb_desc
= usb2
;
711 dev
->usb_desc
= NULL
;
713 if (!dev
->usb_desc
) {
714 error_setg(errp
, "Invalid usb version %d for usb hid device",
720 usb_desc_set_string(dev
, STR_SERIALNUMBER
, dev
->serial
);
723 us
->intr
= usb_ep_get(dev
, USB_TOKEN_IN
, 1);
724 hid_init(&us
->hid
, kind
, usb_hid_changed
);
725 if (us
->display
&& us
->hid
.s
) {
726 qemu_input_handler_bind(us
->hid
.s
, us
->display
, us
->head
, NULL
);
730 static void usb_tablet_realize(USBDevice
*dev
, Error
**errp
)
733 usb_hid_initfn(dev
, HID_TABLET
, &desc_tablet
, &desc_tablet2
, errp
);
736 static void usb_mouse_realize(USBDevice
*dev
, Error
**errp
)
738 usb_hid_initfn(dev
, HID_MOUSE
, &desc_mouse
, &desc_mouse2
, errp
);
741 static void usb_keyboard_realize(USBDevice
*dev
, Error
**errp
)
743 usb_hid_initfn(dev
, HID_KEYBOARD
, &desc_keyboard
, &desc_keyboard2
, errp
);
746 static int usb_ptr_post_load(void *opaque
, int version_id
)
748 USBHIDState
*s
= opaque
;
750 if (s
->dev
.remote_wakeup
) {
751 hid_pointer_activate(&s
->hid
);
756 static const VMStateDescription vmstate_usb_ptr
= {
759 .minimum_version_id
= 1,
760 .post_load
= usb_ptr_post_load
,
761 .fields
= (VMStateField
[]) {
762 VMSTATE_USB_DEVICE(dev
, USBHIDState
),
763 VMSTATE_HID_POINTER_DEVICE(hid
, USBHIDState
),
764 VMSTATE_END_OF_LIST()
768 static const VMStateDescription vmstate_usb_kbd
= {
771 .minimum_version_id
= 1,
772 .fields
= (VMStateField
[]) {
773 VMSTATE_USB_DEVICE(dev
, USBHIDState
),
774 VMSTATE_HID_KEYBOARD_DEVICE(hid
, USBHIDState
),
775 VMSTATE_END_OF_LIST()
779 static void usb_hid_class_initfn(ObjectClass
*klass
, void *data
)
781 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
783 uc
->handle_reset
= usb_hid_handle_reset
;
784 uc
->handle_control
= usb_hid_handle_control
;
785 uc
->handle_data
= usb_hid_handle_data
;
786 uc
->handle_destroy
= usb_hid_handle_destroy
;
787 uc
->handle_attach
= usb_desc_attach
;
790 static const TypeInfo usb_hid_type_info
= {
791 .name
= TYPE_USB_HID
,
792 .parent
= TYPE_USB_DEVICE
,
793 .instance_size
= sizeof(USBHIDState
),
795 .class_init
= usb_hid_class_initfn
,
798 static Property usb_tablet_properties
[] = {
799 DEFINE_PROP_UINT32("usb_version", USBHIDState
, usb_version
, 2),
800 DEFINE_PROP_STRING("display", USBHIDState
, display
),
801 DEFINE_PROP_UINT32("head", USBHIDState
, head
, 0),
802 DEFINE_PROP_END_OF_LIST(),
805 static void usb_tablet_class_initfn(ObjectClass
*klass
, void *data
)
807 DeviceClass
*dc
= DEVICE_CLASS(klass
);
808 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
810 uc
->realize
= usb_tablet_realize
;
811 uc
->product_desc
= "QEMU USB Tablet";
812 dc
->vmsd
= &vmstate_usb_ptr
;
813 dc
->props
= usb_tablet_properties
;
814 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
817 static const TypeInfo usb_tablet_info
= {
818 .name
= "usb-tablet",
819 .parent
= TYPE_USB_HID
,
820 .class_init
= usb_tablet_class_initfn
,
823 static Property usb_mouse_properties
[] = {
824 DEFINE_PROP_UINT32("usb_version", USBHIDState
, usb_version
, 2),
825 DEFINE_PROP_END_OF_LIST(),
828 static void usb_mouse_class_initfn(ObjectClass
*klass
, void *data
)
830 DeviceClass
*dc
= DEVICE_CLASS(klass
);
831 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
833 uc
->realize
= usb_mouse_realize
;
834 uc
->product_desc
= "QEMU USB Mouse";
835 dc
->vmsd
= &vmstate_usb_ptr
;
836 dc
->props
= usb_mouse_properties
;
837 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
840 static const TypeInfo usb_mouse_info
= {
842 .parent
= TYPE_USB_HID
,
843 .class_init
= usb_mouse_class_initfn
,
846 static Property usb_keyboard_properties
[] = {
847 DEFINE_PROP_UINT32("usb_version", USBHIDState
, usb_version
, 2),
848 DEFINE_PROP_STRING("display", USBHIDState
, display
),
849 DEFINE_PROP_END_OF_LIST(),
852 static void usb_keyboard_class_initfn(ObjectClass
*klass
, void *data
)
854 DeviceClass
*dc
= DEVICE_CLASS(klass
);
855 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
857 uc
->realize
= usb_keyboard_realize
;
858 uc
->product_desc
= "QEMU USB Keyboard";
859 dc
->vmsd
= &vmstate_usb_kbd
;
860 dc
->props
= usb_keyboard_properties
;
861 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
864 static const TypeInfo usb_keyboard_info
= {
866 .parent
= TYPE_USB_HID
,
867 .class_init
= usb_keyboard_class_initfn
,
870 static void usb_hid_register_types(void)
872 type_register_static(&usb_hid_type_info
);
873 type_register_static(&usb_tablet_info
);
874 usb_legacy_register("usb-tablet", "tablet", NULL
);
875 type_register_static(&usb_mouse_info
);
876 usb_legacy_register("usb-mouse", "mouse", NULL
);
877 type_register_static(&usb_keyboard_info
);
878 usb_legacy_register("usb-kbd", "keyboard", NULL
);
881 type_init(usb_hid_register_types
)