Skip to content

Commit 5f937bc

Browse files
rmurphy-armwilldeacon
authored andcommitted
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: Rob Herring (Arm) <[email protected]> Tested-by: Jean-Philippe Brucker <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/61972f88e31a6eda8bf5852f0853951164279a3c.1719919669.git.robin.murphy@arm.com Signed-off-by: Will Deacon <[email protected]>
1 parent 78596b5 commit 5f937bc

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

drivers/iommu/of_iommu.c

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,22 +108,16 @@ static int of_iommu_configure_device(struct device_node *master_np,
108108
int of_iommu_configure(struct device *dev, struct device_node *master_np,
109109
const u32 *id)
110110
{
111-
struct iommu_fwspec *fwspec;
112111
int err;
113112

114113
if (!master_np)
115114
return -ENODEV;
116115

117116
/* Serialise to make dev->iommu stable under our potential fwspec */
118117
mutex_lock(&iommu_probe_device_lock);
119-
fwspec = dev_iommu_fwspec_get(dev);
120-
if (fwspec) {
121-
if (fwspec->ops) {
122-
mutex_unlock(&iommu_probe_device_lock);
123-
return 0;
124-
}
125-
/* In the deferred case, start again from scratch */
126-
iommu_fwspec_free(dev);
118+
if (dev_iommu_fwspec_get(dev)) {
119+
mutex_unlock(&iommu_probe_device_lock);
120+
return 0;
127121
}
128122

129123
/*
@@ -143,20 +137,17 @@ int of_iommu_configure(struct device *dev, struct device_node *master_np,
143137
} else {
144138
err = of_iommu_configure_device(master_np, dev, id);
145139
}
146-
mutex_unlock(&iommu_probe_device_lock);
147140

148-
if (err == -ENODEV || err == -EPROBE_DEFER)
149-
return err;
150141
if (err)
151-
goto err_log;
142+
iommu_fwspec_free(dev);
143+
mutex_unlock(&iommu_probe_device_lock);
152144

153-
err = iommu_probe_device(dev);
154-
if (err)
155-
goto err_log;
156-
return 0;
145+
if (!err && dev->bus)
146+
err = iommu_probe_device(dev);
147+
148+
if (err && err != -EPROBE_DEFER)
149+
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
157150

158-
err_log:
159-
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
160151
return err;
161152
}
162153

drivers/of/device.c

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
9696
const struct bus_dma_region *map = NULL;
9797
struct device_node *bus_np;
9898
u64 mask, end = 0;
99-
bool coherent;
100-
int iommu_ret;
99+
bool coherent, set_map = false;
101100
int ret;
102101

103102
if (np == dev->of_node)
@@ -118,6 +117,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
118117
} else {
119118
/* Determine the overall bounds of all DMA regions */
120119
end = dma_range_map_max(map);
120+
set_map = true;
121121
}
122122

123123
/*
@@ -144,7 +144,7 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
144144
dev->coherent_dma_mask &= mask;
145145
*dev->dma_mask &= mask;
146146
/* ...but only set bus limit and range map if we found valid dma-ranges earlier */
147-
if (!ret) {
147+
if (set_map) {
148148
dev->bus_dma_limit = end;
149149
dev->dma_range_map = map;
150150
}
@@ -153,29 +153,21 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
153153
dev_dbg(dev, "device is%sdma coherent\n",
154154
coherent ? " " : " not ");
155155

156-
iommu_ret = of_iommu_configure(dev, np, id);
157-
if (iommu_ret == -EPROBE_DEFER) {
156+
ret = of_iommu_configure(dev, np, id);
157+
if (ret == -EPROBE_DEFER) {
158158
/* Don't touch range map if it wasn't set from a valid dma-ranges */
159-
if (!ret)
159+
if (set_map)
160160
dev->dma_range_map = NULL;
161161
kfree(map);
162162
return -EPROBE_DEFER;
163-
} else if (iommu_ret == -ENODEV) {
164-
dev_dbg(dev, "device is not behind an iommu\n");
165-
} else if (iommu_ret) {
166-
dev_err(dev, "iommu configuration for device failed with %pe\n",
167-
ERR_PTR(iommu_ret));
168-
169-
/*
170-
* Historically this routine doesn't fail driver probing
171-
* due to errors in of_iommu_configure()
172-
*/
173-
} else
174-
dev_dbg(dev, "device is behind an iommu\n");
163+
}
164+
/* Take all other IOMMU errors to mean we'll just carry on without it */
165+
dev_dbg(dev, "device is%sbehind an iommu\n",
166+
!ret ? " " : " not ");
175167

176168
arch_setup_dma_ops(dev, coherent);
177169

178-
if (iommu_ret)
170+
if (ret)
179171
of_dma_set_restricted_buffer(dev, np);
180172

181173
return 0;

0 commit comments

Comments
 (0)