Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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) <robh@kernel.org>
Tested-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/61972f88e31a6eda8bf5852f0853951164279a3c.1719919669.git.robin.murphy@arm.com
Signed-off-by: Will Deacon <will@kernel.org>

authored by

Robin Murphy and committed by
Will Deacon
5f937bc4 78596b5c

+21 -38
+10 -19
drivers/iommu/of_iommu.c
··· 108 108 int of_iommu_configure(struct device *dev, struct device_node *master_np, 109 109 const u32 *id) 110 110 { 111 - struct iommu_fwspec *fwspec; 112 111 int err; 113 112 114 113 if (!master_np) ··· 115 116 116 117 /* Serialise to make dev->iommu stable under our potential fwspec */ 117 118 mutex_lock(&iommu_probe_device_lock); 118 - fwspec = dev_iommu_fwspec_get(dev); 119 - if (fwspec) { 120 - if (fwspec->ops) { 121 - mutex_unlock(&iommu_probe_device_lock); 122 - return 0; 123 - } 124 - /* In the deferred case, start again from scratch */ 125 - iommu_fwspec_free(dev); 119 + if (dev_iommu_fwspec_get(dev)) { 120 + mutex_unlock(&iommu_probe_device_lock); 121 + return 0; 126 122 } 127 123 128 124 /* ··· 137 143 } else { 138 144 err = of_iommu_configure_device(master_np, dev, id); 139 145 } 146 + 147 + if (err) 148 + iommu_fwspec_free(dev); 140 149 mutex_unlock(&iommu_probe_device_lock); 141 150 142 - if (err == -ENODEV || err == -EPROBE_DEFER) 143 - return err; 144 - if (err) 145 - goto err_log; 151 + if (!err && dev->bus) 152 + err = iommu_probe_device(dev); 146 153 147 - err = iommu_probe_device(dev); 148 - if (err) 149 - goto err_log; 150 - return 0; 154 + if (err && err != -EPROBE_DEFER) 155 + dev_dbg(dev, "Adding to IOMMU failed: %d\n", err); 151 156 152 - err_log: 153 - dev_dbg(dev, "Adding to IOMMU failed: %pe\n", ERR_PTR(err)); 154 157 return err; 155 158 } 156 159
+11 -19
drivers/of/device.c
··· 96 96 const struct bus_dma_region *map = NULL; 97 97 struct device_node *bus_np; 98 98 u64 mask, end = 0; 99 - bool coherent; 100 - int iommu_ret; 99 + bool coherent, set_map = false; 101 100 int ret; 102 101 103 102 if (np == dev->of_node) ··· 117 118 } else { 118 119 /* Determine the overall bounds of all DMA regions */ 119 120 end = dma_range_map_max(map); 121 + set_map = true; 120 122 } 121 123 122 124 /* ··· 144 144 dev->coherent_dma_mask &= mask; 145 145 *dev->dma_mask &= mask; 146 146 /* ...but only set bus limit and range map if we found valid dma-ranges earlier */ 147 - if (!ret) { 147 + if (set_map) { 148 148 dev->bus_dma_limit = end; 149 149 dev->dma_range_map = map; 150 150 } ··· 153 153 dev_dbg(dev, "device is%sdma coherent\n", 154 154 coherent ? " " : " not "); 155 155 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) { 158 158 /* Don't touch range map if it wasn't set from a valid dma-ranges */ 159 - if (!ret) 159 + if (set_map) 160 160 dev->dma_range_map = NULL; 161 161 kfree(map); 162 162 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 "); 175 167 176 168 arch_setup_dma_ops(dev, coherent); 177 169 178 - if (iommu_ret) 170 + if (ret) 179 171 of_dma_set_restricted_buffer(dev, np); 180 172 181 173 return 0;