From patchwork Fri Oct 24 15:43:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Catalin Marinas X-Patchwork-Id: 39484 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f72.google.com (mail-wg0-f72.google.com [74.125.82.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 12A6024026 for ; Fri, 24 Oct 2014 15:44:26 +0000 (UTC) Received: by mail-wg0-f72.google.com with SMTP id l18sf816933wgh.7 for ; Fri, 24 Oct 2014 08:44:26 -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: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=GnralspG9KQjgyY4lM6u6Zz0CqG2PJ3vzrG/Ca2HgAs=; b=jBLKOntkIZtZjCDTPTOOP8ugCMfHT1aU8zytYEow9TIUXeWThBZbv1ls8DlfaiP+8l c0QT5WRL1bt5NTvXHFwDk/HqPiLO2xoU+08bO7v9Bxu4yzAUz9/rC9JeijTjz60cFoWG GauC4dg3URCY527tyzVIjm9I8g+RKa14H7va8ho5cC9DaE8cThzyF9C41mFMlnF1YBgy ySs+bg5RLCVbjicc+mQEAki8ikQ3vAS7mqx3wpOZaGFrfef66Qu7EtsOrR9rez13Gfg8 5r3lBvpXmqa9SOgd14EauuFj9jvF2rDoLf/sxOxLxghva8K8TE5heLC597pnBVVOtFsp QsXA== X-Gm-Message-State: ALoCoQlm7vOKvMCg5JMbG3CHIwqw6h4xyL72A3sDE7TgmqfNK2fa6/AoVGlZNb4EACfr4YsqK518 X-Received: by 10.180.19.198 with SMTP id h6mr986360wie.5.1414165466271; Fri, 24 Oct 2014 08:44:26 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.135 with SMTP id k7ls408348lah.78.gmail; Fri, 24 Oct 2014 08:44:26 -0700 (PDT) X-Received: by 10.153.4.44 with SMTP id cb12mr5557733lad.10.1414165466082; Fri, 24 Oct 2014 08:44:26 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id du3si7614671lbc.32.2014.10.24.08.44.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 24 Oct 2014 08:44:26 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id mc6so2916087lab.16 for ; Fri, 24 Oct 2014 08:44:26 -0700 (PDT) X-Received: by 10.152.120.199 with SMTP id le7mr5242701lab.67.1414165465989; Fri, 24 Oct 2014 08:44:25 -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.112.84.229 with SMTP id c5csp455324lbz; Fri, 24 Oct 2014 08:44:24 -0700 (PDT) X-Received: by 10.68.215.2 with SMTP id oe2mr5612477pbc.94.1414165464066; Fri, 24 Oct 2014 08:44:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k8si4429766pdr.201.2014.10.24.08.44.20 for ; Fri, 24 Oct 2014 08:44:24 -0700 (PDT) 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 S932794AbaJXPoN (ORCPT + 26 others); Fri, 24 Oct 2014 11:44:13 -0400 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:48320 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752465AbaJXPoJ (ORCPT ); Fri, 24 Oct 2014 11:44:09 -0400 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 D30C3231; Fri, 24 Oct 2014 10:43:59 -0500 (CDT) 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 B651D5FAD7; Fri, 24 Oct 2014 10:43:57 -0500 (CDT) 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 36E1013F61D; Fri, 24 Oct 2014 10:43:56 -0500 (CDT) Date: Fri, 24 Oct 2014 16:43:54 +0100 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" , "linux@arm.linux.org.uk" Subject: Re: [PATCH v4 3/7] [RFC] arm/arm64: introduce is_dma_coherent Message-ID: <20141024154353.GE20534@e104818-lin.cambridge.arm.com> References: <1412941908-5850-3-git-send-email-stefano.stabellini@eu.citrix.com> <20141010120702.GI7755@arm.com> <20141013125725.GA19156@arm.com> <20141024104746.GC1955@localhost> 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.43 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 Fri, Oct 24, 2014 at 12:39:59PM +0100, Stefano Stabellini wrote: > On Fri, 24 Oct 2014, Catalin Marinas wrote: > > I think a better way would be some Xen hook around > > set_arch_dma_coherent_ops(). Does Xen have its own device tracking > > structures? If not, you may be able to add another bitfield to the > > kernel one. > > We don't have an additional device tracking struct on Xen. > I agree that a new bit somewhere would be the best solution, but I am > not sure where. Maybe in dev_archdata under arm and arm64? After all it > is already used to keep pointers to dma and coherency related > structures. I was thinking about something like below (maybe with some additional ARCH_HAS_NONCOHERENT_DMA config for architectures that are always coherent): This way you don't have to test for swiotlb vs iommu ops (we don't have the latter yet on arm64 but they are coming). diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 3b64d0bf5bba..ae399ccbd569 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 = 1; 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..9c9ba5a5428e 100644 --- a/include/linux/dma-mapping.h +++ b/include/linux/dma-mapping.h @@ -78,6 +78,11 @@ static inline int is_device_dma_capable(struct device *dev) return dev->dma_mask != NULL && *dev->dma_mask != DMA_MASK_NONE; } +static inline int is_device_dma_coherent(struct device *dev) +{ + return dev->dma_coherent; +} + #ifdef CONFIG_HAS_DMA #include #else > However given the timing constraints I hope you would be OK with the > suboptimal solution for now and create a common is_dma_coherent function > in 3.19? If you want to push something for 3.18, you could have a temporary solution but I would prefer a bool or something in the dev_archdata structure. Another untested patch: diff --git a/arch/arm64/include/asm/device.h b/arch/arm64/include/asm/device.h index cf98b362094b..243ef256b8c9 100644 --- a/arch/arm64/include/asm/device.h +++ b/arch/arm64/include/asm/device.h @@ -21,6 +21,7 @@ struct dev_archdata { #ifdef CONFIG_IOMMU_API void *iommu; /* private IOMMU data */ #endif + bool dma_coherent; }; struct pdev_archdata { diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h index adeae3f6f0fc..b6bc4c268878 100644 --- a/arch/arm64/include/asm/dma-mapping.h +++ b/arch/arm64/include/asm/dma-mapping.h @@ -54,11 +54,17 @@ static inline void set_dma_ops(struct device *dev, struct dma_map_ops *ops) static inline int set_arch_dma_coherent_ops(struct device *dev) { + dev->dev_archdata.dma_coherent = true; set_dma_ops(dev, &coherent_swiotlb_dma_ops); return 0; } #define set_arch_dma_coherent_ops set_arch_dma_coherent_ops +static inline int is_device_dma_coherent(struct device *dev) +{ + return dev->dev_archdata.dma_coherent; +} + #include static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)