From patchwork Tue May 7 13:34:33 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 242204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A85CE2C015E for ; Tue, 7 May 2013 23:35:13 +1000 (EST) Received: from localhost ([::1]:53691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZi2x-00019Z-LB for incoming@patchwork.ozlabs.org; Tue, 07 May 2013 09:35:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:43566) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZi2T-000192-IV for qemu-devel@nongnu.org; Tue, 07 May 2013 09:34:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UZi2R-0007Wo-A0 for qemu-devel@nongnu.org; Tue, 07 May 2013 09:34:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52970) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UZi2R-0007WC-0t for qemu-devel@nongnu.org; Tue, 07 May 2013 09:34:39 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r47DYcnC030793 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 7 May 2013 09:34:38 -0400 Received: from rincewind.home.kraxel.org (ovpn-116-34.ams2.redhat.com [10.36.116.34]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r47DYbIe024494; Tue, 7 May 2013 09:34:37 -0400 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id EC9F440B18; Tue, 7 May 2013 15:34:36 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Tue, 7 May 2013 15:34:33 +0200 Message-Id: <1367933676-21854-4-git-send-email-kraxel@redhat.com> In-Reply-To: <1367933676-21854-1-git-send-email-kraxel@redhat.com> References: <1367933676-21854-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 3/6] xhci: add xhci_alloc_epctx 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 Factor out endpoint context allocation to a separate function. xhci live migration will need that too, in post_load. Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index ac683ce..5084e52 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -1198,6 +1198,26 @@ static void xhci_ep_kick_timer(void *opaque) xhci_kick_ep(epctx->xhci, epctx->slotid, epctx->epid, 0); } +static XHCIEPContext *xhci_alloc_epctx(XHCIState *xhci, + unsigned int slotid, + unsigned int epid) +{ + XHCIEPContext *epctx; + int i; + + epctx = g_new0(XHCIEPContext, 1); + epctx->xhci = xhci; + epctx->slotid = slotid; + epctx->epid = epid; + + for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) { + usb_packet_init(&epctx->transfers[i].packet); + } + epctx->kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx); + + return epctx; +} + static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid, dma_addr_t pctx, uint32_t *ctx) @@ -1205,7 +1225,6 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid, XHCISlot *slot; XHCIEPContext *epctx; dma_addr_t dequeue; - int i; trace_usb_xhci_ep_enable(slotid, epid); assert(slotid >= 1 && slotid <= xhci->numslots); @@ -1216,12 +1235,7 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid, xhci_disable_ep(xhci, slotid, epid); } - epctx = g_malloc(sizeof(XHCIEPContext)); - memset(epctx, 0, sizeof(XHCIEPContext)); - epctx->xhci = xhci; - epctx->slotid = slotid; - epctx->epid = epid; - + epctx = xhci_alloc_epctx(xhci, slotid, epid); slot->eps[epid-1] = epctx; dequeue = xhci_addr64(ctx[2] & ~0xf, ctx[3]); @@ -1241,13 +1255,9 @@ static TRBCCode xhci_enable_ep(XHCIState *xhci, unsigned int slotid, xhci_ring_init(xhci, &epctx->ring, dequeue); epctx->ring.ccs = ctx[2] & 1; } - for (i = 0; i < ARRAY_SIZE(epctx->transfers); i++) { - usb_packet_init(&epctx->transfers[i].packet); - } epctx->interval = 1 << (ctx[0] >> 16) & 0xff; epctx->mfindex_last = 0; - epctx->kick_timer = qemu_new_timer_ns(vm_clock, xhci_ep_kick_timer, epctx); epctx->state = EP_RUNNING; ctx[0] &= ~EP_STATE_MASK;