Commit 5f937bc4 authored by Robin Murphy's avatar Robin Murphy Committed by Will Deacon

OF: Simplify of_iommu_configure()

We no longer have a notion of partially-initialised fwspecs existing,
and we also no longer need to use an iommu_ops pointer to return status
to of_dma_configure(). Clean up the remains of those, which lends itself
to clarifying the logic around the dma_range_map allocation as well.
Acked-by: default avatarRob Herring (Arm) <robh@kernel.org>
Tested-by: default avatarJean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/61972f88e31a6eda8bf5852f0853951164279a3c.1719919669.git.robin.murphy@arm.comSigned-off-by: default avatarWill Deacon <will@kernel.org>
parent 78596b5c
...@@ -108,7 +108,6 @@ static int of_iommu_configure_device(struct device_node *master_np, ...@@ -108,7 +108,6 @@ static int of_iommu_configure_device(struct device_node *master_np,
int of_iommu_configure(struct device *dev, struct device_node *master_np, int of_iommu_configure(struct device *dev, struct device_node *master_np,
const u32 *id) const u32 *id)
{ {
struct iommu_fwspec *fwspec;
int err; int err;
if (!master_np) if (!master_np)
...@@ -116,14 +115,9 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np, ...@@ -116,14 +115,9 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
/* Serialise to make dev->iommu stable under our potential fwspec */ /* Serialise to make dev->iommu stable under our potential fwspec */
mutex_lock(&iommu_probe_device_lock); mutex_lock(&iommu_probe_device_lock);
fwspec = dev_iommu_fwspec_get(dev); if (dev_iommu_fwspec_get(dev)) {
if (fwspec) { mutex_unlock(&iommu_probe_device_lock);
if (fwspec->ops) { return 0;
mutex_unlock(&iommu_probe_device_lock);
return 0;
}
/* In the deferred case, start again from scratch */
iommu_fwspec_free(dev);
} }
/* /*
...@@ -143,20 +137,17 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np, ...@@ -143,20 +137,17 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
} else { } else {
err = of_iommu_configure_device(master_np, dev, id); err = of_iommu_configure_device(master_np, dev, id);
} }
mutex_unlock(&iommu_probe_device_lock);
if (err == -ENODEV || err == -EPROBE_DEFER)
return err;
if (err) if (err)
goto err_log; iommu_fwspec_free(dev);
mutex_unlock(&iommu_probe_device_lock);
err = iommu_probe_device(dev); if (!err && dev->bus)
if (err) err = iommu_probe_device(dev);
goto err_log;
return 0; if (err && err != -EPROBE_DEFER)
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
err_log:
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
return err; return err;
} }
......
...@@ -96,8 +96,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, ...@@ -96,8 +96,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
const struct bus_dma_region *map = NULL; const struct bus_dma_region *map = NULL;
struct device_node *bus_np; struct device_node *bus_np;
u64 mask, end = 0; u64 mask, end = 0;
bool coherent; bool coherent, set_map = false;
int iommu_ret;
int ret; int ret;
if (np == dev->of_node) if (np == dev->of_node)
...@@ -118,6 +117,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, ...@@ -118,6 +117,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
} else { } else {
/* Determine the overall bounds of all DMA regions */ /* Determine the overall bounds of all DMA regions */
end = dma_range_map_max(map); end = dma_range_map_max(map);
set_map = true;
} }
/* /*
...@@ -144,7 +144,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, ...@@ -144,7 +144,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
dev->coherent_dma_mask &= mask; dev->coherent_dma_mask &= mask;
*dev->dma_mask &= mask; *dev->dma_mask &= mask;
/* ...but only set bus limit and range map if we found valid dma-ranges earlier */ /* ...but only set bus limit and range map if we found valid dma-ranges earlier */
if (!ret) { if (set_map) {
dev->bus_dma_limit = end; dev->bus_dma_limit = end;
dev->dma_range_map = map; dev->dma_range_map = map;
} }
...@@ -153,29 +153,21 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, ...@@ -153,29 +153,21 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
dev_dbg(dev, "device is%sdma coherent\n", dev_dbg(dev, "device is%sdma coherent\n",
coherent ? " " : " not "); coherent ? " " : " not ");
iommu_ret = of_iommu_configure(dev, np, id); ret = of_iommu_configure(dev, np, id);
if (iommu_ret == -EPROBE_DEFER) { if (ret == -EPROBE_DEFER) {
/* Don't touch range map if it wasn't set from a valid dma-ranges */ /* Don't touch range map if it wasn't set from a valid dma-ranges */
if (!ret) if (set_map)
dev->dma_range_map = NULL; dev->dma_range_map = NULL;
kfree(map); kfree(map);
return -EPROBE_DEFER; return -EPROBE_DEFER;
} else if (iommu_ret == -ENODEV) { }
dev_dbg(dev, "device is not behind an iommu\n"); /* Take all other IOMMU errors to mean we'll just carry on without it */
} else if (iommu_ret) { dev_dbg(dev, "device is%sbehind an iommu\n",
dev_err(dev, "iommu configuration for device failed with %pe\n", !ret ? " " : " not ");
ERR_PTR(iommu_ret));
/*
* Historically this routine doesn't fail driver probing
* due to errors in of_iommu_configure()
*/
} else
dev_dbg(dev, "device is behind an iommu\n");
arch_setup_dma_ops(dev, coherent); arch_setup_dma_ops(dev, coherent);
if (iommu_ret) if (ret)
of_dma_set_restricted_buffer(dev, np); of_dma_set_restricted_buffer(dev, np);
return 0; return 0;
......
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