rockchip: translate DMA for the media IOMMU masters

The video codecs sit behind their own IOMMUs, but with the default
domain set to passthrough their buffers have to be physically
contiguous and come out of the 16 MiB CMA pool. A 4K frame needs
15.8 MiB of it, so hardware decoding of 4K video fails allocation and
falls back to software: 10 seconds of 4K HEVC then cost 22 seconds of
CPU, where the decoder does the same work with 0.15.

Have rockchip-iommu ask for a translated domain for the masters it
serves, so the display, codec, ISP and RGA blocks get scatter-gather
while everything behind another IOMMU, PCIe included, keeps the system
default and its throughput.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
This commit is contained in:
Daniel Golle committed 2026-10-07 10:12:13 +01:00
1 parent b14b8d95d9
commit 48592abf6f
1 file changed
+47
@@ -0,0 +1,47 @@
From f69d2a3b86e90f4141d45be7d234f9a5ab464fe8 Mon Sep 17 00:00:00 2001
From: Daniel Golle <daniel@makrotopia.org>
Date: Thu, 24 Sep 2026 17:39:45 +0100
Subject: [PATCH] iommu/rockchip: use a translated domain for IOMMU masters
The masters behind rockchip-iommu are media blocks: the display
controller, the video codecs, the ISP and the 2D engine. They are wired
to the IOMMU so that their buffers do not have to be physically
contiguous. With a system-wide passthrough default, which is what
IOMMU_DEFAULT_PASSTHROUGH gives, those masters are handed an identity
domain instead, and every buffer has to come from CMA. A 4K frame needs
15.8 MiB of it, so hardware decoding fails the allocation and falls back
to software.
Return IOMMU_DOMAIN_DMA from def_domain_type so these masters get a
translated domain whatever the system default is, the way apple-dart
does for its no-bypass configurations. Masters behind other IOMMUs are
untouched, so a PCIe root port behind an SMMU keeps the system default
and its performance.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
drivers/iommu/rockchip-iommu.c | 7 +++++++
1 file changed, 7 insertions(+)
--- a/drivers/iommu/rockchip-iommu.c
+++ b/drivers/iommu/rockchip-iommu.c
@@ -1174,12 +1174,19 @@ static int rk_iommu_of_xlate(struct devi
return 0;
}
+/* An identity domain would put these media masters back onto CMA. */
+static int rk_iommu_def_domain_type(struct device *dev)
+{
+ return IOMMU_DOMAIN_DMA;
+}
+
static const struct iommu_ops rk_iommu_ops = {
.identity_domain = &rk_identity_domain,
.domain_alloc_paging = rk_iommu_domain_alloc_paging,
.probe_device = rk_iommu_probe_device,
.release_device = rk_iommu_release_device,
.device_group = generic_single_device_group,
+ .def_domain_type = rk_iommu_def_domain_type,
.of_xlate = rk_iommu_of_xlate,
.default_domain_ops = &(const struct iommu_domain_ops) {
.attach_dev = rk_iommu_attach_device,