Skip to content

Commit 7b07cbe

Browse files
Laurent Pinchartjoergroedel
authored andcommitted
iommu: of: Handle IOMMU lookup failure with deferred probing or error
Failures to look up an IOMMU when parsing the DT iommus property need to be handled separately from the .of_xlate() failures to support deferred probing. The lack of a registered IOMMU can be caused by the lack of a driver for the IOMMU, the IOMMU device probe not having been performed yet, having been deferred, or having failed. The first case occurs when the device tree describes the bus master and IOMMU topology correctly but no device driver exists for the IOMMU yet or the device driver has not been compiled in. Return NULL, the caller will configure the device without an IOMMU. The second and third cases are handled by deferring the probe of the bus master device which will eventually get reprobed after the IOMMU. The last case is currently handled by deferring the probe of the bus master device as well. A mechanism to either configure the bus master device without an IOMMU or to fail the bus master device probe depending on whether the IOMMU is optional or mandatory would be a good enhancement. Tested-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Laurent Pichart <laurent.pinchart+renesas@ideasonboard.com> Signed-off-by: Sricharan R <sricharan@codeaurora.org> Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 09515ef commit 7b07cbe

4 files changed

Lines changed: 18 additions & 9 deletions

File tree

‎drivers/base/dma-mapping.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ int dma_configure(struct device *dev)
353353
{
354354
struct device *bridge = NULL, *dma_dev = dev;
355355
enum dev_dma_attr attr;
356+
int ret = 0;
356357

357358
if (dev_is_pci(dev)) {
358359
bridge = pci_get_host_bridge_device(to_pci_dev(dev));
@@ -363,7 +364,7 @@ int dma_configure(struct device *dev)
363364
}
364365

365366
if (dma_dev->of_node) {
366-
of_dma_configure(dev, dma_dev->of_node);
367+
ret = of_dma_configure(dev, dma_dev->of_node);
367368
} else if (has_acpi_companion(dma_dev)) {
368369
attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode));
369370
if (attr != DEV_DMA_NOT_SUPPORTED)
@@ -373,7 +374,7 @@ int dma_configure(struct device *dev)
373374
if (bridge)
374375
pci_put_host_bridge_device(bridge);
375376

376-
return 0;
377+
return ret;
377378
}
378379

379380
void dma_deconfigure(struct device *dev)

‎drivers/iommu/of_iommu.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ const struct iommu_ops *of_iommu_configure(struct device *dev,
236236
ops = ERR_PTR(err);
237237
}
238238

239-
return IS_ERR(ops) ? NULL : ops;
239+
return ops;
240240
}
241241

242242
static int __init of_iommu_init(void)
@@ -247,7 +247,7 @@ static int __init of_iommu_init(void)
247247
for_each_matching_node_and_match(np, matches, &match) {
248248
const of_iommu_init_fn init_fn = match->data;
249249

250-
if (init_fn(np))
250+
if (init_fn && init_fn(np))
251251
pr_err("Failed to initialise IOMMU %s\n",
252252
of_node_full_name(np));
253253
}

‎drivers/of/device.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ int of_device_add(struct platform_device *ofdev)
8282
* can use a platform bus notifier and handle BUS_NOTIFY_ADD_DEVICE events
8383
* to fix up DMA configuration.
8484
*/
85-
void of_dma_configure(struct device *dev, struct device_node *np)
85+
int of_dma_configure(struct device *dev, struct device_node *np)
8686
{
8787
u64 dma_addr, paddr, size;
8888
int ret;
@@ -123,7 +123,7 @@ void of_dma_configure(struct device *dev, struct device_node *np)
123123

124124
if (!size) {
125125
dev_err(dev, "Adjusted size 0x%llx invalid\n", size);
126-
return;
126+
return -EINVAL;
127127
}
128128
dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset);
129129
}
@@ -144,10 +144,15 @@ void of_dma_configure(struct device *dev, struct device_node *np)
144144
coherent ? " " : " not ");
145145

146146
iommu = of_iommu_configure(dev, np);
147+
if (IS_ERR(iommu))
148+
return PTR_ERR(iommu);
149+
147150
dev_dbg(dev, "device is%sbehind an iommu\n",
148151
iommu ? " " : " not ");
149152

150153
arch_setup_dma_ops(dev, dma_addr, size, iommu, coherent);
154+
155+
return 0;
151156
}
152157
EXPORT_SYMBOL_GPL(of_dma_configure);
153158

‎include/linux/of_device.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
5555
return of_node_get(cpu_dev->of_node);
5656
}
5757

58-
void of_dma_configure(struct device *dev, struct device_node *np);
58+
int of_dma_configure(struct device *dev, struct device_node *np);
5959
void of_dma_deconfigure(struct device *dev);
6060
#else /* CONFIG_OF */
6161

@@ -104,8 +104,11 @@ static inline struct device_node *of_cpu_device_node_get(int cpu)
104104
{
105105
return NULL;
106106
}
107-
static inline void of_dma_configure(struct device *dev, struct device_node *np)
108-
{}
107+
108+
static inline int of_dma_configure(struct device *dev, struct device_node *np)
109+
{
110+
return 0;
111+
}
109112
static inline void of_dma_deconfigure(struct device *dev)
110113
{}
111114
#endif /* CONFIG_OF */

0 commit comments

Comments
 (0)