Skip to contentSkip to conversation

usb: remote wakeup improvements

PATCH New Gerd Hoffmann 1 participant 8 messages Nov 20, 2013

lore
Share & tools
lore
#7 lore raw

PATCH 6/6 usb-tablet: add microsoft os descriptor support

In reply to Gerd Hoffmann

Set SelectiveSuspendEnabled registy entry to one.
This makes Windows use remote suspend by default,
without manual registry fiddeling.

---
 hw/usb/dev-hid.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/usb/dev-hid.c +7 -1
index 5e667f0..dbbb394 100644
@@ -211,7 +211,7 @@ static const USBDescDevice desc_device_mouse = {
 };
 
 static const USBDescDevice desc_device_tablet = {
-    .bcdUSB                        = 0x0100,
+    .bcdUSB                        = 0x0200,
     .bMaxPacketSize0               = 8,
     .bNumConfigurations            = 1,
     .confs = (USBDescConfig[]) {
@@ -261,6 +261,10 @@ static const USBDescDevice desc_device_keyboard = {
     },
 };
 
+static const USBDescMSOS desc_msos_suspend = {
+    .SelectiveSuspendEnabled = true,
+};
+
 static const USBDesc desc_mouse = {
     .id = {
         .idVendor          = 0x0627,
@@ -285,6 +289,7 @@ static const USBDesc desc_tablet = {
     },
     .full = &desc_device_tablet,
     .str  = desc_strings,
+    .msos = &desc_msos_suspend,
 };
 
 static const USBDesc desc_tablet2 = {
@@ -299,6 +304,7 @@ static const USBDesc desc_tablet2 = {
     .full = &desc_device_tablet,
     .high = &desc_device_tablet2,
     .str  = desc_strings,
+    .msos = &desc_msos_suspend,
 };
 
 static const USBDesc desc_keyboard = {
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH 2/6 Revert "usb-tablet: Don't claim wakeup capability for USB-2 version"

In reply to Gerd Hoffmann

This reverts commit aa1c9e971e80d25b92908dce3dec7c38b49480ea.

---
 hw/usb/dev-hid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/usb/dev-hid.c +1 -1
index 5956720..5e667f0 100644
@@ -236,7 +236,7 @@ static const USBDescDevice desc_device_tablet2 = {
             .bNumInterfaces        = 1,
             .bConfigurationValue   = 1,
             .iConfiguration        = STR_CONFIG_TABLET,
-            .bmAttributes          = 0x80,
+            .bmAttributes          = 0xa0,
             .bMaxPower             = 50,
             .nif = 1,
             .ifs = &desc_iface_tablet2,
Signature · 1 line
1.8.3.1
#3 lore raw

PATCH 3/6 usb: add vendor request defines

In reply to Gerd Hoffmann

Add defines for vendor specific usb control requests. Group defines by Device / Interface / Endpoint while being at it.

---
 include/hw/usb.h | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
include/hw/usb.h +13 -4
index 0a6ef4a..2a3ea0c 100644
@@ -102,17 +102,26 @@
 
 #define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
 #define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
-#define InterfaceRequest \
+#define VendorDeviceRequest ((USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8)
+#define VendorDeviceOutRequest \
+        ((USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_DEVICE)<<8)
+
+#define InterfaceRequest                                        \
         ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
 #define InterfaceOutRequest \
         ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
-#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
-#define EndpointOutRequest \
-        ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
 #define ClassInterfaceRequest \
         ((USB_DIR_IN|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
 #define ClassInterfaceOutRequest \
         ((USB_DIR_OUT|USB_TYPE_CLASS|USB_RECIP_INTERFACE)<<8)
+#define VendorInterfaceRequest \
+        ((USB_DIR_IN|USB_TYPE_VENDOR|USB_RECIP_INTERFACE)<<8)
+#define VendorInterfaceOutRequest \
+        ((USB_DIR_OUT|USB_TYPE_VENDOR|USB_RECIP_INTERFACE)<<8)
+
+#define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
+#define EndpointOutRequest \
+        ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
 
 #define USB_REQ_GET_STATUS		0x00
 #define USB_REQ_CLEAR_FEATURE		0x01
Signature · 1 line
1.8.3.1
#6 lore raw

PATCH 5/6 usb: add support for microsoft os descriptors

In reply to Gerd Hoffmann

This patch adds support for special usb descriptors used by microsoft windows. They allow more fine-grained control over driver binding and adding entries to the registry for configuration.

---
 hw/usb/Makefile.objs |   2 +-
 hw/usb/desc-msos.c   | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/desc.c        |  12 +++
 hw/usb/desc.h        |   9 ++
 include/hw/usb.h     |   1 +
 trace-events         |   1 +
 6 files changed, 258 insertions(+), 1 deletion(-)
 create mode 100644 hw/usb/desc-msos.c
hw/usb/Makefile.objs +1 -1
index a3eac3e..97b4575 100644
@@ -1,5 +1,5 @@
 # usb subsystem core
-common-obj-y += core.o combined-packet.o bus.o desc.o
+common-obj-y += core.o combined-packet.o bus.o desc.o desc-msos.o
 common-obj-y += libhw.o
 
 # usb host adapters
hw/usb/desc-msos.c new file +234 -0

234 lines not on this page · raw message

hw/usb/desc.c +12 -0
index f18a043..1539d7c 100644
@@ -499,6 +499,9 @@ void usb_desc_init(USBDevice *dev)
     if (desc->super) {
         dev->speedmask |= USB_SPEED_MASK_SUPER;
     }
+    if (desc->msos) {
+        usb_desc_set_string(dev, 0xee, "MSFT100Q");
+    }
     usb_desc_setdefaults(dev);
 }
 
@@ -782,6 +785,15 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
         trace_usb_set_interface(dev->addr, index, value, ret);
         break;
 
+    case VendorDeviceRequest | 'Q':
+        ret = usb_desc_msos(desc, p, index, data, length);
+        trace_usb_desc_msos(dev->addr, index, length, ret);
+        break;
+    case VendorInterfaceRequest | 'Q':
+        ret = usb_desc_msos(desc, p, index, data, length);
+        trace_usb_desc_msos(dev->addr, index, length, ret);
+        break;
+
     }
     return ret;
 }
hw/usb/desc.h +9 -0
index 81327b0..64dfc4a 100644
@@ -2,6 +2,7 @@
 #define QEMU_HW_USB_DESC_H
 
 #include <inttypes.h>
+#include <wchar.h>
 
 /* binary representation */
 typedef struct USBDescriptor {
@@ -182,6 +183,11 @@ struct USBDescOther {
     const uint8_t             *data;
 };
 
+struct USBDescMSOS {
+    const wchar_t             *Label;
+    bool                      SelectiveSuspendEnabled;
+};
+
 typedef const char *USBDescStrings[256];
 
 struct USBDesc {
@@ -190,6 +196,7 @@ struct USBDesc {
     const USBDescDevice       *high;
     const USBDescDevice       *super;
     const char* const         *str;
+    const USBDescMSOS         *msos;
 };
 
 #define USB_DESC_FLAG_SUPER (1 << 1)
@@ -219,6 +226,8 @@ int usb_desc_iface(const USBDescIface *iface, int flags,
 int usb_desc_endpoint(const USBDescEndpoint *ep, int flags,
                       uint8_t *dest, size_t len);
 int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
+int usb_desc_msos(const USBDesc *desc, USBPacket *p,
+                  int index, uint8_t *dest, size_t len);
 
 /* control message emulation helpers */
 void usb_desc_init(USBDevice *dev);
include/hw/usb.h +1 -0
index 2a3ea0c..d6a3354 100644
@@ -182,6 +182,7 @@ typedef struct USBDescIface USBDescIface;
 typedef struct USBDescEndpoint USBDescEndpoint;
 typedef struct USBDescOther USBDescOther;
 typedef struct USBDescString USBDescString;
+typedef struct USBDescMSOS USBDescMSOS;
 
 struct USBDescString {
     uint8_t index;
trace-events +1 -0
index 7322ed8..7070aab 100644
@@ -400,6 +400,7 @@ usb_desc_config(int addr, int index, int len, int ret) "dev %d query config %d,
 usb_desc_other_speed_config(int addr, int index, int len, int ret) "dev %d query config %d, len %d, ret %d"
 usb_desc_string(int addr, int index, int len, int ret) "dev %d query string %d, len %d, ret %d"
 usb_desc_bos(int addr, int len, int ret) "dev %d bos, len %d, ret %d"
+usb_desc_msos(int addr, int index, int len, int ret) "dev %d msos, index 0x%x, len %d, ret %d"
 usb_set_addr(int addr) "dev %d"
 usb_set_config(int addr, int config, int ret) "dev %d, config %d, ret %d"
 usb_set_interface(int addr, int iface, int alt, int ret) "dev %d, interface %d, altsetting %d, ret %d"
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/6 ehci: implement port wakeup

In reply to Gerd Hoffmann

Update portsc register and raise irq in case a suspended port is woken up, so remote wakeup works on our ehci ports.

---
 hw/usb/hcd-ehci.c | 18 ++++++++++++++++--
 trace-events      |  3 +++
 2 files changed, 19 insertions(+), 2 deletions(-)
hw/usb/hcd-ehci.c +16 -2
index 22bdbf4..8765f8f 100644
@@ -826,9 +826,9 @@ static void ehci_child_detach(USBPort *port, USBDevice *child)
 static void ehci_wakeup(USBPort *port)
 {
     EHCIState *s = port->opaque;
-    uint32_t portsc = s->portsc[port->index];
+    uint32_t *portsc = &s->portsc[port->index];
 
-    if (portsc & PORTSC_POWNER) {
+    if (*portsc & PORTSC_POWNER) {
         USBPort *companion = s->companion_ports[port->index];
         if (companion->ops->wakeup) {
             companion->ops->wakeup(companion);
@@ -836,6 +836,12 @@ static void ehci_wakeup(USBPort *port)
         return;
     }
 
+    if (*portsc & PORTSC_SUSPEND) {
+        trace_usb_ehci_port_wakeup(port->index);
+        *portsc |= PORTSC_FPRES;
+        ehci_raise_irq(s, USBSTS_PCD);
+    }
+
     qemu_bh_schedule(s->async_bh);
 }
 
@@ -1067,6 +1073,14 @@ static void ehci_port_write(void *ptr, hwaddr addr,
         }
     }
 
+    if ((val & PORTSC_SUSPEND) && !(*portsc & PORTSC_SUSPEND)) {
+        trace_usb_ehci_port_suspend(port);
+    }
+    if (!(val & PORTSC_FPRES) && (*portsc & PORTSC_FPRES)) {
+        trace_usb_ehci_port_resume(port);
+        val &= ~PORTSC_SUSPEND;
+    }
+
     *portsc &= ~PORTSC_RO_MASK;
     *portsc |= val;
     trace_usb_ehci_portsc_change(addr + s->portscbase, addr >> 2, *portsc, old);
trace-events +3 -0
index 8695e9e..7322ed8 100644
@@ -309,6 +309,9 @@ usb_ehci_sitd(uint32_t addr, uint32_t nxt, uint32_t active) "ITD @ %08x: next %0
 usb_ehci_port_attach(uint32_t port, const char *owner, const char *device) "attach port #%d, owner %s, device %s"
 usb_ehci_port_detach(uint32_t port, const char *owner) "detach port #%d, owner %s"
 usb_ehci_port_reset(uint32_t port, int enable) "reset port #%d - %d"
+usb_ehci_port_suspend(uint32_t port) "port #%d"
+usb_ehci_port_wakeup(uint32_t port) "port #%d"
+usb_ehci_port_resume(uint32_t port) "port #%d"
 usb_ehci_queue_action(void *q, const char *action) "q %p: %s"
 usb_ehci_packet_action(void *q, void *p, const char *action) "q %p p %p: %s"
 usb_ehci_irq(uint32_t level, uint32_t frindex, uint32_t sts, uint32_t mask) "level %d, frindex 0x%04x, sts 0x%x, mask 0x%x"
Signature · 1 line
1.8.3.1
#4 lore raw

PATCH 4/6 usb: move usb_{hi, lo} helpers to header file.

In reply to Gerd Hoffmann
---
 hw/usb/desc.c | 10 ----------
 hw/usb/desc.h | 11 +++++++++++
 2 files changed, 11 insertions(+), 10 deletions(-)
hw/usb/desc.c +0 -10
index 5dbe754..f18a043 100644
@@ -6,16 +6,6 @@
 
 /* ------------------------------------------------------------------ */
 
-static uint8_t usb_lo(uint16_t val)
-{
-    return val & 0xff;
-}
-
-static uint8_t usb_hi(uint16_t val)
-{
-    return (val >> 8) & 0xff;
-}
-
 int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
                     uint8_t *dest, size_t len)
 {
hw/usb/desc.h +11 -0
index ddd3e74..81327b0 100644
@@ -194,6 +194,17 @@ struct USBDesc {
 
 #define USB_DESC_FLAG_SUPER (1 << 1)
 
+/* little helpers */
+static inline uint8_t usb_lo(uint16_t val)
+{
+    return val & 0xff;
+}
+
+static inline uint8_t usb_hi(uint16_t val)
+{
+    return (val >> 8) & 0xff;
+}
+
 /* generate usb packages from structs */
 int usb_desc_device(const USBDescID *id, const USBDescDevice *dev,
                     uint8_t *dest, size_t len);
Signature · 1 line
1.8.3.1
#5 lore raw

PATCH v2 1/1 curses: fixup SIGWINCH handler mess

In reply to Gerd Hoffmann

Don't run code in the signal handler, only set a flag. Use sigaction(2) to avoid non-portable signal(2) semantics. Make #ifdefs less messy.

---
 ui/curses.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)
ui/curses.c +28 -16
index 289a955..dbc3d5e 100644
@@ -106,9 +106,9 @@ static void curses_resize(DisplayChangeListener *dcl,
     curses_calc_pad();
 }
 
-#ifndef _WIN32
-#if defined(SIGWINCH) && defined(KEY_RESIZE)
-static void curses_winch_handler(int signum)
+#if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE)
+static volatile sig_atomic_t got_sigwinch;
+static void curses_winch_check(void)
 {
     struct winsize {
         unsigned short ws_row;
@@ -117,18 +117,34 @@ static void curses_winch_handler(int signum)
         unsigned short ws_ypixel;   /* unused */
     } ws;
 
-    /* terminal size changed */
-    if (ioctl(1, TIOCGWINSZ, &ws) == -1)
+    if (!got_sigwinch) {
+        return;
+    }
+    got_sigwinch = false;
+
+    if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
         return;
+    }
 
     resize_term(ws.ws_row, ws.ws_col);
-    curses_calc_pad();
     invalidate = 1;
+}
 
-    /* some systems require this */
-    signal(SIGWINCH, curses_winch_handler);
+static void curses_winch_handler(int signum)
+{
+    got_sigwinch = true;
 }
-#endif
+
+static void curses_winch_init(void)
+{
+    struct sigaction old, winch = {
+        .sa_handler  = curses_winch_handler,
+    };
+    sigaction(SIGWINCH, &winch, &old);
+}
+#else
+static void curses_winch_check(void) {}
+static void curses_winch_init(void) {}
 #endif
 
 static void curses_cursor_position(DisplayChangeListener *dcl,
@@ -163,6 +179,8 @@ static void curses_refresh(DisplayChangeListener *dcl)
 {
     int chr, nextchr, keysym, keycode, keycode_alt;
 
+    curses_winch_check();
+
     if (invalidate) {
         clear();
         refresh();
@@ -349,13 +367,7 @@ void curses_display_init(DisplayState *ds, int full_screen)
     curses_keyboard_setup();
     atexit(curses_atexit);
 
-#ifndef _WIN32
-#if defined(SIGWINCH) && defined(KEY_RESIZE)
-    /* some curses implementations provide a handler, but we
-     * want to be sure this is handled regardless of the library */
-    signal(SIGWINCH, curses_winch_handler);
-#endif
-#endif
+    curses_winch_init();
 
     dcl = (DisplayChangeListener *) g_malloc0(sizeof(DisplayChangeListener));
     dcl->ops = &dcl_ops;
Signature · 1 line
1.8.3.1
#0 lore raw

cover usb: remote wakeup improvements

Hi,

USB patch series from the ReduceWakeupRate department.

Patch #1 implements remote wakeup support to the ehci emulation. Patch #2 reverts a workaround for lacking ehci remote wakeup
support in the highspeed version of the usb tablet.

Patches #3 + #4 are small preparations for #5. Patch #5 adds support for microsoft os descriptors. Patch #6 puts them into use to set registry keys for
the usb tablet.

This series brings windows guests on par with what we have in Linux for quite a while already: Remote wakeup is used by default, without manual configuration.

Gerd Hoffmann (6):
ehci: implement port wakeup
Revert "usb-tablet: Don't claim wakeup capability for USB-2 version"
usb: add vendor request defines
usb: move usb_{hi,lo} helpers to header file.
usb: add support for microsoft os descriptors
usb-tablet: add microsoft os descriptor support

 hw/usb/Makefile.objs |   2 +-
 hw/usb/desc-msos.c   | 234 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/usb/desc.c        |  22 ++---
 hw/usb/desc.h        |  20 +++++
 hw/usb/dev-hid.c     |  10 ++-
 hw/usb/hcd-ehci.c    |  18 +++-
 include/hw/usb.h     |  18 +++-
 trace-events         |   4 +
 8 files changed, 309 insertions(+), 19 deletions(-)
 create mode 100644 hw/usb/desc-msos.c
Signature · 1 line
1.8.3.1