hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests
v2 cover hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests
This series makes the Qemu usb-tablet work correctly with OS X/macOS guests without the need for a special guest driver.
* The usb-tablet should not have a boot protocol of 2. Other OSes seem to ignore this, but the IOHIDFamily driver stack chokes on it for anything but conventional (relative motion) mice.
* A "mac_compat" boolean option is added to the usb-tablet, which changes its report descriptor to specify a usage of 0x02 (mouse) instead of 0x01 (pointer). This is required for correct operation in the Mac HID driver stack.
Changelog
=========
v1 -> v2:
* v1 Thread was "[PATCH] hw/usb/dev-hid: add a Mac guest compatibility option to usb-tablet"
* Always apply the boot protocol (bInterfaceProtocol) change to usb-tablet, not just when the Mac compatibility option is active. The original value of 0x02 was determined to be incorrect according to the spec anyway.
* As the boot protocol change is permanent, separate interface and device descriptor constants for the Mac/non-Mac variants of the tablet are no longer required, and have been removed.
Phil Dennis-Jordan (2):
hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option
hw/usb/dev-hid.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.3.2 (Apple Git-55)
PATCH v2 1/2 hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet
This should be non-zero for boot protocol devices only, which the usb-tablet is not.
A boot protocol of 0x02 specifically confuses OS X/macOS' HID driver stack, causing it to generate additional bogus HID events with relative motion in addition to the tablet's absolute coordinate events.
--- hw/usb/dev-hid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/usb/dev-hid.c +2 -2
@@ -144,7 +144,7 @@ static const USBDescIface desc_iface_tablet = { .bInterfaceNumber = 0, .bNumEndpoints = 1, .bInterfaceClass = USB_CLASS_HID, - .bInterfaceProtocol = 0x02, + .bInterfaceProtocol = 0x00, .ndesc = 1, .descs = (USBDescOther []) { {
@@ -174,7 +174,7 @@ static const USBDescIface desc_iface_tablet2 = { .bInterfaceNumber = 0, .bNumEndpoints = 1, .bInterfaceClass = USB_CLASS_HID, - .bInterfaceProtocol = 0x02, + .bInterfaceProtocol = 0x00, .ndesc = 1, .descs = (USBDescOther []) { {
Signature · 1 line
2.3.2 (Apple Git-55)
PATCH v2 2/2 hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option
In reply to Phil Dennis-JordanDarwin/OS X/macOS's HID driver stack previously did not correctly drive Qemu's simulated USB Tablet. This adds a boolean option "mac_compat" to the device which subtly changes the device's report descriptor so it behaves in a way that Mac guests can handle.
Absolute pointing devices with HID Report Descriptor usage page of 0x01 (pointing) are handled by the macOS HID driver as analog sticks, and absolute coordinates are not directly translated to absolute mouse cursor positions.
The workaround is to report a usage page of 0x02 (mouse) instead. In combination with the previous commit's boot protocol fix, this allows the usb-tablet to correctly control the mouse cursor in OS X/macOS guest systems.
--- hw/usb/dev-hid.c | 5 +++++ 1 file changed, 5 insertions(+)
hw/usb/dev-hid.c +5 -0
@@ -51,6 +51,7 @@ typedef struct USBHIDState {uint32_t usb_version;char *display;uint32_t head; +bool mac_compat; } USBHIDState;#define TYPE_USB_HID "usb-hid"
@@ -599,6 +600,9 @@ static void usb_hid_handle_control(USBDevice *dev, USBPacket *p,memcpy (data, qemu_tablet_hid_report_descriptor,sizeof (qemu_tablet_hid_report_descriptor)); p->actual_length =sizeof (qemu_tablet_hid_report_descriptor); +if (us->mac_compat) { + data[3 ] =0x02 ;/* Set usage to mouse, not pointing (1) */ + } }else if (hs->kind ==HID_KEYBOARD ) {memcpy (data, qemu_keyboard_hid_report_descriptor,sizeof (qemu_keyboard_hid_report_descriptor));
@@ -801,6 +805,7 @@ static Property usb_tablet_properties[] = {DEFINE_PROP_UINT32 ("usb_version" , USBHIDState, usb_version,2 ),DEFINE_PROP_STRING ("display" , USBHIDState, display),DEFINE_PROP_UINT32 ("head" , USBHIDState, head,0 ), +DEFINE_PROP_BOOL ("mac_compat" , USBHIDState, mac_compat, false), DEFINE_PROP_END_OF_LIST(), };
Signature · 1 line
2.3.2 (Apple Git-55)
Quoted 4 lines · On Fri, Jan 20, 2017 at 13:30:15 +0100, [email protected] wrote:
This series makes the Qemu usb-tablet work correctly with OS X/macOS guests without the need for a special guest driver.
* The usb-tablet should not have a boot protocol of 2. Other OSes seem to ignore this, but the IOHIDFamily driver stack chokes on it for anything but conventional (relative motion) mice.
* A "mac_compat" boolean option is added to the usb-tablet, which changes its report descriptor to specify a usage of0x02(mouse) instead of0x01(pointer). This is required for correct operation in the Mac HID driver stack.
works like a charm on Sierra (10.12.1). Also tried it with Fedora-Workstation-Live-x86_64-25-1.3.iso, where it behaves identically with or without the mac_compat option. All tests used qemu in SDL/X11-client mode.
Thanks,
--Gabriel
Quoted 15 lines
Changelog
=========v1 -> v2:
* v1 Thread was "[PATCH] hw/usb/dev-hid: add a Mac guest compatibility option to usb-tablet"
* Always apply the boot protocol (bInterfaceProtocol) change to usb-tablet, not just when the Mac compatibility option is active. The original value of0x02was determined to be incorrect according to the spec anyway.
* As the boot protocol change is permanent, separate interface and device descriptor constants for the Mac/non-Mac variants of the tablet are no longer required, and have been removed.Phil Dennis-Jordan (2):
hw/usb/dev-hid: set bInterfaceProtocol to0x00for usb-tablet hw/usb/dev-hid: add a usb-tablet Mac guest compatibility optionhw/usb/dev-hid.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Hi,
Quoted 6 lines
works like a charm on Sierra (10.12.1). Also tried it with Fedora-Workstation-Live-x86_64-25-1.3.iso, where it behaves identically with or without the
mac_compatoption. All tests used qemu in SDL/X11-client mode.Tested-by Gabriel Somlo <[email protected]>
Cool. Given that windows guests are happy with the change too and vmware doing the same I think we don't need a config option for this one too.
cheers,
Gerd