From patchwork Thu Apr 6 03:37:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Eddie Cai X-Patchwork-Id: 747595 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 lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vz7gq71lTz9s8S for ; Thu, 6 Apr 2017 13:37:27 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="rUvO9liQ"; dkim-atps=neutral Received: by lists.denx.de (Postfix, from userid 105) id A0448C21C60; Thu, 6 Apr 2017 03:37:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=FREEMAIL_FROM, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 49CF0C21C35; Thu, 6 Apr 2017 03:37:20 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id E8A14C21C35; Thu, 6 Apr 2017 03:37:18 +0000 (UTC) Received: from mail-pg0-f67.google.com (mail-pg0-f67.google.com [74.125.83.67]) by lists.denx.de (Postfix) with ESMTPS id 3E2C4C21C32 for ; Thu, 6 Apr 2017 03:37:18 +0000 (UTC) Received: by mail-pg0-f67.google.com with SMTP id o123so5335556pga.1 for ; Wed, 05 Apr 2017 20:37:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3u9EX7xPkGb2kD056Luq4X2bYLSKEyBReok3tHcLFAk=; b=rUvO9liQSCnAfdnuOvguw51Jip44FY77Nng1qxMJjK3rg/UUaUt5xfAlWQsLHxTwBD JV1curvvDlVZpnotLfGXQySSaG5di12/gyuhkYqP/9sBBfy6qHX2tDoJlZceXdIprO2h 9cQu2tM3EDqgOz1TbhiCuU+s//zmIrNuGx5WZ72PQadLQNJIrHtrd3N9IrW7jrgn2eG0 6F0NufASjptDNIsLpEubJjaPCDJp/r3z+Px8gmH2a+vP5qqw1KAR2w7vM6WcUfdJihcv FEFNb4O9CWTN3g78oRyfKLAhn+8CvR2UqwQXSHTrbObG0tj3vUjYeOeao13PWXp/f2kI yM1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=3u9EX7xPkGb2kD056Luq4X2bYLSKEyBReok3tHcLFAk=; b=muXK4alxqpy/j/YbSLNhLXWctgMjvnFNSsRMHyDZWNq5ArPa5f3wmUysmVmwdsdA8U 7l6OLsIVArMxOThzKrO+QhjiQTAWNqXbfpsKO1tLcyB1hClX4879Af9VWVAIzqdGyfgQ j+Y4iBjZd4RAbK9Cf1iuFO9djfCijfYZoQJJtyu1cN+UIrl0s4WDkaMM7s9Z+qSwgY29 +9z3EKh+qTTooElgSne8E2u1Hxynp3/CQ/jf0qwrz0y+bxxXvhXIvVZ2ZvT3OeWeMDXR zUZVQZukG937A3zWwGh8gEgP6/jKJz0w3vDQz8ico4+RktZqmyMPjSGPj6erVdAv5uf+ 1oNw== X-Gm-Message-State: AFeK/H1LuTdEz8V29N1TXMQtQpXVtbG6m17gNTtAr7nHrlun+0QNfm2VJyvnZHlBHCndEQ== X-Received: by 10.99.143.88 with SMTP id r24mr34451648pgn.177.1491449836968; Wed, 05 Apr 2017 20:37:16 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id o194sm386649pfg.66.2017.04.05.20.37.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Apr 2017 20:37:15 -0700 (PDT) From: Eddie Cai To: marex@denx.de, sjg@chromium.org, stefan.bruens@rwth-aachen.de, kever.yang@rock-chips.com Date: Thu, 6 Apr 2017 11:37:04 +0800 Message-Id: <20170406033704.26258-1-eddie.cai.linux@gmail.com> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATH V3] usb: dwc2: invalidate the dcache before starting the DMA X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" We should invalidate the dcache before starting the DMA. In case there are any dirty lines from the DMA buffer in the cache, subsequent cache-line replacements may corrupt the buffer in memory while the DMA is still going on. Cache-line replacement can happen if the CPU tries to bring some other memory locations into the cache while the DMA is going on. Signed-off-by: Eddie Cai Reviewed-by: Stefan BrĂ¼ns --- drivers/usb/host/dwc2.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/usb/host/dwc2.c b/drivers/usb/host/dwc2.c index 5ac602e..f295843 100644 --- a/drivers/usb/host/dwc2.c +++ b/drivers/usb/host/dwc2.c @@ -811,12 +811,19 @@ static int transfer_chunk(struct dwc2_hc_regs *hc_regs, void *aligned_buffer, (*pid << DWC2_HCTSIZ_PID_OFFSET), &hc_regs->hctsiz); - if (!in && xfer_len) { - memcpy(aligned_buffer, buffer, xfer_len); - - flush_dcache_range((unsigned long)aligned_buffer, - (unsigned long)aligned_buffer + - roundup(xfer_len, ARCH_DMA_MINALIGN)); + if (xfer_len) { + if (in) { + invalidate_dcache_range( + (uintptr_t)aligned_buffer, + (uintptr_t)aligned_buffer + + roundup(xfer_len, ARCH_DMA_MINALIGN)); + } else { + memcpy(aligned_buffer, buffer, xfer_len); + flush_dcache_range( + (uintptr_t)aligned_buffer, + (uintptr_t)aligned_buffer + + roundup(xfer_len, ARCH_DMA_MINALIGN)); + } } writel(phys_to_bus((unsigned long)aligned_buffer), &hc_regs->hcdma);