Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp530317imm; Fri, 11 May 2018 02:13:27 -0700 (PDT) X-Google-Smtp-Source: AB8JxZogjDAooCHA1eNSMWcnVUrejW6j3BgN1vovHS5j+PFePhC8B4BlpC0A05TZEx1A/3DNu0Pr X-Received: by 2002:a63:7d51:: with SMTP id m17-v6mr3890249pgn.52.1526030007062; Fri, 11 May 2018 02:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526030007; cv=none; d=google.com; s=arc-20160816; b=c3lqT8gdRupoEYBrcsbELvUz5X30OPzbUObwdDyH4pzk32YHJEyNouXNzaUZAkLKFR 8LPedVWieG7DHhXcn76fbzuczfI0JdIT9totj76twGnedr9bsQ3M5IiEO2FtGKS3wqkR Fu5nfbqyc04maBmJS5YcdLz86oUcufzU14/iFJJCR6pKs3zx6PdiRSzvHnGy5LC8cpWX fXA5p4MPWTN6vqqnK0xIFgdgd1wL9//GUWawnrFO0ODG6OkjuUHzEOOpXsR4BtZxfGrl +p6DIKmBepAgjsE35/AEoiT74aJj65u8bM/duyTiC97jgQwJssPwgc/WdqtHC0avIOZa wfAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=6WGcNR3XGYJSl9206AAYWWx5d2VNz3Bqv2wQ01MR3+w=; b=NU4DmrqhISMrupdV75f9mZUBd145aYCN5v8JERA551+32mUugUdc+s1bL/PVM7LWMI mL8KF1QIpKcJXWG80GiPVaTRllv2Zs5iJf0F9ZjLy5LKULXmnPnR0W7v/S/SVCbaXjyb vj1/2eiPmA5pY/OSDRWfaeUxOr4ze/mpPbzbugQ5/eqjGapWlKcbM321fVmYFUIkV/gs LFgL37ccukiiWNclGtjGSURioIpEIBgbpEjEpLDwbBx8qd0MGYLC77yRM0nX4HZkBLFP Mets8aAIOkIZP0r5xYjbvmRzCmjsFcK54apdQtFPMRKrrE89CpBPoZiDMfoLs75kc5eO hXfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=L7VbR7Og; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p14-v6si2845411plr.131.2018.05.11.02.13.01; Fri, 11 May 2018 02:13:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@armlinux.org.uk header.s=pandora-2014 header.b=L7VbR7Og; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752755AbeEKJLe (ORCPT + 99 others); Fri, 11 May 2018 05:11:34 -0400 Received: from pandora.armlinux.org.uk ([78.32.30.218]:42726 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752604AbeEKJLb (ORCPT ); Fri, 11 May 2018 05:11:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=6WGcNR3XGYJSl9206AAYWWx5d2VNz3Bqv2wQ01MR3+w=; b=L7VbR7OgxRa2K/HyY0R40IbEY UkfhI16IqA7GcO5AXKStW3ZcPydzqgbtHP5YTkoHIe/5TVzzd1WM6aMhpfNZMwJV0++dEVYqyA/vH mZEFS2DpbAp57USTu8PcDDsKedsfhFGi5WC70dzU/erDiaIv5FAJx85uz6eZET8mkWMOI=; Received: from n2100.armlinux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]:48161) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.90_1) (envelope-from ) id 1fH459-0006mn-JI; Fri, 11 May 2018 10:11:19 +0100 Received: from linux by n2100.armlinux.org.uk with local (Exim 4.90_1) (envelope-from ) id 1fH456-0005hB-Uw; Fri, 11 May 2018 10:11:17 +0100 Date: Fri, 11 May 2018 10:11:15 +0100 From: Russell King - ARM Linux To: Christoph Hellwig Cc: iommu@lists.linux-foundation.org, linux-arch@vger.kernel.org, linux-xtensa@linux-xtensa.org, Michal Simek , Vincent Chen , linux-c6x-dev@linux-c6x.org, linux-parisc@vger.kernel.org, linux-sh@vger.kernel.org, linux-hexagon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-m68k@lists.linux-m68k.org, openrisc@lists.librecores.org, Greentime Hu , linux-alpha@vger.kernel.org, sparclinux@vger.kernel.org, nios2-dev@lists.rocketboards.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 04/20] arm-nommu: use generic dma_noncoherent_ops Message-ID: <20180511091114.GA16141@n2100.armlinux.org.uk> References: <20180511075945.16548-1-hch@lst.de> <20180511075945.16548-5-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180511075945.16548-5-hch@lst.de> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 11, 2018 at 09:59:29AM +0200, Christoph Hellwig wrote: > Switch to the generic noncoherent direct mapping implementation for > the nommu dma map implementation. > > Signed-off-by: Christoph Hellwig > --- > arch/arc/Kconfig | 1 + > arch/arm/Kconfig | 4 + > arch/arm/mm/dma-mapping-nommu.c | 139 +++++--------------------------- > 3 files changed, 23 insertions(+), 121 deletions(-) > > diff --git a/arch/arc/Kconfig b/arch/arc/Kconfig > index 89d47eac18b2..3a492a9aeaad 100644 > --- a/arch/arc/Kconfig > +++ b/arch/arc/Kconfig > @@ -9,6 +9,7 @@ > config ARC > def_bool y > select ARC_TIMERS > + select ARCH_HAS_SYNC_DMA_FOR_DEVICE > select ARCH_HAS_SYNC_DMA_FOR_CPU > select ARCH_HAS_SYNC_DMA_FOR_DEVICE > select ARCH_HAS_SG_CHAIN > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > index c43f5bb55ac8..76ddd0064f87 100644 > --- a/arch/arm/Kconfig > +++ b/arch/arm/Kconfig > @@ -12,6 +12,8 @@ config ARM > select ARCH_HAS_PHYS_TO_DMA > select ARCH_HAS_STRICT_KERNEL_RWX if MMU && !XIP_KERNEL > select ARCH_HAS_STRICT_MODULE_RWX if MMU > + select ARCH_HAS_SYNC_DMA_FOR_CPU if !MMU > + select ARCH_HAS_SYNC_DMA_FOR_DEVICE if !MMU > select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST > select ARCH_HAVE_CUSTOM_GPIO_H > select ARCH_HAS_GCOV_PROFILE_ALL > @@ -27,6 +29,8 @@ config ARM > select CPU_PM if (SUSPEND || CPU_IDLE) > select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS > select DMA_DIRECT_OPS if !MMU > + select DMA_NONCOHERENT_OPS if !MMU > + select DMA_NONCOHERENT_MMAP if !MMU > select EDAC_SUPPORT > select EDAC_ATOMIC_SCRUB > select GENERIC_ALLOCATOR > diff --git a/arch/arm/mm/dma-mapping-nommu.c b/arch/arm/mm/dma-mapping-nommu.c > index f448a0663b10..a74ed6632982 100644 > --- a/arch/arm/mm/dma-mapping-nommu.c > +++ b/arch/arm/mm/dma-mapping-nommu.c > @@ -12,6 +12,7 @@ > #include > #include > #include > +#include > #include > > #include > @@ -26,18 +27,16 @@ > * - MMU/MPU is off > * - cpu is v7m w/o cache support > * - device is coherent > - * otherwise arm_nommu_dma_ops is used. > + * otherwise dma_noncoherent_ops is used. > * > - * arm_nommu_dma_ops rely on consistent DMA memory (please, refer to > + * dma_noncoherent_ops rely on consistent DMA memory (please, refer to > * [1] on how to declare such memory). > * > * [1] Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt > */ > > -static void *arm_nommu_dma_alloc(struct device *dev, size_t size, > - dma_addr_t *dma_handle, gfp_t gfp, > - unsigned long attrs) > - > +void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle, > + gfp_t gfp, unsigned long attrs) > { > void *ret; > > @@ -65,9 +64,8 @@ static void *arm_nommu_dma_alloc(struct device *dev, size_t size, > return ret; > } > > -static void arm_nommu_dma_free(struct device *dev, size_t size, > - void *cpu_addr, dma_addr_t dma_addr, > - unsigned long attrs) > +void arch_dma_free(struct device *dev, size_t size, void *cpu_addr, > + dma_addr_t dma_addr, unsigned long attrs) > { > if (attrs & DMA_ATTR_NON_CONSISTENT) { > dma_direct_free(dev, size, cpu_addr, dma_addr, attrs); > @@ -81,9 +79,9 @@ static void arm_nommu_dma_free(struct device *dev, size_t size, > return; > } > > -static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma, > - void *cpu_addr, dma_addr_t dma_addr, size_t size, > - unsigned long attrs) > +int arch_dma_mmap(struct device *dev, struct vm_area_struct *vma, > + void *cpu_addr, dma_addr_t dma_addr, size_t size, > + unsigned long attrs) > { > int ret; > > @@ -93,9 +91,8 @@ static int arm_nommu_dma_mmap(struct device *dev, struct vm_area_struct *vma, > return dma_common_mmap(dev, vma, cpu_addr, dma_addr, size); > } > > - > -static void __dma_page_cpu_to_dev(phys_addr_t paddr, size_t size, > - enum dma_data_direction dir) > +void arch_sync_dma_for_device(struct device *dev, phys_addr_t paddr, > + size_t size, enum dma_data_direction dir) Please no. There is a lot of history of these (__dma_page_cpu_to_dev etc) functions being abused by out of tree drivers, because they think they know better. This is stopped by making them static and ensuring that drivers have no access to these functions. Please do not re-expose these to the global kernel. While it may make things easier for a cross-architecture point of view, it makes it a lot easier for people to abuse these private APIs. -- RMK's Patch system: http://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 8.8Mbps down 630kbps up According to speedtest.net: 8.21Mbps down 510kbps up