[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20181129140315.28476-1-vivek.gautam@codeaurora.org>
Date: Thu, 29 Nov 2018 19:33:15 +0530
From: Vivek Gautam <vivek.gautam@...eaurora.org>
To: airlied@...ux.ie, robdclark@...il.com
Cc: dri-devel@...ts.freedesktop.org, linux-kernel@...r.kernel.org,
freedreno@...ts.freedesktop.org, tfiga@...omium.org,
architt@...eaurora.org, linux-arm-msm@...r.kernel.org,
Vivek Gautam <vivek.gautam@...eaurora.org>,
Christoph Hellwig <hch@....de>,
Robin Murphy <robin.murphy@....com>,
Jordan Crouse <jcrouse@...eaurora.org>,
Sean Paul <seanpaul@...omium.org>
Subject: [PATCH v3 1/1] drm: msm: Replace dma_map_sg with dma_sync_sg*
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@...eaurora.org>
Suggested-by: Tomasz Figa <tfiga@...omium.org>
Cc: Rob Clark <robdclark@...il.com>
Cc: Christoph Hellwig <hch@....de>
Cc: Robin Murphy <robin.murphy@....com>
Cc: Jordan Crouse <jcrouse@...eaurora.org>
Cc: Sean Paul <seanpaul@...omium.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
Powered by blists - more mailing lists