From: Vivek Gautam <vivek.gautam@codeaurora.org>
To: airlied@linux.ie, robdclark@gmail.com
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
freedreno@lists.freedesktop.org, tfiga@chromium.org,
architt@codeaurora.org, linux-arm-msm@vger.kernel.org,
Vivek Gautam <vivek.gautam@codeaurora.org>,
Christoph Hellwig <hch@lst.de>,
Robin Murphy <robin.murphy@arm.com>,
Jordan Crouse <jcrouse@codeaurora.org>,
Sean Paul <seanpaul@chromium.org>
Subject: [PATCH v3 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg*
Date: Thu, 29 Nov 2018 19:33:15 +0530 [thread overview]
Message-ID: <20181129140315.28476-1-vivek.gautam@codeaurora.org> (raw)
dma_map_sg() expects a DMA domain. However, the drm devices
have been traditionally using unmanaged iommu domain which
is non-dma type. Using dma mapping APIs with that domain is bad.
Replace dma_map_sg() calls with dma_sync_sg_for_device{|cpu}()
to do the cache maintenance.
Signed-off-by: Vivek Gautam <vivek.gautam@codeaurora.org>
Suggested-by: Tomasz Figa <tfiga@chromium.org>
Cc: Rob Clark <robdclark@gmail.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Robin Murphy <robin.murphy@arm.com>
Cc: Jordan Crouse <jcrouse@codeaurora.org>
Cc: Sean Paul <seanpaul@chromium.org>
---
Changes since v2:
- Addressed Tomasz's comment to keep DMA_BIDIRECTIONAL dma direction
flag intact.
- Updated comment for sg's dma-address assignment as per Tomasz'
suggestion.
drivers/gpu/drm/msm/msm_gem.c | 33 ++++++++++++++++++++++++---------
1 file changed, 24 insertions(+), 9 deletions(-)
diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c
index 00c795ced02c..7048e9fe00c6 100644
--- a/drivers/gpu/drm/msm/msm_gem.c
+++ b/drivers/gpu/drm/msm/msm_gem.c
@@ -81,6 +81,8 @@ static struct page **get_pages(struct drm_gem_object *obj)
struct drm_device *dev = obj->dev;
struct page **p;
int npages = obj->size >> PAGE_SHIFT;
+ struct scatterlist *s;
+ int i;
if (use_pages(obj))
p = drm_gem_get_pages(obj);
@@ -104,12 +106,23 @@ static struct page **get_pages(struct drm_gem_object *obj)
return ptr;
}
- /* For non-cached buffers, ensure the new pages are clean
+ /*
+ * Some implementations of the DMA mapping ops expect
+ * physical addresses of the pages to be stored as DMA
+ * addresses of the sglist entries. To work around it,
+ * set them here explicitly.
+ */
+ for_each_sg(msm_obj->sgt->sgl, s, msm_obj->sgt->nents, i)
+ sg_dma_address(s) = sg_phys(s);
+
+ /*
+ * For non-cached buffers, ensure the new pages are clean
* because display controller, GPU, etc. are not coherent:
*/
- if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
- dma_map_sg(dev->dev, msm_obj->sgt->sgl,
- msm_obj->sgt->nents, DMA_BIDIRECTIONAL);
+ if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED))
+ dma_sync_sg_for_device(dev->dev, msm_obj->sgt->sgl,
+ msm_obj->sgt->nents,
+ DMA_BIDIRECTIONAL);
}
return msm_obj->pages;
@@ -133,14 +146,16 @@ static void put_pages(struct drm_gem_object *obj)
if (msm_obj->pages) {
if (msm_obj->sgt) {
- /* For non-cached buffers, ensure the new
+ /*
+ * For non-cached buffers, ensure the new
* pages are clean because display controller,
* GPU, etc. are not coherent:
*/
- if (msm_obj->flags & (MSM_BO_WC|MSM_BO_UNCACHED))
- dma_unmap_sg(obj->dev->dev, msm_obj->sgt->sgl,
- msm_obj->sgt->nents,
- DMA_BIDIRECTIONAL);
+ if (msm_obj->flags & (MSM_BO_WC | MSM_BO_UNCACHED))
+ dma_sync_sg_for_cpu(obj->dev->dev,
+ msm_obj->sgt->sgl,
+ msm_obj->sgt->nents,
+ DMA_BIDIRECTIONAL);
sg_free_table(msm_obj->sgt);
kfree(msm_obj->sgt);
--
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member
of Code Aurora Forum, hosted by The Linux Foundation
next reply other threads:[~2018-11-29 14:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-29 14:03 Vivek Gautam [this message]
2018-11-29 14:14 ` [PATCH v3 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg* Christoph Hellwig
2018-11-29 14:25 ` Rob Clark
2018-11-29 14:42 ` Rob Clark
2018-11-29 15:54 ` Christoph Hellwig
2018-11-29 18:48 ` Rob Clark
2018-11-29 19:40 ` Jordan Crouse
2018-11-29 19:57 ` Tomasz Figa
2018-11-29 20:03 ` Robin Murphy
2018-11-30 0:23 ` Tomasz Figa
2018-12-01 2:05 ` Tomasz Figa
2018-12-01 11:46 ` Rob Clark
2018-12-03 0:12 ` Tomasz Figa
2018-11-29 14:43 ` Daniel Vetter
2018-11-29 15:57 ` Christoph Hellwig
2018-11-29 16:28 ` Daniel Vetter
2018-11-29 16:57 ` Christoph Hellwig
2018-11-29 17:09 ` Daniel Vetter
2018-11-29 17:24 ` Tomasz Figa
2018-11-29 18:35 ` Christoph Hellwig
2018-11-29 18:57 ` Rob Clark
2018-11-30 9:40 ` Daniel Vetter
2018-11-30 9:35 ` Daniel Vetter
2018-11-30 9:44 ` Christoph Hellwig
2018-11-29 18:33 ` Christoph Hellwig
2018-11-30 9:46 ` Daniel Vetter
2018-12-07 1:38 ` Christoph Hellwig
2018-12-07 14:29 ` Rob Clark
2018-11-29 17:33 ` Brian Starkey
2018-11-29 18:35 ` Christoph Hellwig
2018-11-30 1:15 ` Rob Clark
2018-11-30 9:35 ` Christoph Hellwig
2018-11-29 15:53 ` Christoph Hellwig
2018-11-29 18:44 ` 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=20181129140315.28476-1-vivek.gautam@codeaurora.org \
--to=vivek.gautam@codeaurora.org \
--cc=airlied@linux.ie \
--cc=architt@codeaurora.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=freedreno@lists.freedesktop.org \
--cc=hch@lst.de \
--cc=jcrouse@codeaurora.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robdclark@gmail.com \
--cc=robin.murphy@arm.com \
--cc=seanpaul@chromium.org \
--cc=tfiga@chromium.org \
/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;
as well as URLs for NNTP newsgroup(s).