From patchwork Sat Oct 25 13:29:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 5151281 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 9BAAF9F374 for ; Sat, 25 Oct 2014 13:34:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B75F12028D for ; Sat, 25 Oct 2014 13:34:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C71E22027D for ; Sat, 25 Oct 2014 13:34:46 +0000 (UTC) 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 1Xi1Rr-0003dd-KL; Sat, 25 Oct 2014 13:32:03 +0000 Received: from smtp02.citrix.com ([66.165.176.63]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xi1Ro-0003d4-Fz for linux-arm-kernel@lists.infradead.org; Sat, 25 Oct 2014 13:32:01 +0000 X-IronPort-AV: E=Sophos;i="5.04,786,1406592000"; d="scan'208";a="186159032" Received: from ukmail1.uk.xensource.com (10.80.16.128) by smtprelay.citrix.com (10.13.107.78) with Microsoft SMTP Server id 14.3.181.6; Sat, 25 Oct 2014 09:31:37 -0400 Received: from kaball.uk.xensource.com ([10.80.2.59]) by ukmail1.uk.xensource.com with esmtp (Exim 4.69) (envelope-from ) id 1Xi1RQ-0008Jj-Lp; Sat, 25 Oct 2014 14:31:36 +0100 Date: Sat, 25 Oct 2014 14:29:07 +0100 From: Stefano Stabellini X-X-Sender: sstabellini@kaball.uk.xensource.com To: Stefano Stabellini Subject: Re: [PATCH v4 3/7] [RFC] arm/arm64: introduce is_dma_coherent In-Reply-To: Message-ID: References: <1412941908-5850-3-git-send-email-stefano.stabellini@eu.citrix.com> <20141010120702.GI7755@arm.com> <20141013125725.GA19156@arm.com> <20141024104746.GC1955@localhost> <20141024154353.GE20534@e104818-lin.cambridge.arm.com> User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 X-DLP: MIA1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141025_063200_687156_6E0DBA02 X-CRM114-Status: GOOD ( 17.73 ) X-Spam-Score: -3.8 (---) Cc: "xen-devel@lists.xensource.com" , "linux@arm.linux.org.uk" , "Ian.Campbell@citrix.com" , "konrad.wilk@oracle.com" , Catalin Marinas , Will Deacon , "linux-kernel@vger.kernel.org" , "david.vrabel@citrix.com" , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 On Fri, 24 Oct 2014, Stefano Stabellini wrote: > On Fri, 24 Oct 2014, Stefano Stabellini wrote: > > On Fri, 24 Oct 2014, Catalin Marinas wrote: > > > > 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) > > > > > > > > > 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). Your suggestions and looking more at the code gave me another idea, that I think is clean and at the same time suitable for 3.18. What do you think of the following? It is simple, self-contained and doesn't need a new flag in struct device. diff --git a/arch/arm/xen/mm32.c b/arch/arm/xen/mm32.c index 6153d61..2b259f1 100644 --- a/arch/arm/xen/mm32.c +++ b/arch/arm/xen/mm32.c @@ -2,10 +2,16 @@ #include #include #include +#include #include +static inline bool is_dma_coherent(struct device *dev) +{ + return of_dma_is_coherent(dev->of_node); +} + /* functions called by SWIOTLB */ static void dma_cache_maint(dma_addr_t handle, unsigned long offset,