arm: dma-mapping: Set DMA IOMMU ops in arm_iommu_attach_device()

Commit 4bb25789ed28228a ("arm: dma-mapping: plumb our iommu mapping ops
into arch_setup_dma_ops") moved the setting of the DMA operations from
arm_iommu_attach_device() to arch_setup_dma_ops() where the DMA
operations to be used are selected based on whether the device is
connected to an IOMMU. However, the IOMMU detection scheme requires the
IOMMU driver to be ported to the new IOMMU of_xlate API. As no driver
has been ported yet, this effectively breaks all IOMMU ARM users that
depend on the IOMMU being handled transparently by the DMA mapping API.

Fix this by restoring the setting of DMA IOMMU ops in
arm_iommu_attach_device() and splitting the rest of the function into a
new internal __arm_iommu_attach_device() function, called by
arch_setup_dma_ops().

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Tested-by: Heiko Stuebner <heiko@sntech.de>
Signed-off-by: Olof Johansson <olof@lixom.net>

authored by Laurent Pinchart and committed by Olof Johansson eab8d653 764e2c70

+41 -18
+41 -18
arch/arm/mm/dma-mapping.c
··· 1940 } 1941 EXPORT_SYMBOL_GPL(arm_iommu_release_mapping); 1942 1943 - /** 1944 - * arm_iommu_attach_device 1945 - * @dev: valid struct device pointer 1946 - * @mapping: io address space mapping structure (returned from 1947 - * arm_iommu_create_mapping) 1948 - * 1949 - * Attaches specified io address space mapping to the provided device, 1950 - * More than one client might be attached to the same io address space 1951 - * mapping. 1952 - */ 1953 - int arm_iommu_attach_device(struct device *dev, 1954 - struct dma_iommu_mapping *mapping) 1955 { 1956 int err; 1957 ··· 1955 pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev)); 1956 return 0; 1957 } 1958 - EXPORT_SYMBOL_GPL(arm_iommu_attach_device); 1959 1960 /** 1961 - * arm_iommu_detach_device 1962 * @dev: valid struct device pointer 1963 * 1964 - * Detaches the provided device from a previously attached map. 1965 */ 1966 - void arm_iommu_detach_device(struct device *dev) 1967 { 1968 struct dma_iommu_mapping *mapping; 1969 ··· 1998 dev->archdata.mapping = NULL; 1999 2000 pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev)); 2001 } 2002 EXPORT_SYMBOL_GPL(arm_iommu_detach_device); 2003 ··· 2034 return false; 2035 } 2036 2037 - if (arm_iommu_attach_device(dev, mapping)) { 2038 pr_warn("Failed to attached device %s to IOMMU_mapping\n", 2039 dev_name(dev)); 2040 arm_iommu_release_mapping(mapping); ··· 2048 { 2049 struct dma_iommu_mapping *mapping = dev->archdata.mapping; 2050 2051 - arm_iommu_detach_device(dev); 2052 arm_iommu_release_mapping(mapping); 2053 } 2054
··· 1940 } 1941 EXPORT_SYMBOL_GPL(arm_iommu_release_mapping); 1942 1943 + static int __arm_iommu_attach_device(struct device *dev, 1944 + struct dma_iommu_mapping *mapping) 1945 { 1946 int err; 1947 ··· 1965 pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev)); 1966 return 0; 1967 } 1968 1969 /** 1970 + * arm_iommu_attach_device 1971 * @dev: valid struct device pointer 1972 + * @mapping: io address space mapping structure (returned from 1973 + * arm_iommu_create_mapping) 1974 * 1975 + * Attaches specified io address space mapping to the provided device. 1976 + * This replaces the dma operations (dma_map_ops pointer) with the 1977 + * IOMMU aware version. 1978 + * 1979 + * More than one client might be attached to the same io address space 1980 + * mapping. 1981 */ 1982 + int arm_iommu_attach_device(struct device *dev, 1983 + struct dma_iommu_mapping *mapping) 1984 + { 1985 + int err; 1986 + 1987 + err = __arm_iommu_attach_device(dev, mapping); 1988 + if (err) 1989 + return err; 1990 + 1991 + set_dma_ops(dev, &iommu_ops); 1992 + return 0; 1993 + } 1994 + EXPORT_SYMBOL_GPL(arm_iommu_attach_device); 1995 + 1996 + static void __arm_iommu_detach_device(struct device *dev) 1997 { 1998 struct dma_iommu_mapping *mapping; 1999 ··· 1988 dev->archdata.mapping = NULL; 1989 1990 pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev)); 1991 + } 1992 + 1993 + /** 1994 + * arm_iommu_detach_device 1995 + * @dev: valid struct device pointer 1996 + * 1997 + * Detaches the provided device from a previously attached map. 1998 + * This voids the dma operations (dma_map_ops pointer) 1999 + */ 2000 + void arm_iommu_detach_device(struct device *dev) 2001 + { 2002 + __arm_iommu_detach_device(dev); 2003 + set_dma_ops(dev, NULL); 2004 } 2005 EXPORT_SYMBOL_GPL(arm_iommu_detach_device); 2006 ··· 2011 return false; 2012 } 2013 2014 + if (__arm_iommu_attach_device(dev, mapping)) { 2015 pr_warn("Failed to attached device %s to IOMMU_mapping\n", 2016 dev_name(dev)); 2017 arm_iommu_release_mapping(mapping); ··· 2025 { 2026 struct dma_iommu_mapping *mapping = dev->archdata.mapping; 2027 2028 + __arm_iommu_detach_device(dev); 2029 arm_iommu_release_mapping(mapping); 2030 } 2031