qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests
@ 2017-01-20 12:30 Phil Dennis-Jordan
  2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 1/2] hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet Phil Dennis-Jordan
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Phil Dennis-Jordan @ 2017-01-20 12:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Phil Dennis-Jordan

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(-)

-- 
2.3.2 (Apple Git-55)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 1/2] hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet
  2017-01-20 12:30 [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Phil Dennis-Jordan
@ 2017-01-20 12:30 ` Phil Dennis-Jordan
  2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 2/2] hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option Phil Dennis-Jordan
  2017-01-21  1:49 ` [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Gabriel L. Somlo
  2 siblings, 0 replies; 5+ messages in thread
From: Phil Dennis-Jordan @ 2017-01-20 12:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Phil Dennis-Jordan

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.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 hw/usb/dev-hid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index 24d05f7..a23e5d4 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -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[]) {
         {
-- 
2.3.2 (Apple Git-55)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [Qemu-devel] [PATCH v2 2/2] hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option
  2017-01-20 12:30 [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Phil Dennis-Jordan
  2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 1/2] hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet Phil Dennis-Jordan
@ 2017-01-20 12:30 ` Phil Dennis-Jordan
  2017-01-21  1:49 ` [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Gabriel L. Somlo
  2 siblings, 0 replies; 5+ messages in thread
From: Phil Dennis-Jordan @ 2017-01-20 12:30 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Phil Dennis-Jordan

Darwin/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.

Signed-off-by: Phil Dennis-Jordan <phil@philjordan.eu>
---
 hw/usb/dev-hid.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
index a23e5d4..c4a0d22 100644
--- a/hw/usb/dev-hid.c
+++ b/hw/usb/dev-hid.c
@@ -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(),
 };
 
-- 
2.3.2 (Apple Git-55)

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests
  2017-01-20 12:30 [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Phil Dennis-Jordan
  2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 1/2] hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet Phil Dennis-Jordan
  2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 2/2] hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option Phil Dennis-Jordan
@ 2017-01-21  1:49 ` Gabriel L. Somlo
  2017-01-23 12:31   ` Gerd Hoffmann
  2 siblings, 1 reply; 5+ messages in thread
From: Gabriel L. Somlo @ 2017-01-21  1:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: phil, kraxel

On Fri, Jan 20, 2017 at 13:30:15 +0100, phil@philjordan.eu 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 of 0x02 (mouse) instead of 0x01 (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.

Tested-by: Gabriel Somlo <somlo@cmu.edu>

Thanks,
--Gabriel

> 
> 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(-)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests
  2017-01-21  1:49 ` [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Gabriel L. Somlo
@ 2017-01-23 12:31   ` Gerd Hoffmann
  0 siblings, 0 replies; 5+ messages in thread
From: Gerd Hoffmann @ 2017-01-23 12:31 UTC (permalink / raw)
  To: Gabriel L. Somlo; +Cc: qemu-devel, phil

  Hi,

> 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.
> 
> Tested-by: Gabriel Somlo <somlo@cmu.edu>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-23 12:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-20 12:30 [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Phil Dennis-Jordan
2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 1/2] hw/usb/dev-hid: set bInterfaceProtocol to 0x00 for usb-tablet Phil Dennis-Jordan
2017-01-20 12:30 ` [Qemu-devel] [PATCH v2 2/2] hw/usb/dev-hid: add a usb-tablet Mac guest compatibility option Phil Dennis-Jordan
2017-01-21  1:49 ` [Qemu-devel] [PATCH v2 0/2] hw/usb/dev-hid: Make usb-tablet work with OS X/macOS guests Gabriel L. Somlo
2017-01-23 12:31   ` Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).