From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753190AbbKPQ0e (ORCPT ); Mon, 16 Nov 2015 11:26:34 -0500 Received: from mout.kundenserver.de ([212.227.126.187]:63753 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751824AbbKPQ0a (ORCPT ); Mon, 16 Nov 2015 11:26:30 -0500 From: Arnd Bergmann To: Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mark Salter , Suravee Suthikulpanit , "Rafael J. Wysocki" Subject: [RFC] ARM64: simplify dma_get_ops Date: Mon, 16 Nov 2015 17:25:48 +0100 Message-ID: <4270550.cGd11OgA5n@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:MP33XjcP5aynngyoafWZprx5dM0HnGLNUiQVnIh6q2NfnyXjFUj LYB5E2THV5CmGaJtuBb/NE6QKQbytV/cJi3ls8fPu71dbW2fXqfZytGk4kGAOmiQOwn/2zE XwJW9ef/iZIHMAZ7Orpd13BjEkEls0V4PAxmlE+wvSApx6BM2SbzIpgPaYn7emx9HdOUFbX E0m5iRItc9ie7kKiFhLvg== X-UI-Out-Filterresults: notjunk:1;V01:K0:KNizG9mcREY=:42a6VufMVlCmqBxlmbh2tJ fJ3n1ZPjLrQv783rPxx+Lbk9s3zRXcbPDqwdTYZ4REfKtGnik+nLj+LqTLa9O1IymPYNulbDq de2iiU1YHYu+ivs3/k2knYKz0jwS2IqJf9XD8mbmRiY+fvRvw9xSomDJMMPcOHyR2oe50lvYT aX2BVJ1ZmbWxo+8EV7qk9k1Ju8OL24E//LBmx1PJVQ23tLBUg24XDCmSmvI09IV3Y/GW3QILz mpcFzlZS9XqvymVuxW84U69L6TVYRqvO1Fkxp8fuGZO4CBkSt7cCxUT/PVmRq+xEReaz8FIIQ i/msk0W8cjxjgIA5etuz1NsHs6eCEgKai4lfg7SNelVwLp6yYPYijhGLEhdk23zAp/k1sJygA S2MC5KuRYQOimQIHpD6fRhmq0zlwbUMRUx71nV18CbxQ9lxXDSLiGyrzbFYrGcRgI6mSk6H6/ Ri3PgnVBDO7a7BVbvHphf0qtF2BnQbyRBhrbwnsxI34WWXb5t3lhoq1N7EPCB31/TTEdzq0ab dBoA/r6fXAtCxzF1q7mxsx1mDL0HUE3/PCc5V7r07wWXWseaNH/PQ2Zib14IYfy3rTyxLPeZ/ DI3hhli1NVGuA5+Tfo8qJfgJCzXPnU3FwTmo+NuNrRV4JXb4bJ4ffLuZRCUzT6fnKvLxPwohL oO6XLnR0ap2Lhc5vvuYQ+u7upbefKu/Op3aM9cWzfVrWdLe/I76Sjxtgo0T2EmtElF2BnFx/8 cUjfV0QIyU2RA8XP Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Including linux/acpi.h from asm/dma-mapping.h causes tons of compile-time warnings, e.g. drivers/isdn/mISDN/dsp_ecdis.h:43:0: warning: "FALSE" redefined drivers/isdn/mISDN/dsp_ecdis.h:44:0: warning: "TRUE" redefined drivers/net/fddi/skfp/h/targetos.h:62:0: warning: "TRUE" redefined drivers/net/fddi/skfp/h/targetos.h:63:0: warning: "FALSE" redefined However, it looks like the dependency should not even there as I do not see why __generic_dma_ops() cares about whether we have an ACPI based system or not. The current behavior is to fall back to the global dma_ops when a device has not set its own dma_ops, but only for DT based systems. This seems dangerous, as a random device might have different requirements regarding IOMMU or coherency, so we should really never have that fallback and just forbid DMA when we have not initialized DMA for a device. This removes the global dma_ops variable and the special-casing for ACPI, and just returns the dma ops that got set for the device, or the dummy_dma_ops if none were present. The original code has apparently been copied from arm32 where we rely on it for ISA devices things like the floppy controller, but we should have no such devices on ARM64. Signed-off-by: Arnd Bergmann --- diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h index 54d0ead41afc..04e841a1c1f3 100644 --- a/arch/arm64/include/asm/dma-mapping.h +++ b/arch/arm64/include/asm/dma-mapping.h @@ -18,7 +18,6 @@ #ifdef __KERNEL__ -#include #include #include @@ -26,22 +25,17 @@ #include #define DMA_ERROR_CODE (~(dma_addr_t)0) -extern struct dma_map_ops *dma_ops; extern struct dma_map_ops dummy_dma_ops; static inline struct dma_map_ops *__generic_dma_ops(struct device *dev) { - if (unlikely(!dev)) - return dma_ops; - else if (dev->archdata.dma_ops) + if (dev && dev->archdata.dma_ops) return dev->archdata.dma_ops; - else if (acpi_disabled) - return dma_ops; /* - * When ACPI is enabled, if arch_set_dma_ops is not called, - * we will disable device DMA capability by setting it - * to dummy_dma_ops. + * we expect no ISA devices, and all other DMA masters are + * expected to have someone call arch_setup_dma_ops at + * device creation time */ return &dummy_dma_ops; } diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 131a199114b4..9e351c1f89e2 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -28,9 +29,6 @@ #include -struct dma_map_ops *dma_ops; -EXPORT_SYMBOL(dma_ops); - static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot, bool coherent) { @@ -515,13 +513,7 @@ EXPORT_SYMBOL(dummy_dma_ops); static int __init arm64_dma_init(void) { - int ret; - - dma_ops = &swiotlb_dma_ops; - - ret = atomic_pool_init(); - - return ret; + return atomic_pool_init(); } arch_initcall(arm64_dma_init); @@ -985,7 +977,7 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, struct iommu_ops *iommu, bool coherent) { if (!acpi_disabled && !dev->archdata.dma_ops) - dev->archdata.dma_ops = dma_ops; + dev->archdata.dma_ops = &swiotlb_dma_ops; dev->archdata.dma_coherent = coherent; __iommu_setup_dma_ops(dev, dma_base, size, iommu);