* [PATCH v2 1/4] drm/prime: Limit scatter list size with dedicated DMA device
2026-03-11 9:49 [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
@ 2026-03-11 9:49 ` Chen-Yu Tsai
2026-03-11 14:40 ` AngeloGioacchino Del Regno
2026-03-11 9:49 ` [PATCH v2 2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping Chen-Yu Tsai
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Chen-Yu Tsai @ 2026-03-11 9:49 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter
Cc: Chen-Yu Tsai, linux-sunxi, Paul Kocialkowski, linux-mediatek,
dri-devel, linux-arm-kernel, linux-kernel
If a dedicated DMA device is specified for the DRM device, then the
scatter list size limit should pertain to the DMA device.
Use the dedicated DMA device, if given, to limit the scatter list size.
This only applies to drivers that have called drm_dev_set_dma_dev() and
are using drm_prime_pages_to_sg() either directly or through the SHMEM
helpers. At the time of this writing, the former case only includes the
Rockchip DRM driver, while the latter case includes the gud, udl, and
the tiny appletbdrm and gm12u320 drivers.
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
drivers/gpu/drm/drm_prime.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_prime.c b/drivers/gpu/drm/drm_prime.c
index 51fdb06d3e9f..9b44c78cd77f 100644
--- a/drivers/gpu/drm/drm_prime.c
+++ b/drivers/gpu/drm/drm_prime.c
@@ -859,7 +859,7 @@ struct sg_table *drm_prime_pages_to_sg(struct drm_device *dev,
return ERR_PTR(-ENOMEM);
if (dev)
- max_segment = dma_max_mapping_size(dev->dev);
+ max_segment = dma_max_mapping_size(drm_dev_dma_dev(dev));
if (max_segment == 0)
max_segment = UINT_MAX;
err = sg_alloc_table_from_pages_segment(sg, pages, nr_pages, 0,
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 1/4] drm/prime: Limit scatter list size with dedicated DMA device
2026-03-11 9:49 ` [PATCH v2 1/4] drm/prime: Limit scatter list size with dedicated DMA device Chen-Yu Tsai
@ 2026-03-11 14:40 ` AngeloGioacchino Del Regno
0 siblings, 0 replies; 11+ messages in thread
From: AngeloGioacchino Del Regno @ 2026-03-11 14:40 UTC (permalink / raw)
To: Chen-Yu Tsai, Matthias Brugger, Chun-Kuang Hu, Philipp Zabel,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, David Airlie, Simona Vetter
Cc: linux-sunxi, Paul Kocialkowski, linux-mediatek, dri-devel,
linux-arm-kernel, linux-kernel
Il 11/03/26 10:49, Chen-Yu Tsai ha scritto:
> If a dedicated DMA device is specified for the DRM device, then the
> scatter list size limit should pertain to the DMA device.
>
> Use the dedicated DMA device, if given, to limit the scatter list size.
> This only applies to drivers that have called drm_dev_set_dma_dev() and
> are using drm_prime_pages_to_sg() either directly or through the SHMEM
> helpers. At the time of this writing, the former case only includes the
> Rockchip DRM driver, while the latter case includes the gud, udl, and
> the tiny appletbdrm and gm12u320 drivers.
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping
2026-03-11 9:49 [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
2026-03-11 9:49 ` [PATCH v2 1/4] drm/prime: Limit scatter list size with dedicated DMA device Chen-Yu Tsai
@ 2026-03-11 9:49 ` Chen-Yu Tsai
2026-03-11 14:40 ` AngeloGioacchino Del Regno
2026-03-11 9:49 ` [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks Chen-Yu Tsai
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ messages in thread
From: Chen-Yu Tsai @ 2026-03-11 9:49 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter
Cc: Chen-Yu Tsai, linux-sunxi, Paul Kocialkowski, linux-mediatek,
dri-devel, linux-arm-kernel, linux-kernel
Support for a dedicated DMA device for prime imports was added in commit
143ec8d3f939 ("drm/prime: Support dedicated DMA device for dma-buf imports").
This allowed the DRM driver to provide a dedicated DMA device when its
own underlying device was not capable of DMA, for example when it is a
USB device (the original target) or a virtual device. The latter case is
common on embedded SoCs, on which the display pipeline is composed of
various fixed function blocks, and the DRM device is simply a made-up
device, an address space managing the routing between the blocks, or
whichever block the implementor thought made sense at the time. The
point is that the chosen device is often not the actual device doing
the DMA. Various drivers have used workarounds or reimplemented the
GEM DMA helpers to get the DMA addresses and IOMMUs to work correctly.
Add support for the dedicated DMA device to the GEM DMA helpers.
No existing driver currently uses the GEM DMA helpers and calls
drm_dev_set_dma_dev() to set a dedicated DMA device, so no existing
users should be affected.
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
drivers/gpu/drm/drm_gem_dma_helper.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/drm_gem_dma_helper.c b/drivers/gpu/drm/drm_gem_dma_helper.c
index ecb9746f4da8..70f83e464476 100644
--- a/drivers/gpu/drm/drm_gem_dma_helper.c
+++ b/drivers/gpu/drm/drm_gem_dma_helper.c
@@ -146,12 +146,13 @@ struct drm_gem_dma_object *drm_gem_dma_create(struct drm_device *drm,
return dma_obj;
if (dma_obj->map_noncoherent) {
- dma_obj->vaddr = dma_alloc_noncoherent(drm->dev, size,
+ dma_obj->vaddr = dma_alloc_noncoherent(drm_dev_dma_dev(drm),
+ size,
&dma_obj->dma_addr,
DMA_TO_DEVICE,
GFP_KERNEL | __GFP_NOWARN);
} else {
- dma_obj->vaddr = dma_alloc_wc(drm->dev, size,
+ dma_obj->vaddr = dma_alloc_wc(drm_dev_dma_dev(drm), size,
&dma_obj->dma_addr,
GFP_KERNEL | __GFP_NOWARN);
}
@@ -236,12 +237,14 @@ void drm_gem_dma_free(struct drm_gem_dma_object *dma_obj)
drm_prime_gem_destroy(gem_obj, dma_obj->sgt);
} else if (dma_obj->vaddr) {
if (dma_obj->map_noncoherent)
- dma_free_noncoherent(gem_obj->dev->dev, dma_obj->base.size,
+ dma_free_noncoherent(drm_dev_dma_dev(gem_obj->dev),
+ dma_obj->base.size,
dma_obj->vaddr, dma_obj->dma_addr,
DMA_TO_DEVICE);
else
- dma_free_wc(gem_obj->dev->dev, dma_obj->base.size,
- dma_obj->vaddr, dma_obj->dma_addr);
+ dma_free_wc(drm_dev_dma_dev(gem_obj->dev),
+ dma_obj->base.size, dma_obj->vaddr,
+ dma_obj->dma_addr);
}
drm_gem_object_release(gem_obj);
@@ -432,7 +435,7 @@ struct sg_table *drm_gem_dma_get_sg_table(struct drm_gem_dma_object *dma_obj)
if (!sgt)
return ERR_PTR(-ENOMEM);
- ret = dma_get_sgtable(obj->dev->dev, sgt, dma_obj->vaddr,
+ ret = dma_get_sgtable(drm_dev_dma_dev(obj->dev), sgt, dma_obj->vaddr,
dma_obj->dma_addr, obj->size);
if (ret < 0)
goto out;
@@ -539,12 +542,12 @@ int drm_gem_dma_mmap(struct drm_gem_dma_object *dma_obj, struct vm_area_struct *
if (dma_obj->map_noncoherent) {
vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
- ret = dma_mmap_pages(dma_obj->base.dev->dev,
+ ret = dma_mmap_pages(drm_dev_dma_dev(dma_obj->base.dev),
vma, vma->vm_end - vma->vm_start,
virt_to_page(dma_obj->vaddr));
} else {
- ret = dma_mmap_wc(dma_obj->base.dev->dev, vma, dma_obj->vaddr,
- dma_obj->dma_addr,
+ ret = dma_mmap_wc(drm_dev_dma_dev(dma_obj->base.dev), vma,
+ dma_obj->vaddr, dma_obj->dma_addr,
vma->vm_end - vma->vm_start);
}
if (ret)
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping
2026-03-11 9:49 ` [PATCH v2 2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping Chen-Yu Tsai
@ 2026-03-11 14:40 ` AngeloGioacchino Del Regno
0 siblings, 0 replies; 11+ messages in thread
From: AngeloGioacchino Del Regno @ 2026-03-11 14:40 UTC (permalink / raw)
To: Chen-Yu Tsai, Matthias Brugger, Chun-Kuang Hu, Philipp Zabel,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, David Airlie, Simona Vetter
Cc: linux-sunxi, Paul Kocialkowski, linux-mediatek, dri-devel,
linux-arm-kernel, linux-kernel
Il 11/03/26 10:49, Chen-Yu Tsai ha scritto:
> Support for a dedicated DMA device for prime imports was added in commit
> 143ec8d3f939 ("drm/prime: Support dedicated DMA device for dma-buf imports").
> This allowed the DRM driver to provide a dedicated DMA device when its
> own underlying device was not capable of DMA, for example when it is a
> USB device (the original target) or a virtual device. The latter case is
> common on embedded SoCs, on which the display pipeline is composed of
> various fixed function blocks, and the DRM device is simply a made-up
> device, an address space managing the routing between the blocks, or
> whichever block the implementor thought made sense at the time. The
> point is that the chosen device is often not the actual device doing
> the DMA. Various drivers have used workarounds or reimplemented the
> GEM DMA helpers to get the DMA addresses and IOMMUs to work correctly.
>
> Add support for the dedicated DMA device to the GEM DMA helpers.
>
> No existing driver currently uses the GEM DMA helpers and calls
> drm_dev_set_dma_dev() to set a dedicated DMA device, so no existing
> users should be affected.
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks
2026-03-11 9:49 [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
2026-03-11 9:49 ` [PATCH v2 1/4] drm/prime: Limit scatter list size with dedicated DMA device Chen-Yu Tsai
2026-03-11 9:49 ` [PATCH v2 2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping Chen-Yu Tsai
@ 2026-03-11 9:49 ` Chen-Yu Tsai
2026-03-11 14:40 ` AngeloGioacchino Del Regno
2026-03-22 13:57 ` Chun-Kuang Hu
2026-03-11 9:49 ` [PATCH v2 4/4] drm/sun4i: Use backend/mixer as dedicated DMA device Chen-Yu Tsai
2026-03-26 6:58 ` [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
4 siblings, 2 replies; 11+ messages in thread
From: Chen-Yu Tsai @ 2026-03-11 9:49 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter
Cc: Chen-Yu Tsai, linux-sunxi, Paul Kocialkowski, linux-mediatek,
dri-devel, linux-arm-kernel, linux-kernel
In commit 9b54a32c7c6a ("drm/mediatek: mtk_gem: Partial refactor and
use drm_gem_dma_object") the MediaTek DRM driver was refactored to use
drm_gem_dma_object, but custom callbacks were still needed to deal with
using the first device of the pipeline as the DMA device, instead of
the MMSYS device that the DRM driver binds to.
Turns out there is already partial support for dedicated DMA devices in
the DRM subsystem for PRIME imports. The preceding patches add support
for dedicated DMA devices to the GEM DMA helpers.
This allows us to just set the dedicated DMA device for the DRM device,
and drop all the custom GEM callbacks. Also drop the .dma_dev field
from the driver private data as it is no longer needed.
There are slight differences in the mmap helper: the VM_DONTDUMP and
VM_IO flags are no longer set. Both were lifted from drm_gem_mmap_obj().
VM_IO probably doesn't make sense since the buffer is allocated using
dma_alloc_attrs().
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
Changes since v1:
- Also remove reference to mtk_gem.c from the Makefile
---
drivers/gpu/drm/mediatek/Makefile | 1 -
drivers/gpu/drm/mediatek/mtk_crtc.c | 1 -
drivers/gpu/drm/mediatek/mtk_drm_drv.c | 21 +--
drivers/gpu/drm/mediatek/mtk_drm_drv.h | 1 -
drivers/gpu/drm/mediatek/mtk_gem.c | 231 -------------------------
drivers/gpu/drm/mediatek/mtk_gem.h | 17 --
6 files changed, 3 insertions(+), 269 deletions(-)
delete mode 100644 drivers/gpu/drm/mediatek/mtk_gem.c
delete mode 100644 drivers/gpu/drm/mediatek/mtk_gem.h
diff --git a/drivers/gpu/drm/mediatek/Makefile b/drivers/gpu/drm/mediatek/Makefile
index e0ac49b07d50..952d294642fb 100644
--- a/drivers/gpu/drm/mediatek/Makefile
+++ b/drivers/gpu/drm/mediatek/Makefile
@@ -14,7 +14,6 @@ mediatek-drm-y := mtk_crtc.o \
mtk_dsi.o \
mtk_dpi.o \
mtk_ethdr.o \
- mtk_gem.o \
mtk_mdp_rdma.o \
mtk_padding.o \
mtk_plane.o
diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
index 351d58c50b84..fcb16f3f7b23 100644
--- a/drivers/gpu/drm/mediatek/mtk_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
@@ -23,7 +23,6 @@
#include "mtk_crtc.h"
#include "mtk_ddp_comp.h"
#include "mtk_drm_drv.h"
-#include "mtk_gem.h"
#include "mtk_plane.h"
/*
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index a94c51a83261..6f6db2e1980e 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -19,6 +19,7 @@
#include <drm/drm_fbdev_dma.h>
#include <drm/drm_fourcc.h>
#include <drm/drm_gem.h>
+#include <drm/drm_gem_dma_helper.h>
#include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_ioctl.h>
#include <drm/drm_of.h>
@@ -29,7 +30,6 @@
#include "mtk_ddp_comp.h"
#include "mtk_disp_drv.h"
#include "mtk_drm_drv.h"
-#include "mtk_gem.h"
#define DRIVER_NAME "mediatek"
#define DRIVER_DESC "Mediatek SoC DRM"
@@ -565,8 +565,7 @@ static int mtk_drm_kms_init(struct drm_device *drm)
goto err_component_unbind;
}
- for (i = 0; i < private->data->mmsys_dev_num; i++)
- private->all_drm_private[i]->dma_dev = dma_dev;
+ drm_dev_set_dma_dev(drm, dma_dev);
/*
* Configure the DMA segment size to make sure we get contiguous IOVA
@@ -600,26 +599,12 @@ static void mtk_drm_kms_deinit(struct drm_device *drm)
DEFINE_DRM_GEM_FOPS(mtk_drm_fops);
-/*
- * We need to override this because the device used to import the memory is
- * not dev->dev, as drm_gem_prime_import() expects.
- */
-static struct drm_gem_object *mtk_gem_prime_import(struct drm_device *dev,
- struct dma_buf *dma_buf)
-{
- struct mtk_drm_private *private = dev->dev_private;
-
- return drm_gem_prime_import_dev(dev, dma_buf, private->dma_dev);
-}
-
static const struct drm_driver mtk_drm_driver = {
.driver_features = DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
- .dumb_create = mtk_gem_dumb_create,
+ DRM_GEM_DMA_DRIVER_OPS,
DRM_FBDEV_DMA_DRIVER_OPS,
- .gem_prime_import = mtk_gem_prime_import,
- .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table,
.fops = &mtk_drm_fops,
.name = DRIVER_NAME,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.h b/drivers/gpu/drm/mediatek/mtk_drm_drv.h
index 675cdc90a440..1fc3df4b5485 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.h
@@ -54,7 +54,6 @@ struct mtk_mmsys_driver_data {
struct mtk_drm_private {
struct drm_device *drm;
- struct device *dma_dev;
bool mtk_drm_bound;
bool drm_master;
struct device *dev;
diff --git a/drivers/gpu/drm/mediatek/mtk_gem.c b/drivers/gpu/drm/mediatek/mtk_gem.c
deleted file mode 100644
index f059a1452220..000000000000
--- a/drivers/gpu/drm/mediatek/mtk_gem.c
+++ /dev/null
@@ -1,231 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (c) 2015 MediaTek Inc.
- * Copyright (c) 2025 Collabora Ltd.
- * AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
- */
-
-#include <linux/dma-buf.h>
-#include <linux/vmalloc.h>
-
-#include <drm/drm.h>
-#include <drm/drm_device.h>
-#include <drm/drm_gem.h>
-#include <drm/drm_gem_dma_helper.h>
-#include <drm/drm_prime.h>
-#include <drm/drm_print.h>
-
-#include "mtk_drm_drv.h"
-#include "mtk_gem.h"
-
-static int mtk_gem_object_mmap(struct drm_gem_object *obj, struct vm_area_struct *vma);
-
-static void mtk_gem_free_object(struct drm_gem_object *obj)
-{
- struct drm_gem_dma_object *dma_obj = to_drm_gem_dma_obj(obj);
- struct mtk_drm_private *priv = obj->dev->dev_private;
-
- if (dma_obj->sgt)
- drm_prime_gem_destroy(obj, dma_obj->sgt);
- else
- dma_free_wc(priv->dma_dev, dma_obj->base.size,
- dma_obj->vaddr, dma_obj->dma_addr);
-
- /* release file pointer to gem object. */
- drm_gem_object_release(obj);
-
- kfree(dma_obj);
-}
-
-/*
- * Allocate a sg_table for this GEM object.
- * Note: Both the table's contents, and the sg_table itself must be freed by
- * the caller.
- * Returns a pointer to the newly allocated sg_table, or an ERR_PTR() error.
- */
-static struct sg_table *mtk_gem_prime_get_sg_table(struct drm_gem_object *obj)
-{
- struct drm_gem_dma_object *dma_obj = to_drm_gem_dma_obj(obj);
- struct mtk_drm_private *priv = obj->dev->dev_private;
- struct sg_table *sgt;
- int ret;
-
- sgt = kzalloc_obj(*sgt);
- if (!sgt)
- return ERR_PTR(-ENOMEM);
-
- ret = dma_get_sgtable(priv->dma_dev, sgt, dma_obj->vaddr,
- dma_obj->dma_addr, obj->size);
- if (ret) {
- DRM_ERROR("failed to allocate sgt, %d\n", ret);
- kfree(sgt);
- return ERR_PTR(ret);
- }
-
- return sgt;
-}
-
-static const struct drm_gem_object_funcs mtk_gem_object_funcs = {
- .free = mtk_gem_free_object,
- .print_info = drm_gem_dma_object_print_info,
- .get_sg_table = mtk_gem_prime_get_sg_table,
- .vmap = drm_gem_dma_object_vmap,
- .mmap = mtk_gem_object_mmap,
- .vm_ops = &drm_gem_dma_vm_ops,
-};
-
-static struct drm_gem_dma_object *mtk_gem_init(struct drm_device *dev,
- unsigned long size, bool private)
-{
- struct drm_gem_dma_object *dma_obj;
- int ret;
-
- size = round_up(size, PAGE_SIZE);
-
- if (size == 0)
- return ERR_PTR(-EINVAL);
-
- dma_obj = kzalloc_obj(*dma_obj);
- if (!dma_obj)
- return ERR_PTR(-ENOMEM);
-
- dma_obj->base.funcs = &mtk_gem_object_funcs;
-
- if (private) {
- ret = 0;
- drm_gem_private_object_init(dev, &dma_obj->base, size);
- } else {
- ret = drm_gem_object_init(dev, &dma_obj->base, size);
- }
- if (ret) {
- DRM_ERROR("failed to initialize gem object\n");
- kfree(dma_obj);
- return ERR_PTR(ret);
- }
-
- return dma_obj;
-}
-
-static struct drm_gem_dma_object *mtk_gem_create(struct drm_device *dev, size_t size)
-{
- struct mtk_drm_private *priv = dev->dev_private;
- struct drm_gem_dma_object *dma_obj;
- struct drm_gem_object *obj;
- int ret;
-
- dma_obj = mtk_gem_init(dev, size, false);
- if (IS_ERR(dma_obj))
- return ERR_CAST(dma_obj);
-
- obj = &dma_obj->base;
-
- dma_obj->vaddr = dma_alloc_wc(priv->dma_dev, obj->size,
- &dma_obj->dma_addr,
- GFP_KERNEL | __GFP_NOWARN);
- if (!dma_obj->vaddr) {
- DRM_ERROR("failed to allocate %zx byte dma buffer", obj->size);
- ret = -ENOMEM;
- goto err_gem_free;
- }
-
- DRM_DEBUG_DRIVER("vaddr = %p dma_addr = %pad size = %zu\n",
- dma_obj->vaddr, &dma_obj->dma_addr,
- size);
-
- return dma_obj;
-
-err_gem_free:
- drm_gem_object_release(obj);
- kfree(dma_obj);
- return ERR_PTR(ret);
-}
-
-int mtk_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
- struct drm_mode_create_dumb *args)
-{
- struct drm_gem_dma_object *dma_obj;
- int ret;
-
- args->pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
-
- /*
- * Multiply 2 variables of different types,
- * for example: args->size = args->spacing * args->height;
- * may cause coverity issue with unintentional overflow.
- */
- args->size = args->pitch;
- args->size *= args->height;
-
- dma_obj = mtk_gem_create(dev, args->size);
- if (IS_ERR(dma_obj))
- return PTR_ERR(dma_obj);
-
- /*
- * allocate a id of idr table where the obj is registered
- * and handle has the id what user can see.
- */
- ret = drm_gem_handle_create(file_priv, &dma_obj->base, &args->handle);
- if (ret)
- goto err_handle_create;
-
- /* drop reference from allocate - handle holds it now. */
- drm_gem_object_put(&dma_obj->base);
-
- return 0;
-
-err_handle_create:
- mtk_gem_free_object(&dma_obj->base);
- return ret;
-}
-
-static int mtk_gem_object_mmap(struct drm_gem_object *obj,
- struct vm_area_struct *vma)
-
-{
- struct drm_gem_dma_object *dma_obj = to_drm_gem_dma_obj(obj);
- struct mtk_drm_private *priv = obj->dev->dev_private;
- int ret;
-
- /*
- * Set vm_pgoff (used as a fake buffer offset by DRM) to 0 and map the
- * whole buffer from the start.
- */
- vma->vm_pgoff -= drm_vma_node_start(&obj->vma_node);
-
- /*
- * dma_alloc_attrs() allocated a struct page table for mtk_gem, so clear
- * VM_PFNMAP flag that was set by drm_gem_mmap_obj()/drm_gem_mmap().
- */
- vm_flags_mod(vma, VM_IO | VM_DONTEXPAND | VM_DONTDUMP, VM_PFNMAP);
-
- vma->vm_page_prot = pgprot_writecombine(vm_get_page_prot(vma->vm_flags));
- vma->vm_page_prot = pgprot_decrypted(vma->vm_page_prot);
-
- ret = dma_mmap_wc(priv->dma_dev, vma, dma_obj->vaddr,
- dma_obj->dma_addr, obj->size);
- if (ret)
- drm_gem_vm_close(vma);
-
- return ret;
-}
-
-struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach, struct sg_table *sgt)
-{
- struct drm_gem_dma_object *dma_obj;
-
- /* check if the entries in the sg_table are contiguous */
- if (drm_prime_get_contiguous_size(sgt) < attach->dmabuf->size) {
- DRM_ERROR("sg_table is not contiguous");
- return ERR_PTR(-EINVAL);
- }
-
- dma_obj = mtk_gem_init(dev, attach->dmabuf->size, true);
- if (IS_ERR(dma_obj))
- return ERR_CAST(dma_obj);
-
- dma_obj->dma_addr = sg_dma_address(sgt->sgl);
- dma_obj->sgt = sgt;
-
- return &dma_obj->base;
-}
diff --git a/drivers/gpu/drm/mediatek/mtk_gem.h b/drivers/gpu/drm/mediatek/mtk_gem.h
deleted file mode 100644
index afebc3a970a8..000000000000
--- a/drivers/gpu/drm/mediatek/mtk_gem.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (c) 2015 MediaTek Inc.
- */
-
-#ifndef _MTK_GEM_H_
-#define _MTK_GEM_H_
-
-#include <drm/drm_gem.h>
-#include <drm/drm_gem_dma_helper.h>
-
-int mtk_gem_dumb_create(struct drm_file *file_priv, struct drm_device *dev,
- struct drm_mode_create_dumb *args);
-struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev,
- struct dma_buf_attachment *attach, struct sg_table *sg);
-
-#endif
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks
2026-03-11 9:49 ` [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks Chen-Yu Tsai
@ 2026-03-11 14:40 ` AngeloGioacchino Del Regno
2026-03-22 13:57 ` Chun-Kuang Hu
1 sibling, 0 replies; 11+ messages in thread
From: AngeloGioacchino Del Regno @ 2026-03-11 14:40 UTC (permalink / raw)
To: Chen-Yu Tsai, Matthias Brugger, Chun-Kuang Hu, Philipp Zabel,
Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, Chen-Yu Tsai,
Jernej Skrabec, Samuel Holland, David Airlie, Simona Vetter
Cc: linux-sunxi, Paul Kocialkowski, linux-mediatek, dri-devel,
linux-arm-kernel, linux-kernel
Il 11/03/26 10:49, Chen-Yu Tsai ha scritto:
> In commit 9b54a32c7c6a ("drm/mediatek: mtk_gem: Partial refactor and
> use drm_gem_dma_object") the MediaTek DRM driver was refactored to use
> drm_gem_dma_object, but custom callbacks were still needed to deal with
> using the first device of the pipeline as the DMA device, instead of
> the MMSYS device that the DRM driver binds to.
>
> Turns out there is already partial support for dedicated DMA devices in
> the DRM subsystem for PRIME imports. The preceding patches add support
> for dedicated DMA devices to the GEM DMA helpers.
>
> This allows us to just set the dedicated DMA device for the DRM device,
> and drop all the custom GEM callbacks. Also drop the .dma_dev field
> from the driver private data as it is no longer needed.
>
> There are slight differences in the mmap helper: the VM_DONTDUMP and
> VM_IO flags are no longer set. Both were lifted from drm_gem_mmap_obj().
> VM_IO probably doesn't make sense since the buffer is allocated using
> dma_alloc_attrs().
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Aaaaah you're removing all my code! :-P
...but it's so pleasant to see that. Brilliant cleanup. Kudos!
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks
2026-03-11 9:49 ` [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks Chen-Yu Tsai
2026-03-11 14:40 ` AngeloGioacchino Del Regno
@ 2026-03-22 13:57 ` Chun-Kuang Hu
1 sibling, 0 replies; 11+ messages in thread
From: Chun-Kuang Hu @ 2026-03-22 13:57 UTC (permalink / raw)
To: Chen-Yu Tsai
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter, linux-sunxi, Paul Kocialkowski,
linux-mediatek, dri-devel, linux-arm-kernel, linux-kernel
Chen-Yu Tsai <wenst@chromium.org> 於 2026年3月11日週三 上午9:50寫道:
>
> In commit 9b54a32c7c6a ("drm/mediatek: mtk_gem: Partial refactor and
> use drm_gem_dma_object") the MediaTek DRM driver was refactored to use
> drm_gem_dma_object, but custom callbacks were still needed to deal with
> using the first device of the pipeline as the DMA device, instead of
> the MMSYS device that the DRM driver binds to.
>
> Turns out there is already partial support for dedicated DMA devices in
> the DRM subsystem for PRIME imports. The preceding patches add support
> for dedicated DMA devices to the GEM DMA helpers.
>
> This allows us to just set the dedicated DMA device for the DRM device,
> and drop all the custom GEM callbacks. Also drop the .dma_dev field
> from the driver private data as it is no longer needed.
>
> There are slight differences in the mmap helper: the VM_DONTDUMP and
> VM_IO flags are no longer set. Both were lifted from drm_gem_mmap_obj().
> VM_IO probably doesn't make sense since the buffer is allocated using
> dma_alloc_attrs().
Acked-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
>
> Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
> ---
> Changes since v1:
> - Also remove reference to mtk_gem.c from the Makefile
> ---
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 4/4] drm/sun4i: Use backend/mixer as dedicated DMA device
2026-03-11 9:49 [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
` (2 preceding siblings ...)
2026-03-11 9:49 ` [PATCH v2 3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks Chen-Yu Tsai
@ 2026-03-11 9:49 ` Chen-Yu Tsai
2026-03-12 15:43 ` Jernej Škrabec
2026-03-26 6:58 ` [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
4 siblings, 1 reply; 11+ messages in thread
From: Chen-Yu Tsai @ 2026-03-11 9:49 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter
Cc: Chen-Yu Tsai, linux-sunxi, Paul Kocialkowski, linux-mediatek,
dri-devel, linux-arm-kernel, linux-kernel
The sun4i DRM driver deals with DMA constraints in a peculiar way.
Instead of using the actual DMA device in various helpers, it justs
reconfigures the DMA constraints of the virtual display device using
the DMA device's device tree node by calling of_dma_configure().
Turns out of_dma_configure() should only be called from bus code.
Lately this also triggers a big warning through of_iommu_configure()
and ultimately __iommu_probe_device():
late IOMMU probe at driver bind, something fishy here!
Now that the GEM DMA helpers have proper support for allocating
and mapping buffers with a dedicated DMA device, switch over to
it as the proper solution.
The mixer change was tested on a Pine H64 model B. The backend change
was only compile tested. Though I don't expect any issues, help testing
on an older device would be appreciated.
Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
---
drivers/gpu/drm/sun4i/sun4i_backend.c | 27 +++++++++++++++------------
drivers/gpu/drm/sun4i/sun8i_mixer.c | 27 +++++++++++++++------------
2 files changed, 30 insertions(+), 24 deletions(-)
diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c
index 6391bdc94a5c..a57fb5151def 100644
--- a/drivers/gpu/drm/sun4i/sun4i_backend.c
+++ b/drivers/gpu/drm/sun4i/sun4i_backend.c
@@ -798,18 +798,21 @@ static int sun4i_backend_bind(struct device *dev, struct device *master,
dev_set_drvdata(dev, backend);
spin_lock_init(&backend->frontend_lock);
- if (of_property_present(dev->of_node, "interconnects")) {
- /*
- * This assume we have the same DMA constraints for all our the
- * devices in our pipeline (all the backends, but also the
- * frontends). This sounds bad, but it has always been the case
- * for us, and DRM doesn't do per-device allocation either, so
- * we would need to fix DRM first...
- */
- ret = of_dma_configure(drm->dev, dev->of_node, true);
- if (ret)
- return ret;
- }
+ /*
+ * This assume we have the same DMA constraints for all our the
+ * devices in our pipeline (all the backends, but also the
+ * frontends). This sounds bad, but it has always been the case
+ * for us, and DRM doesn't do per-device allocation either, so
+ * we would need to fix DRM first...
+ *
+ * Always use the first bound backend as the DMA device. While
+ * our device trees always have all backends enabled, some in
+ * the wild may actually have the first one disabled. If both
+ * are enabled, the order in which they are bound is guaranteed
+ * since the driver adds components in order.
+ */
+ if (drm_dev_dma_dev(drm) == drm->dev)
+ drm_dev_set_dma_dev(drm, dev);
backend->engine.node = dev->of_node;
backend->engine.ops = &sun4i_backend_engine_ops;
diff --git a/drivers/gpu/drm/sun4i/sun8i_mixer.c b/drivers/gpu/drm/sun4i/sun8i_mixer.c
index 02acc7cbdb97..4071ab38b4ae 100644
--- a/drivers/gpu/drm/sun4i/sun8i_mixer.c
+++ b/drivers/gpu/drm/sun4i/sun8i_mixer.c
@@ -536,18 +536,21 @@ static int sun8i_mixer_bind(struct device *dev, struct device *master,
mixer->engine.ops = &sun8i_engine_ops;
mixer->engine.node = dev->of_node;
- if (of_property_present(dev->of_node, "iommus")) {
- /*
- * This assume we have the same DMA constraints for
- * all our the mixers in our pipeline. This sounds
- * bad, but it has always been the case for us, and
- * DRM doesn't do per-device allocation either, so we
- * would need to fix DRM first...
- */
- ret = of_dma_configure(drm->dev, dev->of_node, true);
- if (ret)
- return ret;
- }
+ /*
+ * This assume we have the same DMA constraints for all our the
+ * devices in our pipeline (all the backends, but also the
+ * frontends). This sounds bad, but it has always been the case
+ * for us, and DRM doesn't do per-device allocation either, so
+ * we would need to fix DRM first...
+ *
+ * Always use the first bound backend as the DMA device. While
+ * our device trees always have all backends enabled, some in
+ * the wild may actually have the first one disabled. If both
+ * are enabled, the order in which they are bound is guaranteed
+ * since the driver adds components in order.
+ */
+ if (drm_dev_dma_dev(drm) == drm->dev)
+ drm_dev_set_dma_dev(drm, dev);
/*
* While this function can fail, we shouldn't do anything
--
2.53.0.473.g4a7958ca14-goog
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH v2 4/4] drm/sun4i: Use backend/mixer as dedicated DMA device
2026-03-11 9:49 ` [PATCH v2 4/4] drm/sun4i: Use backend/mixer as dedicated DMA device Chen-Yu Tsai
@ 2026-03-12 15:43 ` Jernej Škrabec
0 siblings, 0 replies; 11+ messages in thread
From: Jernej Škrabec @ 2026-03-12 15:43 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter, Chen-Yu Tsai
Cc: Chen-Yu Tsai, linux-sunxi, Paul Kocialkowski, linux-mediatek,
dri-devel, linux-arm-kernel, linux-kernel
Dne sreda, 11. marec 2026 ob 10:49:28 Srednjeevropski standardni čas je Chen-Yu Tsai napisal(a):
> The sun4i DRM driver deals with DMA constraints in a peculiar way.
> Instead of using the actual DMA device in various helpers, it justs
> reconfigures the DMA constraints of the virtual display device using
> the DMA device's device tree node by calling of_dma_configure().
>
> Turns out of_dma_configure() should only be called from bus code.
> Lately this also triggers a big warning through of_iommu_configure()
> and ultimately __iommu_probe_device():
>
> late IOMMU probe at driver bind, something fishy here!
>
> Now that the GEM DMA helpers have proper support for allocating
> and mapping buffers with a dedicated DMA device, switch over to
> it as the proper solution.
>
> The mixer change was tested on a Pine H64 model B. The backend change
> was only compile tested. Though I don't expect any issues, help testing
> on an older device would be appreciated.
>
> Signed-off-by: Chen-Yu Tsai <wenst@chromium.org>
Thanks for fixing this!
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Best regards,
Jernej
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation
2026-03-11 9:49 [PATCH v2 0/4] drm/gem-dma: Support dedicated DMA device for allocation Chen-Yu Tsai
` (3 preceding siblings ...)
2026-03-11 9:49 ` [PATCH v2 4/4] drm/sun4i: Use backend/mixer as dedicated DMA device Chen-Yu Tsai
@ 2026-03-26 6:58 ` Chen-Yu Tsai
4 siblings, 0 replies; 11+ messages in thread
From: Chen-Yu Tsai @ 2026-03-26 6:58 UTC (permalink / raw)
To: Matthias Brugger, AngeloGioacchino Del Regno, Chun-Kuang Hu,
Philipp Zabel, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, Chen-Yu Tsai, Jernej Skrabec, Samuel Holland,
David Airlie, Simona Vetter, Chen-Yu Tsai
Cc: linux-sunxi, Paul Kocialkowski, linux-mediatek, dri-devel,
linux-arm-kernel, linux-kernel
On Wed, 11 Mar 2026 17:49:24 +0800, Chen-Yu Tsai wrote:
> This is v2 of my "support dedicated DMA device for allocation and mmap
> in GEM DMA helpers" series.
>
> Changes since v1:
> - Link to v1: https://lore.kernel.org/all/20260310032511.2545500-1-wenst@chromium.org/
> - Collected tags
> - Removed reference to mtk_gem.c from the Makefile
>
> [...]
Applied to drm-misc-next in drm-misc, thanks!
[1/4] drm/prime: Limit scatter list size with dedicated DMA device
commit: 864279920b2b2c1dd491eba0d0c64764c0c03d9f
[2/4] drm/gem-dma: Support dedicated DMA device for allocation and mapping
commit: a9da24732aaa80d631bffc8a1390836d4b896690
[3/4] drm/mediatek: Set dedicated DMA device and drop custom GEM callbacks
commit: e21b1a91430d5ff626a35f72951ed80268e26de6
[4/4] drm/sun4i: Use backend/mixer as dedicated DMA device
commit: 25e90f486f5bc8f606f4263c9d86e2d2b1db4613
Best regards,
--
Chen-Yu Tsai <wenst@chromium.org>
^ permalink raw reply [flat|nested] 11+ messages in thread