linux-next.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Cercueil <paul@crapouillou.net>
To: Christoph Hellwig <hch@lst.de>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
	Dave Airlie <airlied@linux.ie>,
	DRI <dri-devel@lists.freedesktop.org>,
	Linux Next Mailing List <linux-next@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Paul Cercueil <paul@crapouillou.net>
Subject: [PATCH 2/3] drm/ingenic: Update code to mmap GEM buffers cached
Date: Wed, 30 Sep 2020 19:16:43 +0200	[thread overview]
Message-ID: <20200930171644.299363-2-paul@crapouillou.net> (raw)
In-Reply-To: <20200930165212.GA8833@lst.de>

The DMA API changed at the same time commit 37054fc81443 ("gpu/drm:
ingenic: Add option to mmap GEM buffers cached") was added. Rework the
code to work with the new DMA API.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
---
 drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 24 +++++++----------------
 1 file changed, 7 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
index 0225dc1f5eb8..07a1da7266e4 100644
--- a/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
+++ b/drivers/gpu/drm/ingenic/ingenic-drm-drv.c
@@ -526,12 +526,10 @@ void ingenic_drm_sync_data(struct device *dev,
 			   struct drm_plane_state *state)
 {
 	const struct drm_format_info *finfo = state->fb->format;
-	struct ingenic_drm *priv = dev_get_drvdata(dev);
 	struct drm_atomic_helper_damage_iter iter;
 	unsigned int offset, i;
 	struct drm_rect clip;
 	dma_addr_t paddr;
-	void *addr;
 
 	if (!ingenic_drm_cached_gem_buf)
 		return;
@@ -541,12 +539,11 @@ void ingenic_drm_sync_data(struct device *dev,
 	drm_atomic_for_each_plane_damage(&iter, &clip) {
 		for (i = 0; i < finfo->num_planes; i++) {
 			paddr = drm_fb_cma_get_gem_addr(state->fb, state, i);
-			addr = phys_to_virt(paddr);
 
 			/* Ignore x1/x2 values, invalidate complete lines */
 			offset = clip.y1 * state->fb->pitches[i];
 
-			dma_cache_sync(priv->dev, addr + offset,
+			dma_sync_single_for_device(dev, paddr + offset,
 				       (clip.y2 - clip.y1) * state->fb->pitches[i],
 				       DMA_TO_DEVICE);
 		}
@@ -766,14 +763,6 @@ static int ingenic_drm_gem_mmap(struct drm_gem_object *obj,
 				struct vm_area_struct *vma)
 {
 	struct drm_gem_cma_object *cma_obj = to_drm_gem_cma_obj(obj);
-	struct device *dev = cma_obj->base.dev->dev;
-	unsigned long attrs;
-	int ret;
-
-	if (ingenic_drm_cached_gem_buf)
-		attrs = DMA_ATTR_NON_CONSISTENT;
-	else
-		attrs = DMA_ATTR_WRITE_COMBINE;
 
 	/*
 	 * Clear the VM_PFNMAP flag that was set by drm_gem_mmap(), and set the
@@ -784,12 +773,13 @@ static int ingenic_drm_gem_mmap(struct drm_gem_object *obj,
 	vma->vm_pgoff = 0;
 	vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
 
-	ret = dma_mmap_attrs(dev, vma, cma_obj->vaddr, cma_obj->paddr,
-			     vma->vm_end - vma->vm_start, attrs);
-	if (ret)
-		drm_gem_vm_close(vma);
+	if (!ingenic_drm_cached_gem_buf)
+		vma->vm_page_prot = pgprot_writecombine(vma->vm_page_prot);
 
-	return ret;
+	return remap_pfn_range(vma, vma->vm_start,
+			       cma_obj->paddr >> PAGE_SHIFT,
+			       vma->vm_end - vma->vm_start,
+			       vma->vm_page_prot);
 }
 
 static int ingenic_drm_gem_cma_mmap(struct file *filp,
-- 
2.28.0


  parent reply	other threads:[~2020-09-30 17:17 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-28  3:54 linux-next: build failure after merge of the drm tree Stephen Rothwell
2020-09-28  6:04 ` Christoph Hellwig
2020-09-28  6:08   ` Dave Airlie
2020-09-28  6:14     ` Christoph Hellwig
2020-09-28 10:15   ` Paul Cercueil
2020-09-28 11:34     ` Christoph Hellwig
2020-09-28 11:46       ` Paul Cercueil
2020-09-28 12:10         ` Christoph Hellwig
2020-09-28 13:31           ` Paul Cercueil
2020-09-30  9:02             ` Christoph Hellwig
2020-09-30 13:33               ` Paul Cercueil
2020-09-30 16:11                 ` Christoph Hellwig
2020-09-30 16:39                   ` Paul Cercueil
2020-09-30 16:40                     ` Christoph Hellwig
2020-09-30 16:45                       ` Paul Cercueil
2020-09-30 16:52                         ` Christoph Hellwig
2020-09-30 17:16                           ` [PATCH 1/3] drm: Add and export function drm_gem_cma_create_noalloc Paul Cercueil
2020-10-01  8:51                             ` Daniel Vetter
2020-09-30 17:16                           ` Paul Cercueil [this message]
2020-10-01  5:32                             ` [PATCH 2/3] drm/ingenic: Update code to mmap GEM buffers cached Christoph Hellwig
2020-09-30 17:16                           ` [PATCH 3/3] drm/ingenic: Alloc cached GEM buffers with dma_alloc_noncoherent Paul Cercueil
2020-10-01  5:35                             ` Christoph Hellwig
2020-10-04 14:17                           ` [PATCH] Revert "gpu/drm: ingenic: Add option to mmap GEM buffers cached" Paul Cercueil
2020-10-04 19:59                             ` Sam Ravnborg
2020-10-04 20:11                               ` Paul Cercueil
2020-10-05 12:01                                 ` Stephen Rothwell
2020-10-05 14:05                                   ` Daniel Vetter
2020-10-05 14:47                                     ` Paul Cercueil
2020-10-05 17:38                                       ` Daniel Vetter
2020-10-05 22:31                                       ` Daniel Vetter
2020-10-06  4:30                                   ` Stephen Rothwell

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=20200930171644.299363-2-paul@crapouillou.net \
    --to=paul@crapouillou.net \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hch@lst.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    /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).