From patchwork Thu Aug 1 22:18:37 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Troy Kisky X-Patchwork-Id: 264134 X-Patchwork-Delegate: marek.vasut@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 9D9252C008F for ; Fri, 2 Aug 2013 08:22:56 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BD3F74A0F1; Fri, 2 Aug 2013 00:22:18 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id t6pVilZjcUi0; Fri, 2 Aug 2013 00:22:18 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 8DED44A0EB; Fri, 2 Aug 2013 00:20:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id ADC904A08E for ; Fri, 2 Aug 2013 00:20:01 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id L6U8qfVvnfWI for ; Fri, 2 Aug 2013 00:19:57 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com [209.85.192.182]) by theia.denx.de (Postfix) with ESMTPS id 674234A02D for ; Fri, 2 Aug 2013 00:19:27 +0200 (CEST) Received: by mail-pd0-f182.google.com with SMTP id r10so2513909pdi.41 for ; Thu, 01 Aug 2013 15:19:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=Kr71nrWKF43fSGAeJPzzfe9VIefg2v2FW8V5l+wjvH0=; b=ZvvRMvsHEgWVuvJpD03lFISC45pNiqegK7++WpER5ATvNSYK5L2GlAORivddP/4yT/ Xx6r2eK7daDMBl1atjCxWuYjc83MuiTcPi0M29HFxt9qFgDM55QzCijewD0elFsFgaBU sp0T56ohoxOoSDiVBmRHBjQN/bfmB5M4s8rTPDczTCAtj78gVumKtjb4iSywxdm4lYlR WKqSESONPTiKq40rnJFabwBhqAGslbtORo23S7qJVLldqixs/HaMCyxQfshDKq4gZMz+ x9T44O/E1u/C8k5uE/bLs1xuU108JoeecNIcB3UAhrfrKOJG2hgsuvdu8zWHhP99mIs5 mYDA== X-Received: by 10.66.179.143 with SMTP id dg15mr7032598pac.52.1375395565957; Thu, 01 Aug 2013 15:19:25 -0700 (PDT) Received: from officeserver-2 ([70.96.116.236]) by mx.google.com with ESMTPSA id sx7sm6163421pbc.41.2013.08.01.15.19.24 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 01 Aug 2013 15:19:25 -0700 (PDT) Received: from tkisky by officeserver-2 with local (Exim 4.80) (envelope-from ) id 1V51DO-0004s5-96; Thu, 01 Aug 2013 15:19:22 -0700 From: Troy Kisky To: marek.vasut@gmail.com Date: Thu, 1 Aug 2013 15:18:37 -0700 Message-Id: <1375395521-18569-21-git-send-email-troy.kisky@boundarydevices.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375395521-18569-1-git-send-email-troy.kisky@boundarydevices.com> References: <1375395521-18569-1-git-send-email-troy.kisky@boundarydevices.com> X-Gm-Message-State: ALoCoQl3HIQmDadY7iFygRmXbG2jFTzzhy6HFu5OkNIg77zhLex6DbER/NKlnJPTnlcEk1jlDIUx Cc: fabio.estevam@freescale.com, otavio@ossystems.com.br, leiwen@marvell.com, u-boot@lists.denx.de Subject: [U-Boot] [PATCH V2 16/20] usb: gadget: mv_udc: optimize bounce X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Only perform one copy, either in the bounce routine for IN transfers, or the debounce rtn for OUT transfer. On out transfers, only copy the number of bytes received from the bounce buffer Signed-off-by: Troy Kisky --- drivers/usb/gadget/mv_udc.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/drivers/usb/gadget/mv_udc.c b/drivers/usb/gadget/mv_udc.c index c9bd0a7..6e0f9bb 100644 --- a/drivers/usb/gadget/mv_udc.c +++ b/drivers/usb/gadget/mv_udc.c @@ -279,7 +279,7 @@ static int mv_ep_disable(struct usb_ep *ep) return 0; } -static int mv_bounce(struct mv_ep *ep) +static int mv_bounce(struct mv_ep *ep, int in) { uint32_t addr = (uint32_t)ep->req.buf; uint32_t ba; @@ -308,8 +308,8 @@ align: if (!ep->b_buf) return -ENOMEM; } - - memcpy(ep->b_buf, ep->req.buf, ep->req.length); + if (in) + memcpy(ep->b_buf, ep->req.buf, ep->req.length); flush: ba = (uint32_t)ep->b_buf; @@ -318,29 +318,25 @@ flush: return 0; } -static void mv_debounce(struct mv_ep *ep) +static void mv_debounce(struct mv_ep *ep, int in) { uint32_t addr = (uint32_t)ep->req.buf; uint32_t ba = (uint32_t)ep->b_buf; + if (in) { + if (addr == ba) + return; /* not a bounce */ + goto free; + } invalidate_dcache_range(ba, ba + ep->b_len); - /* Input buffer address is not aligned. */ - if (addr & (ARCH_DMA_MINALIGN - 1)) - goto copy; - - /* Input buffer length is not aligned. */ - if (ep->req.length & (ARCH_DMA_MINALIGN - 1)) - goto copy; - - /* The buffer is well aligned, only invalidate cache. */ - return; + if (addr == ba) + return; /* not a bounce */ -copy: memcpy(ep->req.buf, ep->b_buf, ep->req.length); - +free: /* Large payloads use allocated buffer, free it. */ - if (ep->req.length > 64) + if (ep->b_buf != ep->b_fast) free(ep->b_buf); } @@ -358,7 +354,7 @@ static int mv_ep_queue(struct usb_ep *ep, head = mv_get_qh(num, in); len = req->length; - ret = mv_bounce(mv_ep); + ret = mv_bounce(mv_ep, in); if (ret) return ret; @@ -402,10 +398,9 @@ static void handle_ep_complete(struct mv_ep *ep) num, in ? "in" : "out", item->info, item->page0); len = (item->info >> 16) & 0x7fff; - - mv_debounce(ep); - ep->req.length -= len; + mv_debounce(ep, in); + DBG("ept%d %s complete %x\n", num, in ? "in" : "out", len); ep->req.complete(&ep->ep, &ep->req);