From patchwork Wed Dec 1 16:47:06 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 73849 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B349B6F14 for ; Thu, 2 Dec 2010 04:11:03 +1100 (EST) Received: from localhost ([127.0.0.1]:57596 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNqCp-0002Gp-UG for incoming@patchwork.ozlabs.org; Wed, 01 Dec 2010 12:11:00 -0500 Received: from [140.186.70.92] (port=43867 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNpu4-0000gF-3B for qemu-devel@nongnu.org; Wed, 01 Dec 2010 11:51:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNptw-0002f1-Q4 for qemu-devel@nongnu.org; Wed, 01 Dec 2010 11:51:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:12378) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNptw-0002ef-IY for qemu-devel@nongnu.org; Wed, 01 Dec 2010 11:51:28 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id oB1GpCvp004056 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 1 Dec 2010 11:51:13 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oB1GpCh8013797; Wed, 1 Dec 2010 11:51:12 -0500 Received: from amt.cnet (vpn2-8-74.ams2.redhat.com [10.36.8.74]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id oB1GpA0u030226; Wed, 1 Dec 2010 11:51:11 -0500 Received: from amt.cnet (localhost.localdomain [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id 7A21B68A012; Wed, 1 Dec 2010 14:50:38 -0200 (BRST) Received: (from marcelo@localhost) by amt.cnet (8.14.4/8.14.4/Submit) id oB1GoasC013298; Wed, 1 Dec 2010 14:50:36 -0200 Message-Id: <20101201164743.038562673@redhat.com> User-Agent: quilt/0.47-1 Date: Wed, 01 Dec 2010 14:47:06 -0200 From: Marcelo Tosatti To: qemu-devel@nongnu.org References: <20101201164704.729398122@redhat.com> Content-Disposition: inline; filename=usb-uhci-suspend X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: Paul Brook , Marcelo Tosatti , Gerd Hoffmann , Juan Quintela Subject: [Qemu-devel] [patch 2/3] support for UHCI suspend / remote wake up X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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%. To enable autosuspend in Windows: 1) Enable "Allow the computer to turn off this device to save power" checkbox in "Power Management" tab of USB Root Hub properties. 2) Create a REG_BINARY (XP) or REG_DWORD (Vista/2008) key named SelectiveSuspendEnabled under: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\VID_0627&PID_0001\1\Device Parameters With a value of 1. Signed-off-by: Marcelo Tosatti Index: qemu-kvm/hw/usb-hid.c =================================================================== --- qemu-kvm.orig/hw/usb-hid.c +++ qemu-kvm/hw/usb-hid.c @@ -412,6 +412,9 @@ static void usb_hid_changed(USBHIDState 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, Index: qemu-kvm/hw/usb-uhci.c =================================================================== --- qemu-kvm.orig/hw/usb-uhci.c +++ qemu-kvm/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 *opa 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,23 @@ static void uhci_resume (void *opaque) } } +static void uhci_event(USBPort *port, USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + UHCIState *s = container_of(bus, UHCIState, bus); + + if (s->cmd & UHCI_CMD_EGSM) { + UHCIPort *uport = DO_UPCAST(UHCIPort, port, port); + + if (uport->ctrl & UHCI_PORT_RD) { + return; + } + + uport->ctrl |= UHCI_PORT_RD; + uhci_resume(s); + } +} + static void uhci_attach(USBPort *port1, USBDevice *dev) { UHCIState *s = port1->opaque; @@ -1103,6 +1122,7 @@ static void uhci_map(PCIDevice *pci_dev, static USBPortOps uhci_port_ops = { .attach = uhci_attach, + .remote_wakeup = uhci_event, }; static int usb_uhci_common_initfn(UHCIState *s) Index: qemu-kvm/hw/usb.h =================================================================== --- qemu-kvm.orig/hw/usb.h +++ qemu-kvm/hw/usb.h @@ -199,6 +199,7 @@ struct USBDeviceInfo { struct USBPortOps { void (*attach)(USBPort *port, USBDevice *dev); + void (*remote_wakeup)(USBPort *port, USBDevice *dev); }; /* USB port on which a device can be connected */ @@ -253,6 +254,7 @@ static inline void usb_cancel_packet(USB } void usb_attach(USBPort *port, USBDevice *dev); +void usb_remote_wakeup(USBDevice *dev); int usb_generic_handle_packet(USBDevice *s, USBPacket *p); int set_usb_string(uint8_t *buf, const char *str); void usb_send_msg(USBDevice *dev, int msg); Index: qemu-kvm/hw/usb.c =================================================================== --- qemu-kvm.orig/hw/usb.c +++ qemu-kvm/hw/usb.c @@ -31,6 +31,21 @@ void usb_attach(USBPort *port, USBDevice port->ops->attach(port, dev); } +void usb_remote_wakeup(USBDevice *dev) +{ + USBBus *bus = usb_bus_from_device(dev); + USBPort *port; + + QTAILQ_FOREACH(port, &bus->used, next) { + if (port->dev == dev) + break; + } + assert(port != NULL); + + if (port->ops->remote_wakeup) + port->ops->remote_wakeup(port, dev); +} + /**********************/ /* generic USB device helpers (you are not forced to use them when