Commit 49558da0 authored by Magnus Damm's avatar Magnus Damm Committed by Joerg Roedel

iommu/ipmmu-vmsa: Consistent ->of_xlate() handling

The 32-bit ARM code gets updated to make use of ->of_xlate() and the
code is shared between 64-bit and 32-bit ARM. The of_device_is_available()
check gets dropped since it is included in of_iommu_xlate().
Suggested-by: default avatarRobin Murphy <robin.murphy@arm.com>
Signed-off-by: default avatarMagnus Damm <damm+renesas@opensource.se>
Signed-off-by: default avatarJoerg Roedel <jroedel@suse.de>
parent 01da21e5
...@@ -734,6 +734,16 @@ static int ipmmu_init_platform_device(struct device *dev) ...@@ -734,6 +734,16 @@ static int ipmmu_init_platform_device(struct device *dev)
return ret; return ret;
} }
static int ipmmu_of_xlate(struct device *dev,
struct of_phandle_args *spec)
{
/* Initialize once - xlate() will call multiple times */
if (to_priv(dev))
return 0;
return ipmmu_init_platform_device(dev);
}
#if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA) #if defined(CONFIG_ARM) && !defined(CONFIG_IOMMU_DMA)
static struct iommu_domain *ipmmu_domain_alloc(unsigned type) static struct iommu_domain *ipmmu_domain_alloc(unsigned type)
...@@ -750,11 +760,11 @@ static int ipmmu_add_device(struct device *dev) ...@@ -750,11 +760,11 @@ static int ipmmu_add_device(struct device *dev)
struct iommu_group *group; struct iommu_group *group;
int ret; int ret;
if (to_priv(dev)) { /*
dev_warn(dev, "IOMMU driver already assigned to device %s\n", * Only let through devices that have been verified in xlate()
dev_name(dev)); */
return -EINVAL; if (!to_priv(dev))
} return -ENODEV;
/* Create a device group and add the device to it. */ /* Create a device group and add the device to it. */
group = iommu_group_alloc(); group = iommu_group_alloc();
...@@ -773,10 +783,6 @@ static int ipmmu_add_device(struct device *dev) ...@@ -773,10 +783,6 @@ static int ipmmu_add_device(struct device *dev)
goto error; goto error;
} }
ret = ipmmu_init_platform_device(dev);
if (ret < 0)
goto error;
/* /*
* Create the ARM mapping, used by the ARM DMA mapping core to allocate * Create the ARM mapping, used by the ARM DMA mapping core to allocate
* VAs. This will allocate a corresponding IOMMU domain. * VAs. This will allocate a corresponding IOMMU domain.
...@@ -817,24 +823,13 @@ static int ipmmu_add_device(struct device *dev) ...@@ -817,24 +823,13 @@ static int ipmmu_add_device(struct device *dev)
if (!IS_ERR_OR_NULL(group)) if (!IS_ERR_OR_NULL(group))
iommu_group_remove_device(dev); iommu_group_remove_device(dev);
kfree(to_priv(dev)->utlbs);
kfree(to_priv(dev));
set_priv(dev, NULL);
return ret; return ret;
} }
static void ipmmu_remove_device(struct device *dev) static void ipmmu_remove_device(struct device *dev)
{ {
struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev);
arm_iommu_detach_device(dev); arm_iommu_detach_device(dev);
iommu_group_remove_device(dev); iommu_group_remove_device(dev);
kfree(priv->utlbs);
kfree(priv);
set_priv(dev, NULL);
} }
static const struct iommu_ops ipmmu_ops = { static const struct iommu_ops ipmmu_ops = {
...@@ -849,6 +844,7 @@ static const struct iommu_ops ipmmu_ops = { ...@@ -849,6 +844,7 @@ static const struct iommu_ops ipmmu_ops = {
.add_device = ipmmu_add_device, .add_device = ipmmu_add_device,
.remove_device = ipmmu_remove_device, .remove_device = ipmmu_remove_device,
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
.of_xlate = ipmmu_of_xlate,
}; };
#endif /* !CONFIG_ARM && CONFIG_IOMMU_DMA */ #endif /* !CONFIG_ARM && CONFIG_IOMMU_DMA */
...@@ -958,19 +954,6 @@ static struct iommu_group *ipmmu_find_group_dma(struct device *dev) ...@@ -958,19 +954,6 @@ static struct iommu_group *ipmmu_find_group_dma(struct device *dev)
return group; return group;
} }
static int ipmmu_of_xlate_dma(struct device *dev,
struct of_phandle_args *spec)
{
/* If the IPMMU device is disabled in DT then return error
* to make sure the of_iommu code does not install ops
* even though the iommu device is disabled
*/
if (!of_device_is_available(spec->np))
return -ENODEV;
return ipmmu_init_platform_device(dev);
}
static const struct iommu_ops ipmmu_ops = { static const struct iommu_ops ipmmu_ops = {
.domain_alloc = ipmmu_domain_alloc_dma, .domain_alloc = ipmmu_domain_alloc_dma,
.domain_free = ipmmu_domain_free_dma, .domain_free = ipmmu_domain_free_dma,
...@@ -984,7 +967,7 @@ static const struct iommu_ops ipmmu_ops = { ...@@ -984,7 +967,7 @@ static const struct iommu_ops ipmmu_ops = {
.remove_device = ipmmu_remove_device_dma, .remove_device = ipmmu_remove_device_dma,
.device_group = ipmmu_find_group_dma, .device_group = ipmmu_find_group_dma,
.pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K, .pgsize_bitmap = SZ_1G | SZ_2M | SZ_4K,
.of_xlate = ipmmu_of_xlate_dma, .of_xlate = ipmmu_of_xlate,
}; };
#endif /* CONFIG_IOMMU_DMA */ #endif /* CONFIG_IOMMU_DMA */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment