From patchwork Fri Jan 31 11:54:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 3561381 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7C1EEC02DC for ; Fri, 31 Jan 2014 11:54:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9BE7C20200 for ; Fri, 31 Jan 2014 11:54:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF0CC201FE for ; Fri, 31 Jan 2014 11:54:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932217AbaAaLyz (ORCPT ); Fri, 31 Jan 2014 06:54:55 -0500 Received: from moutng.kundenserver.de ([212.227.126.171]:52992 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932143AbaAaLyy (ORCPT ); Fri, 31 Jan 2014 06:54:54 -0500 Received: from axis700.grange (dslb-146-060-127-137.pools.arcor-ip.net [146.60.127.137]) by mrelayeu.kundenserver.de (node=mreue105) with ESMTP (Nemesis) id 0LcP1q-1VReCb0cnm-00jswg; Fri, 31 Jan 2014 12:54:43 +0100 Received: by axis700.grange (Postfix, from userid 1000) id C588540BB4; Fri, 31 Jan 2014 12:54:42 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by axis700.grange (Postfix) with ESMTP id BD7D640BB3; Fri, 31 Jan 2014 12:54:42 +0100 (CET) Date: Fri, 31 Jan 2014 12:54:42 +0100 (CET) From: Guennadi Liakhovetski X-X-Sender: lyakh@axis700.grange To: linux-mmc@vger.kernel.org cc: Chris Ball , Sascha Hauer , linux-arm-kernel@lists.infradead.org Subject: [PATCH 3/3] mmc: mxcmmc: add DMA SG synchronisation In-Reply-To: Message-ID: References: MIME-Version: 1.0 X-Provags-ID: V02:K0:iDx8mTBFk0x+Vo0xs2agyYxW33gJ58ZIxap0gquETM5 MDVr/HlE4gdb8VpmC55GHuIlkf5HS8HdI/dh6THJ1UcV9vRDcO nJL4Mn5TioRCxDebxNHdsUmJzHmDugz3iijtRMVFP2Wa2Reyrh N9wdAVzq2hfH7srd+nPY9Jv07UVVY80IMne0yNOalpZ72pab6t g6L0KhjY0gTQaNpWBDiEwEduJxBWvVQeXbrj7wM13ToIUaBEnX XKb16eBSyPpYrVsF7+kjiPXF9uB/AuiJC8gGjVYj+OIHPbTBOz N1BjqGOBA3GzcUhjQ5k7Waju2C4Zspsdk62wgxMvOIJMoSCx+I BMmXgHFBCxlRtANxTH2SihZ62NNJ8ChUw3XWaZ679ZInBarWFa NopC/j0CugJBQ== Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to the DMA API data has to be synchronised before starting a DMA transfer to device and after completing a DMA transfer from device. Signed-off-by: Guennadi Liakhovetski --- drivers/mmc/host/mxcmmc.c | 18 ++++++++++++------ 1 files changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/host/mxcmmc.c b/drivers/mmc/host/mxcmmc.c index f7199c8..31dfc7b 100644 --- a/drivers/mmc/host/mxcmmc.c +++ b/drivers/mmc/host/mxcmmc.c @@ -326,6 +326,7 @@ static inline void mxcmci_swap_buffers(struct mmc_data *data) {} static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) { + struct device *dev = host->dma->device->dev; unsigned int nob = data->blocks; unsigned int blksz = data->blksz; unsigned int datasize = nob * blksz; @@ -363,18 +364,20 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data) mxcmci_swap_buffers(data); } - nents = dma_map_sg(host->dma->device->dev, data->sg, - data->sg_len, host->dma_dir); + nents = dma_map_sg(dev, data->sg, data->sg_len, host->dma_dir); if (nents != data->sg_len) return -EINVAL; + if (data->flags & MMC_DATA_WRITE) + dma_sync_sg_for_device(dev, data->sg, data->sg_len, + host->dma_dir); + host->desc = dmaengine_prep_slave_sg(host->dma, data->sg, data->sg_len, slave_dirn, DMA_PREP_INTERRUPT | DMA_CTRL_ACK); if (!host->desc) { - dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len, - host->dma_dir); + dma_unmap_sg(dev, data->sg, data->sg_len, host->dma_dir); host->do_dma = 0; return 0; /* Fall back to PIO */ } @@ -487,8 +490,11 @@ static int mxcmci_finish_data(struct mxcmci_host *host, unsigned int stat) int data_error; if (mxcmci_use_dma(host)) { - dma_unmap_sg(host->dma->device->dev, data->sg, data->sg_len, - host->dma_dir); + struct device *dev = host->dma->device->dev; + dma_unmap_sg(dev, data->sg, data->sg_len, host->dma_dir); + if (host->dma_dir == DMA_FROM_DEVICE) + dma_sync_sg_for_cpu(dev, data->sg, data->sg_len, + host->dma_dir); mxcmci_swap_buffers(data); }