diff mbox series

[2/3] iommu: add a connect op

Message ID 20231211-b4-dwc3-qcom-v1-2-46275113b4f2@linaro.org
State Accepted
Commit 76c53dad6b5dc94e4c43069882b2708853c284c0
Headers show
Series Qualcomm quirky SMMU support | expand

Commit Message

Caleb Connolly Dec. 11, 2023, 6:41 p.m. UTC
Add an optional iommu callback to be invoked before a device probes.
This can be used to configure the IOMMU in preparation for the device
(e.g. by allocating a context bank)

Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>
---
 drivers/iommu/iommu-uclass.c | 11 +++++++++++
 include/iommu.h              |  9 +++++++++
 2 files changed, 20 insertions(+)

Comments

Tom Rini Dec. 21, 2023, 9:07 p.m. UTC | #1
On Mon, Dec 11, 2023 at 06:41:41PM +0000, Caleb Connolly wrote:

> Add an optional iommu callback to be invoked before a device probes.
> This can be used to configure the IOMMU in preparation for the device
> (e.g. by allocating a context bank)
> 
> Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/drivers/iommu/iommu-uclass.c b/drivers/iommu/iommu-uclass.c
index 98731d5e2c44..6babc0e3a672 100644
--- a/drivers/iommu/iommu-uclass.c
+++ b/drivers/iommu/iommu-uclass.c
@@ -77,6 +77,7 @@  int dev_iommu_enable(struct udevice *dev)
 {
 	struct ofnode_phandle_args args;
 	struct udevice *dev_iommu;
+	const struct iommu_ops *ops;
 	int i, count, ret = 0;
 
 	count = dev_count_phandle_with_args(dev, "iommus",
@@ -98,6 +99,16 @@  int dev_iommu_enable(struct udevice *dev)
 			return ret;
 		}
 		dev->iommu = dev_iommu;
+
+		if (dev->parent && dev->parent->iommu == dev_iommu)
+			continue;
+
+		ops = device_get_ops(dev->iommu);
+		if (ops && ops->connect) {
+			ret = ops->connect(dev);
+			if (ret)
+				return ret;
+		}
 	}
 
 #if CONFIG_IS_ENABLED(PCI)
diff --git a/include/iommu.h b/include/iommu.h
index cf9719c5e91c..b8ba0b8e7077 100644
--- a/include/iommu.h
+++ b/include/iommu.h
@@ -4,6 +4,15 @@ 
 struct udevice;
 
 struct iommu_ops {
+	/**
+	 * init() - Connect a device to it's IOMMU, called before probe()
+	 * The iommu device can be fetched through dev->iommu
+	 *
+	 * @iommu_dev:	IOMMU device
+	 * @dev:	Device to connect
+	 * @return 0 if OK, -errno on error
+	 */
+	int (*connect)(struct udevice *dev);
 	/**
 	 * map() - map DMA memory
 	 *