All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Zimmermann <tzimmermann@suse.de>
To: daniel@ffwll.ch, airlied@linux.ie, kraxel@redhat.com,
	christian.koenig@amd.com, ray.huang@amd.com, Jerry.Zhang@amd.com,
	hdegoede@redhat.com, z.liuxinliang@hisilicon.com,
	zourongrong@gmail.com, kong.kongxinwei@hisilicon.com,
	puck.chen@hisilicon.com
Cc: Thomas Zimmermann <tzimmermann@suse.de>,
	dri-devel@lists.freedesktop.org,
	virtualization@lists.linux-foundation.org
Subject: [PATCH v3 10/19] drm/ast: Replace mapping code with drm_gem_vram_{kmap/kunmap}()
Date: Mon, 29 Apr 2019 16:43:32 +0200	[thread overview]
Message-ID: <20190429144341.12615-11-tzimmermann@suse.de> (raw)
In-Reply-To: <20190429144341.12615-1-tzimmermann@suse.de>

The AST driver establishes several memory mappings for frame buffers
and cursors. This patch converts the driver to use the equivalent
drm_gem_vram_kmap() functions. It removes the dependencies on TTM
and cleans up the code.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
---
 drivers/gpu/drm/ast/ast_drv.h  |  1 -
 drivers/gpu/drm/ast/ast_fb.c   | 22 +++++++++-----
 drivers/gpu/drm/ast/ast_mode.c | 54 ++++++++++++++++++++++++----------
 3 files changed, 53 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/ast/ast_drv.h b/drivers/gpu/drm/ast/ast_drv.h
index 32096a191aaf..b6cac9511796 100644
--- a/drivers/gpu/drm/ast/ast_drv.h
+++ b/drivers/gpu/drm/ast/ast_drv.h
@@ -256,7 +256,6 @@ struct ast_fbdev {
 	struct ast_framebuffer afb;
 	void *sysram;
 	int size;
-	struct ttm_bo_kmap_obj mapping;
 	int x1, y1, x2, y2; /* dirty rect */
 	spinlock_t dirty_lock;
 };
diff --git a/drivers/gpu/drm/ast/ast_fb.c b/drivers/gpu/drm/ast/ast_fb.c
index 4fd80e31ad55..af0b56cfeab3 100644
--- a/drivers/gpu/drm/ast/ast_fb.c
+++ b/drivers/gpu/drm/ast/ast_fb.c
@@ -53,6 +53,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
 	int src_offset, dst_offset;
 	int bpp = afbdev->afb.base.format->cpp[0];
 	int ret = -EBUSY;
+	u8 *dst;
 	bool unmap = false;
 	bool store_for_later = false;
 	int x2, y2;
@@ -101,24 +102,29 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,
 	afbdev->x2 = afbdev->y2 = 0;
 	spin_unlock_irqrestore(&afbdev->dirty_lock, flags);
 
-	if (!gbo->kmap.virtual) {
-		ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
-		if (ret) {
+	dst = drm_gem_vram_kmap(gbo, false, NULL);
+	if (IS_ERR(dst)) {
+		DRM_ERROR("failed to kmap fb updates\n");
+		goto out;
+	} else if (!dst) {
+		dst = drm_gem_vram_kmap(gbo, true, NULL);
+		if (IS_ERR(dst)) {
 			DRM_ERROR("failed to kmap fb updates\n");
-			drm_gem_vram_unreserve(gbo);
-			return;
+			goto out;
 		}
 		unmap = true;
 	}
+
 	for (i = y; i <= y2; i++) {
 		/* assume equal stride for now */
 		src_offset = dst_offset = i * afbdev->afb.base.pitches[0] + (x * bpp);
-		memcpy_toio(gbo->kmap.virtual + src_offset, afbdev->sysram + src_offset, (x2 - x + 1) * bpp);
-
+		memcpy_toio(dst + dst_offset, afbdev->sysram + src_offset, (x2 - x + 1) * bpp);
 	}
+
 	if (unmap)
-		ttm_bo_kunmap(&gbo->kmap);
+		drm_gem_vram_kunmap(gbo);
 
+out:
 	drm_gem_vram_unreserve(gbo);
 }
 
diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index b75ed3816642..3475591a22c3 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -532,6 +532,7 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
 	struct drm_gem_vram_object *gbo;
 	int ret;
 	s64 gpu_addr;
+	void *base;
 
 	/* push the previous fb to system ram */
 	if (!atomic && fb) {
@@ -564,11 +565,13 @@ static int ast_crtc_do_set_base(struct drm_crtc *crtc,
 
 	if (&ast->fbdev->afb == ast_fb) {
 		/* if pushing console in kmap it */
-		ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &gbo->kmap);
-		if (ret)
+		base = drm_gem_vram_kmap(gbo, true, NULL);
+		if (IS_ERR(base)) {
+			ret = PTR_ERR(base);
 			DRM_ERROR("failed to kmap fbcon\n");
-		else
+		} else {
 			ast_fbdev_set_base(ast, gpu_addr);
+		}
 	}
 	drm_gem_vram_unreserve(gbo);
 
@@ -928,6 +931,7 @@ static int ast_cursor_init(struct drm_device *dev)
 	struct drm_gem_object *obj;
 	struct drm_gem_vram_object *gbo;
 	s64 gpu_addr;
+	void *base;
 
 	size = (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE) * AST_DEFAULT_HWC_NUM;
 
@@ -951,9 +955,11 @@ static int ast_cursor_init(struct drm_device *dev)
 	}
 
 	/* kmap the object */
-	ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &ast->cache_kmap);
-	if (ret)
+	base = drm_gem_vram_kmap_at(gbo, true, NULL, &ast->cache_kmap);
+	if (IS_ERR(base)) {
+		ret = PTR_ERR(base);
 		goto fail;
+	}
 
 	ast->cursor_cache = obj;
 	ast->cursor_cache_gpu_addr = gpu_addr;
