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

drivers: acpi: Handle IOMMU lookup failure with deferred probing or error

This is an equivalent to the DT's handling of the iommu master's probe
with deferred probing when the corrsponding iommu is not probed yet.
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 firmware 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: Hanjun Guo <hanjun.guo@linaro.org>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
[Lorenzo: Added fixes for dma_coherent_mask overflow, acpi_dma_configure
called multiple times for same device]
Signed-off-by: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Signed-off-by: Sricharan R <sricharan@codeaurora.org>
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Sricharan R and committed by
Joerg Roedel
5a1bb638 7b07cbef

+47 -8
+32 -1
drivers/acpi/arm64/iort.c
··· 543 543 const struct iommu_ops *ops = NULL; 544 544 int ret = -ENODEV; 545 545 struct fwnode_handle *iort_fwnode; 546 + struct iommu_fwspec *fwspec = dev->iommu_fwspec; 547 + 548 + /* 549 + * If we already translated the fwspec there 550 + * is nothing left to do, return the iommu_ops. 551 + */ 552 + if (fwspec && fwspec->ops) 553 + return fwspec->ops; 546 554 547 555 if (node) { 548 556 iort_fwnode = iort_get_fwnode(node); ··· 558 550 return NULL; 559 551 560 552 ops = iommu_ops_from_fwnode(iort_fwnode); 553 + /* 554 + * If the ops look-up fails, this means that either 555 + * the SMMU drivers have not been probed yet or that 556 + * the SMMU drivers are not built in the kernel; 557 + * Depending on whether the SMMU drivers are built-in 558 + * in the kernel or not, defer the IOMMU configuration 559 + * or just abort it. 560 + */ 561 561 if (!ops) 562 - return NULL; 562 + return iort_iommu_driver_enabled(node->type) ? 563 + ERR_PTR(-EPROBE_DEFER) : NULL; 563 564 564 565 ret = arm_smmu_iort_xlate(dev, streamid, iort_fwnode, ops); 565 566 } ··· 642 625 643 626 while (parent) { 644 627 ops = iort_iommu_xlate(dev, parent, streamid); 628 + if (IS_ERR_OR_NULL(ops)) 629 + return ops; 645 630 646 631 parent = iort_node_get_id(node, &streamid, 647 632 IORT_IOMMU_TYPE, i++); 648 633 } 634 + } 635 + 636 + /* 637 + * If we have reason to believe the IOMMU driver missed the initial 638 + * add_device callback for dev, replay it to get things in order. 639 + */ 640 + if (!IS_ERR_OR_NULL(ops) && ops->add_device && 641 + dev->bus && !dev->iommu_group) { 642 + int err = ops->add_device(dev); 643 + 644 + if (err) 645 + ops = ERR_PTR(err); 649 646 } 650 647 651 648 return ops;
+8 -3
drivers/acpi/scan.c
··· 1373 1373 * @dev: The pointer to the device 1374 1374 * @attr: device dma attributes 1375 1375 */ 1376 - void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) 1376 + int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr) 1377 1377 { 1378 1378 const struct iommu_ops *iommu; 1379 + u64 size; 1379 1380 1380 1381 iort_set_dma_mask(dev); 1381 1382 1382 1383 iommu = iort_iommu_configure(dev); 1384 + if (IS_ERR(iommu)) 1385 + return PTR_ERR(iommu); 1383 1386 1387 + size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); 1384 1388 /* 1385 1389 * Assume dma valid range starts at 0 and covers the whole 1386 1390 * coherent_dma_mask. 1387 1391 */ 1388 - arch_setup_dma_ops(dev, 0, dev->coherent_dma_mask + 1, iommu, 1389 - attr == DEV_DMA_COHERENT); 1392 + arch_setup_dma_ops(dev, 0, size, iommu, attr == DEV_DMA_COHERENT); 1393 + 1394 + return 0; 1390 1395 } 1391 1396 EXPORT_SYMBOL_GPL(acpi_dma_configure); 1392 1397
+1 -1
drivers/base/dma-mapping.c
··· 368 368 } else if (has_acpi_companion(dma_dev)) { 369 369 attr = acpi_get_dma_attr(to_acpi_device_node(dma_dev->fwnode)); 370 370 if (attr != DEV_DMA_NOT_SUPPORTED) 371 - acpi_dma_configure(dev, attr); 371 + ret = acpi_dma_configure(dev, attr); 372 372 } 373 373 374 374 if (bridge)
+1 -1
include/acpi/acpi_bus.h
··· 575 575 576 576 bool acpi_dma_supported(struct acpi_device *adev); 577 577 enum dev_dma_attr acpi_get_dma_attr(struct acpi_device *adev); 578 - void acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); 578 + int acpi_dma_configure(struct device *dev, enum dev_dma_attr attr); 579 579 void acpi_dma_deconfigure(struct device *dev); 580 580 581 581 struct acpi_device *acpi_find_child_device(struct acpi_device *parent,
+5 -2
include/linux/acpi.h
··· 762 762 return DEV_DMA_NOT_SUPPORTED; 763 763 } 764 764 765 - static inline void acpi_dma_configure(struct device *dev, 766 - enum dev_dma_attr attr) { } 765 + static inline int acpi_dma_configure(struct device *dev, 766 + enum dev_dma_attr attr) 767 + { 768 + return 0; 769 + } 767 770 768 771 static inline void acpi_dma_deconfigure(struct device *dev) { } 769 772