From patchwork Mon Apr 21 18:03:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 28719 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f199.google.com (mail-ob0-f199.google.com [209.85.214.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D22122032B for ; Mon, 21 Apr 2014 18:07:19 +0000 (UTC) Received: by mail-ob0-f199.google.com with SMTP id gq1sf28978456obb.6 for ; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :mime-version:cc:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=i3EOPduQDZ2lm9yOuW03CDJq2sdDdJfaMRBli0QYruc=; b=HD/GXv96lyuc21QnFoVb3yZBN5PcIDaIwQQZiYhTH1cLIZsf73Xeaon4jUz7vCHf4F hHN6OPZqsYSvQDYb5VpYljDkTbz0aH8Pj3ihE+fUexgv8FDHyemSIE14iVJn1cmugtCp ZSSz9UUh9aKUuJS5/lLucwlNrKuk4PTPDMKzZhzsasuggi2K3LMFAwhDIWH79zgnqqIO 7GC5jAoOmBUQXx8dOhHaOg6pkTkfebXWJu7chVXm2zoZ4uDBZ7lRPTluJ15YWqfxysBU XLQkByDFAgNqXF70BWnjVeZrp/9CrMc6c+fm8EpQk/FABbT0JDjVvuMxv8sc7u+xjQ1d 9Ltw== X-Gm-Message-State: ALoCoQmdm51RdwTgInyetdvPYn/VRJ1sWFc67KkIMN6xMkPP8uvMunukjgVdvrLq3ghdAtvUCtEV X-Received: by 10.182.135.200 with SMTP id pu8mr14546701obb.24.1398103638906; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.103.77 with SMTP id x71ls2578255qge.31.gmail; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-Received: by 10.58.90.99 with SMTP id bv3mr1190581veb.34.1398103638775; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id tm8si6351995vdc.8.2014.04.21.11.07.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 11:07:18 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hr9so40946vcb.1 for ; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-Received: by 10.220.106.84 with SMTP id w20mr31473971vco.18.1398103638654; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp308222vcb; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) X-Received: by 10.140.39.227 with SMTP id v90mr4370979qgv.35.1398103638198; Mon, 21 Apr 2014 11:07:18 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id v6si15686331qas.206.2014.04.21.11.07.18 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Apr 2014 11:07:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WcIZQ-00038q-4g; Mon, 21 Apr 2014 18:03:56 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WcIZM-000385-Jp for linux-arm-kernel@lists.infradead.org; Mon, 21 Apr 2014 18:03:53 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3LI3Hsw007292; Mon, 21 Apr 2014 13:03:17 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3LI3Hq8020271; Mon, 21 Apr 2014 13:03:17 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Mon, 21 Apr 2014 13:03:17 -0500 Received: from ula0393909.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3LI3Gc3001099; Mon, 21 Apr 2014 13:03:16 -0500 From: Santosh Shilimkar To: Subject: [PATCH] ARM: mm: dma: Update coherent streaming apis with missing memory barrier Date: Mon, 21 Apr 2014 14:03:10 -0400 Message-ID: <1398103390-31968-1-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140421_110352_736863_6CF741A3 X-CRM114-Status: GOOD ( 13.01 ) X-Spam-Score: -5.7 (-----) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-5.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.152 listed in list.dnswl.org] -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: Nicolas Pitre , Russell King , Arnd Bergmann , Catalin Marinas , Will Deacon , Santosh Shilimkar , Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: santosh.shilimkar@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 ARM coherent CPU dma map APIS are assumed to be nops on cache coherent machines. While this is true, one still needs to ensure that no outstanding writes are pending in CPU write buffers. To take care of that, we at least need a memory barrier to commit those changes to main memory. Patch is trying to fix those cases. Without such a patch, you will end up patching device drivers to avoid the synchronisation issues. Cc: Russell King Cc: Marek Szyprowski Cc: Will Deacon Cc: Catalin Marinas Cc: Nicolas Pitre Cc: Arnd Bergmann Signed-off-by: Santosh Shilimkar --- arch/arm/mm/dma-mapping.c | 57 ++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/arch/arm/mm/dma-mapping.c b/arch/arm/mm/dma-mapping.c index 5260f43..7c9f55d 100644 --- a/arch/arm/mm/dma-mapping.c +++ b/arch/arm/mm/dma-mapping.c @@ -83,6 +83,8 @@ static dma_addr_t arm_coherent_dma_map_page(struct device *dev, struct page *pag unsigned long offset, size_t size, enum dma_data_direction dir, struct dma_attrs *attrs) { + /* Drain cpu write buffer to main memory */ + wmb(); return pfn_to_dma(dev, page_to_pfn(page)) + offset; } @@ -117,6 +119,13 @@ static void arm_dma_sync_single_for_cpu(struct device *dev, __dma_page_dev_to_cpu(page, offset, size, dir); } +static void arm_coherent_dma_sync_single_for_cpu(struct device *dev, + dma_addr_t handle, size_t size, enum dma_data_direction dir) +{ + /* Drain cpu write buffer to main memory */ + wmb(); +} + static void arm_dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size, enum dma_data_direction dir) { @@ -125,6 +134,33 @@ static void arm_dma_sync_single_for_device(struct device *dev, __dma_page_cpu_to_dev(page, offset, size, dir); } +/** + * arm_dma_sync_sg_for_cpu + * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices + * @sg: list of buffers + * @nents: number of buffers to map (returned from dma_map_sg) + * @dir: DMA transfer direction (same as was passed to dma_map_sg) + */ +void arm_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, + int nents, enum dma_data_direction dir) +{ + struct dma_map_ops *ops = get_dma_ops(dev); + struct scatterlist *s; + int i; + + for_each_sg(sg, s, nents, i) + ops->sync_single_for_cpu(dev, sg_dma_address(s), s->length, + dir); +} + +void arm_coherent_dma_sync_sg_for_cpu(struct device *dev, + struct scatterlist *sg, + int nents, enum dma_data_direction dir) +{ + /* Drain cpu write buffer to main memory */ + wmb(); +} + struct dma_map_ops arm_dma_ops = { .alloc = arm_dma_alloc, .free = arm_dma_free, @@ -154,6 +190,8 @@ struct dma_map_ops arm_coherent_dma_ops = { .get_sgtable = arm_dma_get_sgtable, .map_page = arm_coherent_dma_map_page, .map_sg = arm_dma_map_sg, + .sync_single_for_cpu = arm_coherent_dma_sync_single_for_cpu, + .sync_sg_for_cpu = arm_coherent_dma_sync_sg_for_cpu, .set_dma_mask = arm_dma_set_mask, }; EXPORT_SYMBOL(arm_coherent_dma_ops); @@ -994,25 +1032,6 @@ void arm_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, } /** - * arm_dma_sync_sg_for_cpu - * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices - * @sg: list of buffers - * @nents: number of buffers to map (returned from dma_map_sg) - * @dir: DMA transfer direction (same as was passed to dma_map_sg) - */ -void arm_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, - int nents, enum dma_data_direction dir) -{ - struct dma_map_ops *ops = get_dma_ops(dev); - struct scatterlist *s; - int i; - - for_each_sg(sg, s, nents, i) - ops->sync_single_for_cpu(dev, sg_dma_address(s), s->length, - dir); -} - -/** * arm_dma_sync_sg_for_device * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices * @sg: list of buffers