From patchwork Wed Nov 5 16:56:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 40204 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7713324538 for ; Wed, 5 Nov 2014 16:57:07 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id mc6sf748414lab.3 for ; Wed, 05 Nov 2014 08:57:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:in-reply-to:user-agent:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe :content-type:content-disposition; bh=hQLtz6uCjbLBlBkpl34qiJJ0WswSTtLVRialr4U2LWA=; b=cO/HX4VkFU/npBKmsdNlE7V7zL3TzcU5mI5Ab878NhjrkVnqOmgpFW/ySqFt7L45z5 19S+1jGWinvK9xmgi4ST77bxrazeQ/GOe0H8yNvC61ia3hecVq2Rgozc2YsH2u1Ehfhr 4x7ABJUPsYRWoAM09ssHUwxOcVyaOOQLxzeNbieVz8ZdP4p2WG3dDm72M3AzxIRvKU5F FYa5wUEYCyUdHAfqGVCu8GbY+tzzCves+niKWC0skk7H1BNfCkQsvTdT6wGiy8PnEiWf +Sim8UCTQHtIUZCXUVOMcIQhSWMeIqoioAv2HYnumWnT7v8BLbxw3xa1BfLtNEImSBF5 bDcw== X-Gm-Message-State: ALoCoQmi64hNzfV8VKv5dzOL26atsTshxWhzGGxMt4AcToMSPD1f3a6Bjxt034H6nRfasH51Fd3R X-Received: by 10.152.7.73 with SMTP id h9mr592557laa.6.1415206626449; Wed, 05 Nov 2014 08:57:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.97 with SMTP id s1ls1061221lag.81.gmail; Wed, 05 Nov 2014 08:57:06 -0800 (PST) X-Received: by 10.152.120.167 with SMTP id ld7mr17386420lab.77.1415206626275; Wed, 05 Nov 2014 08:57:06 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id ei3si7094357lad.84.2014.11.05.08.57.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 05 Nov 2014 08:57:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id pn19so1050157lab.4 for ; Wed, 05 Nov 2014 08:57:06 -0800 (PST) X-Received: by 10.152.42.226 with SMTP id r2mr38212760lal.29.1415206626133; Wed, 05 Nov 2014 08:57:06 -0800 (PST) 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.112.184.201 with SMTP id ew9csp315194lbc; Wed, 5 Nov 2014 08:57:04 -0800 (PST) X-Received: by 10.66.122.2 with SMTP id lo2mr58919004pab.9.1415206622620; Wed, 05 Nov 2014 08:57:02 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w4si3490205pbz.124.2014.11.05.08.57.01 for ; Wed, 05 Nov 2014 08:57:02 -0800 (PST) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755175AbaKEQ5A (ORCPT + 25 others); Wed, 5 Nov 2014 11:57:00 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:53495 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754004AbaKEQ46 (ORCPT ); Wed, 5 Nov 2014 11:56:58 -0500 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id 73A2B1AA; Wed, 5 Nov 2014 10:56:53 -0600 (CST) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 520535FAD7; Wed, 5 Nov 2014 10:56:51 -0600 (CST) Received: from e104818-lin.cambridge.arm.com (e104818-lin.cambridge.arm.com [10.1.203.148]) by collaborate-mta1.arm.com (Postfix) with ESMTPS id CCB8B13F8F5; Wed, 5 Nov 2014 10:56:49 -0600 (CST) Date: Wed, 5 Nov 2014 16:56:47 +0000 From: Catalin Marinas To: Stefano Stabellini Cc: Will Deacon , "xen-devel@lists.xensource.com" , "konrad.wilk@oracle.com" , "Ian.Campbell@citrix.com" , "david.vrabel@citrix.com" , "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [PATCH v7 3/8] arm64: introduce is_device_dma_coherent Message-ID: <20141105165646.GN32700@e104818-lin.cambridge.arm.com> References: <1414422568-19103-3-git-send-email-stefano.stabellini@eu.citrix.com> <20141103105716.GC23162@arm.com> MIME-Version: 1.0 In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: catalin.marinas@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Content-Disposition: inline On Mon, Nov 03, 2014 at 11:10:18AM +0000, Stefano Stabellini wrote: > On Mon, 3 Nov 2014, Will Deacon wrote: > > On Mon, Nov 03, 2014 at 10:46:03AM +0000, Stefano Stabellini wrote: > > > On Mon, 27 Oct 2014, Stefano Stabellini wrote: > > > > Introduce a boolean flag and an accessor function to check whether a > > > > device is dma_coherent. Set the flag from set_arch_dma_coherent_ops. > > > > > > > > Signed-off-by: Stefano Stabellini > > > > Signed-off-by: Catalin Marinas > > > > CC: will.deacon@arm.com > > > > > > Will, Catalin, > > > are you OK with this patch? > > > > It would be nicer if the dma_coherent flag didn't have to be duplicated by > > each architecture in dev_archdata. Is there any reason not to put it in the > > core code? > > Yes, there is a reason for it: if I added a boolean dma_coherent flag in > struct device as Catalin initially suggested, what would be the default > for each architecture? Where would I set it for arch that don't use > device tree? You don't need to. An architecture that has coherent DMA always doesn't need to do anything. One that has non-coherent DMA always only needs to select HAVE_DMA_NONCOHERENT. One that has a mix of both needs to find a way to set dev->dma_coherent. Since that's a new API you introduce, it doesn't break any existing architectures. Note that if !is_device_dma_coherent(), it doesn't always mean that standard cache maintenance would be enough (but that's a Xen problem, not sure how to solve). --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/arch/Kconfig b/arch/Kconfig index 05d7a8a458d5..8462b2e7491b 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -203,6 +203,9 @@ config HAVE_DMA_ATTRS config HAVE_DMA_CONTIGUOUS bool +config HAVE_DMA_NONCOHERENT + bool + config GENERIC_SMP_IDLE_THREAD bool diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 89c4b5ccc68d..fd7d5522764c 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -40,6 +40,7 @@ config ARM select HAVE_DMA_API_DEBUG select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS if MMU + select HAVE_DMA_NONCOHERENT if OF select HAVE_DYNAMIC_FTRACE if (!XIP_KERNEL) select HAVE_EFFICIENT_UNALIGNED_ACCESS if (CPU_V6 || CPU_V6K || CPU_V7) && MMU select HAVE_FTRACE_MCOUNT_RECORD if (!XIP_KERNEL) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9532f8d5857e..eb7a5aa64e0e 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -46,6 +46,7 @@ config ARM64 select HAVE_DMA_API_DEBUG select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS + select HAVE_DMA_NONCOHERENT select HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS select HAVE_FTRACE_MCOUNT_RECORD diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 3b64d0bf5bba..7e827726b702 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -183,6 +183,7 @@ static void of_dma_configure(struct device *dev) * dma coherent operations. */ if (of_dma_is_coherent(dev->of_node)) { + dev->dma_coherent = true; set_arch_dma_coherent_ops(dev); dev_dbg(dev, "device is dma coherent\n"); } diff --git a/include/linux/device.h b/include/linux/device.h index ce1f21608b16..e00ca876db01 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -796,6 +796,7 @@ struct device { bool offline_disabled:1; bool offline:1; + bool dma_coherent:1; }; static inline struct device *kobj_to_dev(struct kobject *kobj) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index d5d388160f42..0bdffba2337d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -78,6 +78,18 @@ static inline int is_device_dma_capable(struct device *dev) return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE; } +#ifdef CONFIG_HAVE_DMA_NONCOHERENT +static inline int is_device_dma_coherent(struct device *dev) +{ + return dev->dma_coherent; +} +#else +static inline int is_device_dma_coherent(struct device *dev) +{ + return 1 +} +#endif + #ifdef CONFIG_HAS_DMA #include #else diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9532f8d5857e..eb7a5aa64e0e 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -46,6 +46,7 @@ config ARM64 select HAVE_DMA_API_DEBUG select HAVE_DMA_ATTRS select HAVE_DMA_CONTIGUOUS + select HAVE_DMA_NONCOHERENT select HAVE_DYNAMIC_FTRACE select HAVE_EFFICIENT_UNALIGNED_ACCESS select HAVE_FTRACE_MCOUNT_RECORD diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 3b64d0bf5bba..7e827726b702 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -183,6 +183,7 @@ static void of_dma_configure(struct device *dev) * dma coherent operations. */ if (of_dma_is_coherent(dev->of_node)) { + dev->dma_coherent = true; set_arch_dma_coherent_ops(dev); dev_dbg(dev, "device is dma coherent\n"); } diff --git a/include/linux/device.h b/include/linux/device.h index ce1f21608b16..e00ca876db01 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -796,6 +796,7 @@ struct device { bool offline_disabled:1; bool offline:1; + bool dma_coherent:1; }; static inline struct device *kobj_to_dev(struct kobject *kobj) diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h index d5d388160f42..0bdffba2337d 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -78,6 +78,18 @@ static inline int is_device_dma_capable(struct device *dev) return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE; } +#ifdef CONFIG_HAVE_DMA_NONCOHERENT +static inline int is_device_dma_coherent(struct device *dev) +{ + return dev->dma_coherent; +} +#else +static inline int is_device_dma_coherent(struct device *dev) +{ + return 1 +} +#endif + #ifdef CONFIG_HAS_DMA #include #else