Skip to content

Commit 6ff6e18

Browse files
jgunthorpejoergroedel
authored andcommitted
iommmu/of: Do not return struct iommu_ops from of_iommu_configure()
Nothing needs this pointer. Return a normal error code with the usual IOMMU semantic that ENODEV means 'there is no IOMMU driver'. Reviewed-by: Jerry Snitselaar <jsnitsel@redhat.com> Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com> Acked-by: Rob Herring <robh@kernel.org> Tested-by: Hector Martin <marcan@marcan.st> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com> Link: https://lore.kernel.org/r/2-v2-16e4def25ebb+820-iommu_fwspec_p1_jgg@nvidia.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 4720287 commit 6ff6e18

3 files changed

Lines changed: 40 additions & 26 deletions

File tree

drivers/iommu/of_iommu.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,24 +107,30 @@ static int of_iommu_configure_device(struct device_node *master_np,
107107
of_iommu_configure_dev(master_np, dev);
108108
}
109109

110-
const struct iommu_ops *of_iommu_configure(struct device *dev,
111-
struct device_node *master_np,
112-
const u32 *id)
110+
/*
111+
* Returns:
112+
* 0 on success, an iommu was configured
113+
* -ENODEV if the device does not have any IOMMU
114+
* -EPROBEDEFER if probing should be tried again
115+
* -errno fatal errors
116+
*/
117+
int of_iommu_configure(struct device *dev, struct device_node *master_np,
118+
const u32 *id)
113119
{
114120
const struct iommu_ops *ops = NULL;
115121
struct iommu_fwspec *fwspec;
116122
int err = NO_IOMMU;
117123

118124
if (!master_np)
119-
return NULL;
125+
return -ENODEV;
120126

121127
/* Serialise to make dev->iommu stable under our potential fwspec */
122128
mutex_lock(&iommu_probe_device_lock);
123129
fwspec = dev_iommu_fwspec_get(dev);
124130
if (fwspec) {
125131
if (fwspec->ops) {
126132
mutex_unlock(&iommu_probe_device_lock);
127-
return fwspec->ops;
133+
return 0;
128134
}
129135
/* In the deferred case, start again from scratch */
130136
iommu_fwspec_free(dev);
@@ -169,14 +175,15 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
169175
err = iommu_probe_device(dev);
170176

171177
/* Ignore all other errors apart from EPROBE_DEFER */
172-
if (err == -EPROBE_DEFER) {
173-
ops = ERR_PTR(err);
174-
} else if (err < 0) {
175-
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err);
176-
ops = NULL;
178+
if (err < 0) {
179+
if (err == -EPROBE_DEFER)
180+
return err;
181+
dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
182+
return err;
177183
}
178-
179-
return ops;
184+
if (!ops)
185+
return -ENODEV;
186+
return 0;
180187
}
181188

182189
static enum iommu_resv_type __maybe_unused

drivers/of/device.c

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
9393
int of_dma_configure_id(struct device *dev, struct device_node *np,
9494
bool force_dma, const u32 *id)
9595
{
96-
const struct iommu_ops *iommu;
9796
const struct bus_dma_region *map = NULL;
9897
struct device_node *bus_np;
9998
u64 dma_start = 0;
10099
u64 mask, end, size = 0;
101100
bool coherent;
101+
int iommu_ret;
102102
int ret;
103103

104104
if (np == dev->of_node)
@@ -181,21 +181,29 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
181181
dev_dbg(dev, "device is%sdma coherent\n",
182182
coherent ? " " : " not ");
183183

184-
iommu = of_iommu_configure(dev, np, id);
185-
if (PTR_ERR(iommu) == -EPROBE_DEFER) {
184+
iommu_ret = of_iommu_configure(dev, np, id);
185+
if (iommu_ret == -EPROBE_DEFER) {
186186
/* Don't touch range map if it wasn't set from a valid dma-ranges */
187187
if (!ret)
188188
dev->dma_range_map = NULL;
189189
kfree(map);
190190
return -EPROBE_DEFER;
191-
}
191+
} else if (iommu_ret == -ENODEV) {
192+
dev_dbg(dev, "device is not behind an iommu\n");
193+
} else if (iommu_ret) {
194+
dev_err(dev, "iommu configuration for device failed with %pe\n",
195+
ERR_PTR(iommu_ret));
192196

193-
dev_dbg(dev, "device is%sbehind an iommu\n",
194-
iommu ? " " : " not ");
197+
/*
198+
* Historically this routine doesn't fail driver probing
199+
* due to errors in of_iommu_configure()
200+
*/
201+
} else
202+
dev_dbg(dev, "device is behind an iommu\n");
195203

196204
arch_setup_dma_ops(dev, dma_start, size, coherent);
197205

198-
if (!iommu)
206+
if (iommu_ret)
199207
of_dma_set_restricted_buffer(dev, np);
200208

201209
return 0;

include/linux/of_iommu.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,19 @@ struct iommu_ops;
88

99
#ifdef CONFIG_OF_IOMMU
1010

11-
extern const struct iommu_ops *of_iommu_configure(struct device *dev,
12-
struct device_node *master_np,
13-
const u32 *id);
11+
extern int of_iommu_configure(struct device *dev, struct device_node *master_np,
12+
const u32 *id);
1413

1514
extern void of_iommu_get_resv_regions(struct device *dev,
1615
struct list_head *list);
1716

1817
#else
1918

20-
static inline const struct iommu_ops *of_iommu_configure(struct device *dev,
21-
struct device_node *master_np,
22-
const u32 *id)
19+
static inline int of_iommu_configure(struct device *dev,
20+
struct device_node *master_np,
21+
const u32 *id)
2322
{
24-
return NULL;
23+
return -ENODEV;
2524
}
2625

2726
static inline void of_iommu_get_resv_regions(struct device *dev,

0 commit comments

Comments
 (0)