Thread (18 messages) 18 messages, 1 author, 14d ago
COOLING14d

[PATCH v2 16/17] media: rockchip: rga: put all cores into first core iommu domain

From: Sven Püschel <hidden>
Date: 2026-09-16 15:15:24
Also in: linux-media, linux-rockchip, lkml
Subsystem: arm/rockchip soc support, media input infrastructure (v4l/dvb), rockchip raster 2d graphic acceleration unit driver, the rest · Maintainers: Heiko Stuebner, Mauro Carvalho Chehab, Jacob Chen, Ezequiel Garcia, Linus Torvalds

Put all cores into the iommu domain of the first core to allow them to
be used by any core. All buffers accessed by the hardware are allocated
on the first core, as the scheduling to a specific core is done after
the allocation. Therefore put all cores into the same domain to have the
same iommu mapping on all cores.

Signed-off-by: Sven Püschel <redacted>

---
v2
- Fixed domain not being an err ptr
  (https://sashiko.dev/#/patchset/20260606-spu-rga3multicore-v1-0-3ec2b15675f7%40pengutronix.de?part=14)
- Detach domain on unbind callback
  (https://sashiko.dev/#/patchset/20260606-spu-rga3multicore-v1-0-3ec2b15675f7%40pengutronix.de?part=14)
---
 drivers/media/platform/rockchip/rga/rga.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff --git a/drivers/media/platform/rockchip/rga/rga.c b/drivers/media/platform/rockchip/rga/rga.c
index 5348fcc03c525..b2eeae0a61771 100644
--- a/drivers/media/platform/rockchip/rga/rga.c
+++ b/drivers/media/platform/rockchip/rga/rga.c
@@ -10,6 +10,7 @@
 #include <linux/delay.h>
 #include <linux/fs.h>
 #include <linux/interrupt.h>
+#include <linux/iommu.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_platform.h>
@@ -761,6 +762,19 @@ static int rga_core_bind(struct device *dev, struct device *master, void *data)
 		  rga->version.major, rga->version.minor);
 
 	if (rga->num_cores) {
+		/* Attach to the first cores iommu */
+		struct iommu_domain *domain = iommu_get_domain_for_dev(rga->cores[0]->dev);
+
+		if (!domain) {
+			dev_err(core->dev, "Couldn't get domain of the first core\n");
+			return -ENODEV;
+		}
+		ret = iommu_attach_device(domain, core->dev);
+		if (ret) {
+			dev_err(core->dev, "Couldn't attach to the domain of the first core\n");
+			return ret;
+		}
+
 		/* we are not the first core, expect that we have the same version */
 		if (rga->version.major != version.major || rga->version.minor != version.minor) {
 			v4l2_err(&rga->v4l2_dev, "Detected multi-core setup with different core versions!\n");
@@ -788,6 +802,14 @@ static void rga_core_unbind(struct device *dev, struct device *master,
 		if (rga->cores[i] != core)
 			continue;
 
+		if (i) {
+			/* Detach from the first core iommu */
+			struct iommu_domain *domain = iommu_get_domain_for_dev(rga->cores[0]->dev);
+
+			if (domain)
+				iommu_detach_device(domain, core->dev);
+		}
+
 		rga->cores[i] = rga->cores[rga->num_cores - 1];
 		rga->num_cores--;
 		break;
-- 
2.55.0

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help