From patchwork Mon May 16 19:56:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 95829 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 AD77DB6EED for ; Tue, 17 May 2011 06:03:41 +1000 (EST) Received: from localhost ([::1]:40150 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM40x-0000UV-4T for incoming@patchwork.ozlabs.org; Mon, 16 May 2011 16:03:39 -0400 Received: from eggs.gnu.org ([140.186.70.92]:57906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uM-0005bP-TU for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QM3uJ-0004P2-M4 for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QM3uJ-0004Os-Ec for qemu-devel@nongnu.org; Mon, 16 May 2011 15:56:47 -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 p4GJukXp015408 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 16 May 2011 15:56:46 -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 p4GJuXDE027720; Mon, 16 May 2011 15:56:43 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 97FEA429E3; Mon, 16 May 2011 21:56:23 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 16 May 2011 21:56:19 +0200 Message-Id: <1305575782-31766-16-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 15/18] usb: keep track of packet owner. 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 Keep track of the device which owns the usb packet for async processing. Signed-off-by: Gerd Hoffmann --- hw/usb.c | 32 ++++++++++++++++++++++++++++++++ hw/usb.h | 18 +++--------------- 2 files changed, 35 insertions(+), 15 deletions(-) diff --git a/hw/usb.c b/hw/usb.c index 966cb0f..8a9a7fc 100644 --- a/hw/usb.c +++ b/hw/usb.c @@ -313,6 +313,38 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p) { int ret; + assert(p->owner == NULL); ret = dev->info->handle_packet(dev, p); + if (ret == USB_RET_ASYNC) { + if (p->owner == NULL) { + p->owner = dev; + } else { + /* We'll end up here when usb_handle_packet is called + * recursively due to a hub being in the chain. Nothing + * to do. Leave p->owner pointing to the device, not the + * hub. */; + } + } return ret; } + +/* Notify the controller that an async packet is complete. This should only + be called for packets previously deferred by returning USB_RET_ASYNC from + handle_packet. */ +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); + p->owner = NULL; +} + +/* Cancel an active packet. The packed must have been deferred by + returning USB_RET_ASYNC from handle_packet, and not yet + completed. */ +void usb_cancel_packet(USBPacket * p) +{ + assert(p->owner != NULL); + p->cancel_cb(p, p->cancel_opaque); + p->owner = NULL; +} diff --git a/hw/usb.h b/hw/usb.h index 6889467..80e8e90 100644 --- a/hw/usb.h +++ b/hw/usb.h @@ -262,11 +262,14 @@ struct USBPacket { uint8_t *data; int len; /* Internal use by the USB layer. */ + USBDevice *owner; USBCallback *cancel_cb; void *cancel_opaque; }; int usb_handle_packet(USBDevice *dev, USBPacket *p); +void usb_packet_complete(USBDevice *dev, USBPacket *p); +void usb_cancel_packet(USBPacket * p); /* Defer completion of a USB packet. The hadle_packet routine should then return USB_RET_ASYNC. Packets that complete immediately (before @@ -278,21 +281,6 @@ static inline void usb_defer_packet(USBPacket *p, USBCallback *cancel, p->cancel_opaque = opaque; } -/* Notify the controller that an async packet is complete. This should only - be called for packets previously deferred with usb_defer_packet, and - should never be called from within handle_packet. */ -static inline void usb_packet_complete(USBDevice *dev, USBPacket *p) -{ - dev->port->ops->complete(dev, p); -} - -/* Cancel an active packet. The packed must have been deferred with - usb_defer_packet, and not yet completed. */ -static inline void usb_cancel_packet(USBPacket * p) -{ - p->cancel_cb(p, p->cancel_opaque); -} - void usb_attach(USBPort *port, USBDevice *dev); void usb_wakeup(USBDevice *dev); int usb_generic_handle_packet(USBDevice *s, USBPacket *p);