@@ -966,7 +972,9 @@ static int ast_cursor_init(struct drm_device *dev)
 static void ast_cursor_fini(struct drm_device *dev)
 {
 	struct ast_private *ast = dev->dev_private;
-	ttm_bo_kunmap(&ast->cache_kmap);
+	struct drm_gem_vram_object *gbo =
+		drm_gem_vram_of_gem(ast->cursor_cache);
+	drm_gem_vram_kunmap_at(gbo, &ast->cache_kmap);
 	drm_gem_object_put_unlocked(ast->cursor_cache);
 }
 
@@ -1213,13 +1221,21 @@ static int ast_cursor_set(struct drm_crtc *crtc,
 	if (ret)
 		goto fail;
 
-	ret = ttm_bo_kmap(&gbo->bo, 0, gbo->bo.num_pages, &uobj_map);
-
-	src = ttm_kmap_obj_virtual(&uobj_map, &src_isiomem);
-	dst = ttm_kmap_obj_virtual(&ast->cache_kmap, &dst_isiomem);
-
+	memset(&uobj_map, 0, sizeof(uobj_map));
+	src = drm_gem_vram_kmap_at(gbo, true, &src_isiomem, &uobj_map);
+	if (IS_ERR(src)) {
+		ret = PTR_ERR(src);
+		goto fail_unreserve;
+	}
 	if (src_isiomem == true)
 		DRM_ERROR("src cursor bo should be in main memory\n");
+
+	dst = drm_gem_vram_kmap_at(drm_gem_vram_of_gem(ast->cursor_cache),
+				   false, &dst_isiomem, &ast->cache_kmap);
+	if (IS_ERR(dst)) {
+		ret = PTR_ERR(dst);
+		goto fail_unreserve;
+	}
 	if (dst_isiomem == false)
 		DRM_ERROR("dst bo should be in VRAM\n");
 
@@ -1228,11 +1244,14 @@ static int ast_cursor_set(struct drm_crtc *crtc,
 	/* do data transfer to cursor cache */
 	csum = copy_cursor_image(src, dst, width, height);
 
-	/* write checksum + signature */
-	ttm_bo_kunmap(&uobj_map);
+	drm_gem_vram_kunmap_at(gbo, &uobj_map);
 	drm_gem_vram_unreserve(gbo);
+
+	/* write checksum + signature */
 	{
-		u8 *dst = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
+		u8 *dst = drm_gem_vram_kmap_at(drm_gem_vram_of_gem(ast->cursor_cache),
+					       false, NULL, &ast->cache_kmap);
+		dst += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
 		writel(csum, dst);
 		writel(width, dst + AST_HWC_SIGNATURE_SizeX);
 		writel(height, dst + AST_HWC_SIGNATURE_SizeY);
@@ -1258,6 +1277,9 @@ static int ast_cursor_set(struct drm_crtc *crtc,
 
 	drm_gem_object_put_unlocked(obj);
 	return 0;
+
+fail_unreserve:
+	drm_gem_vram_unreserve(gbo);
 fail:
 	drm_gem_object_put_unlocked(obj);
 	return ret;
@@ -1271,7 +1293,9 @@ static int ast_cursor_move(struct drm_crtc *crtc,
 	int x_offset, y_offset;
 	u8 *sig;
 
-	sig = (u8 *)ast->cache_kmap.virtual + (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
+	sig = drm_gem_vram_kmap_at(drm_gem_vram_of_gem(ast->cursor_cache),
+				   false, NULL, &ast->cache_kmap);
+	sig += (AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE)*ast->next_cursor + AST_HWC_SIZE;
 	writel(x, sig + AST_HWC_SIGNATURE_X);
 	writel(y, sig + AST_HWC_SIGNATURE_Y);
 
-- 
2.21.0

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-04-29 14:43 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-29 14:43 [PATCH v3 00/19] Share TTM code among DRM framebuffer drivers Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 01/19] drm: Add |struct drm_gem_vram_object| and helpers Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 19:58   ` Sam Ravnborg
2019-04-29 19:58   ` Sam Ravnborg
2019-04-30  7:18     ` Thomas Zimmermann
2019-04-30  9:23       ` Sam Ravnborg
2019-04-30  9:35         ` Koenig, Christian
2019-05-03 10:14           ` Thomas Zimmermann
2019-05-03 12:01             ` Daniel Vetter
2019-05-03 12:07               ` Koenig, Christian
2019-05-03 12:27                 ` Thomas Zimmermann
2019-05-03 12:27                 ` Thomas Zimmermann
2019-05-03 13:29                   ` Thomas Zimmermann
2019-04-30  9:35         ` Koenig, Christian
2019-04-30  9:23       ` Sam Ravnborg
2019-04-30  7:18     ` Thomas Zimmermann
2019-04-30 14:27     ` Daniel Vetter
2019-04-30 14:27     ` Daniel Vetter
2019-04-30 14:40     ` Daniel Vetter
2019-04-30 14:40     ` Daniel Vetter
2019-04-29 14:43 ` [PATCH v3 02/19] drm: Add |struct drm_gem_vram_object| callbacks for |struct ttm_bo_driver| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 03/19] drm: Add |struct drm_gem_vram_object| callbacks for |struct drm_driver| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 04/19] drm: Add drm_gem_vram_fill_create_dumb() to create dumb buffers Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 05/19] drm: Add VRAM MM, a simple memory manager for dedicated VRAM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 06/19] drm: Add default instance for VRAM MM callback functions Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 07/19] drm: Integrate VRAM MM into struct drm_device Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 08/19] drm/ast: Convert AST driver to |struct drm_gem_vram_object| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 09/19] drm/ast: Convert AST driver to VRAM MM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann [this message]
2019-04-29 14:43 ` [PATCH v3 10/19] drm/ast: Replace mapping code with drm_gem_vram_{kmap/kunmap}() Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 11/19] drm/bochs: Convert bochs driver to |struct drm_gem_vram_object| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 12/19] drm/bochs: Convert bochs driver to VRAM MM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 13/19] drm/mgag200: Convert mgag200 driver to |struct drm_gem_vram_object| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 14/19] drm/mgag200: Convert mgag200 driver to VRAM MM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 15/19] drm/mgag200: Replace mapping code with drm_gem_vram_{kmap/kunmap}() Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-30 14:41   ` Daniel Vetter
2019-04-30 14:41   ` Daniel Vetter
2019-04-29 14:43 ` [PATCH v3 16/19] drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_vram_object| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 17/19] drm/vboxvideo: Convert vboxvideo driver to VRAM MM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 18/19] drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_vram_object| Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann
2019-04-29 14:43 ` [PATCH v3 19/19] drm/hisilicon: Convert hibmc-drm driver to VRAM MM Thomas Zimmermann
2019-04-29 14:43 ` Thomas Zimmermann

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=20190429144341.12615-11-tzimmermann@suse.de \
    --to=tzimmermann@suse.de \
    --cc=Jerry.Zhang@amd.com \
    --cc=airlied@linux.ie \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hdegoede@redhat.com \
    --cc=kong.kongxinwei@hisilicon.com \
    --cc=kraxel@redhat.com \
    --cc=puck.chen@hisilicon.com \
    --cc=ray.huang@amd.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=z.liuxinliang@hisilicon.com \
    --cc=zourongrong@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.