Skip to content

Commit eab8d65

Browse files
Laurent Pinchartolofj
authored andcommitted
arm: dma-mapping: Set DMA IOMMU ops in arm_iommu_attach_device()
Commit 4bb2578 ("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>
1 parent 764e2c7 commit eab8d65

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed

arch/arm/mm/dma-mapping.c

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,13 +1940,32 @@ void arm_iommu_release_mapping(struct dma_iommu_mapping *mapping)
19401940
}
19411941
EXPORT_SYMBOL_GPL(arm_iommu_release_mapping);
19421942

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+
19431959
/**
19441960
* arm_iommu_attach_device
19451961
* @dev: valid struct device pointer
19461962
* @mapping: io address space mapping structure (returned from
19471963
* arm_iommu_create_mapping)
19481964
*
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+
*
19501969
* More than one client might be attached to the same io address space
19511970
* mapping.
19521971
*/
@@ -1955,25 +1974,16 @@ int arm_iommu_attach_device(struct device *dev,
19551974
{
19561975
int err;
19571976

1958-
err = iommu_attach_device(mapping->domain, dev);
1977+
err = __arm_iommu_attach_device(dev, mapping);
19591978
if (err)
19601979
return err;
19611980

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);
19661982
return 0;
19671983
}
19681984
EXPORT_SYMBOL_GPL(arm_iommu_attach_device);
19691985

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)
19771987
{
19781988
struct dma_iommu_mapping *mapping;
19791989

@@ -1989,6 +1999,19 @@ void arm_iommu_detach_device(struct device *dev)
19891999

19902000
pr_debug("Detached IOMMU controller from %s device.\n", dev_name(dev));
19912001
}
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+
}
19922015
EXPORT_SYMBOL_GPL(arm_iommu_detach_device);
19932016

19942017
static struct dma_map_ops *arm_get_iommu_dma_map_ops(bool coherent)
@@ -2011,7 +2034,7 @@ static bool arm_setup_iommu_dma_ops(struct device *dev, u64 dma_base, u64 size,
20112034
return false;
20122035
}
20132036

2014-
if (arm_iommu_attach_device(dev, mapping)) {
2037+
if (__arm_iommu_attach_device(dev, mapping)) {
20152038
pr_warn("Failed to attached device %s to IOMMU_mapping\n",
20162039
dev_name(dev));
20172040
arm_iommu_release_mapping(mapping);
@@ -2025,7 +2048,7 @@ static void arm_teardown_iommu_dma_ops(struct device *dev)
20252048
{
20262049
struct dma_iommu_mapping *mapping = dev->archdata.mapping;
20272050

2028-
arm_iommu_detach_device(dev);
2051+
__arm_iommu_detach_device(dev);
20292052
arm_iommu_release_mapping(mapping);
20302053
}
20312054

0 commit comments

Comments
 (0)