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>
This commit is contained in:
Jason Gunthorpe 2023-12-07 14:03:09 -04:00 committed by Joerg Roedel
parent 4720287c7b
commit 6ff6e184f1
3 changed files with 40 additions and 26 deletions

View File

@ -107,16 +107,22 @@ static int of_iommu_configure_device(struct device_node *master_np,
of_iommu_configure_dev(master_np, dev); of_iommu_configure_dev(master_np, dev);
} }
const struct iommu_ops *of_iommu_configure(struct device *dev, /*
struct device_node *master_np, * Returns:
const u32 *id) * 0 on success, an iommu was configured
* -ENODEV if the device does not have any IOMMU
* -EPROBEDEFER if probing should be tried again
* -errno fatal errors
*/
int of_iommu_configure(struct device *dev, struct device_node *master_np,
const u32 *id)
{ {
const struct iommu_ops *ops = NULL; const struct iommu_ops *ops = NULL;
struct iommu_fwspec *fwspec; struct iommu_fwspec *fwspec;
int err = NO_IOMMU; int err = NO_IOMMU;
if (!master_np) if (!master_np)
return NULL; return -ENODEV;
/* 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);
@ -124,7 +130,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
if (fwspec) { if (fwspec) {
if (fwspec->ops) { if (fwspec->ops) {
mutex_unlock(&iommu_probe_device_lock); mutex_unlock(&iommu_probe_device_lock);
return fwspec->ops; return 0;
} }
/* In the deferred case, start again from scratch */ /* In the deferred case, start again from scratch */
iommu_fwspec_free(dev); iommu_fwspec_free(dev);
@ -169,14 +175,15 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
err = iommu_probe_device(dev); err = iommu_probe_device(dev);
/* Ignore all other errors apart from EPROBE_DEFER */ /* Ignore all other errors apart from EPROBE_DEFER */
if (err == -EPROBE_DEFER) { if (err < 0) {
ops = ERR_PTR(err); if (err == -EPROBE_DEFER)
} else if (err < 0) { return err;
dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err));
ops = NULL; return err;
} }
if (!ops)
return ops; return -ENODEV;
return 0;
} }
static enum iommu_resv_type __maybe_unused static enum iommu_resv_type __maybe_unused

View File

@ -93,12 +93,12 @@ of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
int of_dma_configure_id(struct device *dev, struct device_node *np, int of_dma_configure_id(struct device *dev, struct device_node *np,
bool force_dma, const u32 *id) bool force_dma, const u32 *id)
{ {
const struct iommu_ops *iommu;
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 dma_start = 0; u64 dma_start = 0;
u64 mask, end, size = 0; u64 mask, end, size = 0;
bool coherent; bool coherent;
int iommu_ret;
int ret; int ret;
if (np == dev->of_node) if (np == dev->of_node)
@ -181,21 +181,29 @@ 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 = of_iommu_configure(dev, np, id); iommu_ret = of_iommu_configure(dev, np, id);
if (PTR_ERR(iommu) == -EPROBE_DEFER) { if (iommu_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 (!ret)
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");
} else if (iommu_ret) {
dev_err(dev, "iommu configuration for device failed with %pe\n",
ERR_PTR(iommu_ret));
dev_dbg(dev, "device is%sbehind an iommu\n", /*
iommu ? " " : " not "); * 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, dma_start, size, coherent); arch_setup_dma_ops(dev, dma_start, size, coherent);
if (!iommu) if (iommu_ret)
of_dma_set_restricted_buffer(dev, np); of_dma_set_restricted_buffer(dev, np);
return 0; return 0;

View File

@ -8,20 +8,19 @@ struct iommu_ops;
#ifdef CONFIG_OF_IOMMU #ifdef CONFIG_OF_IOMMU
extern const struct iommu_ops *of_iommu_configure(struct device *dev, extern int of_iommu_configure(struct device *dev, struct device_node *master_np,
struct device_node *master_np, const u32 *id);
const u32 *id);
extern void of_iommu_get_resv_regions(struct device *dev, extern void of_iommu_get_resv_regions(struct device *dev,
struct list_head *list); struct list_head *list);
#else #else
static inline const struct iommu_ops *of_iommu_configure(struct device *dev, static inline int of_iommu_configure(struct device *dev,
struct device_node *master_np, struct device_node *master_np,
const u32 *id) const u32 *id)
{ {
return NULL; return -ENODEV;
} }
static inline void of_iommu_get_resv_regions(struct device *dev, static inline void of_iommu_get_resv_regions(struct device *dev,