From patchwork Mon May 16 19:56:18 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 95821 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 D2DEDB6EF1 for ; Tue, 17 May 2011 06:00:43 +1000 (EST) Received: from localhost ([::1]:40629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3y3-0003UD-QE for incoming@patchwork.ozlabs.org; Mon, 16 May 2011 16:00:39 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57753) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uD-0005KQ-PY for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QM3uC-0004MQ-Mt for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56559) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uC-0004MA-FF for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:40 -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 p4GJud2p000608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 May 2011 15:56:39 -0400 Received: from rincewind.home.kraxel.org (vpn1-4-42.ams2.redhat.com [10.36.4.42]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p4GJuXBF027722; Mon, 16 May 2011 15:56:34 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 8BA01429F1; Mon, 16 May 2011 21:56:23 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 16 May 2011 21:56:18 +0200 Message-Id: <1305575782-31766-15-git-send-email-kraxel@redhat.com> In-Reply-To: <1305575782-31766-1-git-send-email-kraxel@redhat.com> References: <1305575782-31766-1-git-send-email-kraxel@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: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 14/18] usb: add usb_handle_packet 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 Add a usb_handle_packet function, put it into use everywhere. Right now it just calls dev->info->handle_packet(), that will change in future patches though. Signed-off-by: Gerd Hoffmann --- hw/usb-hub.c | 2 +- hw/usb-musb.c | 2 +- hw/usb-ohci.c | 4 ++-- hw/usb-uhci.c | 2 +- hw/usb.c | 17 +++++++++++++++-- hw/usb.h | 2 ++ 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/hw/usb-hub.c b/hw/usb-hub.c index 477927b..6e2a358 100644 --- a/hw/usb-hub.c +++ b/hw/usb-hub.c @@ -495,7 +495,7 @@ static int usb_hub_broadcast_packet(USBHubState *s, USBPacket *p) port = &s->ports[i]; dev = port->port.dev; if (dev && (port->wPortStatus & PORT_STAT_ENABLE)) { - ret = dev->info->handle_packet(dev, p); + ret = usb_handle_packet(dev, p); if (ret != USB_RET_NODEV) { return ret; } diff --git a/hw/usb-musb.c b/hw/usb-musb.c index 38986d3..6037193 100644 --- a/hw/usb-musb.c +++ b/hw/usb-musb.c @@ -601,7 +601,7 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep, ep->packey[dir].dir = dir; if (s->port.dev) - ret = s->port.dev->info->handle_packet(s->port.dev, &ep->packey[dir].p); + ret = usb_handle_packet(s->port.dev, &ep->packey[dir].p); else ret = USB_RET_NODEV; diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c index 32913eb..8b966f7 100644 --- a/hw/usb-ohci.c +++ b/hw/usb-ohci.c @@ -748,7 +748,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN); ohci->usb_packet.data = ohci->usb_buf; ohci->usb_packet.len = len; - ret = dev->info->handle_packet(dev, &ohci->usb_packet); + ret = usb_handle_packet(dev, &ohci->usb_packet); if (ret != USB_RET_NODEV) break; } @@ -944,7 +944,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) ohci->usb_packet.devep = OHCI_BM(ed->flags, ED_EN); ohci->usb_packet.data = ohci->usb_buf; ohci->usb_packet.len = len; - ret = dev->info->handle_packet(dev, &ohci->usb_packet); + ret = usb_handle_packet(dev, &ohci->usb_packet); if (ret != USB_RET_NODEV) break; } diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c index 1e9c1e7..c0de05b 100644 --- a/hw/usb-uhci.c +++ b/hw/usb-uhci.c @@ -632,7 +632,7 @@ static int uhci_broadcast_packet(UHCIState *s, USBPacket *p) USBDevice *dev = port->port.dev; if (dev && (port->ctrl & UHCI_PORT_EN)) - ret = dev->info->handle_packet(dev, p); + ret = usb_handle_packet(dev, p); } DPRINTF("uhci: packet exit. ret %d len %d\n", ret, p->len); diff --git a/hw/usb.c b/hw/usb.c index 60027c6..966cb0f 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -297,9 +297,22 @@ int set_usb_string(uint8_t *buf, const char *str) void usb_send_msg(USBDevice *dev, int msg) { USBPacket p; + int ret; + memset(&p, 0, sizeof(p)); p.pid = msg; - dev->info->handle_packet(dev, &p); - + ret = usb_handle_packet(dev, &p); /* This _must_ be synchronous */ + assert(ret != USB_RET_ASYNC); +} + +/* Hand over a packet to a device for processing. Return value + USB_RET_ASYNC indicates the processing isn't finished yet, the + driver will call usb_packet_complete() when done processing it. */ +int usb_handle_packet(USBDevice *dev, USBPacket *p) +{ + int ret; + + ret = dev->info->handle_packet(dev, p); + return ret; } diff --git a/hw/usb.h b/hw/usb.h index c1d1014..6889467 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -266,6 +266,8 @@ struct USBPacket { void *cancel_opaque; }; +int usb_handle_packet(USBDevice *dev, USBPacket *p); + /* Defer completion of a USB packet. The hadle_packet routine should then return USB_RET_ASYNC. Packets that complete immediately (before handle_packet returns) should not call this method. */