usb-hid: Add high speed mouse configuration
PATCH 1/2 usb-hid: Add high speed mouse configuration
---
Tested on Ubuntu, Fedora, and HelenOS.
hw/usb/dev-hid.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-)
hw/usb/dev-hid.c +59 -8
@@ -55,9 +55,10 @@ enum {STR_PRODUCT_TABLET ,STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER , -STR_CONFIG_MOUSE ,STR_CONFIG_TABLET ,STR_CONFIG_KEYBOARD , +STR_CONFIG_MOUSE_FULL , + STR_CONFIG_MOUSE_HIGH, }; static const USBDescStrings desc_strings = {
@@ -66,12 +67,13 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_TABLET] = "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ - [STR_CONFIG_MOUSE] = "HID Mouse", [STR_CONFIG_TABLET] = "HID Tablet", [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", + [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", }; -static const USBDescIface desc_iface_mouse = { +static const USBDescIface desc_iface_mouse_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,
@@ -102,6 +104,37 @@ static const USBDescIface desc_iface_mouse = { }, }; +static const USBDescIface desc_iface_mouse_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x02 , + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x01 ,0x00 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +52 ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =4 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescIface desc_iface_tablet = { .bInterfaceNumber =0 , .bNumEndpoints =1 ,
@@ -193,19 +226,36 @@ static const USBDescIface desc_iface_keyboard = { }, }; -static const USBDescDevice desc_device_mouse = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_mouse_full = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_MOUSE_FULL , + .bmAttributes =0xa0 , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_mouse_full, + }, + }, +}; + +static const USBDescDevice desc_device_mouse_high = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_MOUSE , + .iConfiguration =STR_CONFIG_MOUSE_HIGH , .bmAttributes =0xa0 , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_mouse, + .ifs = &desc_iface_mouse_high, }, }, };
@@ -274,7 +324,8 @@ static const USBDesc desc_mouse = { .iProduct = STR_PRODUCT_MOUSE, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_mouse, + .full = &desc_device_mouse_full, + .high = &desc_device_mouse_high, .str = desc_strings, .msos = &desc_msos_suspend, };
Signature · 1 line
1.8.3.2
PATCH 2/2 usb-hid: Add high speed keyboard configuration
---
Tested on Ubuntu, Fedora, and HelenOS.
hw/usb/dev-hid.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 8 deletions(-)
hw/usb/dev-hid.c +59 -8
@@ -56,7 +56,8 @@ enum {STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER ,STR_CONFIG_TABLET , -STR_CONFIG_KEYBOARD , +STR_CONFIG_KEYBOARD_FULL , +STR_CONFIG_KEYBOARD_HIGH ,STR_CONFIG_MOUSE_FULL , STR_CONFIG_MOUSE_HIGH, };
@@ -68,7 +69,8 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ [STR_CONFIG_TABLET] = "HID Tablet", - [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_KEYBOARD_FULL] = "HID Keyboard Full speed configuration (usb 1.1)", + [STR_CONFIG_KEYBOARD_HIGH] = "HID Keyboard High speed configuration (usb 2.0)", [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", };
@@ -195,7 +197,7 @@ static const USBDescIface desc_iface_tablet2 = { }, }; -static const USBDescIface desc_iface_keyboard = { +static const USBDescIface desc_iface_keyboard_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,
@@ -226,6 +228,37 @@ static const USBDescIface desc_iface_keyboard = { }, }; +static const USBDescIface desc_iface_keyboard_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x01 ,/* keyboard */ + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x11 ,0x01 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +0x3f ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =8 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescDevice desc_device_mouse_full = { .bcdUSB =0x0200 , .bMaxPacketSize0 =8 ,
@@ -294,19 +327,36 @@ static const USBDescDevice desc_device_tablet2 = { }, }; -static const USBDescDevice desc_device_keyboard = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_keyboard_full = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_KEYBOARD_FULL , + .bmAttributes =0xa0 , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_keyboard_full, + }, + }, +}; + +static const USBDescDevice desc_device_keyboard_high = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_KEYBOARD , + .iConfiguration =STR_CONFIG_KEYBOARD_HIGH , .bmAttributes =0xa0 , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_keyboard, + .ifs = &desc_iface_keyboard_high, }, }, };
@@ -368,7 +418,8 @@ static const USBDesc desc_keyboard = { .iProduct = STR_PRODUCT_KEYBOARD, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_keyboard, + .full = &desc_device_keyboard_full, + .high = &desc_device_keyboard_high, .str = desc_strings, .msos = &desc_msos_suspend, };
Signature · 1 line
1.8.3.2
Quoted 1 line · Jan Vesely
Signed-off-by Jan Vesely <[email protected]>
This should have a usb_version property, like usb-tablet has.
cheers,
Gerd
PATCH v2 1/2 usb-hid: Add high speed mouse configuration
v2: add usb_mouse_properties
use macros for bmAttributes
--- hw/usb/dev-hid.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 8 deletions(-)
hw/usb/dev-hid.c +65 -8
@@ -55,9 +55,10 @@ enum {STR_PRODUCT_TABLET ,STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER , -STR_CONFIG_MOUSE ,STR_CONFIG_TABLET ,STR_CONFIG_KEYBOARD , +STR_CONFIG_MOUSE_FULL , + STR_CONFIG_MOUSE_HIGH, }; static const USBDescStrings desc_strings = {
@@ -66,12 +67,13 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_TABLET] = "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ - [STR_CONFIG_MOUSE] = "HID Mouse", [STR_CONFIG_TABLET] = "HID Tablet", [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", + [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", }; -static const USBDescIface desc_iface_mouse = { +static const USBDescIface desc_iface_mouse_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,
@@ -102,6 +104,37 @@ static const USBDescIface desc_iface_mouse = { }, }; +static const USBDescIface desc_iface_mouse_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x02 , + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x01 ,0x00 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +52 ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =4 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescIface desc_iface_tablet = { .bInterfaceNumber =0 , .bNumEndpoints =1 ,
@@ -193,19 +226,36 @@ static const USBDescIface desc_iface_keyboard = { }, }; -static const USBDescDevice desc_device_mouse = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_mouse_full = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_MOUSE_FULL , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_mouse_full, + }, + }, +}; + +static const USBDescDevice desc_device_mouse_high = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_MOUSE , + .iConfiguration =STR_CONFIG_MOUSE_HIGH , .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_mouse, + .ifs = &desc_iface_mouse_high, }, }, };
@@ -274,7 +324,8 @@ static const USBDesc desc_mouse = { .iProduct = STR_PRODUCT_MOUSE, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_mouse, + .full = &desc_device_mouse_full, + .high = &desc_device_mouse_high, .str = desc_strings, .msos = &desc_msos_suspend, };
@@ -676,6 +727,11 @@ static const TypeInfo usb_tablet_info = { .class_init = usb_tablet_class_initfn, }; +static Property usb_mouse_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void usb_mouse_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -686,6 +742,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data) uc->product_desc ="QEMU USB Mouse" ; uc->usb_desc = &desc_mouse; dc->vmsd = &vmstate_usb_ptr; + dc->props = usb_mouse_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); }
Signature · 1 line
1.9.0
PATCH v2 2/2 usb-hid: Add high speed keyboard configuration
v2: add usb_keyboard_properties
use macros for bmAttributes
--- hw/usb/dev-hid.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 8 deletions(-)
hw/usb/dev-hid.c +65 -8
@@ -56,7 +56,8 @@ enum {STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER ,STR_CONFIG_TABLET , -STR_CONFIG_KEYBOARD , +STR_CONFIG_KEYBOARD_FULL , +STR_CONFIG_KEYBOARD_HIGH ,STR_CONFIG_MOUSE_FULL , STR_CONFIG_MOUSE_HIGH, };
@@ -68,7 +69,8 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ [STR_CONFIG_TABLET] = "HID Tablet", - [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_KEYBOARD_FULL] = "HID Keyboard Full speed configuration (usb 1.1)", + [STR_CONFIG_KEYBOARD_HIGH] = "HID Keyboard High speed configuration (usb 2.0)", [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", };
@@ -195,7 +197,7 @@ static const USBDescIface desc_iface_tablet2 = { }, }; -static const USBDescIface desc_iface_keyboard = { +static const USBDescIface desc_iface_keyboard_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,
@@ -226,6 +228,37 @@ static const USBDescIface desc_iface_keyboard = { }, }; +static const USBDescIface desc_iface_keyboard_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x01 ,/* keyboard */ + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x11 ,0x01 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +0x3f ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =8 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescDevice desc_device_mouse_full = { .bcdUSB =0x0200 , .bMaxPacketSize0 =8 ,
@@ -294,19 +327,36 @@ static const USBDescDevice desc_device_tablet2 = { }, }; -static const USBDescDevice desc_device_keyboard = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_keyboard_full = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_KEYBOARD , + .iConfiguration =STR_CONFIG_KEYBOARD_FULL , .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_keyboard, + .ifs = &desc_iface_keyboard_full, + }, + }, +}; + +static const USBDescDevice desc_device_keyboard_high = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_KEYBOARD_HIGH , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_keyboard_high, }, }, };
@@ -368,7 +418,8 @@ static const USBDesc desc_keyboard = { .iProduct = STR_PRODUCT_KEYBOARD, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_keyboard, + .full = &desc_device_keyboard_full, + .high = &desc_device_keyboard_high, .str = desc_strings, .msos = &desc_msos_suspend, };
@@ -753,6 +804,11 @@ static const TypeInfo usb_mouse_info = { .class_init = usb_mouse_class_initfn, }; +static Property usb_keyboard_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void usb_keyboard_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -763,6 +819,7 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data) uc->product_desc ="QEMU USB Keyboard" ; uc->usb_desc = &desc_keyboard; dc->vmsd = &vmstate_usb_kbd; + dc->props = usb_keyboard_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); }
Signature · 1 line
1.9.0
ping
any problem with v2?
regards,
Jan
Quoted 152 lines · Jan Vesely
v2: add
usb_mouse_properties
use macros for bmAttributesSigned-off-by Jan Vesely <[email protected]>--- hw/usb/dev-hid.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 8 deletions(-)hw/usb/dev-hid.c +65
-9@@ -55,9 +55,10 @@ enum {STR_PRODUCT_TABLET ,STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER , -STR_CONFIG_MOUSE ,STR_CONFIG_TABLET ,STR_CONFIG_KEYBOARD , +STR_CONFIG_MOUSE_FULL , + STR_CONFIG_MOUSE_HIGH, }; static const USBDescStrings desc_strings = {@@ -66,12 +67,13 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_TABLET] = "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ - [STR_CONFIG_MOUSE] = "HID Mouse", [STR_CONFIG_TABLET] = "HID Tablet", [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", + [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", }; -static const USBDescIface desc_iface_mouse = { +static const USBDescIface desc_iface_mouse_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,@@ -102,6 +104,37 @@ static const USBDescIface desc_iface_mouse = { }, }; +static const USBDescIface desc_iface_mouse_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x02 , + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x01 ,0x00 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +52 ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =4 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescIface desc_iface_tablet = { .bInterfaceNumber =0 , .bNumEndpoints =1 ,@@ -193,19 +226,36 @@ static const USBDescIface desc_iface_keyboard = { }, }; -static const USBDescDevice desc_device_mouse = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_mouse_full = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_MOUSE_FULL , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_mouse_full, + }, + }, +}; + +static const USBDescDevice desc_device_mouse_high = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_MOUSE , + .iConfiguration =STR_CONFIG_MOUSE_HIGH , .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_mouse, + .ifs = &desc_iface_mouse_high, }, }, };@@ -274,7 +324,8 @@ static const USBDesc desc_mouse = { .iProduct = STR_PRODUCT_MOUSE, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_mouse, + .full = &desc_device_mouse_full, + .high = &desc_device_mouse_high, .str = desc_strings, .msos = &desc_msos_suspend, };@@ -676,6 +727,11 @@ static const TypeInfo usb_tablet_info = { .class_init = usb_tablet_class_initfn, }; +static Property usb_mouse_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void usb_mouse_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -686,6 +742,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data) uc->product_desc ="QEMU USB Mouse" ; uc->usb_desc = &desc_mouse; dc->vmsd = &vmstate_usb_ptr; + dc->props = usb_mouse_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); } --1.9.0
ping2
is there anything I can do to help these patches get merged?
Jan
Quoted 160 lines · Ján Veselý
ping
any problem with v2?
regards,
JanQuoted 152 lines · Jan Vesely
v2: add
usb_mouse_properties
use macros for bmAttributesSigned-off-by Jan Vesely <[email protected]>--- hw/usb/dev-hid.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 8 deletions(-)hw/usb/dev-hid.c +65
-9@@ -55,9 +55,10 @@ enum {STR_PRODUCT_TABLET ,STR_PRODUCT_KEYBOARD ,STR_SERIALNUMBER , -STR_CONFIG_MOUSE ,STR_CONFIG_TABLET ,STR_CONFIG_KEYBOARD , +STR_CONFIG_MOUSE_FULL , + STR_CONFIG_MOUSE_HIGH, }; static const USBDescStrings desc_strings = {@@ -66,12 +67,13 @@ static const USBDescStrings desc_strings = { [STR_PRODUCT_TABLET] = "QEMU USB Tablet", [STR_PRODUCT_KEYBOARD] = "QEMU USB Keyboard", [STR_SERIALNUMBER] = "42", /* == remote wakeup works */ - [STR_CONFIG_MOUSE] = "HID Mouse", [STR_CONFIG_TABLET] = "HID Tablet", [STR_CONFIG_KEYBOARD] = "HID Keyboard", + [STR_CONFIG_MOUSE_FULL]= "HID Mouse Full speed configuration (usb 1.1)", + [STR_CONFIG_MOUSE_HIGH]= "HID Mouse High speed configuration (usb 2.0)", }; -static const USBDescIface desc_iface_mouse = { +static const USBDescIface desc_iface_mouse_full = { .bInterfaceNumber =0 , .bNumEndpoints =1 , .bInterfaceClass =USB_CLASS_HID ,@@ -102,6 +104,37 @@ static const USBDescIface desc_iface_mouse = { }, }; +static const USBDescIface desc_iface_mouse_high = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x02 , + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x01 ,0x00 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +52 ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =4 , + .bInterval =0x06 , + }, + }, +}; +static const USBDescIface desc_iface_tablet = { .bInterfaceNumber =0 , .bNumEndpoints =1 ,@@ -193,19 +226,36 @@ static const USBDescIface desc_iface_keyboard = { }, }; -static const USBDescDevice desc_device_mouse = { - .bcdUSB =0x0100 , +static const USBDescDevice desc_device_mouse_full = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =8 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_MOUSE_FULL , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_mouse_full, + }, + }, +}; + +static const USBDescDevice desc_device_mouse_high = { + .bcdUSB =0x0200 , .bMaxPacketSize0 =8 , .bNumConfigurations =1 , .confs = (USBDescConfig []) { { .bNumInterfaces =1 , .bConfigurationValue =1 , - .iConfiguration =STR_CONFIG_MOUSE , + .iConfiguration =STR_CONFIG_MOUSE_HIGH , .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , .bMaxPower =50 , .nif =1 , - .ifs = &desc_iface_mouse, + .ifs = &desc_iface_mouse_high, }, }, };@@ -274,7 +324,8 @@ static const USBDesc desc_mouse = { .iProduct = STR_PRODUCT_MOUSE, .iSerialNumber = STR_SERIALNUMBER, }, - .full = &desc_device_mouse, + .full = &desc_device_mouse_full, + .high = &desc_device_mouse_high, .str = desc_strings, .msos = &desc_msos_suspend, };@@ -676,6 +727,11 @@ static const TypeInfo usb_tablet_info = { .class_init = usb_tablet_class_initfn, }; +static Property usb_mouse_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void usb_mouse_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);@@ -686,6 +742,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data) uc->product_desc ="QEMU USB Mouse" ; uc->usb_desc = &desc_mouse; dc->vmsd = &vmstate_usb_ptr; + dc->props = usb_mouse_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); } --1.9.0
Quoted 3 lines · Ján Veselý
ping2
is there anything I can do to help these patches get merged?
Well, v2 is a step into the right direction but not complete yet. The usb_ver property hasn't any effect for mouse and keyboard. Also we'll need a compat property so older machine types continue to have usb1 mouse+keyboard.
The compat property stuff is a bit tricky so my plan was to just do that myself, but I havn't found the time yet.
If you wanna tackle the challenge have a look at 427e3aa151c749225364d0c30640e2e3c1756d9d (tablet patch). keyboard+mouse need to do the same.
Also some cleanups can be done, such as moving the "switch (us->usb_version) { ... }" from usb_tablet_initfn to usb_hid_initfn to avoid duplicating it.
cheers,
Gerd
Hi Gerd,
sorry for taking so long to get back to this. My schedule has been super busy past couple of months.
I have rebased the patches and moved the usb version desc selection to hid_initfn as you suggested. I also made the changes follow the tablet example as closely as possible
I tested the patches on ubuntu 64 and fedora 64 liveCDs and both mouse and keyboard still work ok.
thanks,
jan
Quoted 38 lines · Gerd Hoffmann
Quoted 6 lines · Ján Veselý
Hi,
I found some more time to work on this. However, I'm not sure I understand the purpose of compat property:
I noticed that the only place it's set is inPC_COMPAT_1_3(is this what you meant by older devices?),Older machine types, yes. This switches the tablet to usb1 by default if you start qemu with -M pc-1.3 (or older), because it was usb1 only in qemu 1.3 & older.
Quoted 1 line
I guess same setting for FS mouse and kbd should be added there as well.
They need to go to the (probably not added yet)
PC_COMPAT_2_0.Quoted 10 lines
The switch statement in
usb_tablet_initfnselects between two descriptor structures, however, these structures are almost identical with the sole exception of .high field being set in the HS version (desc_tablet2).So changing the switch statement to:
if (us->usb_version< 2)dev->usb_desc->high = NULL;should be OK for all usb hid devices, right?
No. That struct is shared between all device instances, so if you muck with it all devices are affected, i.e. this ...
qemu -device usb-tablet,usb_ver=1 -device usb_tablet,usb_ver=2
will not work correctly.
cheers,
Gerd
PATCH v3 2/3 usb-hid: Add high speed mouse configuration
In reply to Jan Veselyv2: add usb_mouse_properties
use macros for bmAttributes
v3: rebase
--- hw/usb/dev-hid.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-)
hw/usb/dev-hid.c +70 -1
@@ -104,6 +104,37 @@ static const USBDescIface desc_iface_mouse = { }, }; +static const USBDescIface desc_iface_mouse2 = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x02 , + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x01 ,0x00 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +52 ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =4 , + .bInterval =7 ,/* 2 ^ (8-1) * 125 usecs = 8 ms */ + }, + }, +}; +static const USBDescIface desc_iface_tablet = { .bInterfaceNumber =0 , .bNumEndpoints =1 ,
@@ -212,6 +243,23 @@ static const USBDescDevice desc_device_mouse = { }, }; +static const USBDescDevice desc_device_mouse2 = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =64 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_MOUSE , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_mouse2, + }, + }, +}; +static const USBDescDevice desc_device_tablet = { .bcdUSB =0x0100 , .bMaxPacketSize0 =8 ,
@@ -281,6 +329,21 @@ static const USBDesc desc_mouse = { .msos = &desc_msos_suspend, }; +static const USBDesc desc_mouse2 = { + .id = { + .idVendor =0x0627 , + .idProduct =0x0001 , + .bcdDevice =0 , + .iManufacturer =STR_MANUFACTURER , + .iProduct =STR_PRODUCT_MOUSE , + .iSerialNumber =STR_SERIALNUMBER , + }, + .full = &desc_device_mouse, + .high = &desc_device_mouse2, + .str = desc_strings, + .msos = &desc_msos_suspend, +}; +static const USBDesc desc_tablet = { .id = { .idVendor =0x0627 ,
@@ -602,7 +665,7 @@ static int usb_tablet_initfn(USBDevice *dev)static int usb_mouse_initfn (USBDevice *dev) { -return usb_hid_initfn (dev,HID_MOUSE , &desc_mouse, &desc_mouse); +return usb_hid_initfn (dev,HID_MOUSE , &desc_mouse, &desc_mouse2); }static int usb_keyboard_initfn (USBDevice *dev)
@@ -681,6 +744,11 @@ static const TypeInfo usb_tablet_info = { .class_init = usb_tablet_class_initfn, }; +static Property usb_mouse_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ), +DEFINE_PROP_END_OF_LIST (), +}; +static void usb_mouse_class_initfn (ObjectClass *klass,void *data) {DeviceClass *dc =DEVICE_CLASS (klass);
@@ -690,6 +758,7 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data) uc->init = usb_mouse_initfn; uc->product_desc ="QEMU USB Mouse" ; dc->vmsd = &vmstate_usb_ptr; + dc->props = usb_mouse_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); }
Signature · 1 line
1.9.3
PATCH 1/3 usb-hid: Move descriptor decision to usb-hid initfn
In reply to Jan Vesely--- hw/usb/dev-hid.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-)
hw/usb/dev-hid.c +17 -21
@@ -566,9 +566,22 @@ static void usb_hid_handle_destroy(USBDevice *dev)hid_free (&us->hid); } -static int usb_hid_initfn (USBDevice *dev,int kind) +static int usb_hid_initfn (USBDevice *dev,int kind, +const USBDesc *usb1,const USBDesc *usb2) {USBHIDState *us =DO_UPCAST (USBHIDState, dev, dev); +switch (us->usb_version) { +case 1 : + dev->usb_desc = usb1; +break ; +case 2 : + dev->usb_desc = usb2; +break ; +default : +error_report ("Invalid usb version %d for hid device (must be 1 or 2)" , + us->usb_version); +return -1 ; + }if (dev->serial) {usb_desc_set_string (dev,STR_SERIALNUMBER , dev->serial);
@@ -584,32 +597,17 @@ static int usb_hid_initfn(USBDevice *dev, int kind)static int usb_tablet_initfn (USBDevice *dev) { -USBHIDState *us =DO_UPCAST (USBHIDState, dev, dev); - -switch (us->usb_version) { -case 1 : - dev->usb_desc = &desc_tablet; -break ; -case 2 : - dev->usb_desc = &desc_tablet2; -break ; -default : -error_report ("Invalid usb version %d for usb-tabler (must be 1 or 2)" , - us->usb_version); -return -1 ; - } - -return usb_hid_initfn (dev,HID_TABLET ); +return usb_hid_initfn (dev,HID_TABLET , &desc_tablet, &desc_tablet2); }static int usb_mouse_initfn (USBDevice *dev) { -return usb_hid_initfn (dev,HID_MOUSE ); +return usb_hid_initfn (dev,HID_MOUSE , &desc_mouse, &desc_mouse); }static int usb_keyboard_initfn (USBDevice *dev) { -return usb_hid_initfn (dev,HID_KEYBOARD ); +return usb_hid_initfn (dev,HID_KEYBOARD , &desc_keyboard, &desc_keyboard); }static int usb_ptr_post_load (void *opaque,int version_id)
@@ -691,7 +689,6 @@ static void usb_mouse_class_initfn(ObjectClass *klass, void *data)usb_hid_class_initfn (klass, data); uc->init = usb_mouse_initfn; uc->product_desc ="QEMU USB Mouse" ; - uc->usb_desc = &desc_mouse; dc->vmsd = &vmstate_usb_ptr;set_bit (DEVICE_CATEGORY_INPUT , dc->categories); }
@@ -716,7 +713,6 @@ static void usb_keyboard_class_initfn(ObjectClass *klass, void *data)usb_hid_class_initfn (klass, data); uc->init = usb_keyboard_initfn; uc->product_desc ="QEMU USB Keyboard" ; - uc->usb_desc = &desc_keyboard; dc->vmsd = &vmstate_usb_kbd; dc->props = usb_keyboard_properties;set_bit (DEVICE_CATEGORY_INPUT , dc->categories);
Signature · 1 line
1.9.3
PATCH 3/3 usb-hid: Add high speed keyboard configuration
--- hw/usb/dev-hid.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-)
hw/usb/dev-hid.c +65 -1
@@ -226,6 +226,37 @@ static const USBDescIface desc_iface_keyboard = { }, }; +static const USBDescIface desc_iface_keyboard2 = { + .bInterfaceNumber =0 , + .bNumEndpoints =1 , + .bInterfaceClass =USB_CLASS_HID , + .bInterfaceSubClass =0x01 ,/* boot */ + .bInterfaceProtocol =0x01 ,/* keyboard */ + .ndesc =1 , + .descs = (USBDescOther []) { + { +/* HID descriptor */ + .data = (uint8_t []) { +0x09 ,/* u8 bLength */ +USB_DT_HID ,/* u8 bDescriptorType */ +0x11 ,0x01 ,/* u16 HID_class */ +0x00 ,/* u8 country_code */ +0x01 ,/* u8 num_descriptors */ +USB_DT_REPORT ,/* u8 type: Report */ +0x3f ,0 ,/* u16 len */ + }, + }, + }, + .eps = (USBDescEndpoint []) { + { + .bEndpointAddress =USB_DIR_IN |0x01 , + .bmAttributes =USB_ENDPOINT_XFER_INT , + .wMaxPacketSize =8 , + .bInterval =7 ,/* 2 ^ (8-1) * 125 usecs = 8 ms */ + }, + }, +}; +static const USBDescDevice desc_device_mouse = { .bcdUSB =0x0100 , .bMaxPacketSize0 =8 ,
@@ -311,6 +342,23 @@ static const USBDescDevice desc_device_keyboard = { }, }; +static const USBDescDevice desc_device_keyboard2 = { + .bcdUSB =0x0200 , + .bMaxPacketSize0 =64 , + .bNumConfigurations =1 , + .confs = (USBDescConfig []) { + { + .bNumInterfaces =1 , + .bConfigurationValue =1 , + .iConfiguration =STR_CONFIG_KEYBOARD , + .bmAttributes =USB_CFG_ATT_ONE |USB_CFG_ATT_WAKEUP , + .bMaxPower =50 , + .nif =1 , + .ifs = &desc_iface_keyboard2, + }, + }, +}; +static const USBDescMSOS desc_msos_suspend = { .SelectiveSuspendEnabled = true, };
@@ -387,6 +435,21 @@ static const USBDesc desc_keyboard = { .msos = &desc_msos_suspend, }; +static const USBDesc desc_keyboard2 = { + .id = { + .idVendor =0x0627 , + .idProduct =0x0001 , + .bcdDevice =0 , + .iManufacturer =STR_MANUFACTURER , + .iProduct =STR_PRODUCT_KEYBOARD , + .iSerialNumber =STR_SERIALNUMBER , + }, + .full = &desc_device_keyboard, + .high = &desc_device_keyboard2, + .str = desc_strings, + .msos = &desc_msos_suspend, +}; +static const uint8_t qemu_mouse_hid_report_descriptor[] = {0x05 ,0x01 ,/* Usage Page (Generic Desktop) */ 0x09 ,0x02 ,/* Usage (Mouse) */
@@ -670,7 +733,7 @@ static int usb_mouse_initfn(USBDevice *dev)static int usb_keyboard_initfn (USBDevice *dev) { -return usb_hid_initfn (dev,HID_KEYBOARD , &desc_keyboard, &desc_keyboard); +return usb_hid_initfn (dev,HID_KEYBOARD , &desc_keyboard, &desc_keyboard2); }static int usb_ptr_post_load (void *opaque,int version_id)
@@ -770,6 +833,7 @@ static const TypeInfo usb_mouse_info = { };static Property usb_keyboard_properties[] = { +DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ),DEFINE_PROP_STRING ("display" , USBHIDState, display),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
1.9.3