From patchwork Fri Jun 24 19:32:49 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 101885 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3CE63B6F84 for ; Sat, 25 Jun 2011 05:59:10 +1000 (EST) Received: from localhost ([::1]:42912 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaCWx-00081A-0u for incoming@patchwork.ozlabs.org; Fri, 24 Jun 2011 15:59:07 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42857) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaC6u-00019z-Sb for qemu-devel@nongnu.org; Fri, 24 Jun 2011 15:32:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QaC6s-0002NS-FE for qemu-devel@nongnu.org; Fri, 24 Jun 2011 15:32:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51258) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QaC6r-0002ND-PP for qemu-devel@nongnu.org; Fri, 24 Jun 2011 15:32:10 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p5OJW8HG016515 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 24 Jun 2011 15:32:08 -0400 Received: from shalem.localdomain.com (vpn1-4-129.ams2.redhat.com [10.36.4.129]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p5OJW4uV031987; Fri, 24 Jun 2011 15:32:07 -0400 From: Hans de Goede To: Gerd Hoffmann Date: Fri, 24 Jun 2011 21:32:49 +0200 Message-Id: <1308943978-6152-3-git-send-email-hdegoede@redhat.com> In-Reply-To: <1308943978-6152-1-git-send-email-hdegoede@redhat.com> References: <1308943978-6152-1-git-send-email-hdegoede@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Hans de Goede , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 02/11] usb: Make port wakeup and complete ops take a USBPort instead of a Device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This makes them consistent with the attach and detach ops, and in general it makes sense to make portops take a port as argument. This also makes adding support for a companion controller easier / cleaner. Signed-off-by: Hans de Goede --- hw/usb-ehci.c | 2 +- hw/usb-hub.c | 10 +++++----- hw/usb-ohci.c | 12 +++++------- hw/usb-uhci.c | 11 +++++------ hw/usb.c | 4 ++-- hw/usb.h | 9 +++++++-- 6 files changed, 25 insertions(+), 23 deletions(-) diff --git a/hw/usb-ehci.c b/hw/usb-ehci.c index 91fb7de..051b040 100644 --- a/hw/usb-ehci.c +++ b/hw/usb-ehci.c @@ -1111,7 +1111,7 @@ static int ehci_buffer_rw(EHCIQueue *q, int bytes, int rw) return 0; } -static void ehci_async_complete_packet(USBDevice *dev, USBPacket *packet) +static void ehci_async_complete_packet(USBPort *port, USBPacket *packet) { EHCIQueue *q = container_of(packet, EHCIQueue, packet); diff --git a/hw/usb-hub.c b/hw/usb-hub.c index 6e2a358..d324bba 100644 --- a/hw/usb-hub.c +++ b/hw/usb-hub.c @@ -246,10 +246,10 @@ static void usb_hub_detach(USBPort *port1) } } -static void usb_hub_wakeup(USBDevice *dev) +static void usb_hub_wakeup(USBPort *port1) { - USBHubState *s = dev->port->opaque; - USBHubPort *port = &s->ports[dev->port->index]; + USBHubState *s = port1->opaque; + USBHubPort *port = &s->ports[port1->index]; if (port->wPortStatus & PORT_STAT_SUSPEND) { port->wPortChange |= PORT_STAT_C_SUSPEND; @@ -257,9 +257,9 @@ static void usb_hub_wakeup(USBDevice *dev) } } -static void usb_hub_complete(USBDevice *dev, USBPacket *packet) +static void usb_hub_complete(USBPort *port, USBPacket *packet) { - USBHubState *s = dev->port->opaque; + USBHubState *s = port->opaque; /* * Just pass it along upstream for now. diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 1c29b9f..c4703cf 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -367,15 +367,13 @@ static void ohci_detach(USBPort *port1) ohci_set_interrupt(s, OHCI_INTR_RHSC); } -static void ohci_wakeup(USBDevice *dev) +static void ohci_wakeup(USBPort *port1) { - USBBus *bus = usb_bus_from_device(dev); - OHCIState *s = container_of(bus, OHCIState, bus); - int portnum = dev->port->index; - OHCIPort *port = &s->rhport[portnum]; + OHCIState *s = port1->opaque; + OHCIPort *port = &s->rhport[port1->index]; uint32_t intr = 0; if (port->ctrl & OHCI_PORT_PSS) { - DPRINTF("usb-ohci: port %d: wakeup\n", portnum); + DPRINTF("usb-ohci: port %d: wakeup\n", port1->index); port->ctrl |= OHCI_PORT_PSSC; port->ctrl &= ~OHCI_PORT_PSS; intr = OHCI_INTR_RHSC; @@ -602,7 +600,7 @@ static void ohci_copy_iso_td(OHCIState *ohci, static void ohci_process_lists(OHCIState *ohci, int completion); -static void ohci_async_complete_packet(USBDevice *dev, USBPacket *packet) +static void ohci_async_complete_packet(USBPort *port, USBPacket *packet) { OHCIState *ohci = container_of(packet, OHCIState, usb_packet); #ifdef DEBUG_PACKET diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 405fa7b..7866726 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -620,11 +620,10 @@ static void uhci_detach(USBPort *port1) uhci_resume(s); } -static void uhci_wakeup(USBDevice *dev) +static void uhci_wakeup(USBPort *port1) { - USBBus *bus = usb_bus_from_device(dev); - UHCIState *s = container_of(bus, UHCIState, bus); - UHCIPort *port = s->ports + dev->port->index; + UHCIState *s = port1->opaque; + UHCIPort *port = &s->ports[port1->index]; if (port->ctrl & UHCI_PORT_SUSPEND && !(port->ctrl & UHCI_PORT_RD)) { port->ctrl |= UHCI_PORT_RD; @@ -657,7 +656,7 @@ static int uhci_broadcast_packet(UHCIState *s, USBPacket *p) return ret; } -static void uhci_async_complete(USBDevice *dev, USBPacket *packet); +static void uhci_async_complete(USBPort *port, USBPacket *packet); static void uhci_process_frame(UHCIState *s); /* return -1 if fatal error (frame must be stopped) @@ -849,7 +848,7 @@ done: return len; } -static void uhci_async_complete(USBDevice *dev, USBPacket *packet) +static void uhci_async_complete(USBPort *port, USBPacket *packet) { UHCIAsync *async = container_of(packet, UHCIAsync, packet); UHCIState *s = async->uhci; diff --git a/hw/usb.c b/hw/usb.c index 4a39cbc..735ffd1 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -52,7 +52,7 @@ void usb_attach(USBPort *port, USBDevice *dev) void usb_wakeup(USBDevice *dev) { if (dev->remote_wakeup && dev->port && dev->port->ops->wakeup) { - dev->port->ops->wakeup(dev); + dev->port->ops->wakeup(dev->port); } } @@ -335,7 +335,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p) { /* Note: p->owner != dev is possible in case dev is a hub */ assert(p->owner != NULL); - dev->port->ops->complete(dev, p); + dev->port->ops->complete(dev->port, p); p->owner = NULL; } diff --git a/hw/usb.h b/hw/usb.h index 419ff0c..db53381 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -252,8 +252,13 @@ struct USBDeviceInfo { typedef struct USBPortOps { void (*attach)(USBPort *port); void (*detach)(USBPort *port); - void (*wakeup)(USBDevice *dev); - void (*complete)(USBDevice *dev, USBPacket *p); + void (*wakeup)(USBPort *port); + /* + * Note that port->dev will be different then the device from which + * the packet originated when a hub is involved, if you want the orginating + * device use p->owner + */ + void (*complete)(USBPort *port, USBPacket *p); } USBPortOps; /* USB port on which a device can be connected */