From: Rob Clark <robin.clark@oss.qualcomm.com>
To: dri-devel@lists.freedesktop.org
Cc: linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org,
"Jianfeng Liu" <liujianfeng1994@gmail.com>,
"Christian König" <christian.koenig@amd.com>,
"Dmitry Baryshkov" <lumag@kernel.org>,
"Rob Clark" <robin.clark@oss.qualcomm.com>,
"Abhinav Kumar" <abhinav.kumar@linux.dev>,
"Jessica Zhang" <jesszhan0024@gmail.com>,
"Sean Paul" <sean@poorly.run>,
"Marijn Suijten" <marijn.suijten@somainline.org>,
"David Airlie" <airlied@gmail.com>,
"Simona Vetter" <simona@ffwll.ch>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH v3 2/6] drm/msm/gem: dma_map/unmap_sgtable()
Date: Tue, 27 Oct 2026 16:04:45 -0700 [thread overview]
Message-ID: <20261027230452.130031-3-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20261027230452.130031-1-robin.clark@oss.qualcomm.com>
This should functionally be a no-op for us, since we are managing our
SMMU directly (dma_map_ops is NULL), but it populates the dma_len/
dma_address's so that we can use them for setting up pgtable mappings.
This inlines sync_for_device() and sync_for_cpu() into their only
callers to avoid doubling up on the dma-mapping calls.
Tested-by: Jianfeng Liu <liujianfeng1994@gmail.com> # x1e78100 (Acer SFA14-11), v7.3-rc5 + this series, CONFIG_DMABUF_DEBUG=y
Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
---
drivers/gpu/drm/msm/msm_gem.c | 62 ++++++++++++++---------------------
1 file changed, 25 insertions(+), 37 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 181b9ad32672..c97395e4ea2b 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -116,34 +116,6 @@ void msm_gem_vma_put(struct drm_gem_object *obj)
#endif
}
-/*
- * Cache sync.. this is a bit over-complicated, to fit dma-mapping
- * API. Really GPU cache is out of scope here (handled on cmdstream)
- * and all we need to do is invalidate newly allocated pages before
- * mapping to CPU as uncached/writecombine.
- *
- * On top of this, we have the added headache, that depending on
- * display generation, the display's iommu may be wired up to either
- * the toplevel drm device (mdss), or to the mdp sub-node, meaning
- * that here we either have dma-direct or iommu ops.
- *
- * Let this be a cautionary tail of abstraction gone wrong.
- */
-
-static void sync_for_device(struct msm_gem_object *msm_obj)
-{
- struct device *dev = msm_obj->base.dev->dev;
-
- dma_map_sgtable(dev, msm_obj->sgt, DMA_BIDIRECTIONAL, 0);
-}
-
-static void sync_for_cpu(struct msm_gem_object *msm_obj)
-{
- struct device *dev = msm_obj->base.dev->dev;
-
- dma_unmap_sgtable(dev, msm_obj->sgt, DMA_BIDIRECTIONAL, 0);
-}
-
static void update_lru_active(struct drm_gem_object *obj)
{
struct msm_drm_private *priv = obj->dev->dev_private;
@@ -201,6 +173,7 @@ static struct page **get_pages(struct drm_gem_object *obj)
struct drm_device *dev = obj->dev;
struct page **p;
size_t npages = obj->size >> PAGE_SHIFT;
+ unsigned map_attrs = DMA_ATTR_SKIP_CPU_SYNC;
p = drm_gem_get_pages(obj);
@@ -219,13 +192,20 @@ static struct page **get_pages(struct drm_gem_object *obj)
goto error;
}
- update_device_mem(dev->dev_private, obj->size);
-
- /* For non-cached buffers, ensure the new pages are clean
- * because display controller, GPU, etc. are not coherent:
- */
+ /* For non-cached buffers, ensure the new pages are clean. */
if (msm_obj->flags & MSM_BO_WC)
- sync_for_device(msm_obj);
+ map_attrs = 0;
+
+ ret = dma_map_sgtable(drm_dev_dma_dev(obj->dev),
+ msm_obj->sgt,
+ DMA_BIDIRECTIONAL,
+ map_attrs);
+ if (ret) {
+ DRM_DEV_ERROR(dev->dev, "could not map sgtable: %d\n", ret);
+ goto error;
+ }
+
+ update_device_mem(dev->dev_private, obj->size);
update_lru(obj);
}
@@ -233,6 +213,8 @@ static struct page **get_pages(struct drm_gem_object *obj)
return msm_obj->pages;
error:
+ if (!IS_ERR(msm_obj->sgt))
+ drm_prime_gem_destroy(obj, msm_obj->sgt);
msm_obj->sgt = NULL;
drm_gem_put_pages(obj, msm_obj->pages, false, false);
@@ -253,12 +235,18 @@ static void put_pages(struct drm_gem_object *obj)
drm_gpuvm_bo_gem_evict(obj, true);
if (msm_obj->pages) {
+ unsigned unmap_attrs = DMA_ATTR_SKIP_CPU_SYNC;
+
/* For non-cached buffers, ensure the new
- * pages are clean because display controller,
- * GPU, etc. are not coherent:
+ * pages are clean:
*/
if (msm_obj->flags & MSM_BO_WC)
- sync_for_cpu(msm_obj);
+ unmap_attrs = 0;
+
+ dma_unmap_sgtable(drm_dev_dma_dev(obj->dev),
+ msm_obj->sgt,
+ DMA_BIDIRECTIONAL,
+ unmap_attrs);
sg_free_table(msm_obj->sgt);
kfree(msm_obj->sgt);
--
2.56.0
next prev parent reply other threads:[~2026-10-27 23:05 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 23:04 [PATCH v3 0/6] drm/msm: DMABUF_DEBUG fixes Rob Clark
2026-10-27 23:04 ` [PATCH v3 1/6] drm/msm: Cleanup if pages_to_sg() fails Rob Clark
2026-10-27 23:04 ` Rob Clark [this message]
2026-10-27 23:04 ` [PATCH v3 3/6] drm/msm: Extract out map/unmap helpers Rob Clark
2026-10-27 23:04 ` [PATCH v3 4/6] drm/msm: Convert iommu map/unmap to helpers Rob Clark
2026-10-27 23:04 ` [PATCH v3 5/6] drm/msm: Convert map helper to use dma-address Rob Clark
2026-10-28 1:14 ` Dmitry Baryshkov
2026-10-28 1:34 ` Rob Clark
2026-10-27 23:04 ` [PATCH v3 6/6] drm/msm: Treat !mapped as an error Rob Clark
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261027230452.130031-3-robin.clark@oss.qualcomm.com \
--to=robin.clark@oss.qualcomm.com \
--cc=abhinav.kumar@linux.dev \
--cc=airlied@gmail.com \
--cc=christian.koenig@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=jesszhan0024@gmail.com \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liujianfeng1994@gmail.com \
--cc=lumag@kernel.org \
--cc=marijn.suijten@somainline.org \
--cc=sean@poorly.run \
--cc=simona@ffwll.ch \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®