qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: qemu-devel@nongnu.org, kvm <kvm@vger.kernel.org>
Cc: Matthew Garrett <mjg59@srcf.ucam.org>,
	Adam Jackson <ajax@redhat.com>,
	Glauber de Oliveira Costa <gcosta@redhat.com>
Subject: [Qemu-devel] PATCH: QEMU support for UHCI suspend / remote wake up
Date: Thu, 25 Nov 2010 13:34:55 -0200	[thread overview]
Message-ID: <20101125153455.GA4097@amt.cnet> (raw)


This patch enables USB UHCI global suspend/resume feature. The OS will
stop the HC once all ports are suspended. If there is activity on the
port(s), an interrupt signalling remote wakeup will be triggered.

To enable autosuspend for the USB tablet on Linux guests:

echo auto > /sys/devices/pci0000:00/0000:00:01.2/usb1/1-1/power/level

It reduces CPU consumption of an idle FC12 guest from 2.7% to 0.3%.

Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>

diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 882d933..b7a4dc1 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -412,6 +412,9 @@ static void usb_hid_changed(USBHIDState *hs)
 
     if (hs->datain)
         hs->datain(hs->datain_opaque);
+
+    if (hs->dev.remote_wakeup)
+        usb_remote_wakeup(&hs->dev);
 }
 
 static void usb_mouse_event(void *opaque,
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 1d83400..674cb0c 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -59,6 +59,7 @@
 
 #define UHCI_PORT_RESET (1 << 9)
 #define UHCI_PORT_LSDA  (1 << 8)
+#define UHCI_PORT_RD    (1 << 6)
 #define UHCI_PORT_ENC   (1 << 3)
 #define UHCI_PORT_EN    (1 << 2)
 #define UHCI_PORT_CSC   (1 << 1)
@@ -501,6 +502,7 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
             port->ctrl = (port->ctrl & 0x01fb) | (val & ~0x01fb);
             /* some bits are reset when a '1' is written to them */
             port->ctrl &= ~(val & 0x000a);
+            port->ctrl &= ~(port->ctrl & 0x0040); /* clear port resume detected */
         }
         break;
     }
@@ -593,6 +595,43 @@ static void uhci_resume (void *opaque)
     }
 }
 
+static UHCIPort *find_port(UHCIState *s, USBDevice *d)
+{
+    int i;
+
+    for (i = 0; i < NB_PORTS; i++) {
+        UHCIPort *port = &s->ports[i];
+
+        if (d == port->port.dev) {
+            return port;
+        }
+    }
+
+    return NULL;
+}
+
+static void uhci_event(USBDevice *dev)
+{
+    USBBus *bus = usb_bus_from_device(dev);
+    UHCIState *s = container_of(bus, UHCIState, bus);
+
+    if (s->cmd & UHCI_CMD_EGSM) {
+        UHCIPort *port = find_port(s, dev);
+
+        if (!port) {
+            return;
+        }
+
+        if (port->ctrl & UHCI_PORT_RD) {
+            return;
+        }
+
+        port->ctrl |= UHCI_PORT_RD;
+
+        uhci_resume(s);
+    }
+}
+
 static void uhci_attach(USBPort *port1, USBDevice *dev)
 {
     UHCIState *s = port1->opaque;
@@ -602,6 +641,7 @@ static void uhci_attach(USBPort *port1, USBDevice *dev)
         if (port->port.dev) {
             usb_attach(port1, NULL);
         }
+        dev->info->remote_wakeup_cb = uhci_event;
         /* set connect status */
         port->ctrl |= UHCI_PORT_CCS | UHCI_PORT_CSC;
 
diff --git a/hw/usb.c b/hw/usb.c
index a326bcf..9b24d49 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -229,3 +229,9 @@ void usb_send_msg(USBDevice *dev, int msg)
 
     /* This _must_ be synchronous */
 }
+
+void usb_remote_wakeup(USBDevice *dev)
+{
+    if (dev->info->remote_wakeup_cb)
+        dev->info->remote_wakeup_cb(dev);
+}
diff --git a/hw/usb.h b/hw/usb.h
index 00d2802..16de1c9 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -189,6 +189,11 @@ struct USBDeviceInfo {
      */
     int (*handle_data)(USBDevice *dev, USBPacket *p);
 
+    /*
+     * Process remote wakeup request.
+     */
+    void (*remote_wakeup_cb)(USBDevice *dev);
+
     const char *product_desc;
 
     /* handle legacy -usbdevice command line options */
@@ -317,6 +322,7 @@ void usb_unregister_port(USBBus *bus, USBPort *port);
 int usb_device_attach(USBDevice *dev);
 int usb_device_detach(USBDevice *dev);
 int usb_device_delete_addr(int busnr, int addr);
+void usb_remote_wakeup(USBDevice *dev);
 
 static inline USBBus *usb_bus_from_device(USBDevice *d)
 {

             reply	other threads:[~2010-11-25 15:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-25 15:34 Marcelo Tosatti [this message]
2010-11-25 16:15 ` [Qemu-devel] Re: PATCH: QEMU support for UHCI suspend / remote wake up Gerd Hoffmann
2010-11-25 17:04   ` [Qemu-devel] [patch 0/2] USB UHCI global suspend / remote wakeup Marcelo Tosatti
2010-11-25 17:04     ` [Qemu-devel] [patch 1/2] add USBBusOps to USBBus Marcelo Tosatti
2010-11-25 17:04     ` [Qemu-devel] [patch 2/2] support for UHCI suspend / remote wake up Marcelo Tosatti
2010-12-01 15:12       ` [Qemu-devel] " Gerd Hoffmann
2010-12-01 16:58         ` Marcelo Tosatti
2010-12-01 17:17           ` Gerd Hoffmann
2010-11-26  0:38     ` [Qemu-devel] [patch 0/2] USB UHCI global suspend / remote wakeup Paul Brook
2010-11-26  2:15       ` Marcelo Tosatti
2010-11-26  8:49         ` Gerd Hoffmann
2010-11-26 12:09           ` Paul Brook
2010-12-01 16:47     ` [Qemu-devel] [patch 0/3] QEMU support for UHCI suspend / remote wake up (v3) Marcelo Tosatti
2010-12-01 16:47       ` [Qemu-devel] [patch 1/3] add USBPortOps to USBPort Marcelo Tosatti
2010-12-01 17:10         ` [Qemu-devel] " Gerd Hoffmann
2010-12-01 16:47       ` [Qemu-devel] [patch 2/3] support for UHCI suspend / remote wake up Marcelo Tosatti
2010-12-01 17:12         ` [Qemu-devel] " Gerd Hoffmann
2010-12-01 16:47       ` [Qemu-devel] [patch 3/3] UHCI: Substate section for migration of remote wakeup feature Marcelo Tosatti
2010-12-01 17:16         ` [Qemu-devel] " Gerd Hoffmann
2010-12-01 19:14           ` Juan Quintela
2010-12-01 20:56             ` Marcelo Tosatti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101125153455.GA4097@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=ajax@redhat.com \
    --cc=gcosta@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mjg59@srcf.ucam.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).