Commit eab8d6530cc00744087bb5566e350cf37fcdfc7e
Committed by
Olof Johansson
1 parent
764e2c70ef
Exists in
ti-lsk-linux-4.1.y
and in
10 other branches
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>
Showing 1 changed file with 38 additions and 15 deletions Side-by-side Diff
arch/arm/mm/dma-mapping.c
... | ... | @@ -1940,13 +1940,32 @@ |
1940 | 1940 | } |
1941 | 1941 | EXPORT_SYMBOL_GPL(arm_iommu_release_mapping); |
1942 | 1942 | |
1943 | +static int __arm_iommu_attach_device(struct device *dev, | |
1944 | + struct dma_iommu_mapping *mapping) | |
1945 | +{ | |
1946 | + int err; | |
1947 | + | |
1948 | + err = iommu_attach_device(mapping->domain, dev); | |
1949 | + if (err) | |
1950 | + return err; | |
1951 | + | |
1952 | + kref_get(&mapping->kref); | |
1953 | + dev->archdata.mapping = mapping; | |
1954 | + | |
1955 | + pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev)); | |
1956 | + return 0; | |
1957 | +} | |
1958 | + | |
1943 | 1959 | /** |
1944 | 1960 | * arm_iommu_attach_device |
1945 | 1961 | * @dev: valid struct device pointer |
1946 | 1962 | * @mapping: io address space mapping structure (returned from |
1947 | 1963 | * arm_iommu_create_mapping) |
1948 | 1964 | * |
1949 | - * Attaches specified io address space mapping to the provided device, | |
1965 | + * Attaches specified io address space mapping to the provided device. | |
1966 | + * This replaces the dma operations (dma_map_ops pointer) with the | |
1967 | + * IOMMU aware version. | |
1968 | + * | |
1950 | 1969 | * More than one client might be attached to the same io address space |
1951 | 1970 | * mapping. |
1952 | 1971 | */ |
1953 | 1972 | |
1954 | 1973 | |
... | ... | @@ -1955,25 +1974,16 @@ |
1955 | 1974 | { |
1956 | 1975 | int err; |
1957 | 1976 | |
1958 | - err = iommu_attach_device(mapping->domain, dev); | |
1977 | + err = __arm_iommu_attach_device(dev, mapping); | |
1959 | 1978 | if (err) |
1960 | 1979 | return err; |
1961 | 1980 | |
1962 | - kref_get(&mapping->kref); | |
1963 | - dev->archdata.mapping = mapping; | |
1964 | - | |
1965 | - pr_debug("Attached IOMMU controller to %s device.\n", dev_name(dev)); | |
1981 | + set_dma_ops(dev, &iommu_ops); | |
1966 | 1982 | return 0; |
1967 | 1983 | } |
1968 | 1984 | EXPORT_SYMBOL_GPL(arm_iommu_attach_device); |
1969 | 1985 | |
1970 | -/** | |
1971 | - * arm_iommu_detach_device | |
1972 | - * @dev: valid struct device pointer | |
1973 | - * | |
1974 | - * Detaches the provided device from a previously attached map. | |
1975 | - */ | |
1976 | -void arm_iommu_detach_device(struct device *dev) | |
1986 | +static void __arm_iommu_detach_device(struct device *dev) | |
1977 | 1987 | { |
1978 | 1988 | struct dma_iommu_mapping *mapping; |
1979 | 1989 | |
... | ... | @@ -1989,6 +1999,19 @@ |
1989 | 1999 | |
1990 | 2000 | pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev)); |
1991 | 2001 | } |
2002 | + | |
2003 | +/** | |
2004 | + * arm_iommu_detach_device | |
2005 | + * @dev: valid struct device pointer | |
2006 | + * | |
2007 | + * Detaches the provided device from a previously attached map. | |
2008 | + * This voids the dma operations (dma_map_ops pointer) | |
2009 | + */ | |
2010 | +void arm_iommu_detach_device(struct device *dev) | |
2011 | +{ | |
2012 | + __arm_iommu_detach_device(dev); | |
2013 | + set_dma_ops(dev, NULL); | |
2014 | +} | |
1992 | 2015 | EXPORT_SYMBOL_GPL(arm_iommu_detach_device); |
1993 | 2016 | |
1994 | 2017 | static struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent) |
... | ... | @@ -2011,7 +2034,7 @@ |
2011 | 2034 | return false; |
2012 | 2035 | } |
2013 | 2036 | |
2014 | - if (arm_iommu_attach_device(dev, mapping)) { | |
2037 | + if (__arm_iommu_attach_device(dev, mapping)) { | |
2015 | 2038 | pr_warn("Failed to attached device %s to IOMMU_mapping\n", |
2016 | 2039 | dev_name(dev)); |
2017 | 2040 | arm_iommu_release_mapping(mapping); |
... | ... | @@ -2025,7 +2048,7 @@ |
2025 | 2048 | { |
2026 | 2049 | struct dma_iommu_mapping *mapping = dev->archdata.mapping; |
2027 | 2050 | |
2028 | - arm_iommu_detach_device(dev); | |
2051 | + __arm_iommu_detach_device(dev); | |
2029 | 2052 | arm_iommu_release_mapping(mapping); |
2030 | 2053 | } |
2031 | 2054 